parent = $params["parent"]; // default 0 $this->level = $params["level"]; $this->icon = $params["icon"]; $link_type = $params["link_type"]; $this->link = $params["link"]; $this->name = $params["name"]; $this->description = $params["description"]; $this->status = "normal"; if ($this->parent < 0) { return "invalid parent: " . $this->parent; } if ($this->level < 0) { return "invalid level: " . $this->level; } $this->link_type = trim($link_type); if ($this->link_type == "") { $this->link_type = LINK_TYPE_URL; } $result = $this->save(); if ($result) { Log::debug("AddActionBar success with params: " . json_encode($params)); return "success"; } else { Log::error("AddActionBar failed with params: " . json_encode($params)); return "AddActionBar but fail"; } } /** * 根据菜单的id更新一个菜单内容 * * @param array $params * @return string */ public function ModifyActionBar(array $params) { $update = []; $id = $params["id"]; if ($id == "") { return "invalid id"; } if ($params["parent"] > 0) { $update["parent"] = $params["parent"]; } if ($params["level"] > 0) { $update["level"] = $params["level"]; } if (strlen($params["icon"]) > 0) { $update["icon"] = $params["icon"]; } if (strlen($params["link_type"]) > 0) { $update["link_type"] = $params["link_type"]; } if (strlen($params["link"]) > 0) { $update["link"] = $params["link"]; } if (strlen($params["name"]) > 0) { Log::debug("name is " . $params["name"]); $update["name"] = $params["name"]; } if (strlen($params["description"]) > 0) { $update["description"] = $params["description"]; } if (count($update) == 0) { return "nothing to update"; } $num = $this->where("id", $id) ->where("status", "normal") ->where("is_del", false) ->update($update); return "success"; } // todo. /** * 删除一个菜单项目,这里存在一个问题,就是如果删除上层的菜单,下层的菜单也应该都被删掉。先留空。 * * @param array $params * @return string */ public function DeleteActionBar(array $params) { $id = $params["id"]; if ($id == "") { return "invalid id"; } $num = $this->where("id", $id) ->where("status", "normal") ->where("is_del", false) ->update(["is_del" => true]); return "success"; } /** * 查出当前用户可以访问的所有action_bar的信息 * * @param array $params * @return array */ public function ListActionBar(array $params) { $uid = $params["uid"]; // 收集当前用户有权限的bar_id $userActionBar = new UserActionBarController(); $bar_ids = $userActionBar->ListActionBarIds($uid); if (count($bar_ids) == 0) { return []; } // 查出bars的信息 $result = $this->select("id", "parent", "level", "name", "description", "icon", "link_type", "link") ->where("id", $bar_ids) ->where("status", "normal") ->where("is_del", false) ->all(); return $result; } }