/** * @Route("/file/edit", name="file/edit") * @Access("download: manage downloads") * @Request({"id": "int"}) */ public function editAction($id = 0) { try { if (!($file = File::where(compact('id'))->related('categories')->first())) { if ($id) { App::abort(404, __('Invalid file id.')); } $file = File::create(['status' => 1, 'slug' => '', 'data' => [], 'tags' => [], 'date' => new \DateTime()]); $file->set('markdown', $this->download->config('markdown')); } return ['$view' => ['title' => $id ? __('Edit download') : __('Add download'), 'name' => 'bixie/download/admin/file.php'], '$data' => ['categories' => Category::findAll(), 'statuses' => File::getStatuses(), 'roles' => array_values(Role::findAll()), 'config' => $this->download->config(), 'file' => $file, 'tags' => File::allTags()], 'file' => $file]; } catch (\Exception $e) { App::message()->error($e->getMessage()); return App::redirect('@download/download'); } }
/** * Registers category routes */ public function onRequest() { $categories = Category::findAll(true); uasort($categories, function ($a, $b) { return strcmp(substr_count($a->path, '/'), substr_count($b->path, '/')) * -1; }); $node = Node::query()->where(['link' => '@download'])->first(); foreach ($categories as $category) { if ($category->status !== 1) { continue; } $route = ['label' => $category->title, 'defaults' => ['_node' => $node->id, 'id' => $category->id], 'path' => $node->path . $category->path]; //category views App::routes()->add(array_merge(['name' => '@download/category/' . $category->id, 'controller' => 'Bixie\\Download\\Controller\\SiteController::categoryAction'], $route)); //file view App::routes()->add(array_merge(['name' => '@download/category/file/' . $category->id, 'controller' => 'Bixie\\Download\\Controller\\SiteController::fileAction'], $route)); } }