Minor - Format code, refactor legacy code, fix php errors

pull/3890/head
Julio Montoya 4 years ago
parent 75cb6dbbfc
commit 4670ec3268
  1. 2
      assets/vue/views/account/Home.vue
  2. 7
      public/main/inc/lib/document.lib.php
  3. 58
      public/main/inc/lib/events.lib.php
  4. 3
      public/main/inc/lib/model.lib.php
  5. 2
      public/main/inc/lib/sessionmanager.lib.php
  6. 9
      public/main/inc/lib/skill.lib.php
  7. 407
      public/main/inc/lib/tracking.lib.php
  8. 2
      public/main/lp/LearnPathItemForm.php
  9. 17
      public/main/lp/ScormExport.php
  10. 472
      public/main/lp/learnpath.class.php
  11. 4
      public/main/lp/lp_controller.php
  12. 2
      public/main/lp/lp_view.php
  13. 1
      src/CoreBundle/Controller/CourseHomeController.php
  14. 2
      src/CoreBundle/Entity/AccessUrl.php
  15. 1
      src/CoreBundle/EventListener/LegacyListener.php
  16. 1
      src/CoreBundle/Migrations/Schema/V200/Version20170625144000.php

@ -1,6 +1,6 @@
<template>
<div class="card">
<h6>Hello {{ user.username }}</h6>
<h6>{{ user.firstname }} {{ user.lastname }} </h6>
<q-tabs align="left" dense inline-label no-caps>
<q-route-tab to="/courses" label="Inbox" />
<q-route-tab to="/courses" label="Posts" />

@ -21,13 +21,6 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
*/
class DocumentManager
{
/**
* Construct.
*/
private function __construct()
{
}
/**
* @param string $course_code
*

@ -2448,4 +2448,62 @@ class Event
return $now - $time;
}
public static function logSubscribedUserInCourse(int $subscribedId, int $courseId)
{
$dateTime = api_get_utc_datetime();
$registrantId = api_get_user_id();
self::addEvent(
LOG_SUBSCRIBE_USER_TO_COURSE,
LOG_COURSE_CODE,
api_get_course_entity($courseId)->getCode(),
$dateTime,
$registrantId,
$courseId
);
self::addEvent(
LOG_SUBSCRIBE_USER_TO_COURSE,
LOG_USER_OBJECT,
api_get_user_info($subscribedId),
$dateTime,
$registrantId,
$courseId
);
}
public static function logUserSubscribedInCourseSession(int $subscribedId, int $courseId, int $sessionId)
{
$dateTime = api_get_utc_datetime();
$registrantId = api_get_user_id();
self::addEvent(
LOG_SESSION_ADD_USER_COURSE,
LOG_USER_ID,
$subscribedId,
$dateTime,
$registrantId,
$courseId,
$sessionId
);
self::addEvent(
LOG_SUBSCRIBE_USER_TO_COURSE,
LOG_COURSE_CODE,
api_get_course_entity($courseId)->getCode(),
$dateTime,
$registrantId,
$courseId,
$sessionId
);
self::addEvent(
LOG_SUBSCRIBE_USER_TO_COURSE,
LOG_USER_OBJECT,
api_get_user_info($subscribedId),
$dateTime,
$registrantId,
$courseId,
$sessionId
);
}
}

@ -14,9 +14,6 @@ class Model
public $required;
public $is_course_model = false;
/**
* Constructor.
*/
public function __construct()
{
}

@ -6033,7 +6033,7 @@ class SessionManager
* @param bool $getCount
* @param int $from
* @param int $numberItems
* @param int $column
* @param string $column
* @param string $direction
* @param string $keyword
* @param string $active

@ -1,4 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Component\Utils\ChamiloApi;
@ -22,9 +23,6 @@ class SkillProfile extends Model
{
public $columns = ['id', 'name', 'description'];
/**
* Constructor.
*/
public function __construct()
{
$this->table = Database::get_main_table(TABLE_MAIN_SKILL_PROFILE);
@ -40,9 +38,8 @@ class SkillProfile extends Model
INNER JOIN $this->table_rel_profile sp
ON (p.id = sp.profile_id) ";
$result = Database::query($sql);
$profiles = Database::store_result($result, 'ASSOC');
return $profiles;
return Database::store_result($result, 'ASSOC');
}
/**

@ -157,21 +157,8 @@ class Tracking
}
$hideTime = api_get_configuration_value('hide_lp_time');
$allowNewTracking = api_get_configuration_value('use_new_tracking_in_lp_item');
$lp_id = (int) $lp_id;
if ($allowNewTracking) {
$extraField = new ExtraFieldValue('lp');
$result = $extraField->get_values_by_handler_and_field_variable($lp_id, 'track_lp_item');
if (empty($result)) {
$allowNewTracking = false;
} else {
if (isset($result['value']) && 1 == $result['value']) {
$allowNewTracking = true;
}
}
}
$lp_item_id = (int) $lp_item_id;
$user_id = (int) $user_id;
$sessionId = $session ? $session->getId() : 0;
@ -761,10 +748,6 @@ class Tracking
$subtotal_time += $tmp_row['mytime'];
}
if ($allowNewTracking) {
$subtotal_time = $attemptResult;
}
$title = $row['mytitle'];
// Selecting the exe_id from stats attempts tables in order to look the max score value.
$sql = 'SELECT * FROM '.$tbl_stats_exercices.'
@ -2426,7 +2409,10 @@ class Tracking
";
$result = Database::query($sql);
$row_lp = Database::fetch_row($result);
$lp_name = $row_lp[0];
$lp_name = null;
if ($row_lp && isset($row_lp[0])) {
$lp_name = $row_lp[0];
}
return [$quiz_avg_score, $lp_name];
}
@ -5391,7 +5377,6 @@ class Tracking
$url
);
}
$details .= '</a>';
$data = [
'course_title' => $course_url,
@ -5436,10 +5421,11 @@ class Tracking
* @param int $userId
* @param int $courseId
* @param int $sessionId
* @param bool $showDiagram
*
* @return string html code
*/
public static function show_course_detail($userId, $courseId, $sessionId = 0)
public static function show_course_detail($userId, $courseId, $sessionId = 0, $showDiagram = false)
{
$html = '';
if (empty($courseId)) {
@ -5455,6 +5441,14 @@ class Tracking
$html .= '<a name="course_session_data"></a>';
$html .= Display::page_subheader($course->getTitle());
if ($showDiagram && !empty($session_id)) {
$visibility = api_get_session_visibility($session_id);
if (SESSION_AVAILABLE === $visibility) {
$html .= Display::page_subheader2($course_info['title']);
}
}
$html .= '<div class="table-responsive">';
$html .= '<table class="table table-striped table-hover">';
@ -7423,9 +7417,6 @@ class Tracking
echo $sql_update;
}
Database::query($sql_update);
if ($debug) {
var_dump($sql_update);
}
if (!isset($result_message[$TBL_STUDENT_PUBLICATION_ASSIGNMENT])) {
$result_message[$TBL_STUDENT_PUBLICATION_ASSIGNMENT] = 0;
}
@ -7658,6 +7649,376 @@ class Tracking
}
}
}
private static function generateQuizzesTable(array $courseInfo, int $sessionId = 0): string
{
if (empty($sessionId)) {
$userList = CourseManager::get_user_list_from_course_code(
$courseInfo['code'],
$sessionId,
null,
null,
STUDENT
);
} else {
$userList = CourseManager::get_user_list_from_course_code($courseInfo['code'], $sessionId, null, null, 0);
}
$exerciseList = ExerciseLib::get_all_exercises($courseInfo, $sessionId, false, null);
if (empty($exerciseList)) {
return Display::return_message(get_lang('NoEx'));
}
$toGraphExerciseResult = [];
$quizzesTable = new SortableTableFromArray([], 0, 0, 'quizzes');
$quizzesTable->setHeaders(
[
get_lang('Exercises'),
get_lang('Attempts'),
get_lang('BestAttempt'),
get_lang('Ranking'),
get_lang('BestResultInCourse'),
get_lang('Statistics').Display::return_icon('info3.gif', get_lang('OnlyBestResultsPerStudent')),
]
);
$webCodePath = api_get_path(WEB_CODE_PATH);
foreach ($exerciseList as $exercices) {
$objExercise = new Exercise($courseInfo['real_id']);
$objExercise->read($exercices['id']);
$visibleReturn = $objExercise->is_visible();
// Getting count of attempts by user
$attempts = Event::count_exercise_attempts_by_user(
api_get_user_id(),
$exercices['id'],
$courseInfo['real_id'],
$sessionId
);
$url = $webCodePath.'exercise/overview.php?'
.http_build_query(
['cidReq' => $courseInfo['code'], 'id_session' => $sessionId, 'exerciseId' => $exercices['id']]
);
if ($visibleReturn['value'] == true) {
$exercices['title'] = Display::url(
$exercices['title'],
$url,
['target' => SESSION_LINK_TARGET]
);
} elseif ($exercices['active'] == -1) {
$exercices['title'] = sprintf(get_lang('XParenthesisDeleted'), $exercices['title']);
}
$quizData = [
$exercices['title'],
$attempts,
'-',
'-',
'-',
'-',
];
// Exercise configuration show results or show only score
if (!in_array($exercices['results_disabled'], [0, 2])
|| empty($attempts)
) {
$quizzesTable->addRow($quizData);
continue;
}
//For graphics
$bestExerciseAttempts = Event::get_best_exercise_results_by_user(
$exercices['id'],
$courseInfo['real_id'],
$sessionId
);
$toGraphExerciseResult[$exercices['id']] = [
'title' => $exercices['title'],
'data' => $bestExerciseAttempts,
];
// Getting best results
$bestScoreData = ExerciseLib::get_best_attempt_in_course(
$exercices['id'],
$courseInfo['real_id'],
$sessionId
);
if (!empty($bestScoreData)) {
$quizData[5] = ExerciseLib::show_score(
$bestScoreData['exe_result'],
$bestScoreData['exe_weighting']
);
}
$exerciseAttempt = ExerciseLib::get_best_attempt_by_user(
api_get_user_id(),
$exercices['id'],
$courseInfo['real_id'],
$sessionId
);
if (!empty($exerciseAttempt)) {
// Always getting the BEST attempt
$score = $exerciseAttempt['exe_result'];
$weighting = $exerciseAttempt['exe_weighting'];
$exeId = $exerciseAttempt['exe_id'];
$latestAttemptUrl = $webCodePath.'exercise/result.php?'
.http_build_query(
[
'id' => $exeId,
'cidReq' => $courseInfo['code'],
'show_headers' => 1,
'id_session' => $sessionId,
]
);
$quizData[3] = Display::url(
ExerciseLib::show_score($score, $weighting),
$latestAttemptUrl
);
$myScore = !empty($weighting) && intval($weighting) != 0 ? $score / $weighting : 0;
//@todo this function slows the page
if (is_int($userList)) {
$userList = [$userList];
}
$quizData[4] = ExerciseLib::get_exercise_result_ranking(
$myScore,
$exeId,
$exercices['id'],
$courseInfo['code'],
$sessionId,
$userList
);
$graph = self::generate_exercise_result_thumbnail_graph($toGraphExerciseResult[$exercices['id']]);
$normalGraph = self::generate_exercise_result_graph($toGraphExerciseResult[$exercices['id']]);
$quizData[6] = Display::url(
Display::img($graph, '', [], false),
$normalGraph,
['id' => $exercices['id'], 'class' => 'expand-image']
);
}
$quizzesTable->addRow($quizData);
}
return Display::div(
$quizzesTable->toHtml(),
['class' => 'table-responsive']
);
}
private static function generateLearningPathsTable(int $userId, array $courseInfo, int $sessionId = 0): string
{
$columnHeaders = [
'lp' => get_lang('LearningPath'),
'time' => get_lang('LatencyTimeSpent'),
'progress' => get_lang('Progress'),
'score' => get_lang('Score'),
'best_score' => get_lang('BestScore'),
'last_connection' => get_lang('LastConnexion'),
];
$trackingColumns = api_get_configuration_value('tracking_columns');
if (isset($trackingColumns['my_progress_lp'])) {
$columnHeaders = array_filter(
$columnHeaders,
function ($columHeader, $key) use ($trackingColumns) {
if (!isset($trackingColumns['my_progress_lp'][$key])
|| $trackingColumns['my_progress_lp'][$key] == false
) {
return false;
}
return true;
},
ARRAY_FILTER_USE_BOTH
);
}
if (true === api_get_configuration_value('student_follow_page_add_LP_subscription_info')) {
$columnHeaders['student_follow_page_add_LP_subscription_info'] = get_lang('Unlock');
}
if (true === api_get_configuration_value('student_follow_page_add_LP_acquisition_info')) {
$columnHeaders['student_follow_page_add_LP_acquisition_info'] = get_lang('Acquisition');
}
$addLpInvisibleCheckbox = api_get_configuration_value('student_follow_page_add_LP_invisible_checkbox');
$columnHeadersKeys = array_keys($columnHeaders);
$learningpathsTable = new SortableTableFromArray([], 0, 0, 'learningpaths');
$learningpathsTable->setHeaders($columnHeaders);
// LP table results
$list = new LearnpathList(
api_get_user_id(),
$courseInfo,
$sessionId,
'lp.publicatedOn ASC',
true,
null,
true
);
$lpList = $list->get_flat_list();
if (empty($lpList)) {
return Display::return_message(get_lang('NoLearnpath'));
}
$webCodePath = api_get_path(WEB_CODE_PATH);
foreach ($lpList as $lpId => $learnpath) {
$learningpathData = [];
if (!$learnpath['lp_visibility']) {
continue;
}
if ($addLpInvisibleCheckbox) {
if (!StudentFollowPage::isViewVisible($lpId, $userId, $courseInfo['real_id'], $sessionId)) {
continue;
}
}
$url = $webCodePath.'lp/lp_controller.php?'
.http_build_query(
['cidReq' => $courseInfo['code'], 'id_session' => $sessionId, 'lp_id' => $lpId, 'action' => 'view']
);
if (in_array('lp', $columnHeadersKeys)) {
if ($learnpath['lp_visibility'] == 0) {
$learningpathData[] = $learnpath['lp_name'];
} else {
$learningpathData[] = Display::url(
$learnpath['lp_name'],
$url,
['target' => SESSION_LINK_TARGET]
);
}
}
if (in_array('time', $columnHeadersKeys)) {
$time_spent_in_lp = self::get_time_spent_in_lp(
$userId,
$courseInfo['code'],
[$lpId],
$sessionId
);
$learningpathData[] = api_time_to_hms($time_spent_in_lp);
}
if (in_array('progress', $columnHeadersKeys)) {
$progress = self::get_avg_student_progress(
$userId,
$courseInfo['code'],
[$lpId],
$sessionId
);
if (is_numeric($progress)) {
$progress = sprintf(get_lang('XPercent'), $progress);
}
$learningpathData[] = $progress;
}
if (in_array('score', $columnHeadersKeys)) {
$percentage_score = self::get_avg_student_score(
$userId,
$courseInfo['code'],
[$lpId],
$sessionId
);
if (is_numeric($percentage_score)) {
$percentage_score = sprintf(get_lang('XPercent'), $percentage_score);
} else {
$percentage_score = sprintf(get_lang('XPercent'), 0);
}
$learningpathData[] = $percentage_score;
}
if (in_array('best_score', $columnHeadersKeys)) {
$bestScore = self::get_avg_student_score(
$userId,
$courseInfo['code'],
[$lpId],
$sessionId,
false,
false,
true
);
if (is_numeric($bestScore)) {
$bestScore = sprintf(get_lang('XPercent'), $bestScore);
} else {
$bestScore = '-';
}
$learningpathData[] = $bestScore;
}
if (in_array('last_connection', $columnHeadersKeys)) {
$lastConnectionInLp = self::get_last_connection_time_in_lp(
$userId,
$courseInfo['code'],
$lpId,
$sessionId
);
$lastConnection = '-';
if (!empty($lastConnectionInLp)) {
$lastConnection = api_convert_and_format_date($lastConnectionInLp, DATE_TIME_FORMAT_LONG);
}
$learningpathData[] = $lastConnection;
}
if (in_array('student_follow_page_add_LP_subscription_info', $columnHeadersKeys)) {
$learningpathData[] = StudentFollowPage::getLpSubscription(
$learnpath,
$userId,
$courseInfo['real_id'],
$sessionId
);
}
if (in_array('student_follow_page_add_LP_acquisition_info', $columnHeadersKeys)) {
$learningpathData[] = StudentFollowPage::getLpAcquisition(
$learnpath,
$userId,
$courseInfo['real_id'],
$sessionId
);
}
$learningpathsTable->addRow($learningpathData);
}
return Display::div(
$learningpathsTable->toHtml(),
['class' => 'table-responsive']
);
}
}
/**

@ -14,8 +14,6 @@ class LearnPathItemForm
public static function setForm(FormValidator $form, $action, learnpath $lp, CLpItem $lpItem)
{
$arrLP = $lp->getItemsForForm();
//$lp->tree_array($arrLP);
//$arrLP = $lp->arrMenu ?? [];
switch ($action) {
case 'add':

@ -9,6 +9,23 @@ use Symfony\Component\Filesystem\Filesystem;
class ScormExport
{
/**
* // TODO: The output encoding should be equal to the system encoding.
*
* Exports the learning path as a SCORM package. This is the main function that
* gathers the content, transforms it, writes the imsmanifest.xml file, zips the
* whole thing and returns the zip.
*
* This method needs to be called in PHP5, as it will fail with non-adequate
* XML package (like the ones for PHP4), and it is *not* a static method, so
* you need to call it on a learnpath object.
*
* @TODO The method might be redefined later on in the scorm class itself to avoid
* creating a SCORM structure if there is one already. However, if the initial SCORM
* path has been modified, it should use the generic method here below.
*
* @return string Returns the zip package string, or null if error
*/
public static function export(learnpath $lp)
{
// @todo fix export

@ -2575,7 +2575,7 @@ class learnpath
$lpItemRepo = Container::getLpItemRepository();
if (empty($parent)) {
$rootItem = $lpItemRepo->getRootItem($lp->getIid());
$parent = $rootItem->getIid() ;
$parent = $rootItem->getIid();
}
$criteria = new Criteria();
@ -2651,83 +2651,15 @@ class learnpath
*
* @return array HTML TOC ready to display
*/
public function getListArrayToc($toc_list = [])
public function getListArrayToc()
{
$lpItemRepo = Container::getLpItemRepository();
$itemRoot = $lpItemRepo->getRootItem($this->get_id());
$options = [
'decorate' => false,
];
$list = $lpItemRepo->childrenHierarchy($itemRoot, false, $options);
return $list;
if (empty($toc_list)) {
$toc_list = $this->get_toc();
}
// Temporary variables.
$currentItemId = $this->get_current_item_id();
$list = [];
$arrayList = [];
foreach ($toc_list as $item) {
$list['id'] = $item['id'];
$list['status'] = $item['status'];
$cssStatus = null;
if (array_key_exists($item['status'], self::STATUS_CSS_CLASS_NAME)) {
$cssStatus = self::STATUS_CSS_CLASS_NAME[$item['status']];
}
$classStyle = ' ';
$dirTypes = self::getChapterTypes();
if (in_array($item['type'], $dirTypes)) {
$classStyle = 'scorm_item_section ';
}
if ($item['id'] == $this->current) {
$classStyle = 'scorm_item_normal '.$classStyle.'scorm_highlight';
} elseif (!in_array($item['type'], $dirTypes)) {
$classStyle = 'scorm_item_normal '.$classStyle.' ';
}
$title = $item['title'];
if (empty($title)) {
$title = self::rl_get_resource_name(
api_get_course_id(),
$this->get_id(),
$item['id']
);
}
$title = Security::remove_XSS($item['title']);
if (empty($item['description'])) {
$list['description'] = $title;
} else {
$list['description'] = $item['description'];
}
$list['class'] = $classStyle.' '.$cssStatus;
$list['level'] = $item['level'];
$list['type'] = $item['type'];
if (in_array($item['type'], $dirTypes)) {
$list['css_level'] = 'level_'.$item['level'];
} else {
$list['css_level'] = 'level_'.$item['level'].' scorm_type_'.self::format_scorm_type_item($item['type']);
}
if (in_array($item['type'], $dirTypes)) {
$list['title'] = stripslashes($title);
} else {
$list['title'] = stripslashes($title);
$list['url'] = $this->get_link('http', $item['id'], $toc_list);
$list['current_id'] = $currentItemId;
}
$arrayList[] = $list;
}
return $arrayList;
return $lpItemRepo->childrenHierarchy($itemRoot, false, $options);
}
/**
@ -3235,266 +3167,6 @@ class learnpath
return $has;
}
/**
* Moves an item up and down at its level.
*
* @param int $id Item to move up and down
* @param string $direction Direction 'up' or 'down'
*
* @return bool|int
*/
public function move_item($id, $direction)
{
$course_id = api_get_course_int_id();
if (empty($id) || empty($direction)) {
return false;
}
$tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
$sql_sel = "SELECT *
FROM $tbl_lp_item
WHERE
iid = $id
";
$res_sel = Database::query($sql_sel);
// Check if elem exists.
if (Database::num_rows($res_sel) < 1) {
return false;
}
// Gather data.
$row = Database::fetch_array($res_sel);
$previous = $row['previous_item_id'];
$next = $row['next_item_id'];
$display = $row['display_order'];
$parent = $row['parent_item_id'];
$lp = $row['lp_id'];
// Update the item (switch with previous/next one).
switch ($direction) {
case 'up':
if ($display > 1) {
$sql_sel2 = "SELECT * FROM $tbl_lp_item
WHERE iid = $previous";
$res_sel2 = Database::query($sql_sel2);
if (Database::num_rows($res_sel2) < 1) {
$previous_previous = 0;
}
// Gather data.
$row2 = Database::fetch_array($res_sel2);
$previous_previous = $row2['previous_item_id'];
// Update previous_previous item (switch "next" with current).
if (0 != $previous_previous) {
$sql_upd2 = "UPDATE $tbl_lp_item SET
next_item_id = $id
WHERE iid = $previous_previous";
Database::query($sql_upd2);
}
// Update previous item (switch with current).
if (0 != $previous) {
$sql_upd2 = "UPDATE $tbl_lp_item SET
next_item_id = $next,
previous_item_id = $id,
display_order = display_order +1
WHERE iid = $previous";
Database::query($sql_upd2);
}
// Update current item (switch with previous).
if (0 != $id) {
$sql_upd2 = "UPDATE $tbl_lp_item SET
next_item_id = $previous,
previous_item_id = $previous_previous,
display_order = display_order-1
WHERE c_id = ".$course_id." AND id = $id";
Database::query($sql_upd2);
}
// Update next item (new previous item).
if (!empty($next)) {
$sql_upd2 = "UPDATE $tbl_lp_item SET previous_item_id = $previous
WHERE iid = $next";
Database::query($sql_upd2);
}
$display = $display - 1;
}
break;
case 'down':
if (0 != $next) {
$sql_sel2 = "SELECT * FROM $tbl_lp_item
WHERE iid = $next";
$res_sel2 = Database::query($sql_sel2);
if (Database::num_rows($res_sel2) < 1) {
$next_next = 0;
}
// Gather data.
$row2 = Database::fetch_array($res_sel2);
$next_next = $row2['next_item_id'];
// Update previous item (switch with current).
if (0 != $previous) {
$sql_upd2 = "UPDATE $tbl_lp_item
SET next_item_id = $next
WHERE iid = $previous";
Database::query($sql_upd2);
}
// Update current item (switch with previous).
if (0 != $id) {
$sql_upd2 = "UPDATE $tbl_lp_item SET
previous_item_id = $next,
next_item_id = $next_next,
display_order = display_order + 1
WHERE iid = $id";
Database::query($sql_upd2);
}
// Update next item (new previous item).
if (0 != $next) {
$sql_upd2 = "UPDATE $tbl_lp_item SET
previous_item_id = $previous,
next_item_id = $id,
display_order = display_order-1
WHERE iid = $next";
Database::query($sql_upd2);
}
// Update next_next item (switch "previous" with current).
if (0 != $next_next) {
$sql_upd2 = "UPDATE $tbl_lp_item SET
previous_item_id = $id
WHERE iid = $next_next";
Database::query($sql_upd2);
}
$display = $display + 1;
}
break;
default:
return false;
}
return $display;
}
/**
* Move a LP up (display_order).
*
* @param int $lp_id Learnpath ID
* @param int $categoryId Category ID
*
* @return bool
*/
public static function move_up($lp_id, $categoryId = 0)
{
$courseId = api_get_course_int_id();
$lp_table = Database::get_course_table(TABLE_LP_MAIN);
$categoryCondition = '';
if (!empty($categoryId)) {
$categoryId = (int) $categoryId;
$categoryCondition = " AND category_id = $categoryId";
}
$sql = "SELECT * FROM $lp_table
WHERE c_id = $courseId
$categoryCondition
ORDER BY display_order";
$res = Database::query($sql);
if (false === $res) {
return false;
}
$lps = [];
$lp_order = [];
$num = Database::num_rows($res);
// First check the order is correct, globally (might be wrong because
// of versions < 1.8.4)
if ($num > 0) {
$i = 1;
while ($row = Database::fetch_array($res)) {
if ($row['display_order'] != $i) { // If we find a gap in the order, we need to fix it.
$sql = "UPDATE $lp_table SET display_order = $i
WHERE iid = ".$row['iid'];
Database::query($sql);
}
$row['display_order'] = $i;
$lps[$row['iid']] = $row;
$lp_order[$i] = $row['iid'];
$i++;
}
}
if ($num > 1) { // If there's only one element, no need to sort.
$order = $lps[$lp_id]['display_order'];
if ($order > 1) { // If it's the first element, no need to move up.
$sql = "UPDATE $lp_table SET display_order = $order
WHERE iid = ".$lp_order[$order - 1];
Database::query($sql);
$sql = "UPDATE $lp_table SET display_order = ".($order - 1)."
WHERE iid = $lp_id";
Database::query($sql);
}
}
return true;
}
/**
* Move a learnpath down (display_order).
*
* @param int $lp_id Learnpath ID
* @param int $categoryId Category ID
*
* @return bool
*/
public static function move_down($lp_id, $categoryId = 0)
{
$courseId = api_get_course_int_id();
$lp_table = Database::get_course_table(TABLE_LP_MAIN);
$categoryCondition = '';
if (!empty($categoryId)) {
$categoryId = (int) $categoryId;
$categoryCondition = " AND category_id = $categoryId";
}
$sql = "SELECT * FROM $lp_table
WHERE c_id = $courseId
$categoryCondition
ORDER BY display_order";
$res = Database::query($sql);
if (false === $res) {
return false;
}
$lps = [];
$lp_order = [];
$num = Database::num_rows($res);
$max = 0;
// First check the order is correct, globally (might be wrong because
// of versions < 1.8.4).
if ($num > 0) {
$i = 1;
while ($row = Database::fetch_array($res)) {
$max = $i;
if ($row['display_order'] != $i) {
// If we find a gap in the order, we need to fix it.
$sql = "UPDATE $lp_table SET display_order = $i
WHERE iid = ".$row['iid'];
Database::query($sql);
}
$row['display_order'] = $i;
$lps[$row['iid']] = $row;
$lp_order[$i] = $row['iid'];
$i++;
}
}
if ($num > 1) { // If there's only one element, no need to sort.
$order = $lps[$lp_id]['display_order'];
if ($order < $max) { // If it's the first element, no need to move up.
$sql = "UPDATE $lp_table SET display_order = $order
WHERE iid = ".$lp_order[$order + 1];
Database::query($sql);
$sql = "UPDATE $lp_table SET display_order = ".($order + 1)."
WHERE iid = $lp_id";
Database::query($sql);
}
}
return true;
}
/**
* Updates learnpath attributes to point to the next element
* The last part is similar to set_current_item but processing the other way around.
@ -3717,7 +3389,7 @@ class learnpath
$addShortcut = true;
}
$repo = Container::getLpRepository();
/** @var CLp $lp */
/** @var CLp|null $lp */
$lp = $repo->find($id);
if (null === $lp) {
return false;
@ -3751,7 +3423,7 @@ class learnpath
}
$repo = Container::getLpCategoryRepository();
/** @var CLpCategory $lp */
/** @var CLpCategory|null $lp */
$category = $repo->find($id);
if (null === $category) {
@ -3788,13 +3460,13 @@ class learnpath
$categoryVisibility = $category->isVisible($course, $session);
if (1 !== $categoryVisibility && -1 != $categoryVisibility) {
if (!$categoryVisibility) {
return false;
}
$subscriptionSettings = self::getSubscriptionSettings();
if (false == $subscriptionSettings['allow_add_users_to_lp_category']) {
if (false === $subscriptionSettings['allow_add_users_to_lp_category']) {
return true;
}
@ -4673,94 +4345,6 @@ class learnpath
return $force;
}
/**
* Function that makes a call to the function sort_tree_array and create_tree_array.
*
* @author Kevin Van Den Haute
*
* @param array
*/
public function tree_array($array)
{
$array = $this->sort_tree_array($array);
$this->create_tree_array($array);
}
/**
* Creates an array with the elements of the learning path tree in it.
*
* @author Kevin Van Den Haute
*
* @param array $array
* @param int $parent
* @param int $depth
* @param array $tmp
*/
public function create_tree_array($array, $parent = 0, $depth = -1, $tmp = [])
{
if (is_array($array)) {
for ($i = 0; $i < count($array); $i++) {
if ($array[$i]['parent_item_id'] == $parent) {
if (!in_array($array[$i]['parent_item_id'], $tmp)) {
$tmp[] = $array[$i]['parent_item_id'];
$depth++;
}
$preq = (empty($array[$i]['prerequisite']) ? '' : $array[$i]['prerequisite']);
$audio = isset($array[$i]['audio']) ? $array[$i]['audio'] : null;
$path = isset($array[$i]['path']) ? $array[$i]['path'] : null;
$prerequisiteMinScore = isset($array[$i]['prerequisite_min_score']) ? $array[$i]['prerequisite_min_score'] : null;
$prerequisiteMaxScore = isset($array[$i]['prerequisite_max_score']) ? $array[$i]['prerequisite_max_score'] : null;
$ref = isset($array[$i]['ref']) ? $array[$i]['ref'] : '';
$this->arrMenu[] = [
'id' => $array[$i]['id'],
'ref' => $ref,
'item_type' => $array[$i]['item_type'],
'title' => $array[$i]['title'],
'title_raw' => $array[$i]['title_raw'],
'path' => $path,
'description' => $array[$i]['description'],
'parent_item_id' => $array[$i]['parent_item_id'],
'previous_item_id' => $array[$i]['previous_item_id'],
'next_item_id' => $array[$i]['next_item_id'],
'min_score' => $array[$i]['min_score'],
'max_score' => $array[$i]['max_score'],
'mastery_score' => $array[$i]['mastery_score'],
'display_order' => $array[$i]['display_order'],
'prerequisite' => $preq,
'depth' => $depth,
'audio' => $audio,
'prerequisite_min_score' => $prerequisiteMinScore,
'prerequisite_max_score' => $prerequisiteMaxScore,
];
$this->create_tree_array($array, $array[$i]['id'], $depth, $tmp);
}
}
}
}
/**
* Sorts a multi dimensional array by parent id and display order.
*
* @author Kevin Van Den Haute
*
* @param array $array (array with al the learning path items in it)
*
* @return array
*/
public function sort_tree_array($array)
{
foreach ($array as $key => $row) {
$parent[$key] = $row['parent_item_id'];
$position[$key] = $row['display_order'];
}
if (count($array) > 0) {
array_multisort($parent, SORT_ASC, $position, SORT_ASC, $array);
}
return $array;
}
/**
* Function that creates a html list of learning path items so that we can add audio files to them.
*
@ -5584,7 +5168,6 @@ class learnpath
$dir = $dir.$title;
// Creating LP folder
$documentId = null;
$folder = null;
if ($parent) {
$folder = create_unexisting_directory(
@ -5829,9 +5412,6 @@ class learnpath
$document = $repo->find($lpItem->getPath());
$return .= $this->display_document($document, true, true);
break;
case TOOL_HOTPOTATOES:
$return .= $this->display_document($document, false, true);
break;
}
$return .= '</div>';
@ -5892,10 +5472,6 @@ class learnpath
$return .= $this->displayItemMenu($lpItem);
$return .= $this->display_quiz_form('edit', $lpItem, $resource);
break;
/*case TOOL_HOTPOTATOES:
$return .= $this->displayItemMenu($lpItem);
$return .= $this->display_hotpotatoes_form('edit', $item_id, $row);
break;*/
case TOOL_STUDENTPUBLICATION:
if (!empty($path)) {
$repo = Container::getStudentPublicationRepository();
@ -6037,7 +5613,6 @@ class learnpath
// TODO: Add a path filter.
if ($iframe) {
//$url = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'.str_replace('%2F', '/', urlencode($row_doc['path'])).'?'.api_get_cidreq();
$url = $repo->getResourceFileUrl($document);
$return .= '<iframe
@ -6226,7 +5801,7 @@ class learnpath
$item_type = 'dir';
$lpItem = new CLpItem();
$lpItem->setTitle('dir');
$lpItem->setTitle('');
$lpItem->setItemType('dir');
$url = api_get_self().'?'.api_get_cidreq().'&action='.$action.'&type='.$item_type.'&lp_id='.$this->lp_id;
@ -6401,7 +5976,7 @@ class learnpath
$creatorId
);
$documentId = $document->getId();
$documentId = $document->getIid();
if (!$document) {
return 0;
@ -6531,7 +6106,6 @@ class learnpath
*/
public function get_js_dropdown_array()
{
$course_id = api_get_course_int_id();
$return = 'var child_name = new Array();'."\n";
$return .= 'var child_value = new Array();'."\n\n";
$return .= 'child_name[0] = new Array();'."\n";
@ -7509,33 +7083,6 @@ class learnpath
return $return;
}
/**
* // TODO: The output encoding should be equal to the system encoding.
*
* Exports the learning path as a SCORM package. This is the main function that
* gathers the content, transforms it, writes the imsmanifest.xml file, zips the
* whole thing and returns the zip.
*
* This method needs to be called in PHP5, as it will fail with non-adequate
* XML package (like the ones for PHP4), and it is *not* a static method, so
* you need to call it on a learnpath object.
*
* @TODO The method might be redefined later on in the scorm class itself to avoid
* creating a SCORM structure if there is one already. However, if the initial SCORM
* path has been modified, it should use the generic method here below.
*
* @return string Returns the zip package string, or null if error
*/
public function scormExport()
{
ScormExport::export($this);
}
public function scorm_export_to_pdf($lpId)
{
ScormExport::exportToPdf($lpId, api_get_course_info());
}
/**
* Temp function to be moved in main_api or the best place around for this.
* Creates a file path if it doesn't exist.
@ -8445,7 +7992,6 @@ class learnpath
'final_item',
$documentId,
$values['title'],
''
);
Display::addFlash(

@ -675,7 +675,7 @@ switch ($action) {
if (!$lp_found) {
require 'lp_list.php';
} else {
$oLP->scormExport();
ScormExport::export($oLP);
exit();
}
break;
@ -695,7 +695,7 @@ switch ($action) {
if (!$lp_found) {
require 'lp_list.php';
} else {
$result = $oLP->scorm_export_to_pdf($lpId);
$result = ScormExport::exportToPdf($lpId, api_get_course_info());;
if (!$result) {
require 'lp_list.php';
}

@ -548,8 +548,10 @@ $template->assign('lp_title_scorm', $lp->getName());
} else {*/
$template->assign('data_panel', null);
//echo '<pre>';var_dump($oLP->get_toc(), array_column($oLP->get_toc(), 'status_class', 'id'));
$template->assign('status_list', array_column($oLP->get_toc(), 'status_class', 'id'));
$template->assign('data_list', $oLP->getListArrayToc($get_toc_list));
//var_dump($oLP->getListArrayToc($get_toc_list));
$template->assign('lp_id', $lp->getIid());
$template->assign('lp_current_item_id', $oLP->get_current_item_id());

@ -280,7 +280,6 @@ class CourseHomeController extends ToolBaseController
return $this->redirect($url);
}
/**
* Edit configuration with given namespace.
*

@ -211,7 +211,7 @@ class AccessUrl extends AbstractResource implements ResourceInterface
public function __toString(): string
{
return (string) $this->getUrl();
return $this->getUrl();
}
/**

@ -10,7 +10,6 @@ use Chamilo\CoreBundle\Entity\User;
use Chamilo\CoreBundle\Framework\Container;
use Exception;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;

@ -162,7 +162,6 @@ class Version20170625144000 extends AbstractMigrationChamilo
);
}
if (!$table->hasIndex('IDX_35C509F6BB3453DB')) {
$this->addSql('CREATE INDEX IDX_35C509F6BB3453DB ON c_student_publication_comment (work_id);');
}

Loading…
Cancel
Save