Merge pull request #5828 from christianbeeznest/matra-22055

Session: Add student boss notification on user inscription and new session checkbox field - refs BT#22055
pull/5846/head
Nicolas Ducoulombier 11 months ago committed by GitHub
commit 28a07b5416
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 97
      public/main/inc/lib/sessionmanager.lib.php
  2. 5
      public/main/session/session_add.php
  3. 5
      public/main/session/session_edit.php
  4. 15
      src/CoreBundle/Entity/Session.php
  5. 34
      src/CoreBundle/Migrations/Schema/V200/Version20240927141000.php
  6. 5
      src/CoreBundle/Resources/views/Mailer/Legacy/content_subscription_to_boss_notification.html.twig
  7. 1
      src/CoreBundle/Resources/views/Mailer/Legacy/subject_subscription_to_boss_notification.html.twig

@ -158,7 +158,8 @@ class SessionManager
$sessionAdminId = 0,
$sendSubscriptionNotification = false,
$accessUrlId = 0,
$status = 0
$status = 0,
$notifyBoss = false
) {
global $_configuration;
@ -237,6 +238,7 @@ class SessionManager
->setDescription($description)
->setShowDescription(1 === $showDescription)
->setSendSubscriptionNotification((bool) $sendSubscriptionNotification)
->setNotifyBoss((bool) $notifyBoss)
;
foreach ($coachesId as $coachId) {
@ -1790,7 +1792,8 @@ class SessionManager
$extraFields = [],
$sessionAdminId = 0,
$sendSubscriptionNotification = false,
$status = 0
$status = 0,
$notifyBoss = 0
) {
$id = (int) $id;
$status = (int) $status;
@ -1859,6 +1862,7 @@ class SessionManager
->setShowDescription(1 === $showDescription)
->setVisibility($visibility)
->setSendSubscriptionNotification((bool) $sendSubscriptionNotification)
->setNotifyBoss((bool) $notifyBoss)
->setAccessStartDate(null)
->setAccessStartDate(null)
->setDisplayStartDate(null)
@ -2154,12 +2158,7 @@ class SessionManager
}
if ($session->getSendSubscriptionNotification() && is_array($userList)) {
// Sending emails only
foreach ($userList as $user_id) {
if (in_array($user_id, $existingUsers)) {
continue;
}
$tplSubject = new Template(
null,
false,
@ -2194,6 +2193,7 @@ class SessionManager
);
$content = $tplContent->fetch($layoutContent);
// Send email
api_mail_html(
$user_info['complete_name'],
$user_info['mail'],
@ -2205,6 +2205,30 @@ class SessionManager
),
api_get_setting('emailAdministrator')
);
// Record message in system
MessageManager::send_message_simple(
$user_id,
$subject,
$content,
api_get_user_id(),
false,
true
);
}
}
if ($session->getNotifyBoss()) {
foreach ($userList as $user_id) {
$studentBossList = UserManager::getStudentBossList($user_id);
if (!empty($studentBossList)) {
$studentBossList = array_column($studentBossList, 'boss_id');
foreach ($studentBossList as $bossId) {
$boss = api_get_user_entity($bossId);
self::notifyBossOfInscription($boss, $session, $user_id);
}
}
}
}
@ -2304,6 +2328,60 @@ class SessionManager
return true;
}
/**
* Sends a notification email to the student's boss when the student is enrolled in a session.
*
* @param User $boss The boss of the student to be notified.
* @param Session $session The session the student has been enrolled in.
* @param int $userId The ID of the student being enrolled.
*/
public static function notifyBossOfInscription(User $boss, Session $session, int $userId): void
{
$tpl = Container::getTwig();
$user_info = api_get_user_info($userId);
$subject = $tpl->render(
'@ChamiloCore/Mailer/Legacy/subject_subscription_to_boss_notification.html.twig',
[
'locale' => $boss->getLocale(),
'boss_name' => $boss->getFullname(),
'student_name' => $user_info['complete_name'],
'session_name' => $session->getTitle(),
]
);
$content = $tpl->render(
'@ChamiloCore/Mailer/Legacy/content_subscription_to_boss_notification.html.twig',
[
'locale' => $boss->getLocale(),
'boss_name' => $boss->getFullname(),
'student_name' => $user_info['complete_name'],
'session_name' => $session->getTitle(),
]
);
// Send email
api_mail_html(
$boss->getFullname(),
$boss->getEmail(),
$subject,
$content,
api_get_person_name(api_get_setting('administratorName'), api_get_setting('administratorSurname')),
api_get_setting('emailAdministrator')
);
// Record message in system
MessageManager::send_message_simple(
$boss->getId(),
$subject,
$content,
api_get_user_id(),
false,
true
);
}
/**
* Returns user list of the current users subscribed in the course-session.
*
@ -8162,6 +8240,11 @@ class SessionManager
get_lang('Send an email when a user being subscribed to session'),
);
$form->addCheckBox(
'notify_boss',
get_lang('Notify inscription of user to student boss')
);
// Picture
$form->addFile(
'picture',

@ -237,6 +237,7 @@ if (!$formSent) {
'coach_access_start_date' => $session->getCoachAccessStartDate() ? api_get_local_time($session->getCoachAccessStartDate()) : null,
'coach_access_end_date' => $session->getCoachAccessEndDate() ? api_get_local_time($session->getCoachAccessEndDate()) : null,
'send_subscription_notification' => $session->getSendSubscriptionNotification(),
'notify_boss' => $session->getNotifyBoss(),
'coach_username' => array_map(
function (User $user) {
return $user->getId();
@ -274,6 +275,7 @@ if ($form->validate()) {
$sendSubscriptionNotification = isset($params['send_subscription_notification']);
$isThisImageCropped = isset($params['picture_crop_result']);
$status = isset($params['status']) ? $params['status'] : 0;
$notifyBoss = isset($params['notify_boss']) ? 1 : 0;
$extraFields = [];
foreach ($params as $key => $value) {
@ -329,7 +331,8 @@ if ($form->validate()) {
null,
$sendSubscriptionNotification,
api_get_current_access_url_id(),
$status
$status,
$notifyBoss
);
if ($return == strval(intval($return))) {

@ -65,6 +65,7 @@ $formDefaults = [
'coach_access_start_date' => $session->getCoachAccessStartDate() ? api_get_local_time($session->getCoachAccessStartDate()) : null,
'coach_access_end_date' => $session->getCoachAccessEndDate() ? api_get_local_time($session->getCoachAccessEndDate()) : null,
'send_subscription_notification' => $session->getSendSubscriptionNotification(),
'notify_boss' => $session->getNotifyBoss(),
'coach_username' => array_map(
function (User $user) {
return $user->getId();
@ -110,6 +111,7 @@ if ($form->validate()) {
}
$status = $params['status'] ?? 0;
$notifyBoss = isset($params['notify_boss']) ? 1 : 0;
$return = SessionManager::edit_session(
$id,
@ -129,7 +131,8 @@ if ($form->validate()) {
$extraFields,
null,
$sendSubscriptionNotification,
$status
$status,
$notifyBoss
);
if ($return) {

@ -374,6 +374,9 @@ class Session implements ResourceWithAccessUrlInterface, Stringable
#[Groups(['user_subscriptions:sessions', 'session:read', 'session:item:read'])]
private int $accessVisibility = 0;
#[ORM\Column(name: 'notify_boss', type: 'boolean', options: ['default' => false])]
protected bool $notifyBoss = false;
public function __construct()
{
$this->skills = new ArrayCollection();
@ -1448,4 +1451,16 @@ class Session implements ResourceWithAccessUrlInterface, Stringable
$closedVisibilities
));
}
public function getNotifyBoss(): bool
{
return $this->notifyBoss;
}
public function setNotifyBoss(bool $notifyBoss): self
{
$this->notifyBoss = $notifyBoss;
return $this;
}
}

@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
use Doctrine\DBAL\Schema\Schema;
final class Version20240927141000 extends AbstractMigrationChamilo
{
public function getDescription(): string
{
return 'Add notify_boss field to session table';
}
public function up(Schema $schema): void
{
$this->addSql("
ALTER TABLE session
ADD notify_boss TINYINT(1) DEFAULT 0 NOT NULL
");
}
public function down(Schema $schema): void
{
$this->addSql("
ALTER TABLE session
DROP COLUMN notify_boss
");
}
}

@ -0,0 +1,5 @@
<p>{{ 'Dear'|trans({}, 'messages', locale) }} {{ boss_name }},</p>
<p>{{ 'We would like to inform you that your student, '|trans({}, 'messages', locale) }} {{ student_name }}, {{ 'has been registered to the session'|trans({}, 'messages', locale) }} {{ session_name }}.</p>
<p>{{ 'You can check the session details in the platform.'|trans({}, 'messages', locale) }}</p>
<p>{{ 'Best regards,'|trans({}, 'messages', locale) }}</p>
{% include '@ChamiloCore/Mailer/Legacy/_admin_signature_footer.html.twig' %}

@ -0,0 +1 @@
[ {{ 'platform.site_name' | api_get_setting }} ] {{ 'New student registration'|trans({}, 'messages', locale) }}
Loading…
Cancel
Save