示例#1
0
 /**
  * Gets the query
  *
  * @return rad_query
  */
 function _getListQuery()
 {
     $qb = new rad_query();
     if ($this->getState('select')) {
         $qb->select($this->getState('select'));
     } else {
         $qb->select('a.*');
     }
     if ($this->getState('from')) {
         $qb->from($this->getState('from'));
     } else {
         $qb->from(RAD . 'catalog a');
     }
     if ($this->getState('id')) {
         $qb->where('cat_id=:cat_id')->value(array('cat_id' => $this->getState('id')));
     }
     if ($this->getState('order by')) {
         $qb->order($this->getState('order by'));
     }
     if ($this->getState('cat_code')) {
         $qb->where('cat_code=:cat_code')->value(array('cat_code' => $this->getState('cat_code')));
     }
     if ($this->getState('tre_id')) {
         if (is_array($this->getState('tre_id'))) {
             $treIds = array();
             foreach ($this->getState('tre_id') as $key => $treId) {
                 $treIds[] = (int) $treId;
             }
             $treIds = implode(',', $treIds);
             $qb->join('INNER', RAD . 'cat_in_tree cit ON cit.cit_cat_id=a.cat_id AND cit_tre_id IN (' . $treIds . ')');
         } else {
             $qb->join('INNER', RAD . 'cat_in_tree cit ON cit.cit_cat_id=a.cat_id AND cit_tre_id=:tre_id');
             $qb->value(array('tre_id' => $this->getState('tre_id')));
         }
     }
     if ($this->getState('join.tree')) {
         $qb->join('LEFT', RAD . 'cat_in_tree cit_j ON cit_j.cit_cat_id=a.cat_id');
         $qb->join('LEFT', RAD . 'tree cit_jt ON cit_jt.tre_id=cit_j.cit_tre_id');
         $qb->select('cit_jt.*');
     }
     if ($this->getState('active')) {
         $qb->where('cat_active=1');
     }
     if ($this->getState('group by')) {
         $qb->group($this->getState('group by'));
     }
     if ($this->getState('currency')) {
         $qb->join('INNER', RAD . 'currency cur ON cur.cur_id=a.cat_currency_id')->join('INNER', RAD . 'currency cr ON cr.cur_id=:currency')->value(array('currency' => $this->getState('currency')))->select('(a.cat_cost*cur.cur_cost)/cr.cur_cost AS price');
     }
     if ($this->getState('join.mainimage')) {
         $typeJoin = $this->getState('only.withimages') ? 'INNER' : 'LEFT';
         $qb->join($typeJoin, RAD . 'cat_images i ON img_cat_id=cat_id AND img_main=1');
         $qb->select('i.img_filename');
     }
     if ($this->getState('lang', $this->getState('lang_id'))) {
         $qb->where('a.cat_lngid=:cat_lngid')->value(array('cat_lngid' => $this->getState('lang', $this->getState('lang_id'))));
     }
     if ($this->getState('cat_usercreated')) {
         $qb->where('a.cat_usercreated=:usercreated')->value(array('usercreated' => $this->getState('cat_usercreated')));
     }
     if ($this->getState('where')) {
         $qb->where($this->getState('where'));
     }
     return $qb;
 }