/** * Implementation for 'GET' method for Rest API * * @param mixed $categoryUid Primary key * * @return array $result Returns array within multiple records or a single record depending if * a single selection was requested passing id(s) as param */ protected function get($categoryUid = null) { $result = array(); try { $noArguments = true; $argumentList = func_get_args(); foreach ($argumentList as $arg) { if (!is_null($arg)) { $noArguments = false; } } if ($noArguments) { $criteria = new Criteria('workflow'); $criteria->addSelectColumn(ProcessCategoryPeer::CATEGORY_UID); $criteria->addSelectColumn(ProcessCategoryPeer::CATEGORY_PARENT); $criteria->addSelectColumn(ProcessCategoryPeer::CATEGORY_NAME); $criteria->addSelectColumn(ProcessCategoryPeer::CATEGORY_ICON); $dataset = AppEventPeer::doSelectRS($criteria); $dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); while ($dataset->next()) { $result[] = $dataset->getRow(); } } else { $record = ProcessCategoryPeer::retrieveByPK($categoryUid); if ($record) { $result = $record->toArray(BasePeer::TYPE_FIELDNAME); } else { $paramValues = ""; foreach ($argumentList as $arg) { $paramValues .= strlen($paramValues) ? ', ' : ''; if (!is_null($arg)) { $paramValues .= "{$arg}"; } else { $paramValues .= "NULL"; } } throw new RestException(417, "table ProcessCategory ({$paramValues})"); } } } catch (RestException $e) { throw new RestException($e->getCode(), $e->getMessage()); } catch (Exception $e) { throw new RestException(412, $e->getMessage()); } return $result; }
/** * 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(); } } }
<?php try { $form = $_POST['form']; $CategoryUid = $form['CATEGORY_UID']; $CategoryParent = $form['CATEGORY_PARENT']; $CategoryName = $form['CATEGORY_NAME']; $CategoryIcon = $form['CATEGORY_ICON']; 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 );
/** * Verify if does not exist the Category in table PROCESS_CATEGORY * * @param string $categoryUid Unique id of Category * @param string $fieldNameForException Field name for the exception * * return void Throw exception if does not exist the Category in table PROCESS_CATEGORY */ public function throwExceptionIfNotExistsCategory($categoryUid, $fieldNameForException) { try { $obj = \ProcessCategoryPeer::retrieveByPK($categoryUid); if (is_null($obj)) { throw new \Exception(\G::LoadTranslation("ID_CATEGORY_NOT_EXIST", array($fieldNameForException, $categoryUid))); } } catch (\Exception $e) { throw $e; } }
/** * Verify if doesn't exists the Process Category in table PROCESS_CATEGORY * * @param string $processCategoryUid Unique id of Process Category * @param string $fieldNameForException Field name for the exception * * return void Throw exception if doesn't exists the Process Category in table PROCESS_CATEGORY */ public function throwExceptionIfNotExistsProcessCategory($processCategoryUid, $fieldNameForException) { try { $obj = \ProcessCategoryPeer::retrieveByPK($processCategoryUid); if (!(is_object($obj) && get_class($obj) == "ProcessCategory")) { throw new \Exception(\G::LoadTranslation("ID_PROJECT_CATEGORY_DOES_NOT_EXIST", array($fieldNameForException, $processCategoryUid))); } } catch (\Exception $e) { throw $e; } }