/** * Create ProcessCategory record * * @param $ProcessCategory array. * @return void */ public function createProcessCategoryRow ($row) { if ($row && is_array( $row ) && isset( $row['CATEGORY_UID'] )) { $record = ProcessCategoryPeer::retrieveByPK( $row['CATEGORY_UID'] ); // create only if the category doesn't exists if (! $record) { $processCategory = new ProcessCategory(); $processCategory->fromArray( $row, BasePeer::TYPE_FIELDNAME ); $processCategory->save(); } } }
require_once "classes/model/ProcessCategory.php"; //if exists the row in the database propel will update it, otherwise will insert. $tr = ProcessCategoryPeer::retrieveByPK($CategoryUid); $processCategory = new ProcessCategory(); $aProcessCategory = $processCategory->loadByCategoryName($CategoryName); if (!is_array($aProcessCategory)) { if (!(is_object($tr) && get_class($tr) == 'ProcessCategory')) { $tr = new ProcessCategory(); } $tr->setCategoryUid($CategoryUid); $tr->setCategoryParent($CategoryParent); $tr->setCategoryName($CategoryName); $tr->setCategoryIcon($CategoryIcon); if ($tr->validate()) { // we save it, since we get no validation errors, or do whatever else you like. $res = $tr->save(); } else { // Something went wrong. We can now get the validationFailures and handle them. $msg = ''; $validationFailuresArray = $tr->getValidationFailures(); foreach ($validationFailuresArray as $objValidationFailure) { $msg .= $objValidationFailure->getMessage() . "<br/>"; } //return array ( 'codError' => -100, 'rowsAffected' => 0, 'message' => $msg ); } //return array ( 'codError' => 0, 'rowsAffected' => $res, 'message' => ''); //to do: uniform coderror structures for all classes //if ( $res['codError'] < 0 ) { // G::SendMessageText ( $res['message'] , 'error' ); //} G::Header('location: processCategoryList');
$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'; echo $response; break; case 'deleteCategory':
/** * 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; } }