/** * @param StoreCategory $category * @param bool $withChild * @param null $limit * @return CActiveDataProvider */ public function getListForCategory(StoreCategory $category, $withChild = true, $limit = null) { $categories = []; if (true === $withChild) { $categories = $category->getChildsArray(); } $categories[] = $category->id; $criteria = new CDbCriteria(['scopes' => ['published']]); $builder = new CDbCommandBuilder(Yii::app()->getDb()->getSchema()); $criteria->addInCondition('t.category_id', array_unique($categories)); $criteria->addCondition(sprintf('t.id IN (SELECT product_id FROM {{store_product_category}} WHERE %s)', $builder->createInCondition('{{store_product_category}}', 'category_id', $categories)), 'OR'); $pagination = ['pageSize' => (int) Yii::app()->getModule('store')->itemsPerPage, 'pageVar' => 'page']; if ($limit) { $pagination = false; $criteria->limit = (int) $limit; } return new CActiveDataProvider(Product::model(), ['criteria' => $criteria, 'pagination' => $pagination, 'sort' => ['sortVar' => 'sort', 'defaultOrder' => 't.position']]); }
/** * Generates the expression for selecting rows of specified primary key values. * @param mixed $table the table schema ({@link CDbTableSchema}) or the table name (string). * @param mixed $columnName the column name(s). It can be either a string indicating a single column * or an array of column names. If the latter, it stands for a composite key. * @param array $values list of key values to be selected within * @param string $prefix column prefix (ended with dot). If null, it will be the table name * @return string the expression for selection */ public function createInCondition($table, $columnName, $values, $prefix = null) { parent::createInCondition($table, $columnName, $values); }