-
Notifications
You must be signed in to change notification settings - Fork 487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Internal: Add session replication, reinscription logic, and child session hierarchy for course expiration - refs BT#22057 #5831
Open
christianbeeznest
wants to merge
17
commits into
chamilo:master
Choose a base branch
from
christianbeeznest:matra-22057
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
ba4e25b
Internal: Add session replication, reinscription logic, and child ses…
christianbeeznest c3312db
Merge remote-tracking branch 'upstream/master' into matra-22057
christianbeeznest 7f6e7ae
Session: Add settings and interface fields for session and lesson fun…
christianbeeznest 3f353ef
Resolved merge conflicts with upstream/master
christianbeeznest 2bf9adf
Internal: Add missing settings in migration - refs BT#22057
christianbeeznest d507e64
Resolved merge conflicts with upstream/master
christianbeeznest 66a227d
Internal: Fix error type for validity_id_days field
christianbeeznest 42f207b
Merge remote-tracking branch 'upstream/master' into matra-22057
christianbeeznest 353c19a
Internal: Fix session duplication and reinscription logic improvement…
christianbeeznest 238cbdb
Merge remote-tracking branch 'upstream/master' into matra-22057
christianbeeznest e9cca0b
Internal: Improve session reinscription logic using direct CLpView va…
christianbeeznest 9cbcca1
Merge remote-tracking branch 'upstream/master' into matra-22057
christianbeeznest ba09140
Internal: Fix session duplication and reinscription logic - refs BT#2…
christianbeeznest 8f8fa4f
Adding changes from upstream/master
christianbeeznest 7b66599
Internal: Implement automatic session repetition and coach notificati…
christianbeeznest ad82e0b
Merge remote-tracking branch 'upstream/master' into matra-22057
christianbeeznest 3b34dc1
Internal: Reinscription logic updated to use sessions' validity and g…
christianbeeznest File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -159,7 +159,11 @@ public static function create_session( | |
$sendSubscriptionNotification = false, | ||
$accessUrlId = 0, | ||
$status = 0, | ||
$notifyBoss = false | ||
$notifyBoss = false, | ||
$parentId = null, | ||
$daysBeforeFinishingForReinscription = null, | ||
$lastRepetition = false, | ||
$daysBeforeFinishingToCreateNewRepetition = null | ||
) { | ||
global $_configuration; | ||
|
||
|
@@ -188,42 +192,30 @@ public static function create_session( | |
$endDate = Database::escape_string($endDate); | ||
|
||
if (empty($name)) { | ||
$msg = get_lang('A title is required for the session'); | ||
|
||
return $msg; | ||
return get_lang('A title is required for the session'); | ||
} elseif (!empty($startDate) && !api_is_valid_date($startDate, 'Y-m-d H:i') && | ||
!api_is_valid_date($startDate, 'Y-m-d H:i:s') | ||
) { | ||
$msg = get_lang('Invalid start date was given.'); | ||
|
||
return $msg; | ||
return get_lang('Invalid start date was given.'); | ||
} elseif (!empty($endDate) && !api_is_valid_date($endDate, 'Y-m-d H:i') && | ||
!api_is_valid_date($endDate, 'Y-m-d H:i:s') | ||
) { | ||
$msg = get_lang('Invalid end date was given.'); | ||
|
||
return $msg; | ||
return get_lang('Invalid end date was given.'); | ||
} elseif (!empty($startDate) && !empty($endDate) && $startDate >= $endDate) { | ||
$msg = get_lang('The first date should be before the end date'); | ||
|
||
return $msg; | ||
return get_lang('The first date should be before the end date'); | ||
} else { | ||
$ready_to_create = false; | ||
if ($fixSessionNameIfExists) { | ||
$name = self::generateNextSessionName($name); | ||
if ($name) { | ||
$ready_to_create = true; | ||
} else { | ||
$msg = get_lang('Session title already exists'); | ||
|
||
return $msg; | ||
return get_lang('Session title already exists'); | ||
} | ||
} else { | ||
$rs = Database::query("SELECT 1 FROM $tbl_session WHERE title='".$name."'"); | ||
if (Database::num_rows($rs)) { | ||
$msg = get_lang('Session title already exists'); | ||
|
||
return $msg; | ||
return get_lang('Session title already exists'); | ||
} | ||
$ready_to_create = true; | ||
} | ||
|
@@ -239,7 +231,10 @@ public static function create_session( | |
->setShowDescription(1 === $showDescription) | ||
->setSendSubscriptionNotification((bool) $sendSubscriptionNotification) | ||
->setNotifyBoss((bool) $notifyBoss) | ||
; | ||
->setParentId($parentId) | ||
->setDaysToReinscription($daysBeforeFinishingForReinscription) | ||
->setLastRepetition($lastRepetition) | ||
->setDaysToNewRepetition($daysBeforeFinishingToCreateNewRepetition); | ||
|
||
foreach ($coachesId as $coachId) { | ||
$session->addGeneralCoach(api_get_user_entity($coachId)); | ||
|
@@ -288,18 +283,6 @@ public static function create_session( | |
$extraFields['item_id'] = $session_id; | ||
$sessionFieldValue = new ExtraFieldValue('session'); | ||
$sessionFieldValue->saveFieldValues($extraFields); | ||
/* | ||
Sends a message to the user_id = 1 | ||
|
||
$user_info = api_get_user_info(1); | ||
$complete_name = $user_info['firstname'].' '.$user_info['lastname']; | ||
$subject = api_get_setting('siteName').' - '.get_lang('A new session has been created'); | ||
$message = get_lang('A new session has been created')." <br /> ".get_lang('Session name').' : '.$name; | ||
api_mail_html($complete_name, $user_info['email'], $subject, $message); | ||
* | ||
*/ | ||
// Adding to the correct URL | ||
//UrlManager::add_session_to_url($session_id, $accessUrlId); | ||
|
||
// add event to system log | ||
$user_id = api_get_user_id(); | ||
|
@@ -523,6 +506,10 @@ public static function getSessionsForAdmin( | |
} | ||
$select .= ', status'; | ||
|
||
if ('replication' === $listType) { | ||
$select .= ', parent_id'; | ||
} | ||
|
||
if (isset($options['order'])) { | ||
$isMakingOrder = 0 === strpos($options['order'], 'category_name'); | ||
} | ||
|
@@ -654,6 +641,11 @@ public static function getSessionsForAdmin( | |
) | ||
)"; | ||
break; | ||
case 'replication': | ||
$formatted = false; | ||
$query .= "AND s.days_to_new_repetition IS NOT NULL | ||
AND (SELECT COUNT(id) FROM session AS child WHERE child.parent_id = s.id) <= 1"; | ||
break; | ||
} | ||
|
||
$query .= $order; | ||
|
@@ -668,6 +660,23 @@ public static function getSessionsForAdmin( | |
$session['users'] = Database::fetch_assoc($result)['nbr']; | ||
} | ||
} | ||
|
||
if ('replication' === $listType) { | ||
$formattedSessions = []; | ||
foreach ($sessions as $session) { | ||
$formattedSessions[] = $session; | ||
if (isset($session['id'])) { | ||
$childSessions = array_filter($sessions, fn($s) => isset($s['parent_id']) && $s['parent_id'] === $session['id']); | ||
foreach ($childSessions as $childSession) { | ||
$childSession['title'] = '-- ' . $childSession['title']; | ||
$formattedSessions[] = $childSession; | ||
} | ||
} | ||
} | ||
|
||
return $formattedSessions; | ||
} | ||
|
||
if ('all' === $listType) { | ||
if ($getCount) { | ||
return $sessions[0]['total_rows']; | ||
|
@@ -1793,7 +1802,11 @@ public static function edit_session( | |
$sessionAdminId = 0, | ||
$sendSubscriptionNotification = false, | ||
$status = 0, | ||
$notifyBoss = 0 | ||
$notifyBoss = 0, | ||
$parentId = 0, | ||
$daysBeforeFinishingForReinscription = null, | ||
$daysBeforeFinishingToCreateNewRepetition = null, | ||
$lastRepetition = false | ||
) { | ||
$id = (int) $id; | ||
$status = (int) $status; | ||
|
@@ -1863,6 +1876,10 @@ public static function edit_session( | |
->setVisibility($visibility) | ||
->setSendSubscriptionNotification((bool) $sendSubscriptionNotification) | ||
->setNotifyBoss((bool) $notifyBoss) | ||
->setParentId($parentId) | ||
->setDaysToReinscription($daysBeforeFinishingForReinscription) | ||
->setLastRepetition($lastRepetition) | ||
->setDaysToNewRepetition($daysBeforeFinishingToCreateNewRepetition) | ||
->setAccessStartDate(null) | ||
->setAccessStartDate(null) | ||
->setDisplayStartDate(null) | ||
|
@@ -1871,6 +1888,16 @@ public static function edit_session( | |
->setCoachAccessEndDate(null) | ||
; | ||
|
||
if ($parentId) { | ||
$sessionEntity->setParentId($parentId); | ||
} else { | ||
$sessionEntity->setParentId(null); | ||
} | ||
|
||
$sessionEntity->setDaysToReinscription($daysBeforeFinishingForReinscription); | ||
$sessionEntity->setLastRepetition($lastRepetition); | ||
$sessionEntity->setDaysToNewRepetition($daysBeforeFinishingToCreateNewRepetition); | ||
|
||
$newGeneralCoaches = array_map( | ||
fn($coachId) => api_get_user_entity($coachId), | ||
$coachesId | ||
|
@@ -8271,6 +8298,50 @@ public static function setForm(FormValidator $form, Session $session = null, $fr | |
$extra_field = new ExtraFieldModel('session'); | ||
$extra = $extra_field->addElements($form, $session ? $session->getId() : 0, ['image']); | ||
|
||
if ('true' === api_get_setting('session.enable_auto_reinscription')) { | ||
$form->addElement( | ||
'text', | ||
'days_before_finishing_for_reinscription', | ||
get_lang('Days before finishing for reinscription'), | ||
['maxlength' => 5] | ||
); | ||
} | ||
|
||
if ('true' === api_get_setting('session.enable_session_replication')) { | ||
$form->addElement( | ||
'text', | ||
'days_before_finishing_to_create_new_repetition', | ||
get_lang('Days before finishing to create new repetition'), | ||
['maxlength' => 5] | ||
); | ||
} | ||
|
||
if ('true' === api_get_setting('session.enable_auto_reinscription') || 'true' === api_get_setting('session.enable_session_replication')) { | ||
$form->addElement( | ||
'checkbox', | ||
'last_repetition', | ||
get_lang('Last repetition') | ||
); | ||
} | ||
|
||
/** @var HTML_QuickForm_select $element */ | ||
$element = $form->createElement( | ||
'select', | ||
'parent_id', | ||
get_lang('Parent session'), | ||
[], | ||
['class' => 'form-control'] | ||
); | ||
|
||
$element->addOption(get_lang('None'), 0, []); | ||
$sessions = SessionManager::getListOfParentSessions(); | ||
foreach ($sessions as $id => $title) { | ||
$attributes = []; | ||
$element->addOption($title, $id, $attributes); | ||
} | ||
|
||
$form->addElement($element); | ||
|
||
$form->addElement('html', '</div>'); | ||
|
||
$js = $extra['jquery_ready_content']; | ||
|
@@ -8782,7 +8853,7 @@ public static function getGridColumns( | |
]; | ||
|
||
break; | ||
|
||
case 'replication': | ||
case 'custom': | ||
$columns = [ | ||
'#', | ||
|
@@ -8801,7 +8872,7 @@ public static function getGridColumns( | |
[ | ||
'name' => 'title', | ||
'index' => 's.title', | ||
'width' => '160', | ||
'width' => '260px', | ||
'align' => 'left', | ||
'search' => 'true', | ||
'searchoptions' => ['sopt' => $operators], | ||
|
@@ -9792,9 +9863,9 @@ public static function getDefaultSessionTab() | |
} | ||
|
||
/** | ||
* @return array | ||
* @return string | ||
*/ | ||
public static function getSessionListTabs($listType) | ||
public static function getSessionListTabs($listType): string | ||
{ | ||
$tabs = [ | ||
[ | ||
|
@@ -9813,10 +9884,10 @@ public static function getSessionListTabs($listType) | |
'content' => get_lang('Custom list'), | ||
'url' => api_get_path(WEB_CODE_PATH).'session/session_list.php?list_type=custom', | ||
], | ||
/*[ | ||
'content' => get_lang('Complete'), | ||
'url' => api_get_path(WEB_CODE_PATH).'session/session_list_simple.php?list_type=complete', | ||
],*/ | ||
[ | ||
'content' => get_lang('Replication'), | ||
'url' => api_get_path(WEB_CODE_PATH).'session/session_list.php?list_type=replication', | ||
], | ||
]; | ||
$default = null; | ||
switch ($listType) { | ||
|
@@ -9832,6 +9903,9 @@ public static function getSessionListTabs($listType) | |
case 'custom': | ||
$default = 4; | ||
break; | ||
case 'replication': | ||
$default = 5; | ||
break; | ||
} | ||
|
||
return Display::tabsOnlyLink($tabs, $default); | ||
|
@@ -10213,4 +10287,21 @@ public static function getAllUserIdsInSession(int $sessionId): array | |
|
||
return $users; | ||
} | ||
|
||
/** | ||
* Retrieves a list of parent sessions. | ||
*/ | ||
public static function getListOfParentSessions(): array | ||
{ | ||
$sessions = []; | ||
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); | ||
$sql = "SELECT id, title FROM $tbl_session WHERE parent_id IS NULL ORDER BY title"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Variable "tbl_session" is not in valid camel caps format |
||
$result = Database::query($sql); | ||
|
||
while ($row = Database::fetch_array($result)) { | ||
$sessions[$row['id']] = $row['title']; | ||
} | ||
|
||
return $sessions; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CASE statements must be defined using a colon