<commit_before><?php
namespace dvizh\shop\models;

use Yii;
use dvizh\shop\models\category\CategoryQuery;
use yii\helpers\Url;

class Category extends \yii\db\ActiveRecord
{
    function behaviors()
    {
        return [
            'images' => [
                'class' => 'dvizh\gallery\behaviors\AttachImages',
                'mode' => 'single',
            ],
            'slug' => [
                'class' => 'Zelenin\yii\behaviors\Slug',
            ],
            'seo' => [
                'class' => 'dvizh\seo\behaviors\SeoFields',
            ],
            'field' => [
                'class' => 'dvizh\field\behaviors\AttachFields',
            ],
        ];
    }
    
    public static function tableName()
    {
        return '{{%shop_category}}';
    }
    
    static function find()
    {
        return new CategoryQuery(get_called_class());
    }

    public function rules()
    {
        return [
            [['parent_id', 'sort'], 'integer'],
            [['name'], 'required'],
            [['text', 'code'], 'string'],
            [['name', 'code', 'slug'], 'string', 'max' => 55],
        ];
    }

    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'parent_id' => 'Родительская категория',
            'name' => 'Имя категории',
            'slug' => 'Сео имя',
            'text' => 'Описание',
            'image' => 'Картинка',
            'sort' => 'Сортировка',
            'description' => 'Описание',
        ];
    }
    
    public static function buildTree($parent_id = null)
    {
        $return = [];
        
        if(empty($parent_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' => $parent_id])->orderBy('sort DESC')->asArray()->all();
        }
        
        foreach($categories as $level1) {
            $return[$level1['id']] = $level1;
            $return[$level1['id']]['childs'] = self::buildTree($level1['id']);
        }
        
        return $return;
    }

    public static function buildTextTree($groupCategories = [], $id = null, $level = 1, &$treeCategories = [])
    {
        if($id) {

            if (isset($groupCategories[$id])) {

                $prefix = str_repeat('--', $level);
                $level++;
                foreach($groupCategories[$id] as $category){
                    $treeCategories[$category['id']] = $prefix.$category['name'];
                    self::buildTextTree($groupCategories, $category['id'], $level, $treeCategories);
                }
            }

            return $treeCategories;

        } else {
            $treeCategories = [];
            $groupedCategories = [];
            $categories = Yii::$app->db->createCommand('SELECT id, parent_id, name FROM shop_category ORDER BY id ASC')->queryAll();

            if (!is_array($categories)) {
                return false;
            }
<commit_msg>Corrected the remarks<commit_after><?php
namespace dvizh\shop\models;

use Yii;
use dvizh\shop\models\category\CategoryQuery;
use yii\helpers\Url;

class Category extends \yii\db\ActiveRecord
{
    function behaviors()
    {
        return [
            'images' => [
                'class' => 'dvizh\gallery\behaviors\AttachImages',
                'mode' => 'single',
            ],
            'slug' => [
                'class' => 'Zelenin\yii\behaviors\Slug',
            ],
            'seo' => [
                'class' => 'dvizh\seo\behaviors\SeoFields',
            ],
            'field' => [
                'class' => 'dvizh\field\behaviors\AttachFields',
            ],
        ];
    }
    
    public static function tableName()
    {
        return '{{%shop_category}}';
    }
    
    static function find()
    {
        return new CategoryQuery(get_called_class());
    }

    public function rules()
    {
        return [
            [['parent_id', 'sort'], 'integer'],
            [['name'], 'required'],
            [['text', 'code'], 'string'],
            [['name', 'code', 'slug'], 'string', 'max' => 55],
        ];
    }

    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'parent_id' => 'Родительская категория',
            'name' => 'Имя категории',
            'slug' => 'Сео имя',
            'text' => 'Описание',
            'image' => 'Картинка',
            'sort' => 'Сортировка',
            'description' => 'Описание',
        ];
    }
    
    public static function buildTree($parent_id = null)
    {
        $return = [];
        
        if(empty($parent_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' => $parent_id])->orderBy('sort DESC')->asArray()->all();
        }
        
        foreach($categories as $level1) {
            $return[$level1['id']] = $level1;
            $return[$level1['id']]['childs'] = self::buildTree($level1['id']);
        }
        
        return $return;
    }

    public static function buildTextTree($groupCategories = [], $id = null, $level = 1, &$treeCategories = [])
    {
        if($id) {

            if (isset($groupCategories[$id])) {

                $prefix = str_repeat('--', $level);
                $level++;
                foreach($groupCategories[$id] as $category){
                    $treeCategories[$category['id']] = $prefix.$category['name'];
                    self::buildTextTree($groupCategories, $category['id'], $level, $treeCategories);
                }
            }

            return $treeCategories;

        } else {
            $treeCategories = [];
            $groupedCategories = [];
            $categories = Category::find()->where('parent_id = 0 OR parent_id is null')->orderBy('sort DESC')->asArray()->all();

            if (!is_array($categories)) {
                return false;
            }

{'fraction_non_alphanumeric': 0.16787360105332455, 'fraction_numerical': 0.003127057274522712, 'mean_word_length': 1.6913197519929142, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 64, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3479927', 'n_tokens_mistral': 1808, 'n_tokens_neox': 1762, 'n_words': 313}