/** * @return mixed|null */ public function getPageTitle() { $data = PageData::find()->select('title')->where(['id_page' => $this->id, 'language' => Yii::$app->language, 'status' => PageData::STATUS_ACTIVE])->one(); if (!$data) { $data = PageData::find()->select('title')->where(['id_page' => $this->id, 'status' => PageData::STATUS_ACTIVE])->one(); } return isset($data) ? $data->title : 'unknown'; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = PageData::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id_page' => $this->id_page, 'status' => $this->status, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'language', $this->language])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'keywords', $this->keywords]); return $dataProvider; }
/** * sitemap * @return string */ public function actionSitemap() { /* header */ Yii::$app->response->format = Response::FORMAT_RAW; $headers = Yii::$app->response->headers; $headers->add('Content-Type', 'application/xml'); /* ok */ $query = PageData::find()->select(['id_page', 'language', 'updated_at'])->where(['status' => PageData::STATUS_ACTIVE]); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count()]); $pages->setPageSize(Yii::$app->params['sitemapPageSize']); $models = $query->offset($pages->offset)->limit($pages->limit)->all(); return $this->renderPartial('sitemap', ['models' => $models]); }
/** * sitemap * @return mixed */ public function actionSitemap() { /* header response */ Yii::$app->response->format = Response::FORMAT_RAW; $headers = Yii::$app->response->headers; $headers->add('Content-Type', 'application/xml'); /* begin */ $sitemaps = []; /* blog sitemap */ $query = Blog::find()->where(['status' => Blog::STATUS_PUBLISHED]); $countQuery = clone $query; $pagination = new Pagination(['totalCount' => $countQuery->count()]); $pagination->setPageSize(Yii::$app->params['sitemapPageSize']); $pages = $pagination->getPageCount(); if ($pages > 0) { for ($i = 0; $i < $pages; $i++) { $sitemaps[] = Yii::$app->urlManager->createAbsoluteUrl(['/blog/sitemap', 'page' => $i + 1]); } } /* page sitemap */ $query = PageData::find()->where(['status' => PageData::STATUS_ACTIVE]); $countQuery = clone $query; $pagination = new Pagination(['totalCount' => $countQuery->count()]); $pagination->setPageSize(Yii::$app->params['sitemapPageSize']); $pages = $pagination->getPageCount(); if ($pages > 0) { for ($i = 0; $i < $pages; $i++) { $sitemaps[] = Yii::$app->urlManager->createAbsoluteUrl(['/page/sitemap', 'page' => $i + 1]); } } /* load modules sitemap */ $modules = scandir(\Yii::$app->vendorPath . '/modernkernel'); foreach ($modules as $module) { if (!preg_match('/[\\.]+/', $module)) { $moduleName = str_ireplace('yii2-', '', $module); if (method_exists(Yii::$app->getModule($moduleName), 'sitemap')) { $sitemaps = array_merge($sitemaps, Yii::$app->getModule($moduleName)->sitemap()); } } } return $this->renderPartial('sitemap', ['sitemaps' => $sitemaps]); }