/** * 获得全部分类 * * @return \Illuminate\Database\Eloquent\Collection|static[] */ public static function getAllCategory() { //加载函数库 load_func('common'); $data = obj_to_array(self::all()); $data = array_to_obj(merge_tree_child_node($data)); return $data; }
private function array_to_obj($array, &$obj) { foreach ($array as $key => $value) { if (is_array($value)) { $obj->{$key} = new stdClass(); array_to_obj($value, $obj->{$key}); } else { $obj->{$key} = $value; } } return $obj; }
/** * 获得全部分类 * * @return mixed * @author yangyifan <*****@*****.**> */ public static function getUserChoseCagetory() { //加载函数库 load_func('common'); //获得当前用户全部新闻分类 $user_new_category_id = self::getUserCagetory(); $all_category = self::all(); if (!empty($all_category)) { foreach ($all_category as &$category) { $category->checked = in_array($category->id, $user_new_category_id) ? true : false; } } $all_category = obj_to_array($all_category); return array_to_obj(merge_tree_child_node($all_category)); }
/** * 获得组合用户全部分类[组合好] * * @param null $role_id * @return array * @author yangyifan <*****@*****.**> */ public static function getFullUserMenu($role_id = null) { //加载函数库 load_func('common'); $role_id = self::getRoleId($role_id); $all_menu = self::where('deleted_at', '=', '0000-00-00 00:00:00')->get(); $all_user_menu = self::getUserRelationMenu($role_id); if (!empty($all_menu)) { foreach ($all_menu as &$menu) { $menu->checked = in_array($menu->id, $all_user_menu) ? true : false; } } //组合数据 $all_menu = merge_tree_child_node(obj_to_array($all_menu)); return array_to_obj($all_menu); }
/** * 获得全部分类 * * @return \Illuminate\Database\Eloquent\Collection|static[] */ public static function getAllCategory() { //加载函数库 load_func('common'); $data = obj_to_array(self::where('status', '=', 1)->where('deleted_at', '=', '0000-00-00 00:00:00')->get()); $data = array_to_obj(merge_tree_child_node($data)); return $data; }