Пример #1
0
 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' );
     //}
 }
Пример #2
0
 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 );
     }
 }