public function loadModel($id) { if (($model = Stone::model()->findByPk($id)) === null) { throw new CHttpException(404, 'Страница не найдена'); } return $model; }
public function run() { if (empty($this->model) || empty($this->type)) { return; } // Определяем тип товара для поиска товаров данного типа $productType = ProductType::model()->published()->findByAlias($this->type); if (!$productType) { return; } // Определяем товар данного типа с таким же названием, как заданный $relatedProduct = Stone::model()->published()->type($productType->id)->with('series')->findByAttributes(array('title' => $this->model->title)); // Получаем список рандомных товаров данного типа, похожих на заданный по цвету и виду камня $criteria = new CDbCriteria(); $criteria->compare('t.series_id', $this->model->series_id); $criteria->compare('t.color_id', $this->model->color_id); $notSearchIds = array($this->model->id); if ($relatedProduct !== null) { $notSearchIds[] = $relatedProduct->id; } $criteria->addNotInCondition('t.id', $notSearchIds); $criteria->order = 'RAND()'; $criteria->limit = 7; $models = Stone::model()->published()->type($productType->id)->with('series')->findAll($criteria); if ($relatedProduct !== null) { $models = array($relatedProduct) + $models; } $this->render($this->view, array('productType' => $productType, 'models' => $models, 'model' => $this->model)); }
protected function beforeAction($action) { $actions = array('index', 'create'); if (in_array($action->id, $actions)) { $this->item_id = (int) Yii::app()->getRequest()->getParam('item_id'); if (!$this->item_id) { throw new CHttpException(400, 'Не установлен ID товара'); } if (($this->item = Stone::model()->findByPk($this->item_id)) === null) { throw new CHttpException(404, 'Товар не найден'); } } return parent::beforeAction($action); }
public function run() { if (empty($this->model)) { return; } if (empty($this->model->relatedStones)) { // Получаем список рандомных товаров данного типа, похожих на заданный по цвету и виду камня $criteria = new CDbCriteria(); $criteria->compare('t.series_id', $this->model->series_id); $criteria->compare('t.color_id', $this->model->color_id); $criteria->addCondition('t.id <> :id'); $criteria->params[':id'] = $this->model->id; $criteria->order = 'RAND()'; if ($this->limit > 0) { $criteria->limit = (int) $this->limit; } elseif ($this->limit == '') { $criteria->limit = 4; } $models = Stone::model()->published()->with('series')->type($this->model->type_id)->findAll($criteria); } else { $models = $this->model->relatedStones(array('scopes' => 'published')); } $this->render($this->view, array('models' => $models, 'model' => $this->model)); }
</div> <div class="row-fluid control-group <?php echo $model->hasErrors('relatedStonesArray') ? 'error' : ''; ?> "> <?php echo $form->labelEx($model, 'relatedStonesArray'); ?> <?php $selected = CHtml::listData($model->relatedStones, 'id', 'title'); $options = array(); foreach ($selected as $key => $value) { $options[$key] = array('selected' => true); } $this->widget('bootstrap.widgets.TbSelect2', array('asDropDownList' => true, 'model' => $model, 'attribute' => 'relatedStonesArray', 'data' => CHtml::listData(Stone::model()->findAll(array('order' => 't.title ASC')), 'id', 'title'), 'htmlOptions' => array('multiple' => 'multiple', 'options' => $options), 'options' => array('minimumInputLength' => 3, 'placeholder' => 'Введите список камней', 'width' => '100%', 'allowClear' => true))); ?> </div> <?php $collapse = $this->beginWidget('bootstrap.widgets.TbCollapse'); ?> <div class="accordion-group"> <div class="accordion-heading"> <a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion2" href="#collapseOne"> Данные для SEO </a> </div> <div id="collapseOne" class="accordion-body collapse"> <div class="accordion-inner"> <div class="row-fluid control-group <?php
protected function refreshRelatedStones() { $relatedStones = $this->relatedStonesArray; ProjectStoneRelation::model()->deleteAllByAttributes(array('entity_id' => $this->id, 'entity_name' => 'Project')); if (is_array($relatedStones)) { foreach ($relatedStones as $id) { if (Stone::model()->exists('t.id = :id', array(':id' => $id))) { $relation = new ProjectStoneRelation(); $relation->entity_id = $this->id; $relation->stone_id = $id; $relation->save(); } } } }
/** * Список серий: **/ public function getItemsList() { return CHtml::listData(Stone::model()->findAll(), 'id', 'title'); }
public function actionAjaxstones($term) { if (Yii::app()->request->isAjaxRequest) { $criteria = new CDbCriteria(); $criteria->select = 't.id, t.title'; $criteria->condition = "t.title LIKE '{$term}%' " . "AND t.id IN (SELECT `stone_id` FROM " . InteriorStoneRelation::model()->tableName() . " WHERE `entity_name` = 'interior')"; $criteria->group = 't.title'; $criteria->order = 't.title ASC'; $items = array(); foreach (Stone::model()->findAll($criteria) as $item) { $items[] = array('id' => $item->id, 'label' => $item->title, 'value' => $item->title); } echo CJSON::encode($items); Yii::app()->end(); } }
public function actionRemove_from_favorite($id) { $id = (int) $_GET['id']; $model = Stone::model()->findByPk($id); if ($model !== null) { Yii::app()->favorite->remove($model->getId()); } if (Yii::app()->getRequest()->getIsAjaxRequest()) { Yii::app()->ajax->success(); } else { $this->redirect($model->url); } }
protected function _buildColorCountrySeoArray() { $stones = Stone::model()->resetScope()->findAll(array('order' => 't.sort ASC')); $seoArray = array(); foreach ($stones as $stone) { if ($stone->color_id == null || $stone->country_id == null) { continue; } $key = $stone->type_id . '_' . $stone->series_id . '_' . $stone->color_id . '_' . $stone->country_id; if (!in_array($key, $seoArray)) { $seoArray[] = $key; } } return $seoArray; }
public function actionAjaxstones($term) { if (Yii::app()->request->isAjaxRequest) { $criteria = new CDbCriteria(); $criteria->select = 't.id, t.title'; $criteria->condition = "t.title LIKE '{$term}%'"; $criteria->group = 't.title'; $criteria->order = 't.title ASC'; $items = array(); foreach (Stone::model()->findAll($criteria) as $item) { $items[] = array('id' => $item->id, 'label' => $item->title, 'value' => $item->title); } echo CJSON::encode($items); Yii::app()->end(); } }