Пример #1
0
 public function __construct($categories = null)
 {
     if ($categories === null) {
         $this->categories = PageCategory::model()->findAll();
     } else {
         $this->categories = $categories;
     }
 }
Пример #2
0
 public function testCategoryUrlUnique()
 {
     // Create new category with existing url
     $category = new PageCategory();
     $category->attributes = array('name' => 'Тест тест 2', 'description' => 'Category test desc', 'parent_id' => $this->PageCategory['PageCategory_2']['parent_id'], 'url' => $this->PageCategory['PageCategory_2']['url']);
     $this->assertTrue($category->save());
     $category = PageCategory::model()->findByPk($category->id);
     $this->assertTrue($category instanceof PageCategory);
     $this->assertEquals('fantastika-' . date('YmdHis'), $category->url);
 }
Пример #3
0
 /**
  * Delete category by Pk
  */
 public function actionDelete()
 {
     if (Yii::app()->request->isPostRequest) {
         $model = PageCategory::model()->findAllByPk($_REQUEST['id']);
         if (!empty($model)) {
             foreach ($model as $category) {
                 $category->delete();
             }
         }
         if (!Yii::app()->request->isAjaxRequest) {
             $this->redirect('index');
         }
     }
 }
Пример #4
0
 /**
  * Filter pages by category
  */
 public function actionList()
 {
     // Remove "pages/" from beginning
     $url = substr(Yii::app()->request->getPathInfo(), 6);
     $model = PageCategory::model()->withFullUrl($url)->find();
     if (!$model) {
         throw new CHttpException(404, Yii::t('PagesModule.core', 'Категория не найдена.'));
     }
     $criteria = Page::model()->published()->filterByCategory($model)->getDbCriteria();
     $count = Page::model()->count($criteria);
     $pagination = new CPagination($count);
     $pagination->pageSize = $model->page_size > 0 ? $model->page_size : $model->defaultPageSize;
     $pagination->applyLimit($criteria);
     $pages = Page::model()->findAll($criteria);
     $view = $this->setDesign($model, 'list');
     $this->render($view, array('model' => $model, 'pages' => $pages, 'pagination' => $pagination));
 }
Пример #5
0
 /**
  * `On after create new language` event.
  * Create default translation for each page object.
  * @param $event
  */
 public function insertTranslations($event)
 {
     Yii::import('application.modules.banners.models.Page');
     if (!$event->sender->isNewRecord) {
         return;
     }
     // Find all pages on default language and
     // make copy on new lang.
     $pages = Page::model()->language(Yii::app()->languageManager->default->id)->findAll();
     if ($pages) {
         foreach ($pages as $p) {
             $p->createTranslation($event->sender->getPrimaryKey());
         }
     }
     // Categories
     $categories = PageCategory::model()->language(Yii::app()->languageManager->default->id)->findAll();
     if ($categories) {
         foreach ($categories as $c) {
             $c->createTranslation($event->sender->getPrimaryKey());
         }
     }
 }
Пример #6
0
 /**
  * Count and cache categories by url
  *
  * @param $pathInfo
  * @return int|mixed
  */
 public static function countByPath($pathInfo)
 {
     $count = Yii::app()->cache->get(__CLASS__ . $pathInfo);
     if ($count === false) {
         $model = PageCategory::model()->withFullUrl($pathInfo)->find();
         if ($model) {
             $count = 1;
         } else {
             $count = 0;
         }
     }
     Yii::app()->cache->set('page_category_' . $pathInfo, $count, 3600);
     return $count;
 }
Пример #7
0
 public function getCategory($id)
 {
     return PageCategory::model()->findByPk($id);
 }