/**
  * @desc Deletes a category and items.
  * @param int $id Id of the category to delete.
  */
 public function delete($id)
 {
     if (!$this->get_categories_cache()->category_exists($id) || $id == Category::ROOT_CATEGORY) {
         throw new CategoryNotFoundException($id);
     }
     $category = $this->get_categories_cache()->get_category($id);
     $this->db_querier->delete($this->table_name, 'WHERE id=:id', array('id' => $id));
     //Delete items
     $this->db_querier->delete($this->categories_items_parameters->get_table_name_contains_items(), 'WHERE ' . $this->categories_items_parameters->get_field_name_id_category() . '=:id_category', array('id_category' => $id));
     $result = PersistenceContext::get_querier()->select_rows($this->table_name, array('id', 'c_order'), 'WHERE id_parent=:id_parent AND c_order > :order', array('id_parent' => $category->get_id_parent(), 'order' => $category->get_order()));
     while ($row = $result->fetch()) {
         $this->db_querier->update($this->table_name, array('c_order' => $row['c_order'] - 1), 'WHERE id=:id', array('id' => $row['id']));
     }
     $this->regenerate_cache();
 }