Exemple #1
0
 /**
  * Get markets with filters by category and features
  * @param int $last_market_id
  * @param string|array $categories_ids
  * @param string|array $features_ids
  * @param int $limit
  * @return array of markets
  */
 public static function getAllByFilters($last_market_id, $categories_ids = 'all', $features_ids = 'all', $limit = 25)
 {
     $select = "SELECT m.id, m.title, m.current_date," . " m.price, m.xrl_price," . " COUNT(mp.id) AS proposes_count," . " (" . "     SELECT mi.thumb_src FROM " . MarketsImages::tableName() . " mi " . "     WHERE m.id = mi.markets_id" . "     LIMIT 1" . " ) as thumb_src ";
     $from = " FROM " . self::tableName() . " m ";
     $join = " LEFT JOIN " . MarketsProposes::tableName() . " mp " . " ON m.id = mp.markets_id ";
     $where = " WHERE m.id > :last_market_id ";
     $group_by = " GROUP BY m.id  ";
     $order_by = " ORDER BY m.id DESC ";
     $limits = " LIMIT :limit ";
     if ($categories_ids != 'all' && is_array($categories_ids)) {
         $categories_ids = array_map('intval', $categories_ids);
         $join .= " JOIN " . MarketsCategories::tableName() . " mc " . " ON m.id = mc.markets_id " . " JOIN " . Categories::tableName() . " c " . " ON c.id = mc.categories_id ";
         $where .= " AND c.id IN (" . implode(',', $categories_ids) . ")";
     }
     $sql = $select . $from . $join . $where . $group_by . $order_by . $limits;
     return static::findBySql($sql, [':limit' => $limit, ':last_market_id' => $last_market_id])->asArray()->all();
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCategory()
 {
     return $this->hasOne(Categories::className(), ['id' => 'category_id']);
 }
Exemple #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCategories()
 {
     return $this->hasMany(Categories::className(), ['parent_id' => 'id']);
 }