Beispiel #1
0
 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];
 }
Beispiel #2
0
 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 actionDelete($id)
 {
     $model = Content::findOne($id);
     $model->delete();
     Yii::$app->session->setFlash("success", "Delete " . $model->title . " successful");
     return $this->redirect(\Yii::$app->request->getReferrer());
 }
 public static function getData($type, $id)
 {
     if (!empty($type) && !empty($id)) {
         switch ($type) {
             case SectionConfig::TYPE_CONTENT:
                 $model = Content::findOne(['id' => $id]);
                 break;
             case SectionConfig::TYPE_GALLERY:
                 $model = Gallery::findOne(['id' => $id]);
                 break;
             case SectionConfig::TYPE_FEED:
                 $model = Feed::findOne(['id' => $id]);
                 break;
             case SectionConfig::TYPE_FEED_CONTENT:
                 $model = FeedContent::getFeedItems($id, 3);
                 break;
             case SectionConfig::TYPE_WEATHER:
                 $model = WeatherForecast::findOne(['id' => $id]);
                 break;
             case SectionConfig::TYPE_QUOTE:
                 $model = Quote::findOne(['id' => $id]);
                 break;
             case SectionConfig::TYPE_WIDGET:
                 $model = Widget::findOne(['id' => $id]);
                 break;
         }
         if (empty($model)) {
             return array();
         } else {
             return $model;
         }
     }
 }
Beispiel #5
0
 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;
 }
 protected function findContent($id)
 {
     $content = Content::findOne($id);
     if (!isset($content)) {
         throw new HttpException(404, Yii::t('app', 'The requested page does not exist.'));
     }
     return $content;
 }
Beispiel #7
0
 public function addPost()
 {
     if ($this->validate()) {
         $content = new Content();
         $content->name = $this->name;
         $content->slug = $this->slug;
         $content->text_bb = $this->text_bb;
         $content->author_id = Yii::$app->user->id;
         $content->category_id = 1;
         $content->text_short = $this->text_short;
         $content->status = $this->status == 1 ? 1 : 0;
         if ($content->save()) {
             return $content;
         }
     }
     return null;
 }
Beispiel #8
0
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     //更新slug
     if (trim($this->slug) == '') {
         $this->slug = $this->cid;
         Content::updateAll(['slug' => $this->cid], ['cid' => $this->cid]);
     }
 }
Beispiel #9
0
 public function selectNoText()
 {
     $columns = array_keys(Content::getTableSchema()->columns);
     $key = array_search('text', $columns);
     if ($key !== false) {
         unset($columns[$key]);
     }
     $this->select($columns);
     return $this;
 }
Beispiel #10
0
 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]);
 }
Beispiel #11
0
 public function deletePost($cid)
 {
     $model = Content::findOne(['cid' => $cid, 'type' => Content::TYPE_POST]);
     if (!$model) {
         return false;
     }
     //删除文章的关联分类和tag
     CategoryComp::getInstance()->delCategoryWithPostId($cid);
     TagComp::getInstance()->delTagsWithPostId($cid);
     //删除附件
     MediaComp::getInstance()->delMediaWithPostId($cid);
     return $model->delete();
 }
