/** * Changes layout_id to main layout_id before deleting this layout_id * @throws \yii\db\Exception */ public function changeContentLayoutId() { /** @var $model LayoutRecord */ $model = $this->owner; if ($main_id = LayoutRecord::getMainLayoutId($model->content)) { \Yii::$app->db->createCommand()->update('menu_item', ['layout_id' => $main_id], ['layout_id' => $model->id])->execute(); if ($model->content == 1) { \Yii::$app->db->createCommand()->update('content', ['layout_id' => $main_id], ['layout_id' => $model->id])->execute(); } } else { throw new ErrorException(\Yii::t('app', 'Main layout not exists!')); } }
/** * Finds the Layout model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return LayoutRecord the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = LayoutRecord::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Returns layout options for dropdown * @return array */ public function getLayoutListOptions() { return ArrayHelper::map(LayoutRecord::find()->where(['content' => LayoutRecord::CONTENT_ARTICLE])->activeStatus()->orderBy(['main' => SORT_DESC, 'title' => SORT_ASC])->all(), 'id', 'title'); }
/** * @return \yii\db\ActiveQuery */ public function getLayout() { return $this->hasOne(LayoutRecord::className(), ['id' => 'layout_id']); }
/** * Returns layout list options for dropdown * @return array */ public function getLayoutListOptions() { $session = Yii::$app->session; if (!$session['language_id']) { $session['language_id'] = LanguageRecord::getMainLanguageId(); } $items = []; switch ($this->content_type) { case MenuItemRecord::CONTENT_PAGE: $items = ArrayHelper::map(LayoutRecord::find()->where(['content' => LayoutRecord::CONTENT_PAGE])->activeStatus()->orderBy(['main' => SORT_DESC])->all(), 'id', 'title'); break; case MenuItemRecord::CONTENT_CATEGORY: $items = ArrayHelper::map(LayoutRecord::find()->where(['content' => LayoutRecord::CONTENT_CATEGORY])->activeStatus()->orderBy(['main' => SORT_DESC])->all(), 'id', 'title'); break; default: break; } return $items; }
/** * Returns dropdown layout list options * @param $tid integer content type id * @return \yii\console\Response|Response */ public function actionLayoutListOptions($tid) { $items = null; switch ($tid) { case MenuItemRecord::CONTENT_PAGE: $items = LayoutRecord::find()->where(['content' => LayoutRecord::CONTENT_PAGE])->activeStatus()->orderBy(['main' => SORT_DESC])->all(); break; case MenuItemRecord::CONTENT_CATEGORY: $items = LayoutRecord::find()->where(['content' => LayoutRecord::CONTENT_CATEGORY])->activeStatus()->orderBy(['main' => SORT_DESC])->all(); break; default: break; } $itemsOptions = ['arr' => false, 'prompt' => false]; return $this->renderPartial('_listOptions', compact('items', 'itemsOptions')); }