/** * getListItems - Phương thức dùng để lấy dữ liệu */ public function getListItems($category_id = null) { Yii::import('application.modules.live.models.LiveItem'); $model = new LiveItem('search'); $model->unsetAttributes(); $criteria = new CDbCriteria(); $criteria->order = 'created DESC'; if ($category_id) { Yii::import('application.modules.live.models.LiveCategory'); $categories = LiveCategory::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('live')->entriesLastestShow))); $data = $search->getData(); return $data; }
/** * getData - Phương thức dùng để lấy dữ liệu */ public function getData() { $arrTrees = array(); Yii::import('application.modules.live.models.LiveCategory'); $treeRoot = LiveCategory::model()->roots()->find(); if ($treeRoot) { $descendants = $treeRoot->descendants()->findAll('is_active = 1'); $tree = $treeRoot->toArray($descendants); $arrTrees = $this->__getListChilds($tree); } return $arrTrees; }
/** * Manages all models. */ public function actionAdmin($category = '') { $baseScriptUrl = Yii::app()->assetManager->publish(dirname(__FILE__) . '/../assets'); Yii::app()->getClientScript()->registerCssFile($baseScriptUrl . '/live.css'); if (isset($_POST['product-item-grid_c0'])) { foreach ($_POST['product-item-grid_c0'] as $strNewID) { $model = $this->loadModel($strNewID); $model->delete(); } } $model = new LiveItem('search'); $model->unsetAttributes(); // clear any default values if (isset($_GET['LiveItem'])) { $model->attributes = $_GET['LiveItem']; } if ($category) { $arrCat = array($category); $categories = LiveCategory::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)); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = LiveCategory::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }