예제 #1
0
 /**
  * Save date
  * @param <Object> $request
  * @return true if saved, false otherwise
  */
 public function save(Vtiger_Request $request)
 {
     $response = new Vtiger_Response();
     $moduleName = 'Settings:' . $request->getModule();
     try {
         $id = $request->get('holidayId');
         $date = DateTimeField::convertToDBFormat($request->get('holidayDate'));
         $name = $request->get('holidayName');
         $type = $request->get('holidayType');
         if (empty($name) || empty($date)) {
             $response->setResult(array('success' => false, 'message' => vtranslate('LBL_FILL_FORM_ERROR', $moduleName)));
         } else {
             if (!empty($id)) {
                 if (Settings_PublicHoliday_Module_Model::edit($id, $date, $name, $type)) {
                     $response->setResult(array('success' => true, 'message' => vtranslate('LBL_EDIT_DATE_OK', $moduleName)));
                 } else {
                     $response->setResult(array('success' => false, 'message' => vtranslate('LBL_EDIT_DATE_ERROR', $moduleName)));
                 }
             } else {
                 if (Settings_PublicHoliday_Module_Model::save($date, $name, $type)) {
                     $response->setResult(array('success' => true, 'message' => vtranslate('LBL_NEW_DATE_OK', $moduleName)));
                 } else {
                     $response->setResult(array('success' => false, 'message' => vtranslate('LBL_NEW_DATE_ERROR', $moduleName)));
                 }
             }
         }
     } catch (Exception $e) {
         $response->setError($e->getCode(), $e->getMessage());
     }
     $response->emit();
 }
예제 #2
0
 public function process(Vtiger_Request $request)
 {
     global $log;
     $log->debug("Entering Settings_PublicHoliday_Configuration_View::process() method ...");
     $currentUser = Users_Record_Model::getCurrentUserModel();
     $moduleName = $request->getModule();
     $viewer = $this->getViewer($request);
     $date = $request->get('date');
     if (!$date) {
         $date = array(date('Y-m-d', mktime(0, 0, 0, date('m'), 1, date('Y'))), date('Y-m-d', mktime(23, 59, 59, date('m') + 1, 0, date('Y'))));
     }
     $holidays = Settings_PublicHoliday_Module_Model::getHolidays($date);
     $viewer->assign('DATE', implode(" - ", $date));
     $viewer->assign('THREE_YEARS_BACK', $minus3Years);
     $viewer->assign('HOLIDAYS', $holidays);
     $viewer->assign('CURRENTUSER', $currentUser);
     $viewer->assign('QUALIFIED_MODULE', $request->getModule(false));
     echo $viewer->view('Configuration.tpl', $request->getModule(false), true);
     $log->debug("Exiting Settings_PublicHoliday_Configuration_View::process() method ...");
 }
예제 #3
0
 public function getDays($startDate, $endDate)
 {
     $holidayDays = Settings_PublicHoliday_Module_Model::getHolidays([$startDate, $endDate]);
     $notWorkingDaysType = Settings_Calendar_Module_Model::getNotWorkingDays();
     $begin = strtotime($startDate);
     $end = strtotime($endDate);
     $workDays = 0;
     if ($begin > $end) {
         return 0;
     } else {
         $days = 0;
         $weekends = 0;
         while ($begin <= $end) {
             $days++;
             $whatDay = date("N", $begin);
             $day = date('Y-m-d', $begin);
             $isWorkDay = TRUE;
             $isHolidayNotInWeekend = TRUE;
             foreach ($holidayDays as $key => $value) {
                 if ($day == $value['date']) {
                     $isWorkDay = FALSE;
                     if ($whatDay > 5) {
                         $isHolidayNotInWeekend = FALSE;
                     }
                     unset($holidayDays[$key]);
                 }
             }
             foreach ($notWorkingDaysType as $key => $value) {
                 if ($whatDay == $value) {
                     $isWorkDay = FALSE;
                 }
             }
             if ($isWorkDay) {
                 $workDays++;
             }
             if ($whatDay > 5 && !$isWorkDay && $notWorkingDaysType) {
                 $weekends++;
             }
             $begin += 86400;
         }
         $workingDays = $days - $weekends;
         $result = ['workDays' => $workDays, 'weekends' => $weekends, 'days' => $days];
         return $result;
     }
 }