/** * Gets 3dImages * @return multitype:struct_corecatalog_cat_3dimages */ public function getItems() { $q = new rad_query(); $q->select('*')->from(RAD . 'cat_3dimages'); if ($this->getState('cat_id')) { $q->where('img_cat_id=:cat_id')->value(array('cat_id' => $this->getState('cat_id'))); } $res = $this->queryAll($q->toString(), $q->getValues()); $result = array(); if (count($res)) { foreach ($res as $id) { $result[] = new struct_corecatalog_cat_3dimages($id); } } return $result; }
/** * Get Activation URL record(s) * @return null|struct_coremail_subscribers_activationurl */ function getActivationUrl() { $q = new rad_query(); $q->from(RAD . 'subscribers_activationurl'); $q->select('*'); if ($this->getState('sac_type')) { $q->where('sac_type = :sac_type')->value(array('sac_type' => (int) $this->getState('sac_type'))); } if ($this->getState('sac_url')) { $q->where('sac_url = :sac_url')->value(array('sac_url' => $this->getState('sac_url'))); } if ($this->getState('sac_scrid')) { $q->where('sac_scrid = :sac_scrid')->value(array('sac_scrid' => $this->getState('sac_scrid'))); } if ($res = $this->query($q->toString(), $q->getValues())) { $result = new struct_coremail_subscribers_activationurl($res); return $result; } else { return null; } }
/** * Gets the partners statistics by period * @state date.from * @state date.ro * @return mixed array | NULL */ function getRefStatistics($limit = null) { $limit = empty($limit) && $this->getState('limit') ? $this->getState('limit') : $limit; $limit = !empty($limit) ? ' LIMIT ' . $limit : ''; if (!$this->getState('date.from')) { throw new rad_exception('Not enough actual param "date.from" in referals model!', __LINE__); } if (!$this->getState('date.to')) { throw new rad_exception('Not enough actual param "date.to" in referals model!', __LINE__); } /* calc ref count */ $qRefCount = new rad_query(); $qRefCount->select('count(t1.rrf_id)')->from(RAD . 'referals t1')->where('t1.rrf_user_id=a.u_id')->where('t1.rrf_date BETWEEN :date_from AND :date_to'); /* calc orders count */ $qOrderCount = new rad_query(); $qOrderCount->select('count(*) AS ro_cnt')->from(RAD . 'referals_orders ro')->join('INNER', RAD . 'orders ON order_id=rro_order_id AND order_dt BETWEEN :date_from AND :date_to')->join('INNER', RAD . 'referals r ON rrf_id=rro_referals_id')->where('r.rrf_user_id=a.u_id'); /* full query */ $q = new rad_query(); $q->from(RAD . 'users a'); $q->select('a.*, (' . $qRefCount->toString() . ') refCount, (' . $qOrderCount->toString() . ') ordersCount')->value(array('date_from' => date($this->config('date.format'), $this->getState('date.from')), 'date_to' => date($this->config('date.format'), $this->getState('date.to') + 86400)))->where('a.u_email_confirmed=1')->having('refCount > 0 OR ordersCount > 0'); if ($this->getState('search')) { $q->where('(u_login LIKE :search or u_email LIKE :search OR u_fio LIKE :search OR u_address LIKE :search OR u_phone LIKE :search)')->value(array('search' => '%' . $this->getState('search') . '%')); } $res = $this->queryAll($q->toString() . $limit, $q->getValues()); // die($q->toString().$limit.print_h($q->getValues(),true)); if ($res) { $userIds = array(); foreach ($res as &$id) { $userIds[] = $id['u_id']; } return $res; } return NULL; }
/** * 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); } }