Airship\Cabin\Bridge\Blueprint\Blog::updateCategory PHP Method

updateCategory() public method

Update a blog category
public updateCategory ( integer $id, array $post ) : boolean
$id integer
$post array
return boolean
    public function updateCategory(int $id, array $post) : bool
    {
        $changes = ['name' => $post['name'] ?? 'Unnamed', 'preamble' => $post['preamble'] ?? ''];
        if (!$this->categoryDescendsFrom((int) $post['parent'], $id)) {
            $changes['parent'] = $post['parent'] > 0 ? $post['parent'] : null;
        }
        $this->db->beginTransaction();
        if (!empty($post['slug'])) {
            if ($this->updateCategorySlug($id, $post)) {
                $changes['slug'] = $post['slug'];
            }
        }
        $this->db->update('hull_blog_categories', $changes, ['categoryid' => $id]);
        return $this->db->commit();
    }

Usage Example

Example #1
0
 /**
  * Edit a category
  *
  * @route blog/category/edit/{id}
  * @param string $id
  */
 public function editCategory(string $id = '')
 {
     $id = (int) $id;
     $post = $this->post(new EditCategoryFilter());
     if (!empty($post)) {
         if ($this->blog->updateCategory($id, $post)) {
             \Airship\redirect($this->airship_cabin_prefix . '/blog/category');
         }
     }
     $category = $this->blog->getCategoryInfo($id);
     $this->lens('blog/category_edit', ['active_link' => 'bridge-link-blog-category', 'category' => $category, 'categories' => $this->blog->getCategoryTree(), 'title' => \__('Edit Category "%s"', 'default', Util::noHTML($category['name']))]);
 }