public function loadModel($id)
 {
     if (($model = InteriorItem::model()->findByPk($id)) === null) {
         throw new CHttpException(404, 'Страница не найдена');
     }
     return $model;
 }
 public function run()
 {
     if (empty($this->model)) {
         return;
     }
     $criteria = new CDbCriteria();
     $criteria->order = 'RAND()';
     if ($this->limit > 0) {
         $criteria->limit = (int) $this->limit;
     }
     $models = InteriorItem::model()->published()->stone($this->model->id)->findAll($criteria);
     $this->render($this->view, array('model' => $this->model, 'models' => $models));
 }
 public function run()
 {
     if (empty($this->model)) {
         return;
     }
     $criteria = new CDbCriteria();
     $criteria->addCondition('t.id <> :id');
     $criteria->params[':id'] = $this->model->id;
     $criteria->order = 'RAND()';
     if ($this->limit > 0) {
         $criteria->limit = (int) $this->limit;
     }
     $models = InteriorItem::model()->published()->category($this->model->category_id)->color($this->model->color_id)->findAll($criteria);
     if (empty($models)) {
         $models = InteriorItem::model()->published()->category($this->model->category_id)->findAll($criteria);
     }
     $this->render($this->view, array('models' => $models, 'model' => $this->model));
 }
 public function run()
 {
     if (empty($this->model) || empty($this->attributeName) || $this->model->{$this->attributeName} == '') {
         return;
     }
     $relatedItems = explode(',', $this->model->{$this->attributeName});
     array_walk($relatedItems, function ($data) {
         return (int) trim($data);
     });
     $criteria = new CDbCriteria();
     $criteria->addInCondition('t.id', $relatedItems);
     if ($this->limit > 0) {
         $criteria->limit = (int) $this->limit;
     }
     if (!empty($relatedItems)) {
         $criteria->order = 'FIELD(id, ' . implode(',', $relatedItems) . ')';
     }
     $models = InteriorItem::model()->published()->findAll($criteria);
     $this->render($this->view, array('models' => $models, 'model' => $this->model));
 }
 public function getPrevProduct($filter = array())
 {
     $criteria = $this->_constructCriteriaByFilter($filter);
     $criteria->order = 'category.sort DESC, t.sort DESC';
     // Условие выборки по порядку
     $fullCriteria = clone $criteria;
     $fullCriteria->addCondition('((t.category_id = :category_id AND t.sort <= :sort) OR category.sort < :category_sort) AND t.id <> :id');
     $fullCriteria->params = array_merge($fullCriteria->params, array(':category_id' => $this->category_id, ':sort' => $this->sort, ':category_sort' => $this->category->sort, ':id' => $this->id));
     $prevProduct = InteriorItem::model()->published()->find($fullCriteria);
     if ($prevProduct === null) {
         $prevProduct = InteriorItem::model()->published()->find($criteria);
     }
     return $prevProduct;
 }
 public function actionShow($alias)
 {
     $model = InteriorItem::model()->published()->with(array('category', 'color', 'relatedStones' => array('with' => array('series', 'images' => array('scopes' => 'published')), 'scopes' => 'published', 'order' => 'relatedStones.title ASC')))->findByAlias($alias);
     if (!$model) {
         throw new CHttpException(404);
     }
     // Учитываем фильтр в каталоге
     $filter = Yii::app()->user->getState('interiorCatalogFilter');
     // Определяем следующий товар
     $nextProduct = $model->getNextProduct($filter);
     // Определяем предыдущий товар
     $prevProduct = $model->getPrevProduct($filter);
     // Добавляем в просмотренное
     $this->getModule()->getComponent('watched')->put($model);
     $this->render('item', array('model' => $model, 'nextProduct' => $nextProduct, 'prevProduct' => $prevProduct, 'returnUrl' => Yii::app()->user->getState('interiorCatalogReturnUrl')));
 }