public function actionCreate()
 {
     $model = new Category();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['update', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Example #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Category::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => false, 'sort' => new \yii\data\Sort(['attributes' => ['name']])]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     $query->andFilterWhere(['like', 'text', $this->text]);
     return $dataProvider;
 }
Example #3
0
 public function getParent()
 {
     return $this->hasOne(Category::className(), ['id' => 'parent_id']);
 }
Example #4
0
        <div class="col-md-2">
            <?php 
echo Html::a('Добавить сотрудника', ['create'], ['class' => 'btn btn-success']);
?>
        </div>
        <div class="col-md-10">
            <?php 
echo $this->render('../parts/menu');
?>
        </div>
    </div>
    
    <?php 
echo \kartik\grid\GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'export' => false, 'columns' => [['attribute' => 'image', 'filter' => false, 'content' => function ($image) {
    if ($image->image && ($image = $image->image->getUrl('100x100'))) {
        return "<img src=\"{$image}\" class=\"thumb\" />";
    }
}], ['attribute' => 'id', 'filter' => false, 'options' => ['style' => 'width: 55px;']], ['attribute' => 'organization_id', 'filter' => Html::activeDropDownList($searchModel, 'organization_id', $organizations, ['class' => 'form-control', 'prompt' => 'Организация']), 'content' => function ($model) use($organizations) {
    foreach ($organizations as $id => $name) {
        if ($id == $model->organization_id) {
            return $name;
        }
    }
    return '';
}], 'name', ['attribute' => 'status', 'filter' => Html::activeDropDownList($searchModel, 'status', $module->stafferStatuses, ['class' => 'form-control', 'prompt' => 'Статус']), 'content' => function ($model) use($module) {
    return @$module->stafferStatuses[$model->status];
}], ['attribute' => 'category_id', 'filter' => Html::activeDropDownList($searchModel, 'category_id', Category::buildTextTree(), ['class' => 'form-control', 'prompt' => 'Категория']), 'value' => 'category.name'], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{view} {update} {delete}', 'buttonOptions' => ['class' => 'btn btn-default'], 'options' => ['style' => 'width: 155px;']]]]);
?>

</div>
Example #5
0
        <div class="col-md-3 col-xs-6">
            <?php 
echo $form->field($model, 'persent')->textInput(['type' => 'number']);
?>
        </div>
    </div>

    <div class="row">
        <div class="col-md-3 col-xs-6">
            <?php 
echo $form->field($model, 'fix')->textInput(['type' => 'number']);
?>
        </div>
        <div class="col-md-3 col-xs-6">
            <?php 
echo $form->field($model, 'category_id')->widget(Select2::classname(), ['data' => Category::buildTextTree(), 'language' => 'ru', 'options' => ['placeholder' => 'Выберите категорию ...'], 'pluginOptions' => ['allowClear' => true]]);
?>
        </div>
        <div class="col-md-3 col-xs-6">
            <?php 
echo $form->field($model, 'status')->widget(Select2::classname(), ['data' => $module->stafferStatuses, 'language' => 'ru', 'options' => ['placeholder' => 'Выберите статус ...'], 'pluginOptions' => ['allowClear' => true]]);
?>
        </div>
        <div class="col-md-3 col-xs-6">
            <?php 
echo $form->field($model, 'user_id')->textInput(['type' => 'number']);
?>
        </div>
    </div>
    
    <div class="row">
Example #6
0
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\helpers\Url;
use pistol88\staffer\models\Category;
$this->title = 'Категории';
$this->params['breadcrumbs'][] = $this->title;
\pistol88\staffer\assets\BackendAsset::register($this);
?>
<div class="category-index">
    
    <div class="row">
        <div class="col-md-2">
            <?php 
echo Html::a('Создать категорию', ['create'], ['class' => 'btn btn-success']);
?>
        </div>
        <div class="col-md-10">
            <?php 
echo $this->render('../parts/menu');
?>
        </div>
    </div>

    <br style="clear: both;"></div>

    <?php 
echo \kartik\grid\GridView::widget(['export' => false, 'dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'id', 'filter' => false, 'options' => ['style' => 'width: 55px;']], 'name', ['attribute' => 'parent_id', 'filter' => Html::activeDropDownList($searchModel, 'parent_id', Category::buildTextTree(), ['class' => 'form-control', 'prompt' => 'Категория']), 'value' => 'parent.name'], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{update} {delete}', 'buttonOptions' => ['class' => 'btn btn-default'], 'options' => ['style' => 'width: 125px;']]]]);
?>

</div>
Example #7
0
 public function getCategory()
 {
     return $this->hasOne(Category::className(), ['id' => 'category_id']);
 }