/**
  * @inheritdoc
  */
 public function attributeLabels()
 {
     $attributeLabels = parent::attributeLabels();
     $attributeLabels['cms_widget_i18n_title'] = Yii::t('kalibao', 'model:title');
     $attributeLabels['cms_widget_group_i18n_title'] = Yii::t('kalibao', 'cms_widget:cms_widget_group_id');
     return $attributeLabels;
 }
 /**
  * Parse Widget
  * @param string $html Html to parse
  * @return mixed
  */
 protected function parseWidget($html)
 {
     $list = array();
     preg_match_all("#\\<cms_widget id=\"(.*)\">(.*)</cms_widget>#msU", $html, $list, PREG_SET_ORDER);
     $find = [];
     $replace = [];
     foreach ($list as $function) {
         // cache key
         $cacheKey = 'cms_widget_id:' . $function[1];
         // get model from cache
         if (($widgetModel = Yii::$app->commonCache->get($cacheKey)) === false) {
             $widgetModel = CmsWidget::find()->where(['id' => $function[1]])->asArray()->one();
             Yii::$app->commonCache->set($cacheKey, $widgetModel, CmsWidgetService::$cacheDuration, new TagDependency(['tags' => [CmsWidgetService::getCacheTag(), CmsWidgetService::getCacheTag($function[1])]]));
         }
         if ($widgetModel !== null) {
             $arg = json_decode($widgetModel['arg'], true);
             if ($arg === null) {
                 $arg = [];
             }
             $widget = $widgetModel['path'];
             $find[] = '<cms_widget id="' . $function[1] . '">' . $function[2] . '</cms_widget>';
             $replace[] = $widget::widget($arg);
         }
     }
     return str_replace($find, $replace, $html);
 }
Exemple #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCmsWidget()
 {
     return $this->hasOne(CmsWidget::className(), ['id' => 'cms_widget_id']);
 }
Exemple #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCmsWidgets()
 {
     return $this->hasMany(CmsWidget::className(), ['cms_widget_group_id' => 'id']);
 }