Chamilo is a learning management system focused on ease of use and accessibility
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
chamilo-lms/main/cron/course_finished.php

90 lines
2.6 KiB

<?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('administratorName'),
api_get_setting('administratorSurname'),
null,
PERSON_NAME_EMAIL_ADDRESS
),
'email' => api_get_setting('emailAdministrator')
];
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;
}
}