Example #1
0
 public function update($aData)
 {
     $oConnection = Propel::getConnection(CaseTrackerPeer::DATABASE_NAME);
     try {
         $oCaseTracker = CaseTrackerPeer::retrieveByPK($aData['PRO_UID']);
         if (!is_null($oCaseTracker)) {
             if ($aData['CT_DERIVATION_HISTORY'] == '') {
                 $aData['CT_DERIVATION_HISTORY'] = 0;
             }
             if ($aData['CT_MESSAGE_HISTORY'] == '') {
                 $aData['CT_MESSAGE_HISTORY'] = 0;
             }
             $oCaseTracker->fromArray($aData, BasePeer::TYPE_FIELDNAME);
             if ($oCaseTracker->validate()) {
                 $oConnection->begin();
                 $iResult = $oCaseTracker->save();
                 $oConnection->commit();
                 return $iResult;
             } else {
                 $sMessage = '';
                 $aValidationFailures = $oCaseTracker->getValidationFailures();
                 foreach ($aValidationFailures as $oValidationFailure) {
                     $sMessage .= $oValidationFailure->getMessage() . '<br />';
                 }
                 throw new Exception('The registry cannot be updated!<br />' . $sMessage);
             }
         } else {
             throw new Exception('This row doesn\'t exist!');
         }
     } catch (Exception $oError) {
         $oConnection->rollback();
         throw $oError;
     }
 }
Example #2
0
 /**
  * Implementation for 'GET' method for Rest API
  *
  * @param  mixed $proUid 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($proUid = 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(CaseTrackerPeer::PRO_UID);
             $criteria->addSelectColumn(CaseTrackerPeer::CT_MAP_TYPE);
             $criteria->addSelectColumn(CaseTrackerPeer::CT_DERIVATION_HISTORY);
             $criteria->addSelectColumn(CaseTrackerPeer::CT_MESSAGE_HISTORY);
             $dataset = AppEventPeer::doSelectRS($criteria);
             $dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
             while ($dataset->next()) {
                 $result[] = $dataset->getRow();
             }
         } else {
             $record = CaseTrackerPeer::retrieveByPK($proUid);
             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 CaseTracker ({$paramValues})");
             }
         }
     } catch (RestException $e) {
         throw new RestException($e->getCode(), $e->getMessage());
     } catch (Exception $e) {
         throw new RestException(412, $e->getMessage());
     }
     return $result;
 }