/**
  * @return string
  */
 public function actionIndex()
 {
     /* @var $postType PostType */
     /* @var $post Post */
     /* @var $taxonomies Taxonomy[] */
     /* @var $taxonomy Taxonomy */
     /* @var $lastMedia Media */
     $response = Yii::$app->response;
     $response->headers->set('Content-Type', 'text/xml; charset=UTF-8');
     $response->format = $response::FORMAT_RAW;
     $postTypes = PostType::find()->select(['id', 'post_type_slug'])->all();
     $taxonomies = Taxonomy::find()->select(['id', 'taxonomy_slug'])->all();
     $items = [];
     foreach ($postTypes as $postType) {
         if (!isset($this->_option['post_type'][$postType->id]['enable']) || !$this->_option['post_type'][$postType->id]['enable']) {
             continue;
         }
         if ($post = $postType->getPosts()->andWhere(['post_status' => 'publish'])->orderBy(['id' => SORT_DESC])->one()) {
             $lastmod = new \DateTime($post->post_modified, new \DateTimeZone(Option::get('time_zone')));
             $query = $postType->getPosts()->andWhere(['post_status' => 'publish']);
             $countQuery = clone $query;
             $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => $this->_option['entries_per_page']]);
             for ($i = 1; $i <= $pages->pageCount; $i++) {
                 $items[] = ['loc' => Yii::$app->urlManager->hostInfo . Url::to(['view', 'type' => 'p', 'slug' => $postType->post_type_slug, 'page' => $i]), 'lastmod' => $lastmod->format('r')];
             }
         }
     }
     foreach ($taxonomies as $taxonomy) {
         if (!isset($this->_option['taxonomy'][$taxonomy->id]['enable']) || !$this->_option['taxonomy'][$taxonomy->id]['enable']) {
             continue;
         }
         if ($terms = $taxonomy->terms) {
             $post = Post::find()->from(['post' => Post::tableName()])->innerJoinWith(['terms' => function ($query) {
                 /* @var $query \yii\db\ActiveQuery */
                 $query->from(['term' => Term::tableName()]);
             }])->where(['IN', 'term.id', ArrayHelper::getColumn($terms, 'id')])->andWhere(['post.post_status' => 'publish'])->orderBy(['post.id' => SORT_DESC])->one();
             if ($post) {
                 $query = $taxonomy->getTerms();
                 $lastmod = new \DateTime($post->post_modified, new \DateTimeZone(Option::get('time_zone')));
                 $countQuery = clone $query;
                 $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => $this->_option['entries_per_page']]);
                 for ($i = 1; $i <= $pages->pageCount; $i++) {
                     $items[] = ['loc' => Yii::$app->urlManager->hostInfo . Url::to(['view', 'type' => 'c', 'slug' => $taxonomy->taxonomy_slug, 'page' => $i]), 'lastmod' => $lastmod->format('r')];
                 }
             }
         }
     }
     if (isset($this->_option['media']['enable']) && $this->_option['media']['enable']) {
         $query = Media::find();
         $countQuery = clone $query;
         $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => $this->_option['entries_per_page']]);
         if ($lastMedia = $query->orderBy(['id' => SORT_DESC])->one()) {
             $lastmod = new \DateTime($lastMedia->media_modified, new \DateTimeZone(Option::get('time_zone')));
             for ($i = 1; $i <= $pages->pageCount; $i++) {
                 $items[] = ['loc' => Yii::$app->urlManager->hostInfo . Url::to(['view', 'type' => 'm', 'slug' => 'media', 'page' => $i]), 'lastmod' => $lastmod->format('r')];
             }
         }
     }
     return $this->renderPartial('index', ['items' => $items]);
 }
 /**
  * Finds the Post model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  *
  * @param string $slug Term Slug
  * @throws \yii\web\NotFoundHttpException
  * @internal param string $postslug
  * @return Term the loaded model
  */
 protected function findModelBySlug($slug)
 {
     $model = Term::findOne(['slug' => $slug]);
     if ($model) {
         return $model;
     }
     throw new NotFoundHttpException(Yii::t('writesdown', 'The requested page does not exist.'));
 }