Beispiel #12
0
 /**
 * 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;
 }
Beispiel #13
0
 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]);
 }
Beispiel #14
0
 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 : '';
 }
Beispiel #15
0
 /**
  * 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.');
     }
 }
Beispiel #16
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getContents()
 {
     return $this->hasMany(\common\models\Content::className(), ['flat_page_id' => 'id']);
 }
 public function actionContent($id)
 {
     $model = Content::findOne($id);
     $params['model'] = $model;
     return $this->render("content", $params);
 }
 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]);
 }
Beispiel #19
0
 /**
  * Метод для показа публикации
  */
 public function actionShow($slug)
 {
     $data = Content::find()->where(['slug' => $slug])->one();
     return $this->render('content', ['data' => $data]);
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getContent0()
 {
     return $this->hasOne(Content::className(), ['id' => 'content']);
 }
Beispiel #21
0
 public function afterDelete()
 {
     parent::afterDelete();
     unlink(\Yii::getAlias('@webroot' . $this->path));
 }
Beispiel #22
0
 /**
  * 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::findOne($id)) !== null) {
         $model->setScenario(Content::SCENARIO_PAGE);
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Beispiel #23
0
 public function actionCorporate()
 {
     $content = Content::find()->where(['action' => 'corporate'])->andWhere(['lang' => Yii::$app->language])->asArray()->all();
     return $this->render('corporate', ['content' => $content]);
 }
Beispiel #24
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getContents()
 {
     return $this->hasMany(Content::className(), ['created_by' => 'id']);
 }
Beispiel #25
0
 /**
  * ให้ค่า instance ของ model ที่ระบุด้วย entity type และ $refId
  * @param int $type
  * @param int $refId
  * @return ActiveRecord
  */
 public static function getInstance($type, $refId, $orderNo = NULL)
 {
     $instance = null;
     switch ($type) {
         case self::TYPE_ACTIVITY:
             $instance = Activity::findOne($refId);
             break;
         case self::TYPE_BLOG:
             $instance = Blogs::findOne($refId);
             break;
         case self::TYPE_CARTOON:
             $arr = preg_split('/-/', $refId);
             $instance = CartoonChapter::findOne(array('cartoonId' => $arr[0], 'chapter' => $arr[1]));
             break;
         case self::TYPE_CONTENT:
             $instance = Content::findOne($refId);
             break;
         case self::TYPE_DOCUMENT:
             $instance = Document::findOne(array('type' => $type, 'refId' => $refId, 'itemNo' => $orderNo));
             break;
         case self::TYPE_FAQ:
             $instance = Faq::findOne($refId);
             break;
         case self::TYPE_FEEDCONTENT:
             $instance = FeedContent::findOne($refId);
             break;
         case self::TYPE_FEED:
             $instance = Feed::findOne($refId);
             break;
         case self::TYPE_GALLERY:
             $instance = Gallery::findOne($refId);
             break;
         case self::TYPE_INFOGRAPHIC:
             $instance = InfoGraphic::findOne($refId);
             break;
         case self::TYPE_LIVEREPORT:
             $instance = LiveReport::findOne($refId);
             break;
         case self::TYPE_LOTTERY:
             $instance = Lottery::findOne($refId);
             break;
         case self::TYPE_BUNNY:
         case self::TYPE_MEDIA_COLLECTION:
             $instance = MediaCollection::findOne($refId);
             break;
         case self::TYPE_NEWSPAPER:
             // temporary class for media upload
             $instance = new stdClass();
             $instance->createTime = date('Y-m-d H:i:s');
             break;
         case self::TYPE_NOVEL:
             $instance = Novel::findOne($refId);
             break;
         case self::TYPE_PERSON:
             $instance = Person::findOne($refId);
             break;
         case self::TYPE_SPORT_PLAYER:
             $instance = Player::findOne($refId);
             break;
         case self::TYPE_SPORT_TEAM:
             $instance = Team::findOne($refId);
             break;
         case self::TYPE_QUOTE:
             $instance = Quote::findOne($refId);
             break;
         case self::TYPE_WIDGET:
             $instance = Widget::findOne($refId);
             break;
         case self::TYPE_TV_ANCHOR:
             $instance = TvAnchor::findOne($refId);
             break;
         case self::TYPE_TV_PROGRAM:
             $instance = TvProgram::findOne($refId);
             break;
         case self::TYPE_TV_HIGHLIGHT:
             $instance = TvHighlight::findOne($refId);
             break;
         case self::TYPE_TV_SCHEDULE:
             $instance = TvSchedule::findOne($refId);
             break;
         case self::TYPE_USER:
             $instance = User::findOne($refId);
             break;
         case self::TYPE_VIDEO:
             $instance = Video::findOne($refId);
             break;
         case self::TYPE_VIDEO_PLAYLIST:
             $instance = VideoPlaylist::findOne($refId);
             break;
         case self::TYPE_WATCHTOPIC:
             $instance = WatchTopic::findOne($refId);
             break;
         case self::TYPE_WEATHER:
             $instance = WeatherForecast::findOne($refId);
             break;
     }
     return $instance;
 }
Beispiel #26
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getContent()
 {
     return $this->hasOne(\common\models\Content::className(), ['id' => 'content_id']);
 }
Beispiel #27
0
 public function afterDelete()
 {
     parent::afterDelete();
     $this->deleteCategories($this->status == static::STATUS_PUBLISH);
     $this->deleteTags($this->status == static::STATUS_PUBLISH);
     $this->deleteAttachments();
 }
Beispiel #28
0
 public function afterDelete()
 {
     parent::afterDelete();
     $this->deleteAttachments();
 }