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' ); //} }
function saveCalendarInfo($aData) { $CalendarUid = $aData['CALENDAR_UID']; $CalendarName = $aData['CALENDAR_NAME']; $CalendarDescription = $aData['CALENDAR_DESCRIPTION']; $CalendarStatus = isset($aData['CALENDAR_STATUS']) ? $aData['CALENDAR_STATUS'] : "INACTIVE"; $defaultCalendars[] = '00000000000000000000000000000001'; if (in_array($aData['CALENDAR_UID'], $defaultCalendars)) { $CalendarStatus = 'ACTIVE'; $CalendarName = 'Default'; } $CalendarWorkDays = isset($aData['CALENDAR_WORK_DAYS']) ? implode("|", $aData['CALENDAR_WORK_DAYS']) : ""; //if exists the row in the database propel will update it, otherwise will insert. $tr = CalendarDefinitionPeer::retrieveByPK($CalendarUid); if (!(is_object($tr) && get_class($tr) == 'CalendarDefinition')) { $tr = new CalendarDefinition(); $tr->setCalendarCreateDate('now'); } $tr->setCalendarUid($CalendarUid); $tr->setCalendarName($CalendarName); $tr->setCalendarUpdateDate('now'); $tr->setCalendarDescription($CalendarDescription); $tr->setCalendarStatus($CalendarStatus); $tr->setCalendarWorkDays($CalendarWorkDays); if ($tr->validate()) { // we save it, since we get no validation errors, or do whatever else you like. $res = $tr->save(); //Calendar Business Hours Save code. //First Delete all current records $CalendarBusinessHoursObj = new CalendarBusinessHours(); $CalendarBusinessHoursObj->deleteAllCalendarBusinessHours($CalendarUid); //Save all the sent records foreach ($aData['BUSINESS_DAY'] as $key => $objData) { $objData['CALENDAR_UID'] = $CalendarUid; $CalendarBusinessHoursObj->saveCalendarBusinessHours($objData); } //Holiday Save code. //First Delete all current records $CalendarHolidayObj = new CalendarHolidays(); $CalendarHolidayObj->deleteAllCalendarHolidays($CalendarUid); //Save all the sent records foreach ($aData['HOLIDAY'] as $key => $objData) { if ($objData['CALENDAR_HOLIDAY_NAME'] != "" && $objData['CALENDAR_HOLIDAY_START'] != "" && $objData['CALENDAR_HOLIDAY_END'] != "") { $objData['CALENDAR_UID'] = $CalendarUid; $CalendarHolidayObj->saveCalendarHolidays($objData); } } } 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 ); } //return array ( 'codError' => 0, 'rowsAffected' => $res, 'message' => ''); //to do: uniform coderror structures for all classes //if ( $res['codError'] < 0 ) { // G::SendMessageText ( $res['message'] , 'error' ); //} }
/** * Validates all modified columns of given CalendarBusinessHours object. * If parameter $columns is either a single column name or an array of column names * than only those columns are validated. * * NOTICE: This does not apply to primary or foreign keys for now. * * @param CalendarBusinessHours $obj The object to validate. * @param mixed $cols Column name or array of column names. * * @return mixed TRUE if all columns are valid or the error message of the first invalid column. */ public static function doValidate(CalendarBusinessHours $obj, $cols = null) { $columns = array(); if ($cols) { $dbMap = Propel::getDatabaseMap(CalendarBusinessHoursPeer::DATABASE_NAME); $tableMap = $dbMap->getTable(CalendarBusinessHoursPeer::TABLE_NAME); if (!is_array($cols)) { $cols = array($cols); } foreach ($cols as $colName) { if ($tableMap->containsColumn($colName)) { $get = 'get' . $tableMap->getColumn($colName)->getPhpName(); $columns[$colName] = $obj->{$get}(); } } } else { if ($obj->isNew() || $obj->isColumnModified(CalendarBusinessHoursPeer::CALENDAR_BUSINESS_DAY)) { $columns[CalendarBusinessHoursPeer::CALENDAR_BUSINESS_DAY] = $obj->getCalendarBusinessDay(); } } return BasePeer::doValidate(CalendarBusinessHoursPeer::DATABASE_NAME, CalendarBusinessHoursPeer::TABLE_NAME, $columns); }
public function saveCalendarInfo($aData) { $CalendarUid = $aData['CALENDAR_UID']; $CalendarName = $aData['CALENDAR_NAME']; $CalendarDescription = $aData['CALENDAR_DESCRIPTION']; $CalendarStatus = isset($aData['CALENDAR_STATUS']) ? $aData['CALENDAR_STATUS'] : "INACTIVE"; $defaultCalendars[] = '00000000000000000000000000000001'; if (in_array($aData['CALENDAR_UID'], $defaultCalendars)) { $CalendarStatus = 'ACTIVE'; $CalendarName = G::LoadTranslation('ID_DEFAULT_CALENDAR'); } $CalendarWorkDays = isset($aData['CALENDAR_WORK_DAYS']) ? implode("|", $aData['CALENDAR_WORK_DAYS']) : ""; $msgCalendarDescriptionStatus = $aData["CALENDAR_DESCRIPTION"] != "" ? ", Description: " . $aData["CALENDAR_DESCRIPTION"] . ", Status: " . ucwords(strtolower($aData["CALENDAR_STATUS"])) : ", Status: " . ucwords(strtolower($aData["CALENDAR_STATUS"])); //if exists the row in the database propel will update it, otherwise will insert. $tr = CalendarDefinitionPeer::retrieveByPK($CalendarUid); if (!(is_object($tr) && get_class($tr) == 'CalendarDefinition')) { $tr = new CalendarDefinition(); $tr->setCalendarCreateDate('now'); G::auditLog("CreateCalendar", "Calendar Name: " . $aData['CALENDAR_NAME'] . $msgCalendarDescriptionStatus); } else { G::auditLog("UpdateCalendar", "Calendar Name: " . $aData['CALENDAR_NAME'] . $msgCalendarDescriptionStatus . ", Calendar ID: (" . $CalendarUid . ") "); } $tr->setCalendarUid($CalendarUid); $tr->setCalendarName($CalendarName); $tr->setCalendarUpdateDate('now'); $tr->setCalendarDescription($CalendarDescription); $tr->setCalendarStatus($CalendarStatus); $tr->setCalendarWorkDays($CalendarWorkDays); if ($tr->validate()) { // we save it, since we get no validation errors, or do whatever else you like. $res = $tr->save(); //Calendar Business Hours Save code. //First Delete all current records $CalendarBusinessHoursObj = new CalendarBusinessHours(); $CalendarBusinessHoursObj->deleteAllCalendarBusinessHours($CalendarUid); //Save all the sent records foreach ($aData['BUSINESS_DAY'] as $key => $objData) { $objData['CALENDAR_UID'] = $CalendarUid; $CalendarBusinessHoursObj->saveCalendarBusinessHours($objData); } //Holiday Save code. //First Delete all current records $CalendarHolidayObj = new CalendarHolidays(); $CalendarHolidayObj->deleteAllCalendarHolidays($CalendarUid); //Save all the sent records foreach ($aData['HOLIDAY'] as $key => $objData) { if ($objData['CALENDAR_HOLIDAY_NAME'] != "" && $objData['CALENDAR_HOLIDAY_START'] != "" && $objData['CALENDAR_HOLIDAY_END'] != "") { $objData['CALENDAR_UID'] = $CalendarUid; $CalendarHolidayObj->saveCalendarHolidays($objData); } } } 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 ); } }
/** * Get data of a Calendar from a record * * @param array $record Record * * return array Return an array with data Calendar */ public function getCalendarDataFromRecord($record) { try { $calendarBusinessHours = new \CalendarBusinessHours(); $calendarHolidays = new \CalendarHolidays(); $arrayCalendarWorkHour = array(); $arrayData = $calendarBusinessHours->getCalendarBusinessHours($record["CALENDAR_UID"]); foreach ($arrayData as $value) { $arrayCalendarWorkHour[] = array($this->getFieldNameByFormatFieldName("DAY") => $this->workDaysTransformData($value["CALENDAR_BUSINESS_DAY"] . "", false), $this->getFieldNameByFormatFieldName("HOUR_START") => $value["CALENDAR_BUSINESS_START"] . "", $this->getFieldNameByFormatFieldName("HOUR_END") => $value["CALENDAR_BUSINESS_END"] . ""); } $arrayCalendarHoliday = array(); $arrayData = $calendarHolidays->getCalendarHolidays($record["CALENDAR_UID"]); foreach ($arrayData as $value) { $arrayCalendarHoliday[] = array($this->getFieldNameByFormatFieldName("NAME") => $value["CALENDAR_HOLIDAY_NAME"] . "", $this->getFieldNameByFormatFieldName("DATE_START") => $value["CALENDAR_HOLIDAY_START"] . "", $this->getFieldNameByFormatFieldName("DATE_END") => $value["CALENDAR_HOLIDAY_END"] . ""); } $conf = new \Configurations(); $confEnvSetting = $conf->getFormats(); $dateTime = new \DateTime($record["CALENDAR_CREATE_DATE"]); $dateCreate = $dateTime->format($confEnvSetting["dateFormat"]); $dateTime = new \DateTime($record["CALENDAR_UPDATE_DATE"]); $dateUpdate = $dateTime->format($confEnvSetting["dateFormat"]); $arrayCalendarWorkDays = array(); foreach ($this->workDaysTransformData($record["CALENDAR_WORK_DAYS"] . "", false) as $value) { $arrayCalendarWorkDays[$value] = \G::LoadTranslation("ID_WEEKDAY_" . ($value != 7 ? $value : 0)); } return array($this->getFieldNameByFormatFieldName("CAL_UID") => $record["CALENDAR_UID"], $this->getFieldNameByFormatFieldName("CAL_NAME") => $record["CALENDAR_NAME"], $this->getFieldNameByFormatFieldName("CAL_DESCRIPTION") => $record["CALENDAR_DESCRIPTION"] . "", $this->getFieldNameByFormatFieldName("CAL_WORK_DAYS") => $arrayCalendarWorkDays, $this->getFieldNameByFormatFieldName("CAL_STATUS") => $record["CALENDAR_STATUS"], $this->getFieldNameByFormatFieldName("CAL_WORK_HOUR") => $arrayCalendarWorkHour, $this->getFieldNameByFormatFieldName("CAL_HOLIDAY") => $arrayCalendarHoliday, $this->getFieldNameByFormatFieldName("CAL_CREATE_DATE") => $dateCreate, $this->getFieldNameByFormatFieldName("CAL_UPDATE_DATE") => $dateUpdate, $this->getFieldNameByFormatFieldName("CAL_TOTAL_USERS") => (int) $record["CALENDAR_TOTAL_USERS"], $this->getFieldNameByFormatFieldName("CAL_TOTAL_PROCESSES") => (int) $record["CALENDAR_TOTAL_PROCESSES"], $this->getFieldNameByFormatFieldName("CAL_TOTAL_TASKS") => (int) $record["CALENDAR_TOTAL_TASKS"]); } catch (\Exception $e) { throw $e; } }