| @@ 179-201 (lines=23) @@ | ||
| 176 | * Returns all available to logged user BackendMenu items in yii\widgets\Menu acceptable format |
|
| 177 | * @return BackendMenu[] Tree representation of items |
|
| 178 | */ |
|
| 179 | public static function getAllMenu() |
|
| 180 | { |
|
| 181 | $rows = Yii::$app->cache->get("BackendMenu:all"); |
|
| 182 | if (false === is_array($rows)) { |
|
| 183 | $rows = static::find() |
|
| 184 | ->orderBy('parent_id ASC, sort_order ASC') |
|
| 185 | ->asArray() |
|
| 186 | ->all(); |
|
| 187 | Yii::$app->cache->set( |
|
| 188 | "BackendMenu:all", |
|
| 189 | $rows, |
|
| 190 | 86400, |
|
| 191 | new TagDependency([ |
|
| 192 | 'tags' => [ |
|
| 193 | \devgroup\TagDependencyHelper\ActiveRecordHelper::getCommonTag(static::className()) |
|
| 194 | ] |
|
| 195 | ]) |
|
| 196 | ); |
|
| 197 | } |
|
| 198 | // rebuild rows to tree $all_menu_items |
|
| 199 | $all_menu_items = app\behaviors\Tree::rowsArrayToMenuTree($rows, 1, 1, false); |
|
| 200 | return $all_menu_items; |
|
| 201 | } |
|
| 202 | } |
|
| 203 | ||
| @@ 134-156 (lines=23) @@ | ||
| 131 | return $data; |
|
| 132 | } |
|
| 133 | ||
| 134 | public static function itemsForSelect() |
|
| 135 | { |
|
| 136 | $cacheKey = 'AllWysiwygForSelect'; |
|
| 137 | $items = Yii::$app->cache->get($cacheKey); |
|
| 138 | if (is_array($items) === false) { |
|
| 139 | $items = ArrayHelper::map( |
|
| 140 | self::find()->select(['id', 'name'])->asArray()->all(), |
|
| 141 | 'id', |
|
| 142 | 'name' |
|
| 143 | ); |
|
| 144 | Yii::$app->cache->set( |
|
| 145 | $cacheKey, |
|
| 146 | $items, |
|
| 147 | 86400, |
|
| 148 | new TagDependency([ |
|
| 149 | 'tags' => [ |
|
| 150 | ActiveRecordHelper::getCommonTag(self::className()) |
|
| 151 | ] |
|
| 152 | ]) |
|
| 153 | ); |
|
| 154 | } |
|
| 155 | return $items; |
|
| 156 | } |
|
| 157 | } |
|
| 158 | ||