/** * Deleta as categorias * * @param int $CategoryId */ public function ExeDelete($CategoryId) { $this->CatId = (int) $CategoryId; $WsAreaCategories = new WsAreaCategory(); $WsAreaCategories->setCategory_id($this->CatId); $WsAreaCategories->Execute()->Query("#category_id#"); if (!$WsAreaCategories->Execute()->getResult()) { $this->Result = false; $this->Error = ['Oppsss, você tentou remover uma categoria que não existe no sistema!', WS_INFOR]; } else { extract((array) $WsAreaCategories->Execute()->getResult()[0]); if (!$category_parent && !$this->checkCats()) { $this->Result = false; $this->Error = ["A <b>seção {$category_title}</b> possui categorias cadastradas. Para deletar, antes altere ou remova todas as categorias filhas!", WS_ALERT]; } elseif ($category_parent && !$this->checkArea()) { $this->Result = false; $this->Error = ["A <b>categoria {$category_title}</b> possui artigos cadastradas. Para deletar, antes altere ou remova todos os users desta categoria!", WS_ALERT]; } else { $this->Result = true; $tipo = empty($category_parent) ? 'seção' : 'categoria'; $WsAreaCategories->setCategory_id($this->CatId); $WsAreaCategories->Execute()->delete(); $this->Error = ["A <b>{$tipo} {$category_title}</b> foi removida com sucesso do sistema!", WS_ACCEPT]; } } }
private function getCatParent() { $rCat = new WsAreaCategory(); $rCat->setCategory_id($this->Data['category_id']); $rCat->Execute()->find(); if ($rCat->Execute()->getResult()) { return $rCat->Execute()->getResult()->category_parent; } else { return null; } }
<header> <h1>Atualizar Categoria:</h1> </header> <?php require '_models/AdminAreaCategory.class.php'; $data = filter_input_array(INPUT_POST, FILTER_DEFAULT); $catid = filter_input(INPUT_GET, 'catid', FILTER_VALIDATE_INT); if (!empty($data['SendPostForm'])) { unset($data['SendPostForm']); $cadastra = new AdminAreaCategory(); $cadastra->ExeUpdate($catid, $data); WSErro($cadastra->getError()[0], $cadastra->getError()[1]); } else { $Read = new WsAreaCategory(); $Read->setCategory_id($catid); $Read->Execute()->Query("#category_id#"); if (!$Read->Execute()->getResult()) { header("Location: painel.php?exe=area_category/index&empty=true"); } else { $data = (array) $Read->Execute()->getResult()[0]; } } $checkCreate = filter_input(INPUT_GET, 'create', FILTER_VALIDATE_BOOLEAN); if ($checkCreate && empty($cadastra)) { $tipo = empty($data['category_parent']) ? 'seção' : 'categoria'; WSErro("A {$tipo} <b>{$data['category_title']}</b> foi cadastrada com sucesso no sistema! Continue atualizando a mesma!", WS_ACCEPT); } ?> <form name="PostForm" action="" method="post" enctype="multipart/form-data">