$oCriteria->add(ProcessCategoryPeer::CATEGORY_NAME, $catName); $oCriteria->add(ProcessCategoryPeer::CATEGORY_UID, $catUID, Criteria::NOT_EQUAL); $oDataset = ProcessCategoryPeer::doSelectRS($oCriteria); $oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); $oDataset->next(); $row = $oDataset->getRow(); $response = isset($row['CATEGORY_NAME']) ? 'false' : 'true'; echo $response; break; case 'updateCategory': try { require_once 'classes/model/ProcessCategory.php'; $catUID = $_REQUEST['cat_uid']; $catName = trim($_REQUEST['category']); $pcat = new ProcessCategory(); $pcat->setNew(false); $pcat->setCategoryUid($catUID); $pcat->setCategoryName($catName); $pcat->save(); g::auditLog("UpdateCategory", "Category Name: " . $catName . " Category ID: (" . $catUID . ") "); echo '{success: true}'; } catch (Exception $ex) { echo '{success: false, error: ' . $ex->getMessage() . '}'; } break; case 'canDeleteCategory': require_once 'classes/model/Process.php'; $proc = new Process(); $aProcess = $proc->getAllProcessesByCategory(); $catUID = $_REQUEST['CAT_UID']; $response = isset($aProcess[$catUID]) ? 'false' : 'true';
/** * Update Category * * @param string $categoryUid Unique id of Category * @param array $arrayData Data * * return array Return data of the Category updated */ public function update($categoryUid, array $arrayData) { try { //Verify data $process = new \ProcessMaker\BusinessModel\Process(); $validator = new \ProcessMaker\BusinessModel\Validator(); $validator->throwExceptionIfDataIsEmpty($arrayData, "\$arrayData"); //Set data $arrayData = array_change_key_case($arrayData, CASE_UPPER); $arrayDataBackup = $arrayData; //Verify data $this->throwExceptionIfNotExistsCategory($categoryUid, $this->arrayFieldNameForException["categoryUid"]); $this->throwExceptionIfDataIsInvalid($categoryUid, $arrayData); //Update $category = new \ProcessCategory(); $category->setNew(false); $category->setCategoryUid($categoryUid); if (isset($arrayData["CAT_NAME"])) { $category->setCategoryName($arrayData["CAT_NAME"]); } $result = $category->save(); $arrayData = $arrayDataBackup; //Return if (!$this->formatFieldNameInUppercase) { $arrayData = array_change_key_case($arrayData, CASE_LOWER); } return $arrayData; } catch (\Exception $e) { throw $e; } }