Пример #1
0
 function saveCalendarBusinessHours($aData)
 {
     $CalendarUid = $aData['CALENDAR_UID'];
     $CalendarBusinessDay = $aData['CALENDAR_BUSINESS_DAY'];
     $CalendarBusinessStart = $aData['CALENDAR_BUSINESS_START'];
     $CalendarBusinessEnd = $aData['CALENDAR_BUSINESS_END'];
     //if exists the row in the database propel will update it, otherwise will insert.
     $tr = CalendarBusinessHoursPeer::retrieveByPK($CalendarUid, $CalendarBusinessDay, $CalendarBusinessStart, $CalendarBusinessEnd);
     if (!(is_object($tr) && get_class($tr) == 'CalendarBusinessHours')) {
         $tr = new CalendarBusinessHours();
     }
     $tr->setCalendarUid($CalendarUid);
     $tr->setCalendarBusinessDay($CalendarBusinessDay);
     $tr->setCalendarBusinessStart($CalendarBusinessStart);
     $tr->setCalendarBusinessEnd($CalendarBusinessEnd);
     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 = $CalendarBusinessDay . '<hr/>';
         $validationFailuresArray = $tr->getValidationFailures();
         foreach ($validationFailuresArray as $objValidationFailure) {
             $msg .= $objValidationFailure->getMessage() . "<br/>";
         }
         //return array ( 'codError' => -100, 'rowsAffected' => 0, 'message' => $msg );
         G::SendTemporalMessage($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' );
     //}
 }
 /**
  * Implementation for 'GET' method for Rest API
  *
  * @param  mixed $calendarUid, $calendarBusinessDay, $calendarBusinessStart, $calendarBusinessEnd 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($calendarUid = null, $calendarBusinessDay = null, $calendarBusinessStart = null, $calendarBusinessEnd = 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(CalendarBusinessHoursPeer::CALENDAR_UID);
             $criteria->addSelectColumn(CalendarBusinessHoursPeer::CALENDAR_BUSINESS_DAY);
             $criteria->addSelectColumn(CalendarBusinessHoursPeer::CALENDAR_BUSINESS_START);
             $criteria->addSelectColumn(CalendarBusinessHoursPeer::CALENDAR_BUSINESS_END);
             $dataset = AppEventPeer::doSelectRS($criteria);
             $dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
             while ($dataset->next()) {
                 $result[] = $dataset->getRow();
             }
         } else {
             $record = CalendarBusinessHoursPeer::retrieveByPK($calendarUid, $calendarBusinessDay, $calendarBusinessStart, $calendarBusinessEnd);
             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 CalendarBusinessHours ({$paramValues})");
             }
         }
     } catch (RestException $e) {
         throw new RestException($e->getCode(), $e->getMessage());
     } catch (Exception $e) {
         throw new RestException(412, $e->getMessage());
     }
     return $result;
 }