Blame view

modules/default/model/catalog.class.php 2.26 KB
8d65d0ce   andryeyev   init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
  <?php
  Class Catalog{
  	private $db;
  	private $lang;
  	static $catalog_id = 0;
  	static $brend_translit;
  	static $brend_id = 0;
   
  	function __construct($lang){
  		$this->db = sdb::getInstance();
  		$this->lang = $lang;
  	}
  	
  	
   public function getCatalogUL($url,$id = 0,$level = -1,&$menu = ''){
     // global $menu;
      $sql = "select * from catalogs_rubrics where parent_id=? and is_pic=0 and is_view=0";
  	if(self::$brend_id>0)$sql .= sprintf(" and brend_id='%d'",self::$brend_id);
  	$sql .= " order by sort asc";
      $q=$this->db->query($sql,array($id));
      if(!$q->numRows())
          return;
      $level++;
  	if($level == 0)$menu.= "<ul class='rubrics'>\n";
  	else $menu.= "<ul>\n";
      while($q->fetchInto($arr,DB_FETCHMODE_ASSOC))
      {
          $menu.= '<li>';
          $menu.= '<a href="'.$url.'/products/'.self::$brend_translit.'/'.$arr['translit'].'/">';
          $menu.= $arr['name'];
          $menu.= '</a>';
          if(in_array($arr['id'],$this->getTreeCatalog(self::$catalog_id))){//$this->getCatalogUL($url,$arr['id'],$level,$menu);
  		$p_res = $this->db->getAll("select * from catalogs_products where catalog_id=?",array($arr['id']),DB_FETCHMODE_ASSOC);
  		if(count($p_res)>0){
  			$menu.= '<ul>';
  				foreach($p_res as $p_row){
  					$menu.= '<li>';
  					$menu.= '<a href="'.$url.'/products/'.self::$brend_translit.'/'.$arr['translit'].'/'.$p_row['translit'].'-'.$p_row['id'].'/">';
  					$menu.= $p_row['name'];
  					$menu.= '</a>';
  					$menu.= '</li>';
  				}
  			$menu.= '</ul>';
  			}
  		}
          $menu.= "</li>\n";
      }
      $menu.= "</ul>\n";
  
    return $menu;
   }
   
    private function getTreeCatalog($id){
  	$ids = array();
  	while($id>0){
  		$row = $this->db->getRow('select id,parent_id from catalogs_rubrics where id=?',array($id),DB_FETCHMODE_ASSOC);
  		$ids[] = $row['id'];
  		$id = $row['parent_id'];
  	}   //print_r($ids);
   // sort($ids);
  	return $ids;
   } 
  	
  	public function getRubricsIsPic(){
  		$sql = "select * from catalogs_rubrics where is_pic=?";
  		return $this->db->getAll($sql,array(1),DB_FETCHMODE_ASSOC);
  	}
   
  	public function getRubric($id){
  		return $this->db->getRow("select * from catalogs_rubrics where id=?",array($id),DB_FETCHMODE_ASSOC);
  	}
  
  	public function getTranslit($translit){
  		return $this->db->getOne("select id from catalogs_rubrics where translit=?",array($translit));
  	}	
  
  
  }
  ?>