/** * Delete category * * @param int $id Category ID * @return array * * @url DELETE category/{id} */ function delete($id) { if (!DolibarrApiAccess::$user->rights->categorie->supprimer) { throw new RestException(401); } $result = $this->category->fetch($id); if (!$result) { throw new RestException(404, 'category not found'); } if (!DolibarrApi::_checkAccessToResource('category', $this->category->id)) { throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login); } if (!$this->category->delete(DolibarrApiAccess::$user)) { throw new RestException(401, 'error when delete category'); } return array('success' => array('code' => 200, 'message' => 'Category deleted')); }
require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php'; $tmpobject = new Contact($db); $result = $tmpobject->fetch($removeelem); $elementtype = 'contact'; } } } } } $result = $object->del_type($tmpobject, $elementtype); if ($result < 0) { dol_print_error('', $object->error); } } if ($user->rights->categorie->supprimer && $action == 'confirm_delete' && $confirm == 'yes') { if ($object->delete($user) >= 0) { header("Location: " . DOL_URL_ROOT . '/categories/index.php?type=' . $type); exit; } else { setEventMessages($object->error, $object->errors, 'errors'); } } if ($type == Categorie::TYPE_PRODUCT && $elemid && $action == 'addintocategory' && ($user->rights->produit->creer || $user->rights->service->creer)) { require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; $newobject = new Product($db); $result = $newobject->fetch($elemid); $elementtype = 'product'; // TODO Add into categ $result = $object->add_type($newobject, $elementtype); if ($result >= 0) { setEventMessages($langs->trans("WasAddedSuccessfully", $newobject->ref), null, 'mesgs');
/** * @depends testCategorieOther * The depends says test is run only if previous is ok */ public function testCategorieDelete($id) { global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; $localobject=new Categorie($this->savdb); $result=$localobject->fetch($id); $result=$localobject->delete($id); print __METHOD__." id=".$id." result=".$result."\n"; $this->assertLessThan($result, 0); return $result; }
try { $topic = $categorie->create($_POST['titreTopic']); } catch (Exception $exception) { $error = $exception->getMessage(); } if (empty($error)) { header('Location: ' . str_replace('index.php', '', $_SERVER['SCRIPT_NAME']) . 'home/' . $categorie->getCategory() . '/' . urlencode($topic->getTitre())); exit; } } //Supression d'un topic if (isset($_POST['remove'], $_GET['id'])) { $manager = new Categorie($link); $topic = $manager->selectById($_GET['id']); $id = $topic->getId(); $manager->delete($id); header('Location: ' . str_replace('index.php', '', $_SERVER['SCRIPT_NAME']) . 'home/' . $topic->getCategory()->getCategory()); exit; } //modification d'un topic if (isset($_POST['validate'])) { $manager = new Categorie($link); $topic = $manager->selectById($_GET['id']); try { $topic->setTitre($_POST['titreTopic']); } catch (Exception $e) { $error = $e->getMessage(); } if (empty($error)) { $manager->update($topic); header('Location:' . str_replace('index.php', '', $_SERVER['SCRIPT_NAME']) . '/home/' . $topic->getCategory()->getCategory());