array( 'name' => 'Movies', 'item_prop_name'=> 'Genre', 'item_prop_date'=> 'Released', 'bg' => 'bg_category_movies.jpg', ), 'music' => array( 'name' => 'Music', 'item_prop_name'=> 'Period/Type', 'item_prop_date'=> 'Founded', 'bg' => 'bg_category_music.jpg', ), 'games' => array( 'name' => 'Games', 'item_prop_name'=> 'Type', 'item_prop_date'=> 'Released', 'bg' => 'bg_category_games.jpg', ), 'publications' => array( 'name' => 'Publications', 'item_prop_name'=> 'Type', 'item_prop_date'=> 'Founded', 'bg' => 'bg_category_publications.jpg', ), 'people' => array( 'name' => 'People', 'item_prop_name'=> 'Group', 'item_prop_date'=> 'Birth date', 'bg' => 'bg_category_people.jpg', ), 'software' => array( 'name' => 'Software', 'item_prop_name'=> 'Type', 'item_prop_date'=> 'Released', 'bg' => 'bg_category_software.jpg', ), ); function __construct($id){ // $id e cheie din self::$sections if(self::$sections[$id]){ $this->ID=$id; $this->attr=self::$sections[$id]; } else{ throw new Exception('Not Found '.$id); } foreach (self::$sections as $index=>$section ) { self::$sections[$index]['order_id'] = $this->getSectionOrder($section['name']); } uasort(self::$sections, "sectionSort"); } protected function attrSet($field, $value){ $this->attr[$field]=$value; } protected function attrGet(){ // paramentrii sunt campuri din tabela si_products if(func_num_args()==1){ $field=func_get_arg(0); return $this->attr[$field]; } else{ $fields=func_get_args(); $ret=array(); foreach($fields as $field){ $ret[$field]=$this->attr[$field]; } return $ret; } } protected function attrChk($field){ $tmp=$this->attrGet($field); return !empty($tmp); } protected function attrIsSet($field){ return isset($this->attr[$field]); } private function getSectionOrder($sectionName) { global $_ua; $settingName = 'section_'.strtolower($sectionName).'_sort'; $score = $_ua['settings'][$settingName]; return $score ? $score : 0; } //public functions public function getID(){ return $this->ID; } public function getName(){ return $this->attrGet('name'); } public function setName($v){ return $this->attrSet('name', $v); } public function getItemsCount() { $res = mysql_query("SELECT 0 FROM tms_site_items WHERE siteItemsSection='".$this->getName()."'") or die ( mysql_error()); return mysql_num_rows($res); } public function getItemPropName(){ return $this->attrGet('item_prop_name'); } public function getItemPropRelevantDate(){ return $this->attrGet('item_prop_date'); } public function getItemsByRating($dayrating=false, $reverse_poll=false, $public_poll=false){ if(!$this->cache['getItemsByRating']){ $this->cache['getItemsByRating']=array(); } $cachestr='N'.($dayrating?'D':'').($reverse_poll?'R':'').($public_poll?'P':''); if(!$this->cache['getItemsByRating'][$cachestr]){ $this->cache['getItemsByRating'][$cachestr]=array(); //$res=query("SELECT * FROM tms_site_items WHERE siteItemsSection='{$this->ID}' AND siteItemsVisibility=1 ORDER BY siteItemsVotes".($public_poll?'Public':'').($dayrating?'Day':'Total')." ".($reverse_poll?'ASC':'DESC').", siteItemsLastVoted ".($reverse_poll?'ASC':'DESC').", siteItemsID ".($reverse_poll?'ASC':'DESC').""); $res=query("SELECT * FROM tms_site_items WHERE siteItemsSection='{$this->ID}' AND siteItemsVisibility=1 ORDER BY siteItemsVotes".($public_poll?'Public':'').($dayrating?'Day':'Total')." ".($reverse_poll?'ASC':'DESC').", siteItemsLastVoted ".($reverse_poll?'ASC':'DESC').", siteItemsID ".($reverse_poll?'DESC':'ASC').""); while($r=mysql_fetch_assoc($res)){ $this->cache['getItemsByRating'][$cachestr][]=new siteItems_Item($r); } } return $this->cache['getItemsByRating'][$cachestr]; } public static function getItemsByRatingAll($dayrating=false, $reverse_poll=false, $public_poll=false){ $return=array(); //$res=query("SELECT * FROM tms_site_items WHERE siteItemsVisibility=1 ORDER BY siteItemsVotes".($public_poll?'Public':'').($dayrating?'Day':'Total')." ".($reverse_poll?'ASC':'DESC').", siteItemsLastVoted DESC, siteItemsID DESC"); $query = "SELECT * FROM tms_site_items WHERE siteItemsVisibility=1 ORDER BY siteItemsVotes".($public_poll?'Public':'').($dayrating?'Day':'Total')." ".($reverse_poll?'ASC':'DESC').", siteItemsLastVoted ".($reverse_poll?'ASC':'DESC').", siteItemsID ".($reverse_poll?'ASC':'DESC')." "; $res=query( $query ); while($r=mysql_fetch_assoc($res)){ $return[]=new siteItems_Item($r); } return $return; } public static function getItemsByRatingSearch($search_term='', $dayrating=false, $reverse_poll=false, $public_poll=false){ $return=array(); $res=query("SELECT * FROM tms_site_items WHERE siteItemsVisibility=1 AND siteItemsName LIKE '%{$search_term}%' ORDER BY siteItemsVotes".($public_poll?'Public':'').($dayrating?'Day':'Total')." ".($reverse_poll?'ASC':'DESC').", siteItemsLastVoted ".($reverse_poll?'ASC':'DESC').", siteItemsID ".($reverse_poll?'DESC':'ASC').""); while($r=mysql_fetch_assoc($res)){ $return[]=new siteItems_Item($r); } return $return; } public function getLastVoted(){ if(!$this->cache['getLastVoted']){ list($this->cache['getLastVoted'])=query1("SELECT UNIX_TIMESTAMP(MAX(siteItemsLastVoted)) FROM tms_site_items WHERE siteItemsVisibility=1 AND siteItemsSection='{$this->ID}'", MYSQL_NUM); } return $this->cache['getLastVoted']; } public function getURL(){ if(!isset($this->cache['getURL'])){ $this->cache['getURL']=$this->ID.'/'; } return $this->cache['getURL']; } /** * siteItems_Section::getCategories() * @return array of categories */ public function getCategories(){ if(!isset($this->cache['getCategories'])){ $this->cache['getCategories']=array(); $res=query("SELECT * FROM tms_site_items_categories WHERE siteItemsCategoriesSection='{$this->ID}' ORDER BY sortScore DESC, siteItemsCategoriesID ASC"); while($r=mysql_fetch_assoc($res)){ $this->cache['getCategories'][]=new siteItems_Category($r); } } return $this->cache['getCategories']; } public function getBackground(){ return $this->attrGet('bg'); } } function sectionSort($a, $b) { if ($a['order_id'] == $b['order_id']) { return 0; } return ($a['order_id'] < $b['order_id']) ? -1 : 1; }