Example #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = TaxonomyModel::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'taxonomy_hierarchical' => $this->taxonomy_hierarchical, 'taxonomy_smb' => $this->taxonomy_smb]);
     $query->andFilterWhere(['like', 'taxonomy_name', $this->taxonomy_name])->andFilterWhere(['like', 'taxonomy_slug', $this->taxonomy_slug])->andFilterWhere(['like', 'taxonomy_sn', $this->taxonomy_sn])->andFilterWhere(['like', 'taxonomy_pn', $this->taxonomy_pn]);
     return $dataProvider;
 }
Example #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = TaxonomyModel::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'hierarchical' => $this->hierarchical, 'menu_builder' => $this->menu_builder]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'singular_name', $this->singular_name])->andFilterWhere(['like', 'plural_name', $this->plural_name]);
     return $dataProvider;
 }
Example #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = TaxonomyModel::find();
     $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_hierarchical' => $this->taxonomy_hierarchical, 'taxonomy_smb' => $this->taxonomy_smb]);
     $query->andFilterWhere(['like', 'taxonomy_name', $this->taxonomy_name])->andFilterWhere(['like', 'taxonomy_slug', $this->taxonomy_slug])->andFilterWhere(['like', 'taxonomy_sn', $this->taxonomy_sn])->andFilterWhere(['like', 'taxonomy_pn', $this->taxonomy_pn]);
     return $dataProvider;
 }
Example #4
0
 /**
  * Displays menu page consists of CRUD for Menu and MenuItem model.
  *
  * @param null $id
  * @return mixed
  */
 public function actionIndex($id = null)
 {
     $model = new Menu();
     $postTypes = PostType::find()->where(['menu_builder' => PostType::MENU_BUILDER])->all();
     $taxonomies = Taxonomy::find()->where(['menu_builder' => Taxonomy::MENU_BUILDER])->all();
     if ($available = ArrayHelper::map(Menu::find()->all(), 'id', 'title')) {
         if ($id === null && $available) {
             reset($available);
             $id = key($available);
         }
         $selected = $this->findModel($id);
     }
     return $this->render('index', ['model' => $model, 'available' => $available, 'selected' => isset($selected) ? $selected : null, 'postTypes' => $postTypes, 'taxonomies' => $taxonomies]);
 }
Example #5
0
 /**
  * Generates menu page consists of CRUD Menu and MenuItem model.
  *
  * @param null $id
  *
  * @return mixed
  */
 public function actionIndex($id = null)
 {
     $model = new Menu();
     // List all post types
     $postTypes = PostType::find()->where(['post_type_smb' => 1])->all();
     // List all taxonomies
     $taxonomies = Taxonomy::find()->where(['taxonomy_smb' => 1])->all();
     // Get available menu
     if ($availableMenu = ArrayHelper::map(Menu::find()->all(), 'id', 'menu_title')) {
         if ($id === null && $availableMenu) {
             reset($availableMenu);
             $id = key($availableMenu);
         }
         $selectedMenu = $this->findModel($id);
     }
     return $this->render('index', ['model' => $model, 'availableMenu' => $availableMenu, 'selectedMenu' => isset($selectedMenu) ? $selectedMenu : null, 'postTypes' => $postTypes, 'taxonomies' => $taxonomies]);
 }
Example #6
0
 /**
  * @inheritdoc
  */
 public function beforeAction($action)
 {
     /*  @var $postType \common\models\PostType */
     /*  @var $taxonomy \common\models\Taxonomy */
     if (parent::beforeAction($action)) {
         $this->_defaultOption['enable_sitemap'] = 1;
         $this->_defaultOption['entries_per_page'] = 1000;
         // Home
         $this->_defaultOption['home'] = ['priority' => '1.0', 'changefreq' => 'daily'];
         // Post type default option
         foreach (PostType::find()->all() as $postType) {
             $this->_defaultOption['post_type'][$postType->id] = ['enable' => 1, 'priority' => '0.6', 'changefreq' => 'weekly'];
         }
         // Taxonomy default option
         foreach (Taxonomy::find()->all() as $taxonomy) {
             $this->_defaultOption['taxonomy'][$taxonomy->id] = ['enable' => 1, 'priority' => '0.2', 'changefreq' => 'weekly'];
         }
         // Media default option
         $this->_defaultOption['media'] = ['enable' => 0, 'priority' => '0.2', 'changefreq' => 'monthly'];
         return true;
     }
     return false;
 }
