public function bonusIsExists($attribute) { $this->bonusesModel = Bonuses::model()->findByPk($this->bonus_id); if (!$this->bonusesModel) { $this->addError($attribute, Yii::t('backend', 'Выберите бонус')); } }
public function bonusIsExists() { if (!$this->hasErrors()) { $model = Bonuses::model()->findByPk($this->bonus_id); if ($model === NULL) { $this->addError(__FUNCTION__, Yii::t('backend', 'Выберите бонус.')); } } }
public function actionIndex() { $bonuses = Bonuses::model()->opened()->findAll(); $ids = array(); foreach ($bonuses as $bonus) { $ids[] = $bonus->getPrimaryKey(); } unset($bonuses); $dataProvider = new CActiveDataProvider('UserBonuses', array('criteria' => array('order' => 'created_at DESC', 'condition' => 't.user_id = :user_id', 'params' => array('user_id' => user()->getId()), 'with' => array('bonusInfo' => array('with' => array('items' => array('scopes' => array('opened'), 'with' => 'itemInfo'))))), 'pagination' => array('pageSize' => config('cabinet.bonuses.limit'), 'pageVar' => 'page'))); $dataProvider->criteria->addInCondition('t.bonus_id', $ids); $this->render('//cabinet/bonuses/index', array('dataProvider' => $dataProvider)); }
/** * Редактирование предмета в бонусе * * @param int $bonus_id * @param int $item_id */ public function actionItemEdit($bonus_id, $item_id) { $model = BonusesItems::model()->findByPk($item_id); if ($model === NULL) { user()->setFlash(FlashConst::MESSAGE_ERROR, Yii::t('backend', 'Предмет не найден.')); $this->redirect(array('/backend/bonuses/items')); } $model->item_name = $model->itemInfo->name . ($model->itemInfo->add_name ? ' (' . $model->itemInfo->add_name . ')' : ''); if (isset($_POST['BonusesItems'])) { $model->setAttributes($_POST['BonusesItems']); if ($model->save()) { user()->setFlash(FlashConst::MESSAGE_SUCCESS, Yii::t('backend', 'Предмет сохранен.')); $this->refresh(); } } $this->render('//bonuses/items/form', array('bonus' => Bonuses::model()->findByPk($bonus_id), 'model' => $model)); }
<p class="help-block"><?php echo Yii::t('backend', 'К примеру'); ?> : 1111-MP09-SREW-MP5S <a class="js-generate-new-code"><?php echo Yii::t('backend', 'Сгенерировать код'); ?> </a></p> </div> </div> <div class="form-group"> <?php echo $form->labelEx($model, 'bonus_id', array('class' => 'col-lg-3 control-label')); ?> <div class="col-lg-9"> <?php echo $form->dropDownList($model, 'bonus_id', CHtml::listData(Bonuses::model()->findAll(), 'id', 'title'), array('class' => 'form-control')); ?> </div> </div> <div class="form-group"> <?php echo $form->labelEx($model, 'limit', array('class' => 'col-lg-3 control-label')); ?> <div class="col-lg-9"> <?php echo $form->textField($model, 'limit', array('placeholder' => $model->getAttributeLabel('limit'), 'class' => 'form-control')); ?> <p class="help-block"><?php echo Yii::t('backend', 'Сколько раз можно активировать этот код пользователю'); ?> </p>