1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- /* For licensing terms, see /license.txt */
- /**
- * Cron for send a email when the course are finished
- * @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
- * @package chamilo.cron
- */
- require_once __DIR__ . '/../inc/global.inc.php';
- if (php_sapi_name() != 'cli') {
- exit; //do not run from browser
- }
- $isActive = api_get_setting('cron_remind_course_expiration_activate') === 'true';
- if (!$isActive) {
- exit;
- }
- $endDate = new DateTime('now', new DateTimeZone('UTC'));
- $endDate = $endDate->format('Y-m-d');
- $entityManager = Database::getManager();
- $sessionRepo = $entityManager->getRepository('ChamiloCoreBundle:Session');
- $accessUrlRepo = $entityManager->getRepository('ChamiloCoreBundle:AccessUrl');
- $sessions = $sessionRepo->createQueryBuilder('s')
- ->where('s.accessEndDate LIKE :date')
- ->setParameter('date', "$endDate%")
- ->getQuery()
- ->getResult();
- if (empty($sessions)) {
- echo "No sessions finishing today $endDate" . PHP_EOL;
- exit;
- }
- $administrator = [
- 'complete_name' => api_get_person_name(
- api_get_setting('admin.administrator_name'),
- api_get_setting('admin.administrator_surname'),
- null,
- PERSON_NAME_EMAIL_ADDRESS
- ),
- 'email' => api_get_setting('admin.administrator_email'),
- ];
- foreach ($sessions as $session) {
- $sessionUsers = $session->getUsers();
- if (empty($sessionUsers)) {
- echo 'No users to send mail' . PHP_EOL;
- exit;
- }
- foreach ($sessionUsers as $sessionUser) {
- $user = $sessionUser->getUser();
- $subjectTemplate = new Template(null, false, false, false, false, false);
- $subjectTemplate->assign('session_name', $session->getName());
- $subjectLayout = $subjectTemplate->get_template(
- 'mail/cron_course_finished_subject.tpl'
- );
- $bodyTemplate = new Template(null, false, false, false, false, false);
- $bodyTemplate->assign('complete_user_name', $user->getCompleteName());
- $bodyTemplate->assign('session_name', $session->getName());
- $bodyLayout = $bodyTemplate->get_template(
- 'mail/cron_course_finished_body.tpl'
- );
- api_mail_html(
- $user->getCompleteName(),
- $user->getEmail(),
- $subjectTemplate->fetch($subjectLayout),
- $bodyTemplate->fetch($bodyLayout),
- $administrator['complete_name'],
- $administrator['email']
- );
- echo '============' . PHP_EOL;
- echo "Email sent to: {$user->getCompleteName()} ({$user->getEmail()})" . PHP_EOL;
- echo "Session: {$session->getName()}" . PHP_EOL;
- echo "End date: {$session->getAccessEndDate()->format('Y-m-d h:i')}" . PHP_EOL;
- }
- }
|