Example #7
0
 /**
  * @param string $type
  * @param string $slug
  * @param int    $page
  *
  * @return string
  */
 public function actionView($type, $slug, $page = 1)
 {
     /* @var $taxonomy Taxonomy */
     /* @var $postType PostType */
     /* @var $posts Post[] */
     /* @var $images Media[] */
     /* @var $terms Term[] */
     /* @var $mediaSet Media[] */
     /* @var $post Post */
     $page--;
     $items = [];
     $response = Yii::$app->response;
     $response->headers->set('Content-Type', 'text/xml; charset=UTF-8');
     $response->format = $response::FORMAT_RAW;
     if ($type === 'h') {
         $item['loc'] = Yii::$app->urlManager->hostInfo . Yii::$app->urlManager->baseUrl;
         $item['changefreq'] = $this->_option['home']['changefreq'];
         $item['priority'] = $this->_option['home']['priority'];
         return $this->renderPartial('home', ['item' => $item]);
     } elseif ($type === 'p') {
         $postType = PostType::find()->where(['post_type_slug' => $slug])->one();
         $posts = $postType->getPosts()->andWhere(['post_status' => 'publish'])->offset($page * $this->_option['entries_per_page'])->limit($this->_option['entries_per_page'])->all();
         foreach ($posts as $post) {
             $lastmod = new \DateTime($post->post_modified, new \DateTimeZone(Option::get('time_zone')));
             $items[$post->id]['loc'] = $post->url;
             $items[$post->id]['lastmod'] = $lastmod->format('r');
             $items[$post->id]['changefreq'] = $this->_option['post_type'][$postType->id]['changefreq'];
             $items[$post->id]['priority'] = $this->_option['post_type'][$postType->id]['priority'];
             if ($images = $post->getMedia()->where(['LIKE', 'media_mime_type', 'image/'])->all()) {
                 foreach ($images as $image) {
                     $metadata = $image->getMeta('metadata');
                     $items[$post->id]['image'][$image->id]['loc'] = $image->uploadUrl . $metadata['media_versions']['full']['url'];
                     $items[$post->id]['image'][$image->id]['title'] = $image->media_title ? $image->media_title : null;
                     $items[$post->id]['image'][$image->id]['caption'] = $image->media_excerpt ? $image->media_excerpt : null;
                 }
             }
         }
         return $this->renderPartial('post-type', ['items' => $items]);
     } elseif ($type === 'c') {
         $taxonomy = Taxonomy::find()->where(['taxonomy_slug' => $slug])->one();
         $terms = $taxonomy->getTerms()->offset($page * $this->_option['entries_per_page'])->limit($this->_option['entries_per_page'])->all();
         foreach ($terms as $term) {
             $post = $term->getPosts()->andWhere(['post_status' => 'publish'])->orderBy(['id' => SORT_DESC])->one();
             if ($post) {
                 $lastmod = new \DateTime($post->post_modified, new \DateTimeZone(Option::get('time_zone')));
                 $items[$term->id]['loc'] = $term->url;
                 $items[$term->id]['lastmod'] = $lastmod->format('r');
                 $items[$term->id]['changefreq'] = $this->_option['taxonomy'][$taxonomy->id]['changefreq'];
                 $items[$term->id]['priority'] = $this->_option['taxonomy'][$taxonomy->id]['priority'];
             }
         }
         return $this->renderPartial('taxonomy', ['items' => $items]);
     } elseif ($type === 'm') {
         $mediaSet = Media::find()->offset($page * $this->_option['entries_per_page'])->limit($this->_option['entries_per_page'])->all();
         foreach ($mediaSet as $media) {
             $lastmod = new \DateTime($media->media_modified, new \DateTimeZone(Option::get('time_zone')));
             $items[$media->id]['loc'] = $media->url;
             $items[$media->id]['lastmod'] = $lastmod->format('r');
             $items[$media->id]['changefreq'] = $this->_option['media']['changefreq'];
             $items[$media->id]['priority'] = $this->_option['media']['priority'];
         }
         return $this->renderPartial('media', ['items' => $items]);
     }
     return $this->redirect(['/site/not-found']);
 }
Example #8
0
 /**
  * Get dropdown menu for taxonomy.
  *
  * @return array
  */
 protected function getTaxonomyMenu()
 {
     /* @var $urlManagerBack \yii\web\UrlManager */
     /* @var $taxonomies \common\models\Taxonomy[] */
     $urlManagerBack = Yii::$app->urlManagerBack;
     $menuItems = [];
     $taxonomies = Taxonomy::find()->select(['id', 'taxonomy_sn'])->all();
     foreach ($taxonomies as $taxonomy) {
         $menuItems[] = ['label' => $taxonomy->taxonomy_sn, 'url' => $urlManagerBack->createUrl(['/taxonomy/view', 'id' => $taxonomy->id]), 'visible' => Yii::$app->user->can('editor')];
     }
     return $menuItems;
 }
Example #9
0
 /**
  * Updates an existing PostType model.
  * If update is successful, the browser will be redirected to the 'view' page.
  *
  * @param integer $id
  *
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $taxonomies = ArrayHelper::map(Taxonomy::find()->all(), 'id', 'taxonomy_name');
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         // Delete all PostTypeTaxonomy where post_type_id this id
         PostTypeTaxonomy::deleteAll(['post_type_id' => $id]);
         // Refill PostTypeTaxonomy for this model
         $postTypeTaxonomy = Yii::$app->request->post('PostTypeTaxonomy');
         if ($taxonomyIds = Json::decode($postTypeTaxonomy['taxonomyIds'])) {
             foreach ($taxonomyIds as $taxonomyId) {
                 $postTypeTaxonomy = new PostTypeTaxonomy();
                 $postTypeTaxonomy->post_type_id = $model->id;
                 $postTypeTaxonomy->taxonomy_id = $taxonomyId;
                 $postTypeTaxonomy->save();
             }
         }
         return $this->redirect(['view', 'id' => $model->id]);
     }
     return $this->render('update', ['model' => $model, 'taxonomy' => new Taxonomy(), 'taxonomies' => $taxonomies]);
 }
Example #10
0
<?php

/**
 * @link http://www.writesdown.com/
 * @author Agiel K. Saputra <*****@*****.**>
 * @copyright Copyright (c) 2015 WritesDown
 * @license http://www.writesdown.com/license/
 */
use common\models\Taxonomy;
use yii\bootstrap\Nav;
/* @var $this yii\web\View */
/* @var $taxonomies common\models\Taxonomy[] */
$taxonomies = Taxonomy::find()->all();
$items = [];
?>
<div id="sidebar">
    <div class="widget">
        <?php 
echo $this->render('search-form');
?>
    </div>

    <?php 
foreach ($taxonomies as $taxonomy) {
    foreach ($taxonomy->terms as $term) {
        if ($term->getPosts()->andWhere(['status' => 'publish'])->count()) {
            $items[$taxonomy->id][$term->id]['label'] = $term->name;
            $items[$taxonomy->id][$term->id]['url'] = $term->url;
        }
    }
    ?>