Skip to content

Commit

Permalink
Internal: Reinscription logic updated to use sessions' validity and g…
Browse files Browse the repository at this point in the history
…radebook certificates - refs BT#22057
  • Loading branch information
christianbeeznest committed Dec 18, 2024
1 parent ad82e0b commit 3b34dc1
Show file tree
Hide file tree
Showing 12 changed files with 294 additions and 165 deletions.
30 changes: 27 additions & 3 deletions public/main/inc/lib/sessionmanager.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ public static function create_session(
$parentId = null,
$daysBeforeFinishingForReinscription = null,
$lastRepetition = false,
$daysBeforeFinishingToCreateNewRepetition = null
$daysBeforeFinishingToCreateNewRepetition = null,
$validityInDays = null
) {
global $_configuration;

Expand Down Expand Up @@ -234,7 +235,8 @@ public static function create_session(
->setParentId($parentId)
->setDaysToReinscription((int) $daysBeforeFinishingForReinscription)
->setLastRepetition($lastRepetition)
->setDaysToNewRepetition((int) $daysBeforeFinishingToCreateNewRepetition);
->setDaysToNewRepetition((int) $daysBeforeFinishingToCreateNewRepetition)
->setValidityInDays((int) $validityInDays);

foreach ($coachesId as $coachId) {
$session->addGeneralCoach(api_get_user_entity($coachId));
Expand Down Expand Up @@ -1806,7 +1808,8 @@ public static function edit_session(
$parentId = 0,
$daysBeforeFinishingForReinscription = null,
$daysBeforeFinishingToCreateNewRepetition = null,
$lastRepetition = false
$lastRepetition = false,
$validityInDays = null
) {
$id = (int) $id;
$status = (int) $status;
Expand Down Expand Up @@ -1880,6 +1883,7 @@ public static function edit_session(
->setDaysToReinscription((int) $daysBeforeFinishingForReinscription)
->setLastRepetition($lastRepetition)
->setDaysToNewRepetition((int) $daysBeforeFinishingToCreateNewRepetition)
->setValidityInDays((int) $validityInDays)
->setAccessStartDate(null)
->setAccessStartDate(null)
->setDisplayStartDate(null)
Expand Down Expand Up @@ -8334,6 +8338,26 @@ public static function setForm(FormValidator $form, Session $session = null, $fr
'last_repetition',
get_lang('Last repetition')
);

$form->addElement(
'number',
'validity_in_days',
get_lang('Validity in days'),
[
'min' => 0,
'max' => 365,
'step' => 1,
'placeholder' => get_lang('Enter the number of days'),
]
);

$form->addRule(
'validity_in_days',
get_lang('The field must be a positive number'),
'numeric',
null,
'client'
);
}

/** @var HTML_QuickForm_select $element */
Expand Down
17 changes: 0 additions & 17 deletions public/main/lp/lp_add.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,21 +148,6 @@ function activate_end_date() {

SkillModel::addSkillsToForm($form, ITEM_TYPE_LEARNPATH, 0);

$showValidityField = 'true' === api_get_setting('session.enable_auto_reinscription') || 'true' === api_get_setting('session.enable_session_replication');
if ($showValidityField) {
$form->addElement(
'number',
'validity_in_days',
get_lang('Validity in days'),
[
'min' => 0,
'max' => 365,
'step' => 1,
'placeholder' => get_lang('Enter the number of days'),
]
);
}

$form->addElement('html', '</div>');

$defaults['activate_start_date_check'] = 1;
Expand Down Expand Up @@ -223,8 +208,6 @@ function activate_end_date() {

$lp->setSubscribeUsers(isset($_REQUEST['subscribe_users']) ? 1 : 0);
$lp->setAccumulateScormTime(1 === (int) $_REQUEST['accumulate_scorm_time'] ? 1 : 0);
$validityInDays = $_REQUEST['validity_in_days'] ?? null;
$lp->setValidityInDays($validityInDays);
$lpRepo->update($lp);

$url = api_get_self().'?action=add_item&type=step&lp_id='.$lpId.'&'.api_get_cidreq();
Expand Down
17 changes: 0 additions & 17 deletions public/main/lp/lp_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,21 +137,6 @@ function activate_end_date() {
['jpg', 'jpeg', 'png', 'gif']
);

$showValidityField = 'true' === api_get_setting('session.enable_auto_reinscription') || 'true' === api_get_setting('session.enable_session_replication');
if ($showValidityField) {
$form->addElement(
'number',
'validity_in_days',
get_lang('Validity in days'),
[
'min' => 0,
'max' => 365,
'step' => 1,
'placeholder' => get_lang('Enter the number of days'),
]
);
}

// Search terms (only if search is activated).
if ('true' === api_get_setting('search_enabled')) {
$specific_fields = get_specific_field_list();
Expand Down Expand Up @@ -181,7 +166,6 @@ function activate_end_date() {
$defaults['hide_toc_frame'] = $hideTableOfContents;
$defaults['category_id'] = $learnPath->getCategoryId();
$defaults['accumulate_scorm_time'] = $learnPath->getAccumulateScormTime();
$defaults['validity_in_days'] = $lp->getValidityInDays() ?? null;

$expired_on = $learnPath->expired_on;
$published_on = $learnPath->published_on;
Expand Down Expand Up @@ -379,7 +363,6 @@ function activate_end_date() {
->setExpiredOn(api_get_utc_datetime($expired_on, true, true))
->setCategory($category)
->setSubscribeUsers(isset($_REQUEST['subscribe_users']) ? 1 : 0)
->setValidityInDays(isset($_REQUEST['validity_in_days']) ? (int) $_REQUEST['validity_in_days'] : null)
;

$extraFieldValue = new ExtraFieldValue('lp');
Expand Down
13 changes: 12 additions & 1 deletion public/main/session/session_add.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ function repopulateSelect2Values(selectId) {
</script>";

$form->addButtonNext(get_lang('Next step'));
$showValidityField = 'true' === api_get_setting('session.enable_auto_reinscription') || 'true' === api_get_setting('session.enable_session_replication');

$formDefaults = [];
if (!$formSent) {
Expand Down Expand Up @@ -250,9 +251,17 @@ function (User $user) {
'last_repetition' => $session->getLastRepetition(),
'parent_id' => $session->getParentId() ?? 0,
];

if ($showValidityField) {
$formDefaults['validity_in_days'] = $session->getValidityInDays();
}

} else {
$formDefaults['access_start_date'] = $formDefaults['display_start_date'] = api_get_local_time();
$formDefaults['coach_username'] = [api_get_user_id()];
if ($showValidityField) {
$formDefaults['validity_in_days'] = null;
}
}
}

Expand Down Expand Up @@ -318,6 +327,7 @@ function (User $user) {
$daysBeforeFinishingForReinscription = $params['days_before_finishing_for_reinscription'] ?? null;
$lastRepetition = isset($params['last_repetition']) ? true : false;
$daysBeforeFinishingToCreateNewRepetition = $params['days_before_finishing_to_create_new_repetition'] ?? null;
$validityInDays = $params['validity_in_days'] ?? null;

$return = SessionManager::create_session(
$title,
Expand All @@ -343,7 +353,8 @@ function (User $user) {
$parentId,
$daysBeforeFinishingForReinscription,
$lastRepetition,
$daysBeforeFinishingToCreateNewRepetition
$daysBeforeFinishingToCreateNewRepetition,
$validityInDays
);

if ($return == strval(intval($return))) {
Expand Down
9 changes: 8 additions & 1 deletion public/main/session/session_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
</script>';

$form->addButtonUpdate(get_lang('Edit this session'));
$showValidityField = 'true' === api_get_setting('session.enable_auto_reinscription') || 'true' === api_get_setting('session.enable_session_replication');

$formDefaults = [
'id' => $session->getId(),
Expand Down Expand Up @@ -78,6 +79,10 @@ function (User $user) {
'parent_id' => $session->getParentId() ?? 0,
];

if ($showValidityField) {
$formDefaults['validity_in_days'] = $session->getValidityInDays();
}

$form->setDefaults($formDefaults);

if ($form->validate()) {
Expand Down Expand Up @@ -121,6 +126,7 @@ function (User $user) {
$daysBeforeFinishingForReinscription = $params['days_before_finishing_for_reinscription'] ?? null;
$daysBeforeFinishingToCreateNewRepetition = $params['days_before_finishing_to_create_new_repetition'] ?? null;
$lastRepetition = isset($params['last_repetition']);
$validityInDays = $params['validity_in_days'] ?? null;

$return = SessionManager::edit_session(
$id,
Expand All @@ -145,7 +151,8 @@ function (User $user) {
$parentId,
$daysBeforeFinishingForReinscription,
$daysBeforeFinishingToCreateNewRepetition,
$lastRepetition
$lastRepetition,
$validityInDays
);

if ($return) {
Expand Down
1 change: 0 additions & 1 deletion public/phpinfo.php

This file was deleted.

Loading

0 comments on commit 3b34dc1

Please sign in to comment.