コード例 #1
0
ファイル: table.php プロジェクト: ValenokPC/tabernacms
 /**
  * @return rad_query
  */
 protected function getListQuery($fields)
 {
     $qb = new rad_query();
     if (isset($fields['from'])) {
         $qb->from($fields['from']);
     } else {
         $qb->from($this->_tablename);
     }
     $struct = $this->_struct_name;
     $struct = new $struct();
     foreach ($struct->getKeys('', true) as $id => $field) {
         if (isset($fields[$field])) {
             $qb->where($field . '=:' . $field)->value(array($field => $fields[$field]));
         }
     }
     //foreach
     unset($struct);
     if (isset($fields['select'])) {
         $qb->select($fields['select']);
     } else {
         $qb->select('*');
     }
     if (isset($fields['where'])) {
         $qb->where($fields['where']);
     }
     if (isset($fields['order by'])) {
         $qb->order($fields['order by']);
     }
     if (isset($fields['having'])) {
         $qb->having($fields['having']);
     }
     if (isset($fields['group by'])) {
         $qb->group($fields['group by']);
     }
     if (isset($fields['left join'])) {
         $qb->join('LEFT', $fields['left join']);
     }
     if (isset($fields['inner join'])) {
         $qb->join('INNER', $fields['inner join']);
     }
     if (isset($fields['order'])) {
         $qb->order($fields['order']);
     }
     $struct_name = $this->_struct_name;
     $tmp_struct = new $struct_name();
     if (isset($fields[$tmp_struct->getPrimaryKey()])) {
         $pk = $tmp_struct->getPrimaryKey();
         $qb->where($pk . '=' . (int) $fields[$pk]);
     }
     return $qb;
 }
コード例 #2
0
ファイル: catalog.php プロジェクト: ValenokPC/tabernacms
 /**
  * Return the products list
  * @param boolean $withvals
  * @param integer $ct_showing
  * @return struct_corecatalog_catalog array
  */
 function getProductsList($withvals = false, $ct_showing = 0)
 {
     $tre_id = (int) $this->getState('cit_tre_id', $this->getState('tre_id'));
     if ($tre_id or $this->getState('where_condition') or $this->getState('cat_id') or $this->getState('tag_id')) {
         $result = array();
         $q = new rad_query();
         $q->select('c.*,cr.cur_name AS currency_name, cr.cur_cost AS currency_cost, cr.cur_ind AS currency_indicate, ct.tre_name AS cat_ct_name, ct.*, i.img_filename AS img_filename');
         if ($this->getState('tag_id')) {
             $q->from(RAD . 'catalog c');
         } else {
             $q->from(RAD . 'cat_in_tree');
             $q->join('LEFT', RAD . 'catalog c ON cit_cat_id=cat_id');
         }
         $q->join('LEFT', RAD . 'currency cr ON cat_currency_id=cr.cur_id');
         $q->join('LEFT', RAD . 'tree ct ON cat_ct_id=tre_id');
         $q->join('LEFT', RAD . 'cat_images i ON img_cat_id=cat_id AND img_main=1');
         $orderj = '';
         if ($this->getState('special_offer')) {
             $q->join('INNER', RAD . 'cat_special cs ON cs.cs_catid=c.cat_id AND cs.cs_type=:cs_type')->value(array('cs_type' => (int) $this->getState('special_offer')));
             $orderj = $this->getState('order by') ? ' ' . $this->getState('order by') : ' cs.cs_order,';
         }
         if ($this->getState('where_condition')) {
             $q->where($this->getState('where_condition'));
         } elseif (!$this->getState('tag_id')) {
             $q->where('cit_tre_id=:cit_tre_id')->value(array('cit_tre_id' => $tre_id));
         }
         if ($this->getState('active', 2) == 1 or $this->getState('active', 2) == 0) {
             $q->where('cat_active=:cat_active')->value(array('cat_active' => $this->getState('active')));
         }
         if ($this->getState('lang')) {
             $q->where('cat_lngid=:cat_lngid')->value(array('cat_lngid' => $this->getState('lang')));
         }
         if ($this->getState('cat_id') and is_array($this->getState('cat_id'))) {
             $q->where('cat_id IN (:cat_id_in)')->value(array('cat_id_in' => implode(',', $this->getState('cat_id'))));
         }
         if ($this->getState('tag_id')) {
             $q->join('INNER', RAD . 'tags_in_cat tic ON tic.tic_cat_id = c.cat_id AND tic.tic_tag_id=:tic_tag_id');
             $q->value(array('tic_tag_id' => $this->getState('tag_id')));
         }
         if ($this->getState('group by')) {
             $q->group($this->getState('group by'));
         } else {
             $q->group('cat_id');
         }
         if ($this->getState('order by')) {
             $q->order($this->getState('order by'));
         } else {
             $q->order($orderj . 'cat_position,cat_name');
         }
         if ((int) $this->getState('brand_id')) {
             $q->where('c.cat_brand_id=:brand_id')->value(array('brand_id' => (int) $this->getState('brand_id')));
         }
         if ($this->getState('val_values')) {
             foreach ($this->getState('val_values') as $vvId => $vvVal) {
                 $q->where('EXISTS ( SELECT * FROM rad_cat_val_values WHERE vv_cat_id=c.cat_id AND vv_name_id=' . (int) $vvId . ' AND vv_value=:val_' . (int) $vvId . ' )')->value(array('val_' . (int) $vvId => $vvVal));
             }
         }
         if ($this->getState('currency')) {
             $q->join('INNER', RAD . 'currency cur ON cur.cur_id=:currency')->value(array('currency' => $this->getState('currency')));
             $q->select('(c.cat_cost*cr.cur_cost/cur.cur_cost) AS price');
         }
         if ($this->getState('cost.from')) {
             $q->having('price >= :costfrom')->value(array('costfrom' => $this->getState('cost.from')));
         }
         if ($this->getState('cost.to')) {
             $q->having('price <= :costto')->value(array('costto' => $this->getState('cost.to')));
         }
         $limit = $this->getState('limit');
         $limit = $limit ? ' LIMIT ' . $limit : '';
         $i = 0;
         if ($this->getState('showSQL')) {
             print_h($q->getValues());
             die($q->toString());
         }
         foreach ($this->queryAll($q->toString() . $limit, $q->getValues()) as $row) {
             $result[$i] = new struct_corecatalog_catalog($row);
             $this->assignSpecial($result[$i]);
             if ($withvals) {
                 $result[$i]->type_link = new struct_coremenus_tree($row);
             }
             $i++;
         }
         //foreach
         if (($withvals or $this->getState('val_values')) and count($result)) {
             $this->getValValues($result, $ct_showing);
         }
         return $result;
     } else {
         throw new rad_exception('Not setted the "cit_tre_id" or "tre_id!" in class "' . $this->getClassName() . '" at line: ' . __LINE__, 500);
     }
 }