コード例 #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];
 }
コード例 #2
0
 /**
  * {@inheritdoc}
  */
 public function generate(array $parameters = [])
 {
     $id = $parameters['id'];
     $category_id = isset($parameters['category_id']) ? $parameters['category_id'] : 0;
     if (!isset($this->cacheEntries[$id . '-' . $category_id])) {
         if (!($file = File::find($id))) {
             throw new RouteNotFoundException('File not found.');
         }
         if ($category_id && !($category = Category::find($category_id))) {
             throw new RouteNotFoundException('Category not found.');
         }
         $this->addCache($file, $category_id, isset($category) ? $category->slug : App::config('bixie/download')->get('root_category', 'root'));
     }
     $meta = $this->cacheEntries[$id . '-' . $category_id];
     $parameters['slug'] = $meta['slug'];
     unset($parameters['id']);
     unset($parameters['category_id']);
     return $parameters;
 }
コード例 #3
0
 /**
  * @Saving
  */
 public static function saving($event, Category $category)
 {
     $db = self::getConnection();
     $i = 2;
     $id = $category->id;
     if (!$category->slug) {
         $category->slug = $category->title;
     }
     // Ensure unique slug
     while (self::where(['slug = ?', 'parent_id= ?'], [$category->slug, $category->parent_id])->where(function ($query) use($id) {
         if ($id) {
             $query->where('id <> ?', [$id]);
         }
     })->first()) {
         $category->slug = preg_replace('/-\\d+$/', '', $category->slug) . '-' . $i++;
     }
     // Update own path
     $path = '/' . $category->slug;
     if ($category->parent_id && ($parent = Category::find($category->parent_id))) {
         $path = $parent->path . $path;
     } else {
         // set Parent to 0, if old parent is not found
         $category->parent_id = 0;
     }
     // Update children's paths
     if ($id && $path != $category->path) {
         $db->executeUpdate('UPDATE ' . self::getMetadata()->getTable() . ' SET path = REPLACE (' . $db->getDatabasePlatform()->getConcatExpression($db->quote('//'), 'path') . ", '//{$category->path}', '{$path}')" . ' WHERE path LIKE ' . $db->quote($category->path . '//%'));
     }
     $category->path = $path;
     // Set priority
     if (!$id) {
         $category->priority = 1 + $db->createQueryBuilder()->select($db->getDatabasePlatform()->getMaxExpression('priority'))->from(self::getMetadata()->getTable())->where(['parent_id' => $category->parent_id])->execute()->fetchColumn();
     }
 }
コード例 #4
0
 /**
  * @Route("/updateOrder", methods="POST")
  * @Request({"categories": "array"}, csrf=true)
  */
 public function updateOrderAction($categories = [])
 {
     foreach ($categories as $data) {
         if ($category = Category::find($data['id'])) {
             $category->priority = $data['order'];
             $category->parent_id = $data['parent_id'] ?: 0;
             $category->save();
         }
     }
     return ['message' => 'success'];
 }
コード例 #5
0
 /**
  * @Route("/{id}", name="id")
  * @Request({"id":"int", "category_id":"int"})
  */
 public function fileAction($id = 0, $category_id = 0)
 {
     /** @var File $file */
     if (!($file = File::where(['id = ?', 'status = ?'], [$id, '1'])->where(function ($query) {
         return $query->where('roles IS NULL')->whereInSet('roles', App::user()->roles, false, 'OR');
     })->first())) {
         App::abort(404, __('File not found.'));
     }
     $file->setActiveCategory($category_id);
     App::trigger('bixie.prepare.file', [$file, App::view()]);
     $file->content = App::content()->applyPlugins($file->content, ['file' => $file, 'markdown' => $file->get('markdown')]);
     $previous = File::getPrevious($file);
     $next = File::getNext($file);
     /** @var Category $category */
     if ($category_id && !($category = Category::where(['id = ?', 'status = ?'], [$category_id, '1'])->where(function ($query) {
         return $query->where('roles IS NULL')->whereInSet('roles', App::user()->roles, false, 'OR');
     })->related('files')->first())) {
         App::abort(404, __('Category not found.'));
     }
     if ($breadcrumbs = App::module('bixie/breadcrumbs')) {
         if ($category_id) {
             $cat = $category;
             $crumbs = [['title' => $category->title, 'url' => $category->getUrl()]];
             while ($parent_id = $cat->parent_id) {
                 if ($cat = $cat->find($parent_id, true)) {
                     $crumbs[] = ['title' => $cat->title, 'url' => $cat->getUrl()];
                 }
             }
             foreach (array_reverse($crumbs) as $data) {
                 $breadcrumbs->addUrl($data);
             }
         }
         //add file
         $breadcrumbs->addUrl(['title' => $file->title, 'url' => $file->getUrl()]);
     }
     return ['$view' => ['title' => __($file->title), 'name' => 'bixie/download/file.php'], 'download' => $this->download, 'config' => $this->download->config(), 'previous' => $previous, 'next' => $next, 'file' => $file, 'node' => App::node()];
 }
コード例 #6
0
 public function onRoleDelete($event, $role)
 {
     Category::removeRole($role);
 }