/** * getListItems - Phương thức dùng để lấy dữ liệu */ public function getListItems($category_id = null) { Yii::import('application.modules.products.models.ProductItem'); $model = new ProductItem('search'); $model->unsetAttributes(); $criteria = new CDbCriteria(); $criteria->order = 'created DESC'; if ($category_id) { Yii::import('application.modules.products.models.ProductCategory'); $categories = ProductCategory::model()->findByPk($category_id); if (!$categories) { return null; } $this->__category = $categories; $descendants = $categories->descendants()->findAll('is_active = 1'); $arrCat = array($category_id); foreach ($descendants as $cat) { $arrCat[] = $cat->id; } $criteria->with = array('categoryitem'); $criteria->together = true; foreach ($arrCat as $cat) { $criteria->compare('categoryitem.category_id', $cat, false, 'OR'); } } $criteria->compare('status', 1); $search = new CActiveDataProvider($model, array('criteria' => $criteria, 'pagination' => array('pageSize' => Yii::app()->getModule('products')->entriesShow))); $data = $search->getData(); $this->__pagination = $search->pagination; return $data; }
/** * Manages all models. */ public function actionAdmin($category = '') { $baseScriptUrl = Yii::app()->assetManager->publish(dirname(__FILE__) . '/../assets'); Yii::app()->getClientScript()->registerCssFile($baseScriptUrl . '/products.css'); if (isset($_POST['product-item-grid_c0'])) { foreach ($_POST['product-item-grid_c0'] as $strNewID) { $model = $this->loadModel($strNewID); $model->delete(); } } $model = new ProductItem('search'); $model->unsetAttributes(); // clear any default values if (isset($_GET['ProductItem'])) { $model->attributes = $_GET['ProductItem']; } if ($category) { $arrCat = array($category); $categories = ProductCategory::model()->findByPk($category); if ($categories) { $descendants = $categories->descendants()->findAll('is_active = 1'); foreach ($descendants as $cat) { $arrCat[] = $cat->id; } } $model->categories = $arrCat; } $this->render('admin', array('model' => $model)); }