Exemple #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  * @param int $taxonomyId
  * @return ActiveDataProvider
  */
 public function search($params, $taxonomyId)
 {
     $query = TermModel::find();
     $query->andWhere(['taxonomy_id' => $taxonomyId]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'taxonomy_id' => $this->taxonomy_id, 'parent' => $this->parent, 'count' => $this->count]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
Exemple #4
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  * @param int   $taxonomy_id
  *
  * @return ActiveDataProvider
  */
 public function search($params, $taxonomy_id)
 {
     $query = TermModel::find();
     $query->andWhere(['taxonomy_id' => $taxonomy_id]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $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, 'taxonomy_id' => $this->taxonomy_id, 'term_parent' => $this->term_parent, 'term_count' => $this->term_count]);
     $query->andFilterWhere(['like', 'term_name', $this->term_name])->andFilterWhere(['like', 'term_slug', $this->term_slug])->andFilterWhere(['like', 'term_description', $this->term_description]);
     return $dataProvider;
 }
 /**
  * Finds the Term model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  *
  * @param integer $id
  *
  * @return Term|false the loaded model
  */
 protected function findTerm($id)
 {
     if ($model = Term::findOne($id)) {
         return $model;
     } else {
         return false;
     }
 }
Exemple #6
0
 /**
  * @param AcceptanceTester $I
  */
 public function testUpdateTerm(AcceptanceTester $I)
 {
     $I->wantTo('ensure that update term works');
     $updateTermPage = UpdateTermPage::openBy($I);
     $I->see('View Taxonomy: Tag');
     $I->amGoingTo('submit update term form');
     $updateTermPage->submit(['slug' => 'new-sample-tag-slug', 'description' => 'New sample tag description']);
     $I->expectTo('see the term updated');
     $I->see('New sample tag description', '#term-grid-view');
     $I->see('new-sample-tag-slug', '#term-grid-view');
     Term::findOne(2)->updateAttributes(['description' => 'This is sample tag description', 'slug' => 'sample-tag hlhl']);
 }
Exemple #7
0
 /**
  * @param bool $sameType
  * @param bool $sameTerm
  *
  * @return array|null|Post
  */
 public function getPrevPost($sameType = true, $sameTerm = false)
 {
     /* @var $query \yii\db\ActiveQuery */
     $query = static::find()->from(['post' => $this->tableName()])->andWhere(['<', 'post.id', $this->id])->andWhere(['post_status' => 'publish'])->orderBy(['post.id' => SORT_DESC]);
     if ($sameType) {
         $query->andWhere(['post_type' => $this->post_type]);
     }
     if ($sameTerm) {
         $query->innerJoinWith(['terms' => function ($query) {
             /* @var $query \yii\db\ActiveQuery */
             $query->from(['term' => Term::tableName()])->andWhere(['IN', 'term.id', implode(',', ArrayHelper::getColumn($this->terms, 'id'))]);
         }]);
     }
     return $query->one();
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTerm()
 {
     return $this->hasOne(Term::className(), ['id' => 'term_id']);
 }
Exemple #9
0
 /**
  * Finds the Post model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  *
  * @param $term_slug
  *
  * @throws \yii\web\NotFoundHttpException
  * @internal param string $post_slug
  *
  * @return Term the loaded model
  */
 protected function findModelBySlug($term_slug)
 {
     $model = Term::find()->andWhere(['term_slug' => $term_slug])->one();
     if ($model) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemple #10
0
 /**
  * Finds the Term model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  *
  * @param integer $id
  * @return Term the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Term::findOne($id)) !== null) {
         return $model;
     }
     throw new NotFoundHttpException('The requested page does not exist.');
 }
Exemple #11
0
 /**
  * Finds the Term model based on its primary key value.
  * If the model is not found, it return false.
  *
  * @param integer $id
  *
  * @return Term|bool|null|static
  */
 protected function findTerm($id)
 {
     if (($model = Term::findOne($id)) !== null) {
         return $model;
     }
     return false;
 }
Exemple #12
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTerms()
 {
     return $this->hasMany(Term::className(), ['taxonomy_id' => 'id']);
 }
 /**
  * Finds the Term model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  *
  * @param integer $id
  * @return Term the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findTerm($id)
 {
     if (($model = Term::findOne($id)) !== null) {
         return $model;
     }
     throw new NotFoundHttpException(Yii::t('writesdown', 'The requested page does not exist.'));
 }