예제 #1
0
 static function treeItems($route_show, $id, $indent, array $params = [], $selected = null)
 {
     if ($indent < 15) {
         $items = Folder::withTrashed()->whereFolderId($id)->orderBy('order')->orderBy('name')->get();
         if ($items->count() > 0) {
             static::$treeResult .= PHP_EOL . '<ul style="padding-left: 15px;">';
             foreach ($items as $item) {
                 if ($item->id == $selected) {
                     if ($item->trashed()) {
                         static::$treeResult .= PHP_EOL . '<li><strong><del>' . $item->name . '</strong></del>';
                     } else {
                         static::$treeResult .= PHP_EOL . '<li><strong>' . $item->name . '</strong>';
                     }
                 } else {
                     if ($item->trashed()) {
                         static::$treeResult .= PHP_EOL . '<li><del>' . link_to_route($route_show, $item->name, array_merge(['id' => $item->id], $params)) . '</del>';
                     } else {
                         static::$treeResult .= PHP_EOL . '<li>' . link_to_route($route_show, $item->name, array_merge(['id' => $item->id], $params));
                     }
                 }
                 static::treeItems($route_show, $item->id, $indent + 1, $params, $selected);
                 static::$treeResult .= PHP_EOL . '</li>';
             }
             static::$treeResult .= PHP_EOL . '</ul>';
         }
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function delsubfolders($root_id, DeleteRequest $request)
 {
     try {
         $ids = $request->input('remove_children');
         try {
             DB::beginTransaction();
             foreach ($ids as $id) {
                 $model = Folder::withTrashed()->find($id);
                 if ($model) {
                     if ($model->trashed()) {
                         $model->restore();
                     } else {
                         $model->delete();
                     }
                 }
             }
             DB::commit();
             Flash::info(trans($this->resource_name . 'trashed/untrashed', ['model' => $this->model_name]));
             return redirect(route($this->show_route, [$root_id, 'tab' => 'tab_data']));
         } catch (Exception $e) {
             DB::rollBack();
             throw $e;
         }
     } catch (Exception $e) {
         if ($e instanceof PDOException) {
             Flash::error($e->errorInfo[2]);
         } else {
             Flash::error($e->getMessage());
         }
         return $request->response([]);
     }
 }