Destroy given category.

@param \Cortex\Categories\Models\Category $category

@throws \Exception

@return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
431387
public function destroy(Category $category)
    {
        $category->delete();

        return intend([
            'url' => route('adminarea.categories.index'),
            'with' => ['warning' => trans('cortex/foundation::messages.resource_deleted', ['resource' => trans('cortex/categories::common.category'), 'identifier' => $category->name])],
        ]);
    }
282437
public static function delete_category(category_controller $category) : bool {
        $event = category_deleted::create_from_object($category);

        // Delete all fields.
        foreach ($category->get_fields() as $field) {
            self::delete_field_configuration($field);
        }

        $result = $category->delete();
        $event->trigger();
        return $result;
    }
729331
public function destroy(UserPolicy $user, Category $category)
    {
        return $category->user_id == user_id() && $category->user_type == user_type();
    }
1364137
public function delete_category(category_controller $category) : bool {
        $category = $this->validate_category($category);
        $result = api::delete_category($category);
        $this->clear_configuration_cache();
        return $result;
    }
946032
static function updateCategory($category)
    {
        // Update the category thread and post counts
        $threads = $category->threads()->where('deleted_at', null)->get();
        $category->thread_count = $threads->count();

        $postCount = 0;
        foreach ($threads as $thread) {
            $postCount += $thread->posts->count();
        }

        $category->post_count = $postCount;
        $category->saveWithoutTouch();
    }
1222113
public function setCategory(\HarvestCloud\CoreBundle\Entity\Category $category)
    {
        $this->category = $category;

        // copy over the path
        $this->setCategoryPath($category->getPath());
    }
1007092
public function fatal( $object , $category , $message )
	{
		$this->message( self::getMessagePrefix( $object , $category , 'fatal' ) . $message , self::LEVEL_FATAL );

		throw new Exception( $message );
	}
1063361
public static function delete_categories($categories) {
        global $CFG, $DB;
        require_once($CFG->dirroot . "/course/lib.php");

        // Validate parameters.
        $params = self::validate_parameters(self::delete_categories_parameters(), array('categories' => $categories));

        $transaction = $DB->start_delegated_transaction();

        foreach ($params['categories'] as $category) {
            $deletecat = core_course_category::get($category['id'], MUST_EXIST);
            $context = context_coursecat::instance($deletecat->id);
            require_capability('moodle/category:manage', $context);
            self::validate_context($context);
            self::validate_context(get_category_or_system_context($deletecat->parent));

            if ($category['recursive']) {
                // If recursive was specified, then we recursively delete the category's contents.
                if ($deletecat->can_delete_full()) {
                    $deletecat->delete_full(false);
                } else {
                    throw new moodle_exception('youcannotdeletecategory', '', '', $deletecat->get_formatted_name());
                }
            } else {
                // In this situation, we don't delete the category's contents, we either move it to newparent or parent.
                // If the parent is the root, moving is not supported (because a course must always be inside a category).
                // We must move to an existing category.
                if (!empty($category['newparent'])) {
                    $newparentcat = core_course_category::get($category['newparent']);
                } else {
                    $newparentcat = core_course_category::get($deletecat->parent);
                }

                // This operation is not allowed. We must move contents to an existing category.
                if (!$newparentcat->id) {
                    throw new moodle_exception('movecatcontentstoroot');
                }

                self::validate_context(context_coursecat::instance($newparentcat->id));
                if ($deletecat->can_move_content_to($newparentcat->id)) {
                    $deletecat->delete_move($newparentcat->id, false);
                } else {
                    throw new moodle_exception('youcannotdeletecategory', '', '', $deletecat->get_formatted_name());
                }
            }
        }

        $transaction->allow_commit();
    }
221949
public function removeCategory(\Enhavo\Bundle\CategoryBundle\Entity\Category $category)
    {
        $category->setCollection(null);
        $this->categories->removeElement($category);
    }
1319164
public function save(Category $category, Request $request)
    {
        $attributes = $request->get('category');

        if (! $category->exists) {
            $category->newWithCreateTerm($attributes['term']);
        }

        $category->setParent($attributes['parent_id']);

        $category->term->fill($attributes['term'])->save();
        $category->save();

        Alert::info(__('Category was saved'));

        return redirect()->route('platform.systems.category');
    }
979869
protected function deleteCategory()
    {
        $this->controlAccess('category_delete');

        if ($this->category->delete($this->data_category['category_id'])) {
            $url = "admin/content/category/{$this->data_category_group['category_group_id']}";
            $this->redirect($url, $this->text('Category has been deleted'), 'success');
        }

        $this->redirect('', $this->text('Category has not been deleted'), 'warning');
    }
