public function getListByCategory($slug, $fields = [], $with = [], $page = false, $pageSize = false, $order = '') { $category = Category::getInstance()->getBySlug($slug); $model = self::$model->find()->select($fields)->where(['type' => Content::TYPE_ARTICLE, 'status' => Content::STATUS_ACTIVE, 'meta_id' => $category['id']])->join('RIGHT JOIN', Relationship::tableName() . ' relation', 'content_id=id'); $countModel = clone $model; $pagination = new Pagination(['totalCount' => $countModel->count(), 'pageSize' => $pageSize]); if ($page) { $pagination->setPage($page, true); } switch (strtoupper($order)) { case 'VIEW': $model->orderBy('view_total DESC'); break; case 'COMMENT': $model->orderBy('comment_total DESC'); break; case 'CREATED': $model->orderBy('created_at DESC'); break; case 'UPDATED': $model->orderBy('updated_at DESC'); break; } return ['data' => $model->with($with)->limit($pagination->getLimit())->offset($pagination->getOffset())->all(), 'pagination' => $pagination]; }
public function getList($fields = [], $with = [], $pageSize = false, $page = false) { $model = self::$model->find()->where(['type' => Content::TYPE_PAGE, 'status' => Content::STATUS_ACTIVE]); $countModel = clone $model; $pagination = new Pagination(['totalCount' => $countModel->count('id'), 'pageSize' => $pageSize]); if ($page) { $pagination->setPage($page, true); } return ['data' => $model->select($fields)->with($with)->orderBy('created_at desc')->limit($pagination->getLimit())->offset($pagination->getOffset())->asArray()->all(), 'pagination' => $pagination]; }
public function search($params) { $query = Content::find(); switch ($this->scenario) { case Content::SCENARIO_PAGE: $query->andFilterWhere(['type' => Content::TYPE_PAGE]); break; case Content::SCENARIO_ARTICLE: $query->andFilterWhere(['type' => Content::TYPE_ARTICLE]); break; case Content::SCENARIO_LINK: $query->andFilterWhere(['type' => Content::TYPE_LINK]); break; default: $query->andFilterWhere(['type' => Content::TYPE_ARTICLE]); break; } $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'order' => $this->order, 'status' => $this->status, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, 'allow_comment' => $this->allow_comment, 'allow_feed' => $this->allow_feed, 'view_total' => $this->view_total]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'text', $this->text]); return $dataProvider; }
/** * 统计文章数量 * @param bool $isAllStatus 默认统计全部,如果false只统计发布状态的文章 * @return int */ public function getPostCount($isAllStatus = true) { $whereArr = ['type' => Content::TYPE_POST]; if (!$isAllStatus) { $whereArr['status'] = Content::STATUS_PUBLISH; } return Content::find()->where($whereArr)->count(); }
public function actionEdit($id) { $model = Content::find()->where(['id' => $id])->one(); if (isset($_POST['Content']) && $model->load(Yii::$app->request->post())) { if ($model->validate() && $model->save()) { Yii::$app->getSession()->addFlash('success', '<b>Запись успешно отредактирована!</b>'); } else { Yii::$app->getSession()->addFlash('error', '<b>Произошла ошибка. Запись не изменена</b>'); } } return $this->render('edit', ['model' => $model]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Content::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'flat_page_id' => $this->flat_page_id, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
public function actionCategory($id) { $model = Category::findOne($id); $params['model'] = $model; $query = Content::find(); $query->andFilterWhere(['status' => Content::STATUS_PUBLISH, 'category_id' => $model->id]); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count()]); $pages->pageSize = 5; $params['pages'] = $pages; $models = $query->offset($pages->offset)->limit($pages->limit)->orderBy('id DESC')->all(); $params['models'] = $models; return $this->render("category", $params); }
public function actionIndex() { $search = new SearchContent(); $params['search'] = $search; $query = Content::find(); if ($search->load(Yii::$app->request->get())) { foreach ($search->attributes as $k => $v) { $query->andFilterWhere(['like', $k, $v]); } } $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count()]); $params['pages'] = $pages; $pages->pageSize = 20; $models = $query->offset($pages->offset)->limit($pages->limit)->orderBy('id DESC')->all(); $params['models'] = $models; return $this->render("index", $params); }
public function actionView($slug) { $commentForm = new Comment(); $article = Content::find()->where(['slug' => $slug, 'type' => Content::TYPE_ARTICLE, 'status' => Content::STATUS_ACTIVE])->with(['createdBy', 'category', 'tags'])->one(); if (empty($article)) { throw new NotFoundHttpException('没有找到相应文章。。。'); } if ($commentForm->load(Yii::$app->request->post())) { $commentForm->content_id = $article['id']; if ($commentForm->save()) { Yii::$app->session->setFlash('success', '评论发表成功'); return $this->refresh(); } else { Yii::$app->session->setFlash('error', '评论发表失败'); } } $article->updateCounters(['view_total' => 1]); $model = Comment::find()->where(['content_id' => $article['id'], 'status' => Comment::STATUS_ACTIVE]); $countModel = clone $model; $commentsPagination = new Pagination(['totalCount' => $countModel->count('id')]); $comments = $model->orderBy('created_at')->select(['id', 'ip', 'url', 'text', 'created_at', 'email', 'nickname', 'parent_id'])->asArray()->all(); return $this->render('view', ['article' => $article, 'commentForm' => $commentForm, 'comments' => $comments, 'commentsPagination' => $commentsPagination]); }
/** * Метод для показа публикации */ public function actionShow($slug) { $data = Content::find()->where(['slug' => $slug])->one(); return $this->render('content', ['data' => $data]); }
public function actionCorporate() { $content = Content::find()->where(['action' => 'corporate'])->andWhere(['lang' => Yii::$app->language])->asArray()->all(); return $this->render('corporate', ['content' => $content]); }
/** * Finds the Content model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Content the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Content::find()->with(['category', 'tags'])->where(['id' => $id])->one()) !== null) { $model->setScenario(Content::SCENARIO_ARTICLE); return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionExportcontentlog() { $request = \Yii::$app->request; $arrUser = []; $filename = ""; $query = User::find()->andWhere(['status' => User::STATUS_ACTIVE])->all(); foreach ($query as $Object) { $arrUser[$Object->id] = $Object->firstName . ' - ' . $Object->lastName; } $logQuery = LogSystem::find(); $logQuery->andWhere(['entityType' => Entity::TYPE_CONTENT]); $datefrom = $request->post('datefrom', null); if (empty($datefrom)) { $datefrom = $request->get('datefrom', null); } $dateto = $request->post('dateto', null); if (empty($dateto)) { $dateto = $request->get('dateto', null); } if (!empty($datefrom) && !empty($dateto)) { $logQuery->andWhere(['between', 'ts', $datefrom, $dateto]); $filename .= $datefrom . "_" . $dateto; } $status = $request->post('status', ''); if (empty($status)) { $status = $request->get('status', ''); } if (!empty($status)) { $logQuery->andWhere('status=:status', [':status' => $status]); $filename .= "_" . Workflow::$arrStatusTpbs[$status]; } $userId = $request->post('userId', ''); if (empty($userId)) { $userId = $request->get('userId', ''); } if (!empty($userId)) { $logQuery->andWhere('userId=:userId', [':userId' => $userId]); $filename .= "_user_" . $userId; } $logQuery->orderBy('ts DESC'); $logLst = $logQuery->all(); $arrUserName = []; $arrContent = []; $arrUserId = []; $arrContentId = []; if ($logLst) { foreach ($logLst as $Object) { $arrUserId[$Object->userId] = $Object->userId; $arrContentId[$Object->refId] = $Object->refId; } if (!empty($arrUserId)) { $query = User::find(); $query->andWhere(['in', 'id', $arrUserId]); $lst = $query->all(); foreach ($lst as $Object) { $arrUserName[$Object->id] = $Object->firstName . ' - ' . $Object->lastName; } } if (!empty($arrContentId)) { $query = Content::find(); $query->andWhere(['in', 'id', $arrContentId]); $lst = $query->all(); foreach ($lst as $Object) { $arrContent[$Object->id] = $Object->title; } } } $dataProvider = new ActiveDataProvider(['query' => $logQuery]); $filename = trim($filename, "_"); $filename = $filename ? $filename : "all_content_log"; $extension = 'xls'; $response = \Yii::$app->response; $response->headers->set("Cache-Control", "no-cache"); $response->headers->set("Expires", "0"); $response->headers->set("Pragma", "no-cache"); $response->headers->set("Content-Type", "application/{$extension}"); $response->headers->set("Content-Disposition", "attachment; filename={$filename}.{$extension}"); return $this->renderPartial('excel', ['dataProvider' => $dataProvider, 'arrUserName' => $arrUserName, 'arrContent' => $arrContent]); }
public static function t($flatPageUrl, $contentName) { $content = Content::find()->joinWith('flatPage')->where(['content.name' => $contentName])->andWhere(['flat_page.url' => $flatPageUrl])->one(); return isset($content) ? $content->text : ''; }