/** * Get category cua tat ca cac module hoac cho tung module. Trong truong hop module do chua co danh muc root thi se tao danh muc root * @param string $module * @param string $prefix * @return array */ public static function getCategory($module = '', $prefix = '') { $level = NULL; $categorys = array(); if (empty($module) or !in_array($module, self::getModules())) { $data = self::find()->addOrderBy('lft')->all(); } else { $root = self::find()->where('module = :module', [':module' => $module])->andWhere('lft = 1')->addOrderBy('lft')->one(); if ($root === null) { // Create root for module $root = new LetCategory(); $root->title = $module; $root->module = $module; $root->saveNode(); } $data = self::find()->where('module = :module', [':module' => $module])->andWhere('lft != 1')->addOrderBy('lft')->all(); $categorys[$root->id] = 'Danh mục gốc của module: ' . $root->module; } foreach ($data as $category) { if ($level == NULL) { $level = $category->level - 1; } $categorys[$category->id] = str_repeat($prefix, $category->level - $level) . $category->title; } return $categorys; }