Example #1
0
 /**
  * Update model page.
  *
  * @param integer $vid
  * @param integer $id
  *
  * @return mixed
  */
 public function actionUpdate($vid, $id)
 {
     $model = $this->findModel($id, $vid);
     $model->setScenario('admin-update');
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate()) {
             if ($model->save(false)) {
                 return $this->refresh();
             } else {
                 Yii::$app->session->setFlash('danger', Module::t('admin', 'Failed to update term {name}', ['{name}' => $model->name]));
                 return $this->refresh();
             }
         } elseif (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         }
     }
     return $this->render('update', ['model' => $model, 'vid' => $vid, 'parent' => $model->getParent()]);
 }
 /**
  * Update model page.
  *
  * @param integer $id Post ID
  *
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $model->setScenario('admin-update');
     $statusArray = TaxonomyVocabulary::statusLabels();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate()) {
             if ($model->save(false)) {
                 return $this->refresh();
             } else {
                 Yii::$app->session->setFlash('danger', Module::t('admin', 'Failed to update vocabulary {name}', ['{name}' => $model->name]));
                 return $this->refresh();
             }
         } elseif (Yii::$app->request->isAjax) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             return ActiveForm::validate($model);
         }
     }
     return $this->render('update', ['model' => $model, 'statusArray' => $statusArray]);
 }
Example #3
0
<?php

/**
 * @var \yii\base\View $this View
 * @var TaxonomyTerm $model
 * @var int $vid
 * @var TaxonomyTerm $parent
 */
use artkost\taxonomy\models\TaxonomyTerm;
use artkost\taxonomy\Module;
$this->title = Module::t('admin', 'Taxonomy');
$this->params['subtitle'] = Module::t('admin', 'Update term');
$this->params['breadcrumbs'] = [['label' => $this->title, 'url' => ['index']], $this->params['subtitle']];
?>
<div class="row">
    <div class="col-sm-12">
        <?php 
echo $this->render('_form', ['model' => $model]);
?>
    </div>
</div>
 /**
  * @return array Status array.
  */
 public static function statusLabels()
 {
     return [self::STATUS_DISABLED => Module::t('model', 'Unpublished'), self::STATUS_ENABLED => Module::t('model', 'Published')];
 }
 /**
  * @inheritdoc
  */
 public function attributeLabels()
 {
     return ['vid' => Module::t('model', 'Vocabulary ID'), 'parent_id' => Module::t('model', 'Parent ID'), 'child_id' => Module::t('model', 'Child ID')];
 }
Example #6
0
<?php

/**
 * TaxonomyVocabulary model create view.
 *
 * @var \yii\web\View $this View
 * @var TaxonomyVocabulary $model Model
 * @var array $statusArray Statuses array
 */
use artkost\taxonomy\Module;
use artkost\taxonomy\models\TaxonomyVocabulary;
$this->title = Module::t('admin', 'Taxonomy');
$this->params['subtitle'] = Module::t('admin', 'Create vocabulary');
$this->params['breadcrumbs'] = [['label' => $this->title, 'url' => ['index']], $this->params['subtitle']];
?>
<div class="row">
    <div class="col-sm-12">
        <?php 
echo $this->render('_form', ['model' => $model, 'statusArray' => $statusArray]);
?>
    </div>
</div>
Example #7
0
<?php

/**
 * TaxonomyTerm model create view.
 *
 * @var \yii\base\View $this View
 * @var array $statusArray Statuses array
 */
use artkost\taxonomy\Module;
$this->title = Module::t('admin', 'Taxonomy');
$this->params['subtitle'] = Module::t('admin', 'Create a term');
$this->params['breadcrumbs'] = [['label' => $this->title, 'url' => ['index']], $this->params['subtitle']];
?>
<div class="row">
    <div class="col-sm-12">
        <?php 
echo $this->render('_form', ['model' => $model]);
?>
    </div>
</div>
Example #8
0
 public function validateHasParent($attribute, $params)
 {
     if (!$this->hasErrors() && $this->getParent() == null) {
         $this->addError($attribute, Module::t('model', 'Invalid parent term id'));
     }
 }
Example #9
0
<?php

/**
 * @var \yii\base\View $this View
 * @var \yii\data\ActiveDataProvider $dataProvider Data provider
 * @var Taxonomy $searchModel Search model
 * @var int $vid Statuses array
 */
