Skip to content

Commit 90ea493

Browse files
committed
Add auto launch settings for documents and exercises see BT#14251
- configuration "allow_exercise_auto_launch" requires DB change
1 parent a9a8d50 commit 90ea493

File tree

7 files changed

+265
-25
lines changed

7 files changed

+265
-25
lines changed

main/course_home/course_home.php

Lines changed: 75 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,17 @@
169169
}
170170

171171
/*Auto launch code */
172-
$show_autolaunch_lp_warning = false;
173-
$auto_launch = api_get_course_setting('enable_lp_auto_launch');
172+
$autoLaunchWarning = '';
173+
$showAutoLaunchLpWarning = false;
174+
$course_id = api_get_course_int_id();
175+
176+
$lpAutoLaunch = api_get_course_setting('enable_lp_auto_launch');
174177
$session_id = api_get_session_id();
175-
if (!empty($auto_launch)) {
176-
if ($auto_launch == 2) { //LP list
178+
if (!empty($lpAutoLaunch)) {
179+
if ($lpAutoLaunch == 2) {
180+
// LP list
177181
if (api_is_platform_admin() || api_is_allowed_to_edit()) {
178-
$show_autolaunch_lp_warning = true;
182+
$showAutoLaunchLpWarning = true;
179183
} else {
180184
$session_key = 'lp_autolaunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
181185
if (!isset($_SESSION[$session_key])) {
@@ -188,7 +192,6 @@
188192
}
189193
} else {
190194
$lp_table = Database::get_course_table(TABLE_LP_MAIN);
191-
$course_id = api_get_course_int_id();
192195
$condition = '';
193196
if (!empty($session_id)) {
194197
$condition = api_get_session_condition($session_id);
@@ -210,7 +213,7 @@
210213
$lp_data = Database::fetch_array($result, 'ASSOC');
211214
if (!empty($lp_data['id'])) {
212215
if (api_is_platform_admin() || api_is_allowed_to_edit()) {
213-
$show_autolaunch_lp_warning = true;
216+
$showAutoLaunchLpWarning = true;
214217
} else {
215218
$session_key = 'lp_autolaunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
216219
if (!isset($_SESSION[$session_key])) {
@@ -227,22 +230,76 @@
227230
}
228231
}
229232

233+
if ($showAutoLaunchLpWarning) {
234+
$autoLaunchWarning = get_lang('TheLPAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificLP');
235+
}
236+
230237
$forumAutoLaunch = api_get_course_setting('enable_forum_auto_launch');
231238
if ($forumAutoLaunch == 1) {
232239
if (api_is_platform_admin() || api_is_allowed_to_edit()) {
233-
Display::addFlash(Display::return_message(
234-
get_lang('TheForumAutoLaunchSettingIsOnStudentsWillBeRedirectToTheForumTool'),
235-
'warning'
236-
));
240+
if (empty($autoLaunchWarning)) {
241+
$autoLaunchWarning = get_lang('TheForumAutoLaunchSettingIsOnStudentsWillBeRedirectToTheForumTool');
242+
}
237243
} else {
238-
//$forumKey = 'forum_auto_launch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id();
239-
//if (!isset($_SESSION[$forumKey])) {
240-
//redirecting to the LP
241244
$url = api_get_path(WEB_CODE_PATH).'forum/index.php?'.api_get_cidreq().'&id_session='.$session_id;
242-
// $_SESSION[$forumKey] = true;
243245
header("Location: $url");
244246
exit;
245-
//}
247+
}
248+
}
249+
250+
if (api_get_configuration_value('allow_exercise_auto_launch')) {
251+
$exerciseAutoLaunch = (int)api_get_course_setting('enable_exercise_auto_launch');
252+
if ($exerciseAutoLaunch == 2) {
253+
if (api_is_platform_admin() || api_is_allowed_to_edit()) {
254+
if (empty($autoLaunchWarning)) {
255+
$autoLaunchWarning = get_lang(
256+
'TheExerciseAutoLaunchSettingIsONStudentsWillBeRedirectToTheExerciseList'
257+
);
258+
}
259+
} else {
260+
// Redirecting to the document
261+
$url = api_get_path(WEB_CODE_PATH).'exercise/exercise.php?'.api_get_cidreq().'&id_session='.$session_id;
262+
header("Location: $url");
263+
exit;
264+
}
265+
} elseif ($exerciseAutoLaunch == 1) {
266+
if (api_is_platform_admin() || api_is_allowed_to_edit()) {
267+
if (empty($autoLaunchWarning)) {
268+
$autoLaunchWarning = get_lang(
269+
'TheExerciseAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificExercise'
270+
);
271+
}
272+
} else {
273+
// Redirecting to an exercise
274+
$table = Database::get_course_table(TABLE_QUIZ_TEST);
275+
$sessionCondition = api_get_session_condition($session_id, true);
276+
$sql = "SELECT iid FROM $table
277+
WHERE c_id = $course_id AND autolaunch = 1 $sessionCondition
278+
LIMIT 1";
279+
$result = Database::query($sql);
280+
if (Database::num_rows($result) > 0) {
281+
$row = Database::fetch_array($result, 'ASSOC');
282+
$exerciseId = $row['iid'];
283+
$url = api_get_path(WEB_CODE_PATH).
284+
'exercise/overview.php?exerciseId='.$exerciseId.'&'.api_get_cidreq().'&id_session='.$session_id;
285+
header("Location: $url");
286+
exit;
287+
}
288+
}
289+
}
290+
}
291+
292+
$documentAutoLaunch = api_get_course_setting('enable_document_auto_launch');
293+
if ($documentAutoLaunch == 1) {
294+
if (api_is_platform_admin() || api_is_allowed_to_edit()) {
295+
if (empty($autoLaunchWarning)) {
296+
$autoLaunchWarning = get_lang('TheDocumentAutoLaunchSettingIsOnStudentsWillBeRedirectToTheDocumentTool');
297+
}
298+
} else {
299+
// Redirecting to the document
300+
$url = api_get_path(WEB_CODE_PATH).'document/document.php?'.api_get_cidreq().'&id_session='.$session_id;
301+
header("Location: $url");
302+
exit;
246303
}
247304
}
248305

@@ -266,9 +323,9 @@
266323
the setting homepage_view is adjustable through
267324
the platform administration section */
268325

269-
if ($show_autolaunch_lp_warning) {
326+
if (!empty($autoLaunchWarning)) {
270327
$show_message .= Display::return_message(
271-
get_lang('TheLPAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificLP'),
328+
$autoLaunchWarning,
272329
'warning'
273330
);
274331
}

main/course_info/infocours.php

Lines changed: 109 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,19 @@ function is_settings_editable()
283283
];
284284
$form->addGroup($group, '', [get_lang('ShowSystemFolders')]);
285285

286+
287+
$group = [];
288+
$group[] = $form->createElement(
289+
'radio',
290+
'enable_document_auto_launch',
291+
get_lang('DocumentAutoLaunch'),
292+
get_lang('RedirectToTheDocumentList'),
293+
1
294+
);
295+
$group[] = $form->createElement('radio', 'enable_document_auto_launch', null, get_lang('Deactivate'), 0);
296+
$form->addGroup($group, '', [get_lang('DocumentAutoLaunch')]);
297+
298+
286299
$form->addButtonSave(get_lang('SaveSettings'), 'submit_save');
287300
$form->addHtml('
288301
</div>
@@ -476,7 +489,7 @@ function is_settings_editable()
476489
$group[] = $form->createElement('radio', 'enable_lp_auto_launch', get_lang('LPAutoLaunch'), get_lang('RedirectToALearningPath'), 1);
477490
$group[] = $form->createElement('radio', 'enable_lp_auto_launch', get_lang('LPAutoLaunch'), get_lang('RedirectToTheLearningPathList'), 2);
478491
$group[] = $form->createElement('radio', 'enable_lp_auto_launch', null, get_lang('Deactivate'), 0);
479-
$form->addGroup($group, '', [get_lang("LPAutoLaunch")]);
492+
$form->addGroup($group, '', [get_lang('LPAutoLaunch')]);
480493

481494
if (api_get_setting('allow_course_theme') == 'true') {
482495
// Allow theme into Learning path
@@ -554,6 +567,73 @@ function is_settings_editable()
554567
');
555568
$form->addHtml('</div>');
556569

570+
// Exercise
571+
if (api_get_configuration_value('allow_exercise_auto_launch')) {
572+
$form->addHtml('<div class="panel panel-default">');
573+
$form->addHtml(
574+
'
575+
<div class="panel-heading" role="tab" id="heading-exercise">
576+
<h4 class="panel-title">
577+
<a class="collapsed"
578+
role="button" data-toggle="collapse"
579+
data-parent="#accordion"
580+
href="#collapse-exercise" aria-expanded="false" aria-controls="collapse-exercise">
581+
'
582+
);
583+
$form->addHtml(
584+
Display::return_icon('quiz.png', get_lang('Exercise')).' '.get_lang('Exercise')
585+
);
586+
$form->addHtml(
587+
'
588+
</a>
589+
</h4>
590+
</div>
591+
'
592+
);
593+
$form->addHtml(
594+
'
595+
<div id="collapse-exercise" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading-exercise">
596+
<div class="panel-body">
597+
'
598+
);
599+
600+
// Auto launch exercise
601+
$group = [];
602+
$group[] = $form->createElement(
603+
'radio',
604+
'enable_exercise_auto_launch',
605+
get_lang('ExerciseAutoLaunch'),
606+
get_lang('RedirectToExercise'),
607+
1
608+
);
609+
$group[] = $form->createElement(
610+
'radio',
611+
'enable_exercise_auto_launch',
612+
get_lang('ExerciseAutoLaunch'),
613+
get_lang('RedirectToTheExerciseList'),
614+
2
615+
);
616+
$group[] = $form->createElement('radio', 'enable_exercise_auto_launch', null, get_lang('Deactivate'), 0);
617+
$form->addGroup($group, '', [get_lang('ExerciseAutoLaunch')]);
618+
619+
if (is_settings_editable()) {
620+
$form->addButtonSave(get_lang('SaveSettings'), 'submit_save');
621+
} else {
622+
// Is it allowed to edit the course settings?
623+
if (!is_settings_editable()) {
624+
$disabled_output = "disabled";
625+
}
626+
$form->freeze();
627+
}
628+
$form->addHtml(
629+
'
630+
</div>
631+
</div>
632+
'
633+
);
634+
$form->addHtml('</div>');
635+
}
636+
557637
// THEMATIC ADVANCE SETTINGS
558638
$form->addHtml('<div class="panel panel-default">');
559639
$form->addHtml('
@@ -578,10 +658,34 @@ function is_settings_editable()
578658
');
579659

580660
$group = [];
581-
$group[] = $form->createElement('radio', 'display_info_advance_inside_homecourse', get_lang('InfoAboutAdvanceInsideHomeCourse'), get_lang('DisplayAboutLastDoneAdvance'), 1);
582-
$group[] = $form->createElement('radio', 'display_info_advance_inside_homecourse', null, get_lang('DisplayAboutNextAdvanceNotDone'), 2);
583-
$group[] = $form->createElement('radio', 'display_info_advance_inside_homecourse', null, get_lang('DisplayAboutNextAdvanceNotDoneAndLastDoneAdvance'), 3);
584-
$group[] = $form->createElement('radio', 'display_info_advance_inside_homecourse', null, get_lang('DoNotDisplayAnyAdvance'), 0);
661+
$group[] = $form->createElement(
662+
'radio',
663+
'display_info_advance_inside_homecourse',
664+
get_lang('InfoAboutAdvanceInsideHomeCourse'),
665+
get_lang('DisplayAboutLastDoneAdvance'),
666+
1
667+
);
668+
$group[] = $form->createElement(
669+
'radio',
670+
'display_info_advance_inside_homecourse',
671+
null,
672+
get_lang('DisplayAboutNextAdvanceNotDone'),
673+
2
674+
);
675+
$group[] = $form->createElement(
676+
'radio',
677+
'display_info_advance_inside_homecourse',
678+
null,
679+
get_lang('DisplayAboutNextAdvanceNotDoneAndLastDoneAdvance'),
680+
3
681+
);
682+
$group[] = $form->createElement(
683+
'radio',
684+
'display_info_advance_inside_homecourse',
685+
null,
686+
get_lang('DoNotDisplayAnyAdvance'),
687+
0
688+
);
585689
$form->addGroup($group, '', [get_lang("InfoAboutAdvanceInsideHomeCourse")]);
586690
$form->addButtonSave(get_lang('SaveSettings'), 'submit_save');
587691
$form->addHtml('

main/exercise/exercise.class.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class Exercise
8383
public $showPreviousButton;
8484
public $notifications;
8585
public $export = false;
86+
public $autolaunch;
8687

8788
/**
8889
* Constructor of the class.
@@ -192,6 +193,7 @@ public function read($id, $parseQuestionList = true)
192193
$this->globalCategoryId = isset($object->global_category_id) ? $object->global_category_id : null;
193194
$this->questionSelectionType = isset($object->question_selection_type) ? $object->question_selection_type : null;
194195
$this->hideQuestionTitle = isset($object->hide_question_title) ? (int) $object->hide_question_title : 0;
196+
$this->autolaunch = isset($object->autolaunch) ? (int) $object->autolaunch : 0;
195197

196198
$this->notifications = [];
197199
if (!empty($object->notifications)) {
@@ -8292,4 +8294,34 @@ private function getUnformattedTitle()
82928294
{
82938295
return strip_tags(api_html_entity_decode($this->title));
82948296
}
8297+
8298+
/**
8299+
* @return int
8300+
*/
8301+
public function getAutoLaunch()
8302+
{
8303+
return $this->autolaunch;
8304+
}
8305+
8306+
/**
8307+
* Clean auto launch settings for all exercise in course/course-session
8308+
*/
8309+
public function enableAutoLaunch()
8310+
{
8311+
$table = Database::get_course_table(TABLE_QUIZ_TEST);
8312+
$sql = "UPDATE $table SET autolaunch = 1
8313+
WHERE iid = ".$this->iId;
8314+
Database::query($sql);
8315+
}
8316+
8317+
/**
8318+
* Clean auto launch settings for all exercise in course/course-session
8319+
*/
8320+
public function cleanCourseLaunchSettings()
8321+
{
8322+
$table = Database::get_course_table(TABLE_QUIZ_TEST);
8323+
$sql = "UPDATE $table SET autolaunch = 0
8324+
WHERE c_id = ".$this->course_id." AND session_id = ".$this->sessionId;
8325+
Database::query($sql);
8326+
}
82958327
}

0 commit comments

Comments
 (0)