<?php
	require_once dirname(__FILE__)."/../bin/web/repeater.php";
	require_once dirname(__FILE__)."/../dal/pictureDAL.php";
	require_once dirname(__FILE__)."/../dal/productDAL.php";

	class _sidePage2 extends webPartBase{
		public $picturetype;
		public $htLink4;
		public function load(){
			$this->loadData();
			parent::loadTemplateFile(dirname(__FILE__)."/../templates/webParts/".$this->registry->webTemplates."/sidePage2.html");
			parent::load();
		}

		public function loadData(){
			//相關產品
			$aryOP = array();
			$dalOP = new productDAL();
			$dataOP = $dalOP->executeRecordset($filter,"d.`AverageStar` DESC,a.`CreatedTime`",0,10);
			for($i=0;$i<count($dataOP);$i++){
				$dataOP[$i]["htLink"] = $this->htLink4;
				if(trim($dataOP[$i]["IconImage"]) == "" || !file_exists(".".$dataOP[$i]["IconImage"])){
					$dataOP[$i]["IconImage"] = "/images/no-pic.jpg";
					$dataOP[$i]["imageStyle"] = " style='display:none;'";
				}else{
					$dataOP[$i]["imageStyle"] = "";
				}
				
				$dataOP[$i]["AverageStar"] = round($dataOP[$i]["AverageStar"]);
				$dataOP[$i]["AverageStar2"] = 5 - (int)$dataOP[$i]["AverageStar"];
				$dataOP[$i]["averageStarIcon"] = "";
				for($j=0;$j<$dataOP[$i]["AverageStar"];$j++){
					$dataOP[$i]["averageStarIcon"] .= "<i class='fa fa-star light'></i>";
				}
				for($k=0;$k<$dataOP[$i]["AverageStar2"];$k++){
					$dataOP[$i]["averageStarIcon"] .= "<i class='fa fa-star'></i>";
				}
				if($dataOP[$i]["AverageStar"] > 0){
					$dataOP[$i]["Star"] = $dataOP[$i]["AverageStar"];
				}else{
					$dataOP[$i]["Star"] = "0";
				}
			}
			$listOP = new repeater();
			$listOP->id = "listOP";
			$listOP->dataSource = $dataOP;
			parent::addControl($listOP);
		}
	}
?>