public function run() { $model = \app\models\Block::find()->where(['slug' => $this->slug])->one(); if ($model !== null) { return $this->render('block', ['model' => $model]); } }
public function actionIndex() { $curUser = \Yii::$app->user->id; UserSettingsBlock::sync($curUser); //todo return data model $block = Block::find()->with('links')->where(['hidden' => Block::STATUS_SHOW, 'type' => Block::TYPE_TAB])->orderBy('order')->all(); $model = UserSettingsBlock::find()->with('block')->orderBy('column, order')->where(['{{%user_settings_block}}.user_id' => $curUser])->all(); $msg = Message::find()->where(['status' => Message::STATUS_SHOW])->all(); return $this->render('index', ['model' => $model, 'blocks' => $block, 'messages' => $msg, 'link' => Link::getLinksBlocks()]); }
public function actionEditUserBlock($id) { $userModel = $this->findUserBlock($id); $model = Block::find()->with('links')->where(['id' => $userModel->block_id])->one(); $states = State::find()->all(); $test = Link::find()->where(['id' => 2])->one(); if ($userModel->load(Yii::$app->request->post()) && $userModel->save()) { Yii::$app->getSession()->setFlash('success', Yii::t('app', '{model} SUCCESS_UPDATED', ['model' => $model->title])); } return $this->render('userSettings', ['userModel' => $userModel, 'model' => $model, 'states' => $states, 'test' => $test]); }
public static function sync($userId) { $blocks = Block::find()->where(['type' => Block::TYPE_BLOCK])->all(); //TODO add this template $userBlocks = self::find()->where(['user_id' => $userId])->indexBy('block_id')->all(); foreach ($blocks as $block) { if (!array_key_exists($block->id, $userBlocks)) { $ub = new self(); $ub->attributes = $block->attributes; $ub->user_id = $userId; $ub->block_id = $block->id; $ub->save(); } } $blocksId = ArrayHelper::map($blocks, 'id', 'id'); self::deleteAll('block_id NOT IN (' . implode(', ', $blocksId) . ') and user_id = ' . $userId); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Block::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere(['active' => $this->active]); $query->andFilterWhere(['like', 'id', $this->id])->andFilterWhere(['like', 'url_code', $this->url_code]); $query->joinWith('blockLangs'); $query->andFilterWhere(['like', 'block_lang.title', $this->title]); return $dataProvider; }
?> </div> <div class="col-md-6"> <?php echo $form->field($model, 'tooltip')->textInput(['maxlength' => 128]); ?> </div> </div> <?php echo $form->field($model, 'href')->textInput(['maxlength' => 128]); ?> <?php echo $form->field($model, 'block_id')->dropDownList(ArrayHelper::map(Block::find()->all(), 'id', 'title')); ?> <div class="row"> <div class="col-md-3"> <?php echo $form->field($model, 'order')->textInput(); ?> </div> <div class="col-md-3"> <?php if ($model->isNewRecord) { $model->status = $model::STATUS_ACTIVE; } ?>
public function updateURLCode($name = null) { if (empty($this->url_code)) { if (empty($name)) { $name = $this->getTitle(); } $code = StoreUtils::url_slug($name); $urlCode = $code; $exists = Block::find()->where('id<>:id and url_code=:code', [':id' => $this->id, ':code' => $urlCode])->exists(); $index = 1; while ($exists) { $urlCode = $code . '-' . $index++; $exists = Block::find()->where('id<>:id and url_code=:code', [':id' => $this->id, ':code' => $urlCode])->exists(); } $this->url_code = $urlCode; $this->save(); } }
public function actionPage() { $request = Yii::$app->request; $block = null; if ($code = $request->get('code')) { $block = Block::find()->where(['url_code' => $code])->one(); if (is_null($block)) { $block = Block::findOne($code); } } if (!is_null($block)) { return $this->render('page', ['model' => $block]); } else { return $this->goHome(); } }
/** * Lists all Block models. * @return mixed */ public function actionAdmin() { $dataProvider = new ActiveDataProvider(['query' => Block::find()]); return $this->render('admin', ['dataProvider' => $dataProvider]); }