/**
  * Create new TermRelationship model through AJAX via Seletize box on 'create' and 'update post' page.
  */
 public function actionAjaxCreateNonHierarchical()
 {
     $model = new TermRelationship();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         if ($term = $this->findTerm($model->term_id)) {
             $term->updateAttributes(['count' => ++$term->count]);
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Create a new Term model for hierarchical Taxonomy through AJAX request.
  */
 public function actionAjaxCreateHierarchical()
 {
     $item = '';
     $term = new Term();
     $termRelationship = new TermRelationship();
     if ($term->load(Yii::$app->request->post())) {
         if ($termRelationship->load(Yii::$app->request->post()) && $termRelationship->post_id) {
             $term->count = 1;
             if ($term->save()) {
                 $termRelationship->term_id = $term->id;
                 if ($termRelationship->save()) {
                     $item = $item . '<br />' . Html::label(Html::checkbox('termIds[]', true, ['value' => $term->id]) . $term->name);
                 }
             }
         } elseif ($term->save()) {
             $item = $item . '<br />' . Html::label(Html::checkbox('termIds[]', true, ['value' => $term->id]) . $term->name);
         }
     }
     return $item;
 }
Ejemplo n.º 3
0
 /**
  * Create term taxonomy non-hierarchical
  */
 public function actionAjaxCreateHierarchical()
 {
     $term = new Term();
     $termRelationship = new TermRelationship();
     if ($term->load(Yii::$app->request->post())) {
         if ($termRelationship->load(Yii::$app->request->post()) && $termRelationship->post_id) {
             $term->term_count = 1;
             if ($term->save()) {
                 $termRelationship->term_id = $term->id;
                 if ($termRelationship->save()) {
                     echo '<br />';
                     echo Html::label(Html::checkbox('termIds', true, ['value' => $term->id]) . $term->term_name);
                 }
             }
         } else {
             if ($term->save()) {
                 echo '<br />';
                 echo Html::label(Html::checkbox('termIds', true, ['value' => $term->id]) . $term->term_name);
             }
         }
     }
 }