Example #1
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 #2
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 #3
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'))) {
    ?>
 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));
 }