コード例 #1
0
ファイル: DbText.php プロジェクト: rafalsky/home-finance
 /**
  * @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;
 }
コード例 #2
0
ファイル: DbText.php プロジェクト: efabrikov/qreachers
 /**
  * @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;
 }
コード例 #3
0
ファイル: DbText.php プロジェクト: allhaze/renault
 /**
  * @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;
 }