Beispiel #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()) {
         // 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;
 }
 /**
  * Lists all Menu models.
  *
  * @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) {
             foreach ($availableMenu as $key => $menu) {
                 $id = $key;
                 break;
             }
         }
         $selectedMenu = $this->findModel($id);
     }
     return $this->render('index', ['model' => $model, 'availableMenu' => $availableMenu, 'selectedMenu' => isset($selectedMenu) ? $selectedMenu : null, 'postTypes' => $postTypes, 'taxonomies' => $taxonomies]);
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTaxonomy()
 {
     return $this->hasOne(Taxonomy::className(), ['id' => 'taxonomy_id']);
 }
Beispiel #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getTaxonomies()
 {
     return $this->hasMany(Taxonomy::className(), ['id' => 'taxonomy_id'])->viaTable('{{%post_type_taxonomy}}', ['post_type_id' => 'id']);
 }
 /**
  * Finds the Taxonomy model based on its primary ke value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  *
  * @param integer $id
  *
  * @return Taxonomy the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Taxonomy::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * 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
         //var_dump(Yii::$app->request->post('PostTypeTaxonomy')); exit;
         if (($postTypeTaxonomy = Yii::$app->request->post('PostTypeTaxonomy')) && ($taxonomyIds = Json::decode($postTypeTaxonomy['taxonomyIds']))) {
             foreach ($taxonomyIds as $taxonomy_id) {
                 $postTypeTaxonomy = new PostTypeTaxonomy();
                 $postTypeTaxonomy->post_type_id = $model->id;
                 $postTypeTaxonomy->taxonomy_id = $taxonomy_id;
                 $postTypeTaxonomy->save();
             }
         }
         return $this->redirect(['view', 'id' => $model->id]);
     }
     return $this->render('update', ['model' => $model, 'taxonomy' => new Taxonomy(), 'taxonomies' => $taxonomies]);
 }