/** * Deletes an existing AboutCategory model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionDelete($id) { $aboutAbout = About::find()->andWhere(['category_id' => $id])->one(); if (null === $aboutAbout) { $this->findAbout($id)->delete(); } else { Yii::$app->session->setFlash('alert', ['body' => \Yii::t('backend', 'Can not delete category #' . $id . '. It used in other table. Change category for about #' . $aboutAbout->id . ' before delete.'), 'options' => ['class' => 'alert-error']]); } return $this->redirect(['index']); }
/** * Creates data provider instance with search query applied * @return ActiveDataProvider */ public function search($params) { $query = About::find(); if (!\Yii::$app->user->can('administrator')) { $query->forDomain(); } $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'slug' => $this->slug, 'author_id' => $this->author_id, 'category_id' => $this->category_id, 'updater_id' => $this->updater_id, 'status' => $this->status, 'published_at' => $this->published_at, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'domain_id' => $this->domain_id]); $query->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'price', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'weight', $this->weight])->andFilterWhere(['like', 'body', $this->body])->andFilterWhere(['like', 'before_body', $this->before_body])->andFilterWhere(['like', 'after_body', $this->after_body])->andFilterWhere(['like', 'on_scenario', $this->on_scenario]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = About::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'description_en', $this->description_en])->andFilterWhere(['like', 'description_ru', $this->description_ru])->andFilterWhere(['like', 'description_am', $this->description_am]); return $dataProvider; }
/** * Lists all AboutPage models. * @return mixed */ public function actionIndex() { $searchModel = new AboutPageSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); $dataProvider->sort = ['defaultOrder' => ['published_at' => SORT_DESC]]; $dataProvider->query->andFilterWhere(['locale' => Yii::$app->language]); if (Yii::$app->request->get('mid')) { $parentModel = About::find(['id' => Yii::$app->request->get('mid')])->one(); $parentModel = About::find()->andFilterWhere(['domain_id' => Yii::getAlias('@defaultDomainId'), 'locale' => 'uk-UA', 'locale_group_id' => $parentModel->locale_group_id])->one(); $models = AboutPage::find()->andFilterWhere(['domain_id' => Yii::getAlias('@defaultDomainId'), 'locale' => 'uk-UA', 'about_id' => $parentModel->id])->all(); } else { $models = AboutPage::find()->andFilterWhere(['domain_id' => Yii::getAlias('@defaultDomainId'), 'locale' => 'uk-UA'])->all(); } $list = \yii\helpers\ArrayHelper::map($models, 'locale_group_id', 'title'); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'list' => $list]); }
/** * Finds the About model based on its primary key value. * If the about is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return About the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findAbout($id) { if (($about = About::findOne($id)) !== null) { return $about; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getAbout() { return $this->hasOne(About::className(), ['id' => 'about_id']); }
public function actionAbout() { $about = About::find()->one(); //var_dump($about); exit; return $this->render('about', ['about' => $about]); }
public static function multiSave($model) { //\yii\helpers\VarDumper::dump(Yii::$app->request->post(),11,1); die(); $defaultAttributes = []; foreach ($model->getModels() as $key => $v) { foreach ($model->getModel($key)->attributes() as $attrKey) { if (empty($defaultAttributes[$attrKey])) { if (!empty($model->getModel($key)->{$attrKey})) { if ('[]' != $model->getModel($key)->{$attrKey}) { $defaultAttributes[$attrKey] = $model->getModel($key)->{$attrKey}; } } } } } unset($defaultAttributes['id']); unset($defaultAttributes['locale']); unset($defaultAttributes['locale_group_id']); //unset($defaultAttributes['slug']); $groupId = self::getLastLocaleGroupId() + 1; foreach ($model->getModels() as $key => $v) { if (!$model->getModel($key)->locale_group_id) { $model->getModel($key)->locale_group_id = $groupId; } foreach ($defaultAttributes as $key2 => $value2) { if (empty($model->getModel($key)->{$key2}) or "[]" == $model->getModel($key)->{$key2}) { $model->getModel($key)->{$key2} = $value2; } } //about_id fix $modelGroupId = About::findOne(['id' => $model->getModel($key)->about_id])->locale_group_id; $currentAboutId = About::findOne(['locale_group_id' => $modelGroupId, 'locale' => $model->getModel($key)->locale])->id; $model->getModel($key)->about_id = $currentAboutId; //\yii\helpers\VarDumper::dump($model->getModel($key),11,1); } return $model->save(); }
public function afterDelete() { $about = About::find()->andWhere(['locale_group_id' => $this->locale_group_id, 'domain_id' => Yii::$app->user->identity->domain_id])->one(); if ($about) { $about->delete(); } return parent::afterDelete(); }
<?php $forms = ['label' => Yii::t('backend', 'Forms'), 'icon' => '<i class="fa fa-edit"></i>', 'options' => ['class' => 'treeview'], 'items' => [['label' => Yii::t('backend', 'Subscribes'), 'url' => ['/subscribes/index'], 'icon' => '<i class="fa fa-angle-double-right"></i>'], ['label' => Yii::t('backend', 'Corporate Sales'), 'url' => ['/corporate/index'], 'icon' => '<i class="fa fa-angle-double-right"></i>']]]; $feedbacks = ['label' => Yii::t('backend', 'Feedback'), 'icon' => '<i class="fa fa-envelope-o"></i>', 'options' => ['class' => 'treeview'], 'items' => [['label' => Yii::t('backend', 'Emails'), 'url' => ['/emailf/index'], 'icon' => '<i class="fa fa-at"></i>'], ['label' => Yii::t('backend', 'Questions'), 'url' => ['/feedback/index'], 'icon' => '<i class="fa fa-comments-o"></i>']]]; ?> <?php } else { ?> <?php $feedbacks = ['label' => Yii::t('backend', 'Feedback'), 'icon' => '<i class="fa fa-envelope-o"></i>', 'options' => ['class' => 'treeview'], 'url' => ['/feedback/index']]; ?> <?php } ?> <?php echo Menu::widget(['options' => ['class' => 'sidebar-menu'], 'labelTemplate' => '<a href="#">{icon}<span>{label}</span>{right-icon}{badge}</a>', 'linkTemplate' => '<a href="{url}">{icon}<span>{label}</span>{right-icon}{badge}</a>', 'submenuTemplate' => "\n<ul class=\"treeview-menu\">\n{items}\n</ul>\n", 'activateParents' => true, 'items' => [['label' => Yii::t('backend', 'Timeline'), 'icon' => '<i class="fa fa-bar-chart-o"></i>', 'url' => ['/timeline-event/index'], 'badge' => TimelineEvent::find()->today()->count(), 'badgeBgClass' => 'label-success'], ['label' => Yii::t('backend', 'Content'), 'icon' => '<i class="fa fa-edit"></i>', 'options' => ['class' => 'treeview'], 'items' => [['label' => Yii::t('backend', 'Pages'), 'url' => ['/page/index'], 'icon' => '<i class="fa fa-angle-double-right"></i>', 'active' => preg_match('/^page/', Yii::$app->request->pathinfo)], ['label' => Yii::t('backend', 'News'), 'url' => ['/article/index'], 'icon' => '<i class="fa fa-angle-double-right"></i>', 'active' => preg_match('/^article/', Yii::$app->request->pathinfo)], ['label' => Yii::t('backend', 'Promo'), 'url' => ['/promo/index'], 'icon' => '<i class="fa fa-angle-double-right"></i>', 'active' => preg_match('/^promo/', Yii::$app->request->pathinfo)], ['label' => Yii::t('backend', 'Models'), 'icon' => '<i class="fa fa-edit"></i>', 'options' => ['class' => 'treeview'], 'items' => [['label' => Yii::t('backend', 'Categories'), 'url' => ['/model-category/index'], 'icon' => '<i class="fa fa-angle-double-right"></i>'], ['label' => Yii::t('backend', 'List'), 'icon' => '<i class="fa fa-edit"></i>', 'options' => ['class' => 'treeview'], 'items' => Model::getLeftMenuListItems()], ['label' => Yii::t('backend', 'Pages'), 'icon' => '<i class="fa fa-edit"></i>', 'options' => ['class' => 'treeview'], 'items' => Model::getLeftMenuPageItems()]]], $forms, ['label' => Yii::t('backend', 'Service pages'), 'icon' => '<i class="fa fa-edit"></i>', 'options' => ['class' => 'treeview'], 'items' => Service::getLeftMenuItems()], ['label' => Yii::t('backend', 'About pages'), 'icon' => '<i class="fa fa-edit"></i>', 'options' => ['class' => 'treeview'], 'items' => About::getLeftMenuItems()], ['label' => Yii::t('backend', 'Finance pages'), 'icon' => '<i class="fa fa-edit"></i>', 'options' => ['class' => 'treeview'], 'items' => Finance::getLeftMenuItems()], ['label' => Yii::t('backend', 'Common blocks'), 'url' => ['/block/index'], 'icon' => '<i class="fa fa-angle-double-right"></i>']]], ['label' => Yii::t('backend', 'SEO'), 'icon' => '<i class="fa fa-edit"></i>', 'options' => ['class' => 'treeview'], 'items' => [['label' => Yii::t('backend', 'robots.txt'), 'url' => ['widget-text/update?id=frontend.web.robots.txt'], 'icon' => '<i class="fa fa-angle-double-right"></i>'], ['label' => Yii::t('backend', 'sitemap.xml'), 'url' => Domain::getFrontendUrl() . '/sitemap.xml', 'icon' => '<i class="fa fa-angle-double-right"></i>', 'template' => '<a href="{url}" target="_blank"><i class="fa fa-angle-double-right"></i><span>{label}</span></a>'], ['label' => Yii::t('backend', 'Third-party code'), 'url' => ['custom-code/index'], 'icon' => '<i class="fa fa-angle-double-right"></i>']]], $feedbacks, ['label' => Yii::t('backend', 'Domains'), 'icon' => '<i class="fa fa-university"></i>', 'url' => ['/domain/index'], 'visible' => Yii::$app->user->can('administrator')], ['label' => Yii::t('backend', 'Users'), 'icon' => '<i class="fa fa-users"></i>', 'url' => ['/user/index'], 'visible' => Yii::$app->user->can('administrator')], ['label' => Yii::t('backend', 'System'), 'icon' => '<i class="fa fa-cogs"></i>', 'options' => ['class' => 'treeview'], 'visible' => Yii::$app->user->can('administrator'), 'items' => [['label' => Yii::t('backend', 'i18n'), 'icon' => '<i class="fa fa-flag"></i>', 'options' => ['class' => 'treeview'], 'items' => [['label' => Yii::t('backend', 'i18n Source Message'), 'url' => ['/i18n/i18n-source-message/index'], 'icon' => '<i class="fa fa-angle-double-right"></i>'], ['label' => Yii::t('backend', 'i18n Message'), 'url' => ['/i18n/i18n-message/index'], 'icon' => '<i class="fa fa-angle-double-right"></i>']]], ['label' => Yii::t('backend', 'Key-Value Storage'), 'url' => ['/key-storage/index'], 'icon' => '<i class="fa fa-angle-double-right"></i>'], ['label' => Yii::t('backend', 'File Storage'), 'url' => ['/file-storage/index'], 'icon' => '<i class="fa fa-angle-double-right"></i>'], ['label' => Yii::t('backend', 'Cache'), 'url' => ['/cache/index'], 'icon' => '<i class="fa fa-angle-double-right"></i>'], ['label' => Yii::t('backend', 'File Manager'), 'url' => ['/file-manager/index'], 'icon' => '<i class="fa fa-angle-double-right"></i>'], ['label' => Yii::t('backend', 'Widgets list'), 'url' => ['/site/widgets'], 'icon' => '<i class="fa fa-angle-double-right"></i>'], ['label' => Yii::t('backend', 'Logs'), 'url' => ['/log/index'], 'icon' => '<i class="fa fa-angle-double-right"></i>', 'badge' => \backend\models\SystemLog::find()->count(), 'badgeBgClass' => 'label-danger']]]]]); ?> </section> <!-- /.sidebar --> </aside> <!-- Right side column. Contains the navbar and content of the page --> <aside class="content-wrapper"> <!-- Content Header (Page header) --> <section class="content-header"> <h1> <?php echo $this->title; ?> <?php if (isset($this->params['subtitle'])) {
/** * @return \yii\db\ActiveQuery */ public function getAbouts() { return $this->hasMany(About::className(), ['category_id' => 'id']); }