Example #1
0
 public function run()
 {
     $model = \app\models\Block::find()->where(['slug' => $this->slug])->one();
     if ($model !== null) {
         return $this->render('block', ['model' => $model]);
     }
 }
Example #2
0
 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()]);
 }
Example #3
0
 public function render()
 {
     $id = $this->params->id;
     $app = Application::instance();
     $blocks = \App\Models\Block::findAllBySection($id, ['order' => '`order`']);
     $ret = '<section role="section" data-section-id="' . $id . '">' . "\n";
     foreach ($blocks as $block) {
         try {
             $content = $app->callBlock($block->path, $block->template, new Std(json_decode($block->options, true)));
         } catch (Exception $e) {
             $content = $e->getMessage();
         }
         $ret .= '<article role="block" data-block-id="' . $block->getPk() . '">' . $content . '</article>' . "\n";
     }
     return $ret . '</section>' . "\n";
 }
 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);
 }
Example #5
0
 /**
  * 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;
 }
Example #6
0
 public function actionUpdateBlockOptions($id, $options)
 {
     $block = Block::findByPK($id);
     if (empty($block)) {
         $this->data->result = false;
         return;
     }
     $opt = [];
     foreach ($options as $option) {
         if ('template' == $option['name']) {
             $block->template = $option['value'];
             continue;
         }
         $opt[$option['name']] = $option['value'];
     }
     $block->options = json_encode($opt);
     if (false !== $block->save()) {
         $this->data->result = true;
     } else {
         $this->data->result = false;
     }
 }
Example #7
0
 public static function getBlockContent($id, $language)
 {
     /** @var Block $model */
     $model = Block::findOne($id);
     return !is_null($model) ? $model->getContent($language, '') : '';
 }
Example #8
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getBlocks()
 {
     return $this->hasMany(Block::className(), ['state' => 'name']);
 }
Example #9
0
 protected function clearDatabasesForScenario()
 {
     \App\Models\Block::truncate();
     \App\Models\Transaction::truncate();
     \App\Models\Notification::truncate();
     \App\Models\MonitoredAddress::truncate();
     \App\Models\PaymentAddress::truncate();
     \App\Models\Send::truncate();
     \App\Models\User::truncate();
     \App\Models\Account::truncate();
     \App\Models\APICall::truncate();
     \App\Models\LedgerEntry::truncate();
     return;
 }
Example #10
0
 /**
  * Finds the Link model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Link the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Block::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException(Yii::t('app', 'PAGE_NOT_FOUND'));
     }
 }
Example #11
0
 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();
     }
 }
Example #12
0
 /**
  * Finds the Block model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Block the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Block::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #13
0
 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();
     }
 }
Example #14
0
 /**
  * Finds the Block model based on its slug value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $slug
  * @return Block the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModelBySlug($slug)
 {
     if (($model = Block::findOne(['slug' => $slug])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #15
0
?>
        </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;
}
?>
Example #16
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getBlock()
 {
     return $this->hasOne(Block::className(), ['id' => 'block_id']);
 }
 /**
  * remove a block
  *
  * @return Redirect
  */
 protected function postRemoveBlock(Request $request, $id)
 {
     $block = Block::where('id', $id)->firstOrFail();
     $questionaire = $block->questionaire()->get()->first();
     $this->authorize('questionaire-block-edit', $questionaire);
     $this->removeBlock($block, $request);
     return Redirect::action('Observation\\QuestionaireController@getBlocks', $questionaire->id)->with('status', 'Removed');
 }
Example #18
0
 public function deleteAll()
 {
     return Block::truncate();
 }
Example #19
0
<?php

use app\models\Block;
/** @var $id string */
/** @var Block $block */
$block = Block::findOne($id);
if (!is_null($block)) {
    ?>
<div class="block_<?php 
    echo $id;
    ?>
">
    <?php 
    echo $block->getContent(Yii::$app->language);
    ?>
</div>
<?php 
}