Minor - improve LearnpathList load performance see BT#15881

pull/2970/head
Julio Montoya 6 years ago
parent c93a451a56
commit e3e1b8365f
  1. 5
      main/admin/user_move_stats.php
  2. 5
      main/gamification/my_progress.php
  3. 7
      main/inc/ajax/course_home.ajax.php
  4. 4
      main/inc/lib/GamificationUtils.php
  5. 4
      main/inc/lib/api.lib.php
  6. 10
      main/inc/lib/sessionmanager.lib.php
  7. 4
      main/inc/lib/text.lib.php
  8. 6
      main/inc/lib/tracking.lib.php
  9. 2
      main/inc/lib/webservices/Rest.php
  10. 30
      main/lp/learnpathList.class.php
  11. 2
      main/lp/lp_list.php
  12. 2
      main/mySpace/myStudents.php
  13. 2
      main/session/index.php
  14. 2
      main/tracking/course_log_tools.php
  15. 2
      main/tracking/course_session_report.php
  16. 2
      main/tracking/lp_results_by_user.php
  17. 2
      main/tracking/question_course_report.php
  18. 2
      main/webservices/lp.php
  19. 2
      main/webservices/webservice_report.php

@ -239,6 +239,7 @@ if (isset($_REQUEST['load_ajax'])) {
while ($row = Database::fetch_array($res, 'ASSOC')) {
$list[] = $row['access_id'];
}
if (!empty($list)) {
foreach ($list as $id) {
if ($update_database) {
@ -262,7 +263,7 @@ if (isset($_REQUEST['load_ajax'])) {
$res = Database::query($sql);
//Getting the list of LPs in the new session
$lp_list = new LearnpathList($user_id, $origin_course_code, $new_session_id);
$lp_list = new LearnpathList($user_id, $course_info, $new_session_id);
$flat_list = $lp_list->get_flat_list();
$list = [];
@ -315,7 +316,7 @@ if (isset($_REQUEST['load_ajax'])) {
$res = Database::query($sql);
// Getting the list of LPs in the new session
$lp_list = new LearnpathList($user_id, $origin_course_code, $new_session_id);
$lp_list = new LearnpathList($user_id, $course_info, $new_session_id);
$flat_list = $lp_list->get_flat_list();
$list = [];

@ -105,9 +105,10 @@ if ($currentSession) {
'stats' => [],
];
$courseInfo = api_get_course_info($course->getCode());
$learningPathList = new LearnpathList(
$user->getId(),
$course->getCode(),
$courseInfo,
$currentSession->getId()
);
@ -123,10 +124,8 @@ if ($currentSession) {
]).api_get_cidreq(),
];
}
$sessionData[$course->getId()] = $courseData;
}
$template->assign('session_data', $sessionData);
}

@ -204,7 +204,8 @@ switch ($action) {
$count = 0;
$temp = [];
foreach ($course_list as $item) {
$list = new LearnpathList(api_get_user_id(), $item['code'], $session_id);
$courseInfo = api_get_course_info($item['code']);
$list = new LearnpathList(api_get_user_id(), $courseInfo, $session_id);
$flat_list = $list->get_flat_list();
$lps[$item['code']] = $flat_list;
$course_url = api_get_path(WEB_COURSE_PATH).$item['directory'].'/?id_session='.$session_id;
@ -342,7 +343,7 @@ switch ($action) {
$list = new LearnpathList(
api_get_user_id(),
$item['code'],
api_get_course_info($item['code']),
$session_id,
'lp.publicatedOn DESC'
);
@ -485,7 +486,7 @@ switch ($action) {
$list = new LearnpathList(
api_get_user_id(),
$item['code'],
api_get_course_info($item['code']),
$session_id
);
$flat_list = $list->get_flat_list();

@ -59,7 +59,7 @@ class GamificationUtils
foreach ($courses as $course) {
$learnPathListObject = new LearnpathList(
$userId,
$course['code'],
api_get_course_info($course['code']),
$sessionId
);
$learnPaths = $learnPathListObject->get_flat_list();
@ -145,7 +145,7 @@ class GamificationUtils
foreach ($courses as $course) {
$learnPathListObject = new LearnpathList(
$userId,
$course['code'],
api_get_course_info($course['code']),
$sessionId
);
$learnPaths = $learnPathListObject->get_flat_list();

@ -2744,10 +2744,10 @@ function api_get_session_condition(
$session_id = (int) $session_id;
if (empty($session_field)) {
$session_field = "session_id";
$session_field = 'session_id';
}
// Condition to show resources by session
$condition_add = $and ? " AND " : " WHERE ";
$condition_add = $and ? ' AND ' : ' WHERE ';
if ($with_base_content) {
$condition_session = $condition_add." ( $session_field = $session_id OR $session_field = 0 OR $session_field IS NULL) ";

@ -3930,10 +3930,10 @@ class SessionManager
$tbl_course = Database::get_main_table(TABLE_MAIN_COURSE);
$tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
$session_id = (int) $session_id;
$sqlSelect = "*, c.id, c.id as real_id";
$sqlSelect = '*, c.id, c.id as real_id';
if ($getCount) {
$sqlSelect = "COUNT(1) as count";
$sqlSelect = 'COUNT(1) as count';
}
// select the courses
@ -3953,9 +3953,9 @@ class SessionManager
$orderBy = " ORDER BY $orderBy";
} else {
if (self::orderCourseIsEnabled()) {
$orderBy .= " ORDER BY position ";
$orderBy .= ' ORDER BY position ';
} else {
$orderBy .= " ORDER BY title ";
$orderBy .= ' ORDER BY title ';
}
}
@ -4504,7 +4504,7 @@ class SessionManager
if ($course_info) {
//By default new elements are invisible
if ($set_exercises_lp_invisible) {
$list = new LearnpathList('', $course_info['code'], $sid);
$list = new LearnpathList('', $course_info, $sid);
$flat_list = $list->get_flat_list();
if (!empty($flat_list)) {
foreach ($flat_list as $lp_id => $data) {

@ -414,9 +414,7 @@ function api_trunc_str($text, $length = 30, $suffix = '...', $middle = false, $e
*/
function domesticate($input)
{
$input = stripslashes($input);
$input = str_replace("'", "''", $input);
$input = str_replace('"', "''", $input);
$input = str_replace(["'", '"'], "''", stripslashes($input));
return $input;
}

@ -2751,7 +2751,7 @@ class Tracking
if (empty($lpIdList)) {
$lpList = new LearnpathList(
$studentId,
$courseCode,
$courseInfo,
$sessionId,
null,
false,
@ -5867,7 +5867,7 @@ class Tracking
$list = new LearnpathList(
api_get_user_id(),
$course_info['code'],
$course_info,
$session_id,
'lp.publicatedOn ASC',
true,
@ -5877,7 +5877,7 @@ class Tracking
$lp_list = $list->get_flat_list();
if (!empty($lp_list) > 0) {
if (!empty($lp_list)) {
foreach ($lp_list as $lp_id => $learnpath) {
if (!$learnpath['lp_visibility']) {
continue;

@ -737,7 +737,7 @@ class Rest extends WebService
foreach ($categories as $category) {
$learnPathList = new LearnpathList(
$this->user->getId(),
$this->course->getCode(),
api_get_course_info($this->course->getCode()),
$sessionId,
null,
false,

@ -28,7 +28,7 @@ class LearnpathList
* (only displays) items if he has enough permissions to view them.
*
* @param int $user_id
* @param string $course_code Optional course code (otherwise we use api_get_course_id())
* @param array $courseInfo Optional course code (otherwise we use api_get_course_id())
* @param int $session_id Optional session id (otherwise we use api_get_session_id())
* @param string $order_by
* @param bool $check_publication_dates
@ -38,7 +38,7 @@ class LearnpathList
*/
public function __construct(
$user_id,
$course_code = '',
$courseInfo = [],
$session_id = 0,
$order_by = null,
$check_publication_dates = false,
@ -46,23 +46,16 @@ class LearnpathList
$ignoreCategoryFilter = false,
$ignoreLpVisibility = false
) {
$course_info = api_get_course_info($course_code);
if (empty($course_info['real_id'])) {
return false;
if (empty($courseInfo)) {
$courseInfo = api_get_course_info();
}
$this->course_code = $course_info['code'];
$this->course_code = $courseInfo['code'];
$course_id = $courseInfo['real_id'];
$this->user_id = $user_id;
$course_id = $course_info['real_id'];
// Condition for the session.
if (!empty($session_id)) {
$session_id = (int) $session_id;
} else {
$session_id = api_get_session_id();
}
$session_id = empty($session_id) ? api_get_session_id() : (int) $session_id;
$condition_session = api_get_session_condition(
$session_id,
true,
@ -78,8 +71,8 @@ class LearnpathList
}
$now = api_get_utc_datetime();
$time_conditions = '';
$time_conditions = '';
if ($check_publication_dates) {
$time_conditions = " AND (
(lp.publicatedOn IS NOT NULL AND lp.publicatedOn < '$now' AND lp.expiredOn IS NOT NULL AND lp.expiredOn > '$now') OR
@ -107,7 +100,6 @@ class LearnpathList
$categoryFilter
$order
";
$learningPaths = Database::getManager()->createQuery($dql)->getResult();
$showBlockedPrerequisite = api_get_configuration_value('show_prerequisite_as_blocked');
$names = [];
@ -121,7 +113,7 @@ class LearnpathList
$link = 'lp/lp_controller.php?action=view&lp_id='.$row->getId().'&id_session='.$session_id;
$oldLink = 'newscorm/lp_controller.php?action=view&lp_id='.$row->getId().'&id_session='.$session_id;
$sql2 = "SELECT * FROM $tbl_tool
$sql2 = "SELECT visibility FROM $tbl_tool
WHERE
c_id = $course_id AND
name = '$name' AND
@ -140,7 +132,7 @@ class LearnpathList
// Check if visible.
$visibility = api_get_item_visibility(
$course_info,
$courseInfo,
'learnpath',
$row->getId(),
$session_id
@ -152,7 +144,7 @@ class LearnpathList
$lpVisibility = learnpath::is_lp_visible_for_student(
$row->getId(),
$user_id,
$course_info
$courseInfo
);
if ($lpVisibility === false) {
continue;

@ -215,7 +215,7 @@ foreach ($categories as $item) {
$list = new LearnpathList(
$userId,
api_get_course_id(),
$courseInfo,
$sessionId,
null,
false,

@ -1391,7 +1391,7 @@ if (empty($details)) {
$list = new LearnpathList(
api_get_user_id(),
$courseInfo['code'],
$courseInfo,
$sessionId,
null,
false,

@ -114,7 +114,7 @@ if (!empty($courseList)) {
$list = new LearnpathList(
api_get_user_id(),
$course_data['code'],
api_get_course_info($course_data['code']),
$session_id,
'lp.publicatedOn ASC',
true,

@ -116,7 +116,7 @@ $course_code = api_get_course_id();
$course_id = api_get_course_int_id();
if ($lpReporting) {
$list = new LearnpathList(null, $course_code, $session_id);
$list = new LearnpathList(null, $course_info, $session_id);
$flat_list = $list->get_flat_list();
if (count($flat_list) > 0) {

@ -98,7 +98,7 @@ foreach ($course_list as $current_course) {
$attempt_result = [];
// Getting LP list
$list = new LearnpathList('', $current_course['code'], $session_id);
$list = new LearnpathList('', $course_info, $session_id);
$lp_list = $list->get_flat_list();
// Looping LPs

@ -133,7 +133,7 @@ foreach ($course_list as $current_course) {
$_course = $course_info;
// Getting LP list
$list = new LearnpathList('', $current_course['code'], $session_id);
$list = new LearnpathList('', $course_info, $session_id);
$lp_list = $list->get_flat_list();
// Looping LPs

@ -93,7 +93,7 @@ $form->setDefaults(['course_code' => (string) $course_code]);
$course_info = api_get_course_info($course_code);
if (!empty($course_info)) {
$list = new LearnpathList('', $course_code);
$list = new LearnpathList('', $course_info);
$lp_list = $list->get_flat_list();
$main_question_list = [];

@ -356,7 +356,7 @@ function WSGetLpList($params)
}
}
$list = new LearnpathList(null, $courseInfo['code'], $sessionId);
$list = new LearnpathList(null, $courseInfo, $sessionId);
$flatList = $list->get_flat_list();
$result = [];
foreach ($flatList as $id => $lp) {

@ -145,7 +145,7 @@ class WSReport extends WS
);
}
$lp = new LearnpathList($user_id, $course_code);
$lp = new LearnpathList($user_id, api_get_course_info($course_code));
$list = $lp->list;
$return = [];
foreach ($list as $id => $item) {

Loading…
Cancel
Save