use artkost\taxonomy\models\TaxonomyTermSearch;
use artkost\taxonomy\Module;
use yii\grid\ActionColumn;
use yii\grid\CheckboxColumn;
use yii\helpers\Url;
$this->title = Module::t('admin', 'Taxonomy');
$this->params['subtitle'] = Module::t('admin', 'Terms');
$this->params['breadcrumbs'] = [$this->title];
$gridId = 'taxonomy-terms-grid';
$gridConfig = ['id' => $gridId, 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => CheckboxColumn::classname()], 'name', 'description']];
$user = Yii::$app->user;
$actions = [];
$showActions = false;
if ($user->can('taxonomyTermCreate')) {
    $actions[] = '{create}';
}
if ($user->can('taxonomyTermUpdate')) {
    $actions[] = '{update}';
    $showActions = $showActions || true;
}
if ($user->can('taxonomyTermDelete')) {
    $actions[] = '{delete}';
    $showActions = $showActions || true;
Example #10
0
<?php

/**
 * TaxonomyVocabulary model update view.
 *
 * @var \yii\base\View $this View
 * @var TaxonomyVocabulary $model Model
 * @var array $statusArray Statuses array
 */
use artkost\taxonomy\Module;
use artkost\taxonomy\models\TaxonomyVocabulary;
$user = Yii::$app->user;
$this->title = Module::t('admin', 'Taxonomy');
$this->params['subtitle'] = Module::t('admin', 'Update Vocabulary');
$this->params['breadcrumbs'] = [['label' => $this->title, 'url' => ['index']], $this->params['subtitle']];
?>
<div class="row">
    <div class="col-sm-12">
        <?php 
echo $this->render('_form', ['model' => $model, 'statusArray' => $statusArray]);
?>
    </div>
</div>
Example #11
0
use artkost\taxonomy\Module;
use yii\grid\ActionColumn;
use yii\grid\CheckboxColumn;
use yii\grid\GridView;
use yii\helpers\Html;
use yii\jui\DatePicker;
$this->title = Module::t('admin', 'Taxonomy');
$this->params['subtitle'] = Module::t('admin', 'Vocabulary list');
$this->params['breadcrumbs'] = [$this->title];
$gridId = 'vocabularies-grid';
$gridConfig = ['id' => $gridId, 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => CheckboxColumn::classname()], 'id', ['attribute' => 'title', 'format' => 'html', 'value' => function ($model) {
    return Html::a($model->title, ['/taxonomy/term/index', 'vid' => $model->id]);
}], 'name', ['attribute' => 'status_id', 'format' => 'html', 'value' => function ($model) {
    $class = $model->status_id === $model::STATUS_ENABLED ? 'label-success' : 'label-danger';
    return '<span class="label ' . $class . '">' . $model->status . '</span>';
}, 'filter' => Html::activeDropDownList($searchModel, 'status_id', $statusArray, ['class' => 'form-control', 'prompt' => Module::t('admin', 'Select status')])], ['attribute' => 'created_at', 'format' => 'date', 'filter' => DatePicker::widget(['model' => $searchModel, 'attribute' => 'created_at', 'options' => ['class' => 'form-control'], 'clientOptions' => ['dateFormat' => 'dd.mm.yy']])], ['attribute' => 'updated_at', 'format' => 'date', 'filter' => DatePicker::widget(['model' => $searchModel, 'attribute' => 'updated_at', 'options' => ['class' => 'form-control'], 'clientOptions' => ['dateFormat' => 'dd.mm.yy']])]]];
$user = Yii::$app->user;
$actions = [];
$showActions = false;
if ($user->can('taxonomyVocabularyCreate')) {
    $actions[] = '{create}';
}
if ($user->can('taxonomyVocabularyUpdate')) {
    $actions[] = '{update}';
    $showActions = $showActions || true;
}
if ($user->can('taxonomyVocabularyDelete')) {
    $actions[] = '{delete}';
    $showActions = $showActions || true;
}
if ($showActions === true) {
Example #12
0
/**
 * TaxonomyTerm model form view.
 *
 * @var \yii\base\View $this View
 * @var \yii\widgets\ActiveForm $form Form
 * @var array $statusArray Statuses array
 */
use artkost\taxonomy\models\TaxonomyTerm;
use artkost\taxonomy\Module;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
$form = ActiveForm::begin();
?>
    <div class="row">
        <div class="col-sm-12">
            <?php 
echo $form->field($model, 'name')->textInput(['placeholder' => Module::t('admin', 'Name')]);
?>
            <?php 
echo $form->field($model, 'description')->textInput(['placeholder' => Module::t('admin', 'Description')]);
?>
            <?php 
echo $form->field($model, 'parent_id')->dropDownList(ArrayHelper::merge(['' => Module::t('admin', 'None')], $model->vocabulary->termsTreeData));
?>
        </div>
    </div>

<?php 
echo Html::submitButton($model->isNewRecord ? Module::t('admin', 'Create term') : Module::t('admin', 'Update term'), ['class' => $model->isNewRecord ? 'btn btn-primary btn-large' : 'btn btn-success btn-large']);
ActiveForm::end();