public function actionAdmin()
 {
     $lang = $this->getLanguageCode();
     //tạo array để hiện thị trên dropDownList category
     $listCategory_Array = CategoryLanguage::model()->getListCategoryWithLanguage($lang);
     unset($listCategory_Array[1]);
     reset($listCategory_Array);
     $category_id = key($listCategory_Array);
     //lây phan tu dau tien
     if (Yii::app()->request->getParam('id')) {
         //nếu không tồn tại thì lấy phần tử đầu tiên trong category
         $category_id = Yii::app()->request->getParam('id');
     }
     $model = new Post('search');
     $model->unsetAttributes();
     // clear any default values
     $this->render('admin', array('model' => $model->getListPost($lang, $category_id, 1), 'category_id' => $category_id, 'listCategory_Array' => $listCategory_Array, 'lang' => $lang));
 }
 public function actionLoadLinkData()
 {
     $modelCategoryLanguage = CategoryLanguage::model()->getListCategoryWithLanguage($this->getLanguageCode());
     $modelPostLanguage = PostLanguage::model()->getListPostLanguage($this->getLanguageCode());
     $modelStaticHtml = StaticHtml::model()->findAll();
     echo $this->renderPartial('_linkData', array('modelCategoryLanguage' => $modelCategoryLanguage, 'modelPostLanguage' => $modelPostLanguage, 'modelStaticHtml' => $modelStaticHtml));
 }
 /**
  * Deletes a particular model.
  * If deletion is successful, the browser will be redirected to the 'admin' page.
  * @param integer $id the ID of the model to be deleted
  */
 public function actionDelete()
 {
     if (Yii::app()->request->getPost('value')) {
         $cate_id = Yii::app()->request->getPost('value');
         $model = $this->loadModel($cate_id);
         $count = count(Post::model()->getListPostWithCategoryID($cate_id, '*'));
         if ($count) {
             Yii::app()->user->setFlash('error', Yii::t('category', 'Delete fails.'));
             Yii::app()->user->setFlash('message', Yii::t('category', 'Do not delete this category because it contains some post.'));
         } else {
             $transaction = Yii::app()->db->beginTransaction();
             try {
                 $children = Category::model()->getChildrenInNode($model->id);
                 $children = implode(',', $children);
                 CategoryLanguage::model()->deleteAll('category_id IN (' . $children . ')');
                 if ($model->deleteNode()) {
                     $transaction->commit();
                     Yii::app()->user->setFlash('success', Yii::t('category', 'Success.'));
                     Yii::app()->user->setFlash('message', Yii::t('category', 'Successfully deleted category.'));
                 }
             } catch (Exception $ex) {
                 $transaction->rollback();
                 Yii::app()->user->setFlash('error', Yii::t('category', 'Fails.'));
                 Yii::app()->user->setFlash('message', Yii::t('category', 'Delete category fails.'));
             }
         }
     } else {
         throw new CHttpException(404, Yii::t('category', 'The specified category cannot be found.'));
     }
 }