Ejemplo n.º 1
0
 /**
  * @inheritdoc
  */
 public function attributeLabels()
 {
     $attributeLabels = parent::attributeLabels();
     $attributeLabels['cms_layout_i18n_name'] = Yii::t('kalibao', 'model:title');
     return $attributeLabels;
 }
Ejemplo n.º 2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCmsLayout()
 {
     return $this->hasOne(CmsLayout::className(), ['id' => 'cms_layout_id']);
 }
Ejemplo n.º 3
0
 /**
  * Load page content models
  * @param integer $layout Layout ID
  * @param integer|null $page Page ID
  * @return array
  * @throws Exception
  */
 protected function loadPageContentsModels($layout, $page = null)
 {
     $cmsPageContents = [];
     $cmsLayout = CmsLayout::find()->select('max_container')->where(['id' => $layout])->one();
     if ($cmsLayout !== null) {
         for ($i = 1; $i <= $cmsLayout->max_container; ++$i) {
             $cmsPageContents[$i]['main'] = new CmsPageContent(['scenario' => 'insert']);
             $cmsPageContents[$i]['main']->index = $i;
             $cmsPageContents[$i]['i18n'] = new CmsPageContentI18n(['scenario' => 'beforeInsert']);
             $cmsPageContents[$i]['i18n']->i18n_id = Yii::$app->language;
         }
         if ($page !== null) {
             $results = CmsPageContent::find()->joinWith(['cmsPageContentI18ns' => function ($query) {
                 $query->onCondition(['cms_page_content_i18n.i18n_id' => Yii::$app->language]);
             }])->where(['cms_page_id' => $page])->all();
             foreach ($results as $result) {
                 $scenario = 'update';
                 if (!isset($cmsPageContents[$result->index]['main'])) {
                     $scenario = 'delete';
                 }
                 $cmsPageContents[$result->index]['main'] = $result;
                 $cmsPageContents[$result->index]['main']->scenario = $scenario;
                 if (isset($result->cmsPageContentI18ns[0])) {
                     $cmsPageContents[$result->index]['i18n'] = $result->cmsPageContentI18ns[0];
                     $cmsPageContents[$result->index]['i18n']->scenario = $scenario;
                 }
             }
         }
     } else {
         throw new Exception('No layout');
     }
     return $cmsPageContents;
 }