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; }
/** * Retrieve object using using composite pkey values. * @param string $calendar_uid * @param string $calendar_business_day * @param string $calendar_business_start * @param string $calendar_business_end * @param Connection $con * @return CalendarBusinessHours */ public static function retrieveByPK($calendar_uid, $calendar_business_day, $calendar_business_start, $calendar_business_end, $con = null) { if ($con === null) { $con = Propel::getConnection(self::DATABASE_NAME); } $criteria = new Criteria(); $criteria->add(CalendarBusinessHoursPeer::CALENDAR_UID, $calendar_uid); $criteria->add(CalendarBusinessHoursPeer::CALENDAR_BUSINESS_DAY, $calendar_business_day); $criteria->add(CalendarBusinessHoursPeer::CALENDAR_BUSINESS_START, $calendar_business_start); $criteria->add(CalendarBusinessHoursPeer::CALENDAR_BUSINESS_END, $calendar_business_end); $v = CalendarBusinessHoursPeer::doSelect($criteria, $con); return !empty($v) ? $v[0] : null; }
public function getCalendarBusinessHours ($calendarUid = null) { require_once ( 'classes/model/CalendarBusinessHours.php' ); $calendarUid = (is_null($calendarUid)) ? $this->pmCalendarUid : $calendarUid; $this->pmCalendarUid = $calendarUid; $criteria = new Criteria('workflow'); $criteria->clearSelectColumns ( ); $criteria->addSelectColumn ( CalendarBusinessHoursPeer::CALENDAR_UID ); $criteria->addSelectColumn ( CalendarBusinessHoursPeer::CALENDAR_BUSINESS_DAY ); $criteria->addSelectColumn ( CalendarBusinessHoursPeer::CALENDAR_BUSINESS_START ); $criteria->addSelectColumn ( CalendarBusinessHoursPeer::CALENDAR_BUSINESS_END ); $criteria->add ( CalendarBusinessHoursPeer::CALENDAR_UID, $calendarUid , CRITERIA::EQUAL ); $criteria->addDescendingOrderByColumn ( CalendarBusinessHoursPeer::CALENDAR_BUSINESS_DAY ); $criteria->addAscendingOrderByColumn ( CalendarBusinessHoursPeer::CALENDAR_BUSINESS_START ); $rs = CalendarBusinessHoursPeer::doSelectRS($criteria); $rs->setFetchmode(ResultSet::FETCHMODE_ASSOC); $rs->next(); $row = $rs->getRow(); $fields = array(); $count = 0; while (is_array($row)) { $count++; $iniTime = (float)str_replace(':', '', $row['CALENDAR_BUSINESS_START']); $finTime = (float)str_replace(':', '', $row['CALENDAR_BUSINESS_END']); $row['DIFF_HOURS'] = (($finTime-$iniTime)/100); $fields[$count] = $row; $rs->next(); $row = $rs->getRow(); } return $fields; }
/** * Populates the object using an array. * * This is particularly useful when populating an object from one of the * request arrays (e.g. $_POST). This method goes through the column * names, checking to see whether a matching key exists in populated * array. If so the setByName() method is called for that column. * * You can specify the key type of the array by additionally passing one * of the class type constants TYPE_PHPNAME, TYPE_COLNAME, TYPE_FIELDNAME, * TYPE_NUM. The default key type is the column's phpname (e.g. 'authorId') * * @param array $arr An array to populate the object from. * @param string $keyType The type of keys the array uses. * @return void */ public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = CalendarBusinessHoursPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setCalendarUid($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setCalendarBusinessDay($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setCalendarBusinessStart($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setCalendarBusinessEnd($arr[$keys[3]]); } }