protected function findModel($id)
 {
     if (($model = Category::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
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]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id, 'organization_id' => $this->organization_id]);
     $query->andFilterWhere(['like', 'name', $this->name]);
     return $dataProvider;
 }
Example #3
0
 public static function buildTextTree($id = null, $level = 1, $ban = [])
 {
     $return = [];
     $prefix = str_repeat('--', $level);
     $level++;
     if (empty($id)) {
         $categories = Category::find()->where('parent_id = 0 OR parent_id is null')->orderBy('sort DESC')->asArray()->all();
     } else {
         $categories = Category::find()->where(['parent_id' => $id])->orderBy('sort DESC')->asArray()->all();
     }
     foreach ($categories as $category) {
         if (!in_array($category['id'], $ban)) {
             $return[$category['id']] = "{$prefix} {$category['name']}";
             $return = $return + self::buildTextTree($category['id'], $level, $ban);
         }
     }
     return $return;
 }
Example #4
0
 public function getCategory()
 {
     return $this->hasOne(Category::className(), ['id' => 'category_id']);
 }
Example #5
0
<?php

use yii\helpers\Html;
use yii\helpers\ArrayHelper;
use yii\bootstrap\ActiveForm;
use pistol88\service\models\Category;
$categories = Category::find()->where("id != :id AND (parent_id = 0 OR parent_id IS NULL)", [':id' => (int) $model->id])->all();
$categories = ArrayHelper::map($categories, 'id', 'name');
$categories['0'] = 'Нет';
if (!$model->parent_id) {
    $model->parent_id = 0;
}
//$categories = array_reverse($categories);
?>

<div class="category-form">

    <?php 
$form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]);
?>
        <?php 
echo $form->errorSummary($model);
?>

        <?php 
echo $form->field($model, 'name')->textInput(['maxlength' => true]);
?>
    
        <?php 
if (yii::$app->has('organization') && ($organization = yii::$app->get('organization'))) {
    ?>
Example #6
0
            <div class="col-lg-2 col-md-4 col-xs-6">
                <?php 
    if (!$model->status) {
        $model->status = 'active';
    }
    ?>
                <?php 
    echo $form->field($model, 'status')->widget(Select2::classname(), ['data' => $module->propertyStatuses, 'language' => 'ru', 'options' => ['placeholder' => 'Выберите статус ...'], 'pluginOptions' => ['allowClear' => true]]);
    ?>
            </div>
        <?php 
}
?>
        <div class="col-lg-2 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-lg-2 col-md-3 col-xs-6">
            <?php 
echo $form->field($model, 'client_id')->textInput();
?>
            <?php 
if ($model->client_id) {
    ?>
                <a href="<?php 
    echo Url::toRoute(['/client/client/view', 'id' => $model->client_id]);
    ?>
"><i class="glyphicon glyphicon-eye-open"></i> <?php 
    echo $model->client->name;
    ?>
 public function actionGetCategories()
 {
     $categories = Category::find()->where('parent_id IS NULL OR parent_id = 0')->orderBy('sort DESC, id ASC')->all();
     $json = [];
     $json['HtmlBlock'] = $this->renderPartial('order-type/net/categories', ['categories' => $categories]);
     die(json_encode($json));
 }
Example #8
0
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\helpers\Url;
use pistol88\service\models\Category;
$this->title = $module->propertyName;
$this->params['breadcrumbs'][] = $this->title;
\pistol88\service\assets\BackendAsset::register($this);
?>
<div class="model-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>
    
    <?php 
echo \kartik\grid\GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'export' => false, 'columns' => [['attribute' => 'id', 'filter' => false, 'options' => ['style' => 'width: 55px;']], 'name', 'client.name', ['attribute' => 'category_id', 'filter' => Html::activeDropDownList($searchModel, 'category_id', Category::buildTextTree(), ['class' => 'form-control', 'prompt' => 'Категория']), 'value' => 'category.name'], ['attribute' => 'status', 'filter' => Html::activeDropDownList($searchModel, 'status', $module->propertyStatuses, ['class' => 'form-control', 'prompt' => 'Статус']), 'content' => function ($model) use($module) {
    return @$module->propertyStatuses[$model->status];
}], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{view} {update} {delete}', 'buttonOptions' => ['class' => 'btn btn-default'], 'options' => ['style' => 'width: 155px;']]]]);
?>

</div>