getRepository('ChamiloCoreBundle:AgendaReminder'); $reminders = $remindersRepo->findBySent(false); $senderId = api_get_configuration_value('agenda_reminders_sender_id'); if (empty($senderId)) { $firstAdmin = current(UserManager::get_all_administrators()); $senderId = $firstAdmin['user_id']; } foreach ($reminders as $reminder) { if ('personal' === $reminder->getType()) { $event = $em->find('ChamiloCoreBundle:PersonalAgenda', $reminder->getEventId()); if (null === $event) { continue; } $notificationDate = clone $event->getDate(); $notificationDate->sub($reminder->getDateInterval()); if ($notificationDate > $now) { continue; } $eventDetails = []; $eventDetails[] = '

'.$event->getTitle().'

'; if ($event->getAllDay()) { $eventDetails[] = '

'.get_lang('AllDay').'

'; } else { $eventDetails[] = sprintf( '

'.get_lang('FromDateX').'

', api_get_local_time($event->getDate(), null, null, false, true, true) ); if (!empty($event->getEnddate())) { $eventDetails[] = sprintf( '

'.get_lang('UntilDateX').'

', api_get_local_time($event->getEnddate(), null, null, false, true, true) ); } } if (!empty($event->getText())) { $eventDetails[] = $event->getText(); } $messageSubject = sprintf(get_lang('ReminderXEvent'), $event->getTitle()); $messageContent = implode(PHP_EOL, $eventDetails); MessageManager::send_message_simple( $event->getUser(), $messageSubject, $messageContent, $event->getUser() ); if ($agendaCollectiveInvitations) { $invitees = Agenda::getInviteesForPersonalEvent($reminder->getEventId()); $inviteesIdList = array_column($invitees, 'id'); foreach ($inviteesIdList as $userId) { MessageManager::send_message_simple( $userId, $messageSubject, $messageContent, $event->getUser() ); } } } if ('course' === $reminder->getType()) { $event = $em->find('ChamiloCourseBundle:CCalendarEvent', $reminder->getEventId()); if (null === $event) { continue; } $agenda = new Agenda('course'); $notificationDate = clone $event->getStartDate(); $notificationDate->sub($reminder->getDateInterval()); if ($notificationDate > $now) { continue; } $eventDetails = []; $eventDetails[] = '

'.$event->getTitle().'

'; if ($event->getAllDay()) { $eventDetails[] = '

'.get_lang('AllDay').'

'; } else { $eventDetails[] = sprintf( '

'.get_lang('FromDateX').'

', api_get_local_time($event->getStartDate(), null, null, false, true, true) ); if (!empty($event->getEndDate())) { $eventDetails[] = sprintf( '

'.get_lang('UntilDateX').'

', api_get_local_time($event->getEndDate(), null, null, false, true, true) ); } } if (!empty($event->getContent())) { $eventDetails[] = $event->getContent(); } if (!empty($event->getComment())) { $eventDetails[] = '

'.$event->getComment().'

'; } $messageSubject = sprintf(get_lang('ReminderXEvent'), $event->getTitle()); $messageContent = implode(PHP_EOL, $eventDetails); $courseInfo = api_get_course_info_by_id($event->getCId()); $sendTo = $agenda->getUsersAndGroupSubscribedToEvent( $event->getIid(), $event->getCId(), $event->getSessionId() ); if ($sendTo['everyone']) { $users = CourseManager::get_user_list_from_course_code($courseInfo['code'], $event->getSessionId()); $userIdList = array_keys($users); if ($event->getSessionId()) { $coaches = SessionManager::getCoachesByCourseSession($event->getSessionId(), $event->getCId()); $userIdList += $coaches; } foreach ($userIdList as $userId) { MessageManager::send_message_simple( $userId, $messageSubject, $messageContent, $senderId ); } } else { foreach ($sendTo['groups'] as $groupId) { $groupUserList = GroupManager::get_users($groupId, false, null, null, false, $event->getSessionId()); foreach ($groupUserList as $groupUserId) { MessageManager::send_message_simple( $groupUserId, $messageSubject, $messageContent, $senderId ); } } foreach ($sendTo['users'] as $userId) { MessageManager::send_message_simple( $userId, $messageSubject, $messageContent, $senderId ); } } } $reminder->setSent(true); $em->persist($reminder); $batchCounter++; if (($batchCounter % $batchSize) === 0) { $em->flush(); } } $em->flush(); $em->clear();