/**
  * Finds the WidgetText model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return WidgetText the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = WidgetText::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * Creates data provider instance with search query applied
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = WidgetText::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'key', $this->key])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'body', $this->body]);
     return $dataProvider;
 }
Example #3
0
 /**
  * @return string
  */
 public function run()
 {
     $cacheKey = [WidgetText::className(), $this->key];
     $content = \Yii::$app->cache->get($cacheKey);
     if (!$content) {
         $model = WidgetText::findOne(['key' => $this->key, 'status' => WidgetText::STATUS_ACTIVE]);
         if ($model) {
             $content = $model->body;
             \Yii::$app->cache->set($cacheKey, $content, 60 * 60 * 24);
         }
     }
     return $content;
 }
Example #4
0
 /**
  * Creates data provider instance with search query applied
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = WidgetText::find();
     if (!\Yii::$app->user->can('administrator')) {
         $query->forDomain();
     }
     if ('custom-code' == Yii::$app->controller->id) {
         $query->customCode();
     }
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'status' => $this->status, 'domain_id' => $this->domain_id]);
     $query->andFilterWhere(['like', 'key', $this->key])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'body', $this->body]);
     return $dataProvider;
 }
Example #5
0
 /**
  * @return string
  */
 public function run()
 {
     $cacheKey = [WidgetText::className(), $this->key];
     $content = Yii::$app->cache->get($cacheKey);
     if (!$content) {
         $model = WidgetText::findOne(['key' => $this->key, 'status' => WidgetText::STATUS_ACTIVE]);
         if (!$model) {
             //try find en-us locale
             $pos = strrpos($this->key, '.');
             $base = substr($this->key, 0, $pos);
             $this->key = $base . '.' . Yii::$app->sourceLanguage;
             $model = WidgetText::findOne(['key' => $this->key, 'status' => WidgetText::STATUS_ACTIVE]);
         }
         if ($model) {
             $content = $model->body;
             Yii::$app->cache->set($cacheKey, $content, 60 * 60 * 24);
         }
     }
     return $content;
 }
Example #6
0
 /**
  * @return string
  */
 public function run()
 {
     $cacheKey = [WidgetText::className(), $this->key, $this->domain_id];
     $content = Yii::$app->cache->get($cacheKey);
     if (!$content) {
         $models = WidgetText::findAll(['key' => $this->key, 'status' => WidgetText::STATUS_ACTIVE, 'domain_id' => $this->domain_id]);
         if (!$models) {
             //try find en-us locale
             $pos = strrpos($this->key, '.');
             $base = substr($this->key, 0, $pos);
             $this->key = $base . '.' . Yii::$app->sourceLanguage;
             $models = WidgetText::findAll(['key' => $this->key, 'status' => WidgetText::STATUS_ACTIVE]);
         }
         if ($models) {
             $content = '';
             foreach ($models as $model) {
                 $content .= $model->body;
             }
             Yii::$app->cache->set($cacheKey, $content, 1);
         }
     }
     return $content;
 }
Example #7
0
 private function saveRobotsRow($key, $title)
 {
     $model = new WidgetText();
     $model->key = $key;
     $model->title = $title;
     $model->domain_id = \Yii::$app->user->identity->domain_id;
     $model->body = 'User-agent: * ' . PHP_EOL . 'Disallow:/';
     $model->status = 1;
     $model->save();
 }