Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menu enhancement #434

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions components/MenuHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,14 @@ public static function getAssignedMenu($userId, $root = null, $callback = null,
$assigned = $query->where(['route' => $filter2])->column();
}
if (count($filter1)) {
$filtered = [];
$query->where('route like :filter');
foreach ($filter1 as $filter) {
$assigned = array_merge($assigned, $query->params([':filter' => $filter])->column());
$filtered[] = $query->params([':filter' => $filter])->column();
}
$assigned = array_merge($assigned, ...$filtered);
}
$assigned = static::requiredParent($assigned, $menus);
static::requiredParent($assigned, $menus);
if ($cache !== null) {
$cache->set($key, $assigned, $config->cacheDuration, new TagDependency([
'tags' => Configs::CACHE_TAG
Expand All @@ -143,20 +145,17 @@ public static function getAssignedMenu($userId, $root = null, $callback = null,
* Ensure all item menu has parent.
* @param array $assigned
* @param array $menus
* @return array
* @return void
*/
private static function requiredParent($assigned, &$menus)
private static function requiredParent(&$assigned, &$menus)
{
$l = count($assigned);
for ($i = 0; $i < $l; $i++) {
$id = $assigned[$i];
$parent_id = $menus[$id]['parent'];
foreach ($assigned as $item) {
$parent_id = $menus[$item]['parent'];
if ($parent_id !== null && !in_array($parent_id, $assigned)) {
$assigned[$l++] = $parent_id;
$assigned[] = $parent_id;
self::requiredParent($assigned, $menus);
}
}

return $assigned;
}

/**
Expand Down