/**
  * Дата уведомления с учетом часового пояса пользователя
  */
 private function _makeNotificationDate($date, $days, $hours, $mins)
 {
     // Дата в часовом поясе пользователя
     $date = new DateTime($date, new DateTimeZone($this->_user->getUserProps('time_zone')));
     if ($days) {
         $date->modify("-{$days} days");
     }
     $date->setTime($hours, $mins);
     // Перевести в часовой пояс сервера
     $date->setTimezone(new DateTimeZone(date_default_timezone_get()));
     return $date->format('Y-m-d H:i:s');
 }
예제 #2
0
 /**
  * Добавляет в запись информацию о напоминаниях
  *
  * @param oldUser $user
  * @param array $row
  * @return array
  */
 private static function _addNotificationInfo(oldUser $user, array &$rows)
 {
     // Предполагаем, что в ключах массивов лежат ID записей
     // см. self::_find()
     assert(!isset($rows[0]));
     $opIds = array_keys($rows);
     // Выбираем только те напомининания, которые еще не отработали
     $sql = "SELECT * FROM operation_notifications\n                WHERE operation_id IN (?a) AND is_done=0";
     $notifications = Core::getInstance()->db->select($sql, $opIds);
     // Напоминания об операциях
     if ($notifications) {
         foreach ($notifications as $notrow) {
             $row =& $rows[$notrow['operation_id']];
             $notificationDate = new DateTime($notrow['schedule']);
             $notificationDate->setTimezone(new DateTimeZone($user->getUserProps('time_zone')));
             // дата операции
             // TODO: !!! Дата записана в БД без учета часового пояса пользователя
             $operationDate = new DateTime($row['date']);
             $notificationDate->setTimezone(new DateTimeZone($user->getUserProps('time_zone')));
             $opTime = strtotime($operationDate->format('Y-m-d'));
             $notTime = strtotime($notificationDate->format('Y-m-d'));
             $daysBefore = floor(($opTime - $notTime) / (3600 * 24));
             // SMS
             if ($notrow['type'] == 0) {
                 $row['smsEnabled'] = 1;
                 $row['smsDaysBefore'] = $daysBefore;
                 $row['smsHour'] = $notificationDate->format('H');
                 $row['smsMinutes'] = $notificationDate->format('i');
             }
             // Email
             if ($notrow['type'] == 1) {
                 $row['mailEnabled'] = 1;
                 $row['mailDaysBefore'] = $daysBefore;
                 $row['mailHour'] = $notificationDate->format('H');
                 $row['mailMinutes'] = $notificationDate->format('i');
             }
         }
     }
 }