private function _getListQuery() { $qb = new rad_query(); if ($this->getState('from')) { $qb->from($this->getState('from')); } else { $qb->from(RAD . 'comments a'); } if ($this->getState('select')) { $qb->select($this->getState('select')); } else { $qb->select('*'); } if ($this->getState('join.news')) { $qb->join('LEFT', RAD . 'news ON nw_id=a.rcm_item_id AND rcm_type="' . self::TYPE_NEWS . '"'); } if ($this->getState('join.articles')) { $qb->join('LEFT', RAD . 'articles ON art_id=a.rcm_item_id AND rcm_type="' . self::TYPE_ARTICLES . '"'); } if ($this->getSTate('join.orders')) { $qb->join('LEFT', RAD . 'orders o ON o.order_id=a.rcm_item_id AND rcm_type="' . self::TYPE_ORDER . '"'); } if ($this->getSTate('join.products')) { $qb->join('LEFT', RAD . 'catalog c ON c.cat_id=a.rcm_item_id AND rcm_type="' . self::TYPE_PRODUCT . '"'); } if ($this->getState('order', $this->getState('order by'))) { $qb->order($this->getState('order', $this->getState('order by'))); } if ($this->getState('group')) { $qb->group($this->getState('group')); } if ($this->getState('rcm_item_id', $this->getState('item_id'))) { $qb->where('rcm_item_id=:item_id')->value(array('item_id' => $this->getState('rcm_item_id', $this->getState('item_id')))); } if ($this->getState('rcm_active', $this->getState('active'))) { $qb->where('rcm_active=:rcm_active')->value(array('rcm_active' => $this->getState('rcm_active', $this->getState('active')))); } if ($this->getState('rcm_type', $this->getState('type'))) { $qb->where('rcm_type=:rcm_type')->value(array('rcm_type' => $this->getState('rcm_type', $this->getState('type')))); } if ((int) $this->getState('rcm_id', $this->getState('id'))) { $qb->where('rcm_id=:id')->value(array('id' => (int) $this->getState('rcm_id', $this->getState('id')))); } return $qb; }
/** * Gets the list query * @param array mixed $options * @param array mixed $fk * @return rad_query */ private function _getListQuery($options, $fk = array()) { $qb = new rad_query(); if (isset($options['from'])) { $qb->from($options['from']); } else { $qb->from(RAD . 'users a'); } if (isset($options['select'])) { $qb->select($options['select']); } else { if (count($fk)) { //if need to join some... } else { $qb->select('a.*'); } } if (isset($options['id']) || isset($options['u_id'])) { $tmp = (int) isset($options['id']) ? $options['id'] : $options['u_id']; $qb->where('a.id=:a_id')->value(array('a_id' => $tmp)); } if (isset($options['order by'])) { $qb->order($options['order by']); } else { $qb->order('u_active,u_email,u_login,u_group,u_access'); } if (isset($options['u_group'])) { if (is_array($options['u_group'])) { foreach ($options['u_group'] as $key => $value) { $grIds[(int) $key] = (int) $value; } $qb->where('u_group IN (' . implode(',', $grIds) . ')'); } else { $qb->where('u_group=:u_group')->value(array('u_group' => (int) $options['u_group'])); } } if (isset($options['u_active'])) { $qb->select('g.*'); $qb->join('INNER', RAD . 'tree g ON g.tre_id=a.u_group'); } if (isset($options['u_active'])) { $qb->where('u_active=:u_active')->value(array('u_active' => $options['u_active'])); } if (isset($options['u_id'])) { $qb->where('u_id=:u_id')->value(array('u_id' => (int) $options['u_id'])); } if (isset($options['u_login'])) { $qb->where('u_login=:u_login')->value(array('u_login' => $options['u_login'])); } if (isset($options['u_pass'])) { $qb->where('u_pass=:u_pass')->value(array('u_pass' => $options['u_pass'])); } if (isset($options['is_admin'])) { $qb->where('is_admin=:is_admin')->value(array('is_admin' => (int) $options['is_admin'])); } if (isset($options['u_email'])) { $qb->where('u_email=:u_email')->value(array('u_email' => $options['u_email'])); } if (isset($options['u_access'])) { $qb->where('u_access<:u_access')->value(array('u_access' => (int) $options['u_access'])); } if (isset($options['u_email_confirmed'])) { $qb->where('u_email_confirmed=:u_confirmed')->value(array('u_confirmed' => $options['u_email_confirmed'])); } if (isset($options['u_subscribe_active'])) { $qb->where('u_subscribe_active=:u_subscribe_active')->value(array('u_subscribe_active' => (int) $options['u_subscribe_active'])); } if (isset($options['u_subscribe_langid'])) { $qb->where('u_subscribe_langid=:u_subscribe_langid')->value(array('u_subscribe_langid' => (int) $options['u_subscribe_langid'])); } // SOCIAL SITE's USER ACCOUNT ID: if (isset($options['u_facebook_id'])) { $qb->where('u_facebook_id=:u_facebook_id')->value(array('u_facebook_id' => $options['u_facebook_id'])); } if (isset($options['u_twitter_id'])) { $qb->where('u_twitter_id=:u_twitter_id')->value(array('u_twitter_id' => $options['u_twitter_id'])); } // --- if (isset($options['where'])) { $qb->where($options['where']); } if (isset($options['code'])) { $qb->join('INNER', RAD . 'subscribers_activationurl ON sac_scrid=a.u_id AND sac_url=:sac_url AND sac_type=2 AND date_confirmed=0')->value(array('sac_url' => $options['code'])); } return $qb; }
private function _getListQuery($options, $fk = array()) { $qb = new rad_query(); if (isset($options['from'])) { $qb->from($options['from']); } else { $qb->from(RAD . 'votes a'); } if (isset($options['select'])) { $qb->select($options['select']); } else { $qb->select('a.*'); } if (isset($options['order by'])) { $qb->order($options['order by']); } else { $qb->order('a.vt_position'); } if (isset($options['pid'])) { $val = $options['pid']; if (is_array($val)) { $treeIds = ''; //Do NOT use IMPLODE HERE!!! For safe method use foreach and (int) foreach ($val as $key => $value) { $treeIds .= (int) $value . ','; } $treeIds = substr($treeIds, 0, -1); $qb->where('a.vt_treid IN (' . $treeIds . ')'); } else { $qb->where('a.vt_treid=' . (int) $val); } } if (isset($options['vt_id'])) { $qb->where('a.vt_id=' . (int) $options['vt_id']); } if (isset($options['lang'])) { $qb->where('a.vt_lngid=' . (int) $options['lang']); } if (isset($options['!vta_hash'])) { $qb->join('LEFT', RAD . 'votes_answers va on vta_vtid=vt_id and va.vta_hash="' . $options['!vta_hash'] . '"'); $qb->where('ISNULL(vta_id)'); } if (isset($options['where'])) { $qb->where($options['where']); } return $qb; }
/** * List query * * @param array $fields * @param array $fk * @return rad_query */ function getListQuery($fields, $fk = array()) { $qb = new rad_query(); if (isset($fields['select'])) { $qb->select($fields['select']); } else { $qb->select('*'); } if (isset($fields['vl_id'])) { $qb->where('vl_id=:vl_id')->value(array('vl_id' => (int) $fields['vl_id'])); } if (isset($fields['pid']) or isset($fields['vl_tre_id']) or isset($fields['tre_id'])) { $val = isset($fields['pid']) ? $fields['pid'] : isset($fields['vl_tre_id']) ? $fields['vl_tre_id'] : $fields['tre_id']; if (is_array($val)) { $treeIds = ''; //Do NOT use IMPLODE HERE!!! For safe method use foreach and (int) foreach ($val as $key => $value) { $treeIds .= (int) $value . ','; } $treeIds = substr($treeIds, 0, -1); $qb->where('vl_tre_id IN (' . $treeIds . ')'); } else { $qb->where('vl_tre_id=:vl_tre_id')->value(array('vl_tre_id' => (int) $val)); } } if (isset($fields['vl_name']) or isset($fields['name'])) { $val = isset($fields['vl_name']) ? $fields['vl_name'] : $fields['name']; $qb->where('vl_name=:vl_name')->value(array('vl_name' => $val)); } if (isset($fields['vl_type_in']) or isset($fields['type_in'])) { $val = isset($fields['vl_type_in']) ? $fields['vl_type_in'] : $fields['type_in']; $qb->where('vl_type_in=:vl_type_in')->value(array('vl_type_in' => $val)); } if (isset($fields['vl_type_print']) or isset($fields['type_print'])) { $val = isset($fields['vl_type_print']) ? $fields['vl_type_print'] : $fields['type_print']; $qb->where('vl_type_print=:vl_type_print')->value(array('vl_type_print' => $val)); } if (isset($fields['vl_measurement_id']) or isset($fields['measurement_id'])) { $val = isset($fields['vl_measurement_id']) ? $fields['vl_measurement_id'] : $fields['measurement_id']; $qb->where('vl_measurement_id=:vl_measurement_id')->value(array('vl_measurement_id' => $val)); } if (isset($fields['active']) or isset($fields['vl_active'])) { $val = isset($fields['active']) ? $fields['active'] : $fields['vl_active']; $qb->where('vl_active=:vl_active')->value(array('vl_active' => $val)); } if (isset($fk['measurement'])) { $qb->join('LEFT', RAD . 'measurement as m on m.ms_id=a.vl_measurement_id'); } if (isset($fk['ct_showing']) and isset($fields['cts_show'])) { $val = isset($fk['ct_showing']) ? $fk['ct_showing'] : $fields['cts_show']; $qb->join('LEFT', RAD . 'ct_showing as cts on cts.cts_vl_id=a.vl_id WHERE cts_show=:cts_show')->value(array('cts_show' => $val)); } if (!empty($fields['filter'])) { $qb->where('vl_filter=1'); $qb->join('RIGHT', RAD . 'cat_val_values ON vv_name_id=vl_id'); if (!empty($fields['cat_id'])) { if (is_array($fields['cat_id'])) { $catIds = array(); foreach ($fields['cat_id'] as $idN => $idV) { $catIds[] = (int) $idV; } $qb->where('vv_cat_id IN (' . implode(',', $catIds) . ')'); } else { $qb->where('vv_cat_id=:cat_id')->value(array('cat_id' => $fields['cat_id'])); } } } if (isset($fields['order'])) { $qb->order($fields['order']); } else { $qb->order('a.vl_position'); } if (!empty($fields['group by'])) { $qb->group($fields['group by']); } $qb->from(RAD . 'cat_val_names a'); return $qb; }
/** * @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; }
/** * for the searching aliases * * @param string $sw */ function search($sw = '') { $q = new rad_query(); $q->select('a.*,t.filename as filename'); $q->from(RAD . 'aliases a'); $q->join('LEFT', RAD . 'templates t on t.id = a.template_id'); $q->where('a.ali_admin=' . (int) $this->getState('is_admin', 0), 'AND'); $sql = $q->toString(); $sql .= ' AND(alias like "%' . $sw . '%" OR filename like "%' . $sw . '%" OR description like "%' . $sw . '%")'; // $q->where('alias like "%'.$sw.'%"','OR'); // $q->where('filename like "%'.$sw.'%"','OR'); // $q->where('description like "%'.$sw.'%"','OR'); $result = array(); //die(); // foreach( $this->queryAll( $q->toString() ) as $key){ foreach ($this->queryAll($sql) as $key) { $result[] = new struct_core_alias($key); } return $result; }
/** * 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; }