コード例 #1
0
 static function treeItems($route_show, $id, $indent, $name)
 {
     if ($indent < 15) {
         $items = Category::withTrashed()->whereCategoryId($id)->orderBy('order')->orderBy('name')->get();
         if ($items->count() > 0) {
             static::$treeResult .= PHP_EOL . '<ul>';
             foreach ($items as $item) {
                 static::$treeResult .= PHP_EOL . '<li>' . link_to_route($route_show, $item->name, ['id' => $item->id]) . ' - ' . ($item->trashed() ? '<del>' . e($item->display_name) . '</del>' : e($item->display_name));
                 static::treeItems($route_show, $item->id, $indent + 1, $item->name);
                 static::$treeResult .= PHP_EOL . '</li>';
             }
             static::$treeResult .= PHP_EOL . '</ul>';
         }
     }
 }
コード例 #2
0
 /**
  *
  */
 public function __construct()
 {
     $this->middleware('admin');
     /*
      * check the ROOT_ITEM with a null parent
      * check all items with null parent to be ROOT_ITEM owned
      */
     $root = Category::withTrashed()->find(Category::ROOT_CATEGORY);
     if (!$root) {
         $root = new Category();
         $root->name = '*';
         $root->acronym = '*';
         $root->display_name = '*';
         $root->category_id = null;
         $root->save();
         $root->id = Category::ROOT_CATEGORY;
         $root->save();
     } else {
         if ($root->trashed()) {
             $root->restore();
         }
         if ($root->category_id != null) {
             $root->category_id = null;
             $root->save();
         }
     }
     Category::withTrashed()->whereCategoryId(null)->where('id', '<>', Category::ROOT_CATEGORY)->update(['category_id' => Category::ROOT_CATEGORY]);
 }