726805
public function DeleteCategory($CategoryID = FALSE) {
      // Check permission
      $this->Permission('Garden.Settings.Manage');
      
      // Set up head
      $this->AddJsFile('categories.js');
      $this->Title(T('Delete Category'));
      $this->AddSideMenu('vanilla/settings/managecategories');

      // Get category data
      $this->Category = $this->CategoryModel->GetID($CategoryID);
      
      
      if (!$this->Category) {
         $this->Form->AddError('The specified category could not be found.');
      } else {
         // Make sure the form knows which item we are deleting.
         $this->Form->AddHidden('CategoryID', $CategoryID);
         
         // Get a list of categories other than this one that can act as a replacement
         $this->OtherCategories = $this->CategoryModel->GetWhere(
            array(
               'CategoryID <>' => $CategoryID,
               'AllowDiscussions' => $this->Category->AllowDiscussions, // Don't allow a category with discussion to be the replacement for one without discussions (or vice versa)
               'CategoryID >' => 0
            ),
            'Sort'
         );
         
         if (!$this->Form->AuthenticatedPostBack()) {
            $this->Form->SetFormValue('DeleteDiscussions', '1'); // Checked by default
         } else {
            $ReplacementCategoryID = $this->Form->GetValue('ReplacementCategoryID');
            $ReplacementCategory = $this->CategoryModel->GetID($ReplacementCategoryID);
            // Error if:
            // 1. The category being deleted is the last remaining category that
            // allows discussions.
            if ($this->Category->AllowDiscussions == '1'
               && $this->OtherCategories->NumRows() == 0)
               $this->Form->AddError('You cannot remove the only remaining category that allows discussions');
            
            /*
            // 2. The category being deleted allows discussions, and it contains
            // discussions, and there is no replacement category specified.
            if ($this->Form->ErrorCount() == 0
               && $this->Category->AllowDiscussions == '1'
               && $this->Category->CountDiscussions > 0
               && ($ReplacementCategory == FALSE || $ReplacementCategory->AllowDiscussions != '1'))
               $this->Form->AddError('You must select a replacement category in order to remove this category.');
            */
            
            // 3. The category being deleted does not allow discussions, and it
            // does contain other categories, and there are replacement parent
            // categories available, and one is not selected.
            /*
            if ($this->Category->AllowDiscussions == '0'
               && $this->OtherCategories->NumRows() > 0
               && !$ReplacementCategory) {
               if ($this->CategoryModel->GetWhere(array('ParentCategoryID' => $CategoryID))->NumRows() > 0)
                  $this->Form->AddError('You must select a replacement category in order to remove this category.');
            }
            */
            
            if ($this->Form->ErrorCount() == 0) {
               // Go ahead and delete the category
               try {
                  $this->CategoryModel->Delete($this->Category, $this->Form->GetValue('ReplacementCategoryID'));
               } catch (Exception $ex) {
                  $this->Form->AddError($ex);
               }
               if ($this->Form->ErrorCount() == 0) {
                  $this->RedirectUrl = Url('vanilla/settings/managecategories');
                  $this->InformMessage(T('Deleting category...'));
               }
            }
         }
      }
      
      // Render default view
      $this->Render();
   }
176182
public function addCategory(CategoryInterface $category)
    {
        if (!$this
            ->categories
            ->contains($category)
        ) {
            $this
                ->categories
                ->add($category);
        }

        return $this;
    }
1079689
public function destroy(CategoryRequest $request, Category $category)
    {
        try {

            $category->delete();
            return $this->response->message(trans('messages.success.deleted', ['Module' => trans('faq::category.name')]))
                ->code(202)
                ->status('success')
                ->url(guard_url('faq/category/0'))
                ->redirect();

        } catch (Exception $e) {

            return $this->response->message($e->getMessage())
                ->code(400)
                ->status('error')
                ->url(guard_url('faq/category/' . $category->getRouteKey()))
                ->redirect();
        }

    }
870824
public function addChild(Category $category): Category
    {
        $this->children->add($category);

        if ($category->getParent() !== $this) {
            $category->setParent($this);
        }

        return $this;
    }
990983
public function category(Category $category)
    {
        $this->category = $category;

        $this->category->categorise($this);
    }
1140060
def remove_category(self, categories):
        
        categories = element_resolver(categories)
        diff = [category for category in self.data['category_child_ref']
                if category not in categories]
        self.update(category_child_ref=diff)