Exemplo n.º 1
0
 /**
  * @Route("category/edit", name="admin/category/edit")
  * @Access("download: manage categories")
  * @Request({"id": "int"})
  */
 public function editCategoryAction($id = 0)
 {
     if (!($category = Category::where(compact('id'))->related('files')->first())) {
         if ($id) {
             App::abort(404, __('Invalid file id.'));
         }
         $category = Category::create(['status' => 1, 'slug' => '']);
         $category->set('markdown', $this->download->config('markdown'));
     }
     return ['$view' => ['title' => $id ? __('Edit category') : __('Add category'), 'name' => 'bixie/download/admin/category.php'], '$data' => ['roles' => array_values(Role::findAll()), 'category' => $category], 'category' => $category];
 }
 /**
  * @Route("/", methods="POST")
  * @Route("/{id}", methods="POST", requirements={"id"="\d+"})
  * @Request({"category": "array", "id": "int"}, csrf=true)
  */
 public function saveAction($data, $id = 0)
 {
     if (!($category = Category::where(compact('id'))->related('files')->first())) {
         $category = Category::create();
         unset($data['id']);
     }
     if (!($data['slug'] = App::filter($data['slug'] ?: $data['title'], 'slugify'))) {
         App::abort(400, __('Invalid slug.'));
     }
     $category->updateOrdering($data);
     //unset array typed files
     unset($data['files']);
     $category->save($data);
     return ['message' => 'success', 'category' => $category];
 }