/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Blog::find(); $query->joinWith(['author']); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]); $dataProvider->sort->attributes['fullname'] = ['asc' => ['{{%core_account}}.fullname' => SORT_ASC], 'desc' => ['{{%core_account}}.fullname' => SORT_DESC]]; /* user's blog */ if (Core::checkMCA(null, 'blog', 'manage')) { $query->andFilterWhere(['{{%core_blog}}.created_by' => Yii::$app->user->id]); } /* list all public blog */ if (Core::checkMCA(null, 'blog', 'index')) { $query->andFilterWhere(['{{%core_blog}}.status' => Blog::STATUS_PUBLISHED]); } $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; } // grid filtering conditions $query->andFilterWhere(['{{%core_blog}}.id' => $this->id, '{{%core_blog}}.created_by' => $this->created_by, '{{%core_blog}}.views' => $this->views, '{{%core_blog}}.status' => $this->status]); $query->andFilterWhere(['like', '{{%core_blog}}.title', $this->title])->andFilterWhere(['like', '{{%core_account}}.fullname', $this->fullname])->andFilterWhere(['like', '{{%core_blog}}.desc', $this->desc])->andFilterWhere(['like', '{{%core_blog}}.content', $this->content])->andFilterWhere(['like', '{{%core_blog}}.tags', $this->tags]); $query->andFilterWhere(['DATE(FROM_UNIXTIME(`{{%core_blog}}.updated_at`))' => $this->updated_at]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Blog::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'author', $this->author]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Blog::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['updated_at' => SORT_DESC]]]); $timestamp = null; if (isset($params['datetime'])) { $timestamp = strtotime($params['datetime']); } if (isset($params['category'])) { $query->joinWith("category")->andFilterWhere(['category.id' => $params['category'], "category.status" => Category::STATUS_ON]); } $query->andFilterWhere(['user_id' => $this->user_id, 'created_at' => $timestamp]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Blog::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, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'topic', $this->topic])->andFilterWhere(['like', 'detail', $this->detail])->andFilterWhere(['like', 'tag', $this->tag]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Blog::find(); // add conditions that should always apply here $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; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id, 'views' => $this->views, 'status' => $this->status, 'published_at' => $this->published_at, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'short_text', $this->short_text])->andFilterWhere(['like', 'text', $this->text]); return $dataProvider; }
public function actionEditBlog($id) { $categoriesId = Yii::$app->request->post("categorys"); $model = Blog::find()->where(['id' => $id, 'user_id' => Yii::$app->user->id])->one(); if (!empty($model)) { $model->load(Yii::$app->request->post(), ''); if ($model->save()) { if (!empty($model->categorys)) { CategoryVia::deleteAll(['blog_id' => $model->id]); $model->setCategories(); } return $model; } return $model->getErrors(); } return "Blog not found"; }
/** * find blog by $slug * @param string $slug * @return array|Blog|null * @throws NotFoundHttpException */ protected function findBySlug($slug) { if (($model = Blog::find()->where(['slug' => $slug, 'status' => Blog::STATUS_PUBLISHED])->one()) !== null) { return $model; } else { throw new NotFoundHttpException(Yii::t('app', 'The requested page does not exist.')); } }
/** * get random blog * @param int $limit * @return Blog[] */ public static function random($limit = 10) { return Blog::find()->orderBy('rand()')->limit($limit)->all(); }
public function actionViews() { $this->layout = '/blog'; $slug = Yii::$app->request->get('slug'); $blog = Blog::find()->where(['slug' => $slug])->one(); if ($blog) { $viwsQuantity = (int) $blog->view; $blog->view = $viwsQuantity + 1; $blog->updateAttributes(['view']); $coment_model = Comment::find()->where(['blog_id' => $blog->id])->all(); $this->meta = $blog; $prevBlog = Blog::find()->where('id >' . $blog->id)->orderBy('id ASC')->limit(1)->asArray()->all(); $nextBlog = Blog::find()->where('id <' . $blog->id)->orderBy('id DESC')->limit(1)->asArray()->all(); //vd($prevBlog[0]['slug']); return $this->render('views', ['model' => $blog, 'coment_model' => $coment_model, 'nextBlog' => !empty($nextBlog) ? $nextBlog[0]['slug'] : NULL, 'prevBlog' => !empty($prevBlog) ? $prevBlog[0]['slug'] : NULL]); } else { $this->redirect('site/index'); } }
public function actionBlog() { $countPostOnPage = SetupSite::getParam('countPostOnPage'); $data = $this->getCommonDate(); $modelGoodsCategories = GoodsCategory::find()->all(); $modelBanner = Banner::find()->where(['status' => 0])->all(); $modelBrends = Brend::find()->all(); $modelBlog = Blog::find(); $countQuery = clone $modelBlog; $pages = new Pagination(['totalCount' => $countQuery->count(), 'defaultPageSize' => 3]); $models = $modelBlog->offset($pages->offset)->limit($countPostOnPage)->orderBy('created_at DESC')->all(); return $this->render('blog', ['models' => $models, 'pages' => $pages, 'data' => $data, 'modelGoodsCategories' => $modelGoodsCategories, 'modelBrends' => $modelBrends, 'modelBanner' => $modelBanner]); }
public function actionViews($id) { $this->layout = '/blog'; $id = Yii::$app->request->get('id'); $blog = Blog::find()->where(['id' => $id])->one(); $viwsQuantity = (int) $blog->view; $blog->view = $viwsQuantity + 1; $blog->updateAttributes(['view']); $coment_model = Comment::find()->where(['blog_id' => $id])->all(); return $this->render('views', ['model' => $blog, 'coment_model' => $coment_model]); }
/** * 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]); }