/**
  * Implementation for 'GET' method for Rest API
  *
  * @param  mixed $objectUid 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($objectUid = 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(CalendarAssignmentsPeer::OBJECT_UID);
             $criteria->addSelectColumn(CalendarAssignmentsPeer::CALENDAR_UID);
             $criteria->addSelectColumn(CalendarAssignmentsPeer::OBJECT_TYPE);
             $dataset = AppEventPeer::doSelectRS($criteria);
             $dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
             while ($dataset->next()) {
                 $result[] = $dataset->getRow();
             }
         } else {
             $record = CalendarAssignmentsPeer::retrieveByPK($objectUid);
             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 CalendarAssignments ({$paramValues})");
             }
         }
     } catch (RestException $e) {
         throw new RestException($e->getCode(), $e->getMessage());
     } catch (Exception $e) {
         throw new RestException(412, $e->getMessage());
     }
     return $result;
 }
Esempio n. 2
0
 function assignCalendarTo($objectUid, $calendarUid, $objectType)
 {
     //if exists the row in the database propel will update it, otherwise will insert.
     $tr = CalendarAssignmentsPeer::retrieveByPK($objectUid);
     if ($calendarUid != "") {
         if (!(is_object($tr) && get_class($tr) == 'CalendarAssignments')) {
             $tr = new CalendarAssignments();
         }
         $tr->setObjectUid($objectUid);
         $tr->setCalendarUid($calendarUid);
         $tr->setObjectType($objectType);
         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 );
         }
     } else {
         //Delete record
         if (is_object($tr) && get_class($tr) == 'CalendarAssignments') {
             $tr->delete();
         }
     }
 }