diff --git a/documentation/changelog.html b/documentation/changelog.html index 767de1217f..b0106a9fa1 100755 --- a/documentation/changelog.html +++ b/documentation/changelog.html @@ -111,6 +111,29 @@
Chamilo 1.11.8 is a minor, bugfix release on top of 1.11.6.
+?????????????
+In Chamilo 1.11.x you can boost the DB tables related surveys invitations by adding the following indexes:
++ CREATE INDEX idx_survey_q_qid ON c_survey_question (question_id); + CREATE INDEX idx_survey_code ON c_survey (code); + CREATE INDEX idx_survey_inv_code ON c_survey_invitation (survey_code); + CREATE INDEX idx_survey_qo_qid ON c_survey_question_option (question_id); ++ Also by adding a index on access_url_rel_session to improve the course/session list +
+ CREATE INDEX idx_accessurs_sid ON access_url_rel_session (session_id); +
We recommend you don't take security issues too lightly. Chamilo is security-audited at least once a year, @@ -85,7 +86,7 @@ This will prevent direct access to your settings and make it seem totally the sa
Don't hesitate to hire an experienced administrator to do that, it might be a bit more expensive now, but you'll be happy not to have to loose all of your data to a hacker who attacked your site.
-Only the following directories have required (or optional) write +
Only the following directories have required (or optional) write
permissions from the web server:
'.$objQuestion->get_question_type_name().'
'; + if ($objQuestion->type == FILL_IN_BLANKS) { + echo ''; + } ExerciseLib::showQuestion( $objExercise, $questionId, diff --git a/main/inc/ajax/extra_field.ajax.php b/main/inc/ajax/extra_field.ajax.php index 1dc8253f9b..eaba87543c 100755 --- a/main/inc/ajax/extra_field.ajax.php +++ b/main/inc/ajax/extra_field.ajax.php @@ -6,14 +6,26 @@ use Chamilo\CoreBundle\Entity\Tag; require_once __DIR__.'/../global.inc.php'; $action = isset($_GET['a']) ? $_GET['a'] : ''; +$type = isset($_REQUEST['type']) ? $_REQUEST['type'] : null; +$fieldId = isset($_REQUEST['field_id']) ? $_REQUEST['field_id'] : null; switch ($action) { + case 'delete_file': + api_protect_admin_script(); + + $itemId = isset($_REQUEST['item_id']) ? $_REQUEST['item_id'] : null; + $extraFieldValue = new ExtraFieldValue($type); + $data = $extraFieldValue->get_values_by_handler_and_field_id($itemId, $fieldId); + if (!empty($data) && isset($data['id']) && !empty($data['value'])) { + $extraFieldValue->deleteValuesByHandlerAndFieldAndValue($itemId, $data['field_id'], $data['value']); + echo 1; + break; + } + echo 0; + break; case 'get_second_select_options': - $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : null; - $field_id = isset($_REQUEST['field_id']) ? $_REQUEST['field_id'] : null; $option_value_id = isset($_REQUEST['option_value_id']) ? $_REQUEST['option_value_id'] : null; - - if (!empty($type) && !empty($field_id) && !empty($option_value_id)) { + if (!empty($type) && !empty($fieldId) && !empty($option_value_id)) { $field_options = new ExtraFieldOption($type); echo $field_options->get_second_select_field_options_by_field( $option_value_id, @@ -23,9 +35,6 @@ switch ($action) { break; case 'search_tags': header('Content-Type: application/json'); - - $type = isset($_REQUEST['type']) ? $_REQUEST['type'] : null; - $fieldId = isset($_REQUEST['field_id']) ? $_REQUEST['field_id'] : null; $tag = isset($_REQUEST['q']) ? $_REQUEST['q'] : null; $result = []; diff --git a/main/inc/ajax/lp.ajax.php b/main/inc/ajax/lp.ajax.php index a281ed06d9..e6d9cd0ae0 100755 --- a/main/inc/ajax/lp.ajax.php +++ b/main/inc/ajax/lp.ajax.php @@ -8,12 +8,17 @@ use ChamiloSession as Session; */ require_once __DIR__.'/../global.inc.php'; api_protect_course_script(true); -$action = $_REQUEST['a']; + +$debug = false; +$action = isset($_REQUEST['a']) ? $_REQUEST['a'] : ''; $course_id = api_get_course_int_id(); -$tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM); $sessionId = api_get_session_id(); +if ($debug) { + error_log('----------lp.ajax-------------- action '.$action); +} + switch ($action) { case 'get_documents': $courseInfo = api_get_course_info(); @@ -102,6 +107,8 @@ switch ($action) { } } + $table = Database::get_course_table(TABLE_LP_ITEM); + foreach ($LP_item_list->list as $LP_item) { $params = []; $params['display_order'] = $LP_item->display_order; @@ -110,7 +117,7 @@ switch ($action) { $params['parent_item_id'] = $LP_item->parent_item_id; Database::update( - $tbl_lp_item, + $table, $params, [ 'id = ? AND c_id = ? ' => [ @@ -289,6 +296,23 @@ switch ($action) { echo json_encode($position); + break; + case 'get_parent_names': + $newItemId = isset($_GET['new_item']) ? intval($_GET['new_item']) : 0; + + if (!$newItemId) { + break; + } + + /** @var \learnpath $lp */ + $lp = Session::read('oLP'); + $parentNames = $lp->getCurrentItemParentNames($newItemId); + $response = ''; + foreach ($parentNames as $parentName) { + $response .= ''; + } + + echo $response; break; default: echo ''; diff --git a/main/inc/ajax/model.ajax.php b/main/inc/ajax/model.ajax.php index 23283c3e80..77c637e516 100755 --- a/main/inc/ajax/model.ajax.php +++ b/main/inc/ajax/model.ajax.php @@ -1194,6 +1194,10 @@ switch ($action) { $course = api_get_course_info(); // Used inside ExerciseLib::get_exam_results_data() $documentPath = api_get_path(SYS_COURSE_PATH).$course['path']."/document"; + $is_allowedToEdit = api_is_allowed_to_edit(null, true) || + api_is_drh() || + api_is_student_boss() || + api_is_session_admin(); if ($is_allowedToEdit || api_is_student_boss()) { $columns = [ 'firstname', @@ -1316,7 +1320,8 @@ switch ($action) { $courseInfo['code'], true, true, - $extraFieldsToAdd + $extraFieldsToAdd, + true ); break; case 'get_hotpotatoes_exercise_results': diff --git a/main/inc/ajax/skill.ajax.php b/main/inc/ajax/skill.ajax.php index aae21dc072..e36c48dc35 100755 --- a/main/inc/ajax/skill.ajax.php +++ b/main/inc/ajax/skill.ajax.php @@ -1,5 +1,6 @@ edit($_REQUEST); + $skillId = $skill->edit($_REQUEST); } else { - $skill_id = $skill->add($_REQUEST); + $skillId = $skill->add($_REQUEST); } } - echo $skill_id; + echo $skillId; break; case 'delete_skill': if (api_is_platform_admin() || api_is_drh()) { @@ -73,10 +74,10 @@ switch ($action) { echo json_encode($return); break; case 'get_course_info_popup': - $course_info = api_get_course_info($_REQUEST['code']); + $courseInfo = api_get_course_info($_REQUEST['code']); $courses = CourseManager::processHotCourseItem( [ - ['c_id' => $course_info['real_id']], + ['c_id' => $courseInfo['real_id']], ] ); Display::display_no_header(); @@ -93,39 +94,39 @@ switch ($action) { } break; case 'get_skills_by_profile': - $skill_rel_profile = new SkillRelProfile(); + $skillRelProfile = new SkillRelProfile(); $profile_id = isset($_REQUEST['profile_id']) ? $_REQUEST['profile_id'] : null; - $skills = $skill_rel_profile->getSkillsByProfile($profile_id); + $skills = $skillRelProfile->getSkillsByProfile($profile_id); echo json_encode($skills); break; case 'get_saved_profiles': - $skill_profile = new SkillProfile(); - $profiles = $skill_profile->get_all(); + $skillProfile = new SkillProfile(); + $profiles = $skillProfile->get_all(); Display::display_no_header(); Display::$global_template->assign('profiles', $profiles); $template = Display::$global_template->get_template('skill/profile_item.tpl'); echo Display::$global_template->fetch($template); break; case 'get_skills': - $load_user_data = isset($_REQUEST['load_user_data']) ? $_REQUEST['load_user_data'] : null; + $loadUserData = isset($_REQUEST['load_user_data']) ? $_REQUEST['load_user_data'] : null; $id = intval($_REQUEST['id']); - $skills = $skill->get_all($load_user_data, false, $id); + $skills = $skill->get_all($loadUserData, false, $id); echo json_encode($skills); break; case 'get_skill_info': $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : null; - $skill_info = $skill->getSkillInfo($id); - echo json_encode($skill_info); + $skillInfo = $skill->getSkillInfo($id); + echo json_encode($skillInfo); break; case 'get_skill_course_info': $id = isset($_REQUEST['id']) ? $_REQUEST['id'] : null; - $skill_info = $skill->getSkillInfo($id); + $skillInfo = $skill->getSkillInfo($id); $courses = $skill->getCoursesBySkill($id); $sessions = $skill->getSessionsBySkill($id); $html = ''; if (!empty($courses) || !empty($sessions)) { Display::display_no_header(); - Display::$global_template->assign('skill', $skill_info); + Display::$global_template->assign('skill', $skillInfo); Display::$global_template->assign('courses', $courses); Display::$global_template->assign('sessions', $sessions); $template = Display::$global_template->get_template('skill/skill_info.tpl'); @@ -218,7 +219,6 @@ switch ($action) { $user_info = api_get_user_info($user['user_id']); $user_list[$user['user_id']]['user'] = $user_info; $my_user_skills = $skill_rel_user->getUserSkills($user['user_id']); - $user_skill_list = []; foreach ($my_user_skills as $skill_item) { $user_skill_list[] = $skill_item['skill_id']; @@ -349,14 +349,36 @@ switch ($action) { ] ); $returnSkills = []; - foreach ($skills as $skill) { $returnSkills[] = [ 'id' => $skill['id'], 'text' => $skill['name'], ]; } + echo json_encode([ + 'items' => $returnSkills, + ]); + break; + case 'search_skills_in_course': + $courseId = isset($_REQUEST['course_id']) ? (int) $_REQUEST['course_id'] : 0; + $sessionId = isset($_REQUEST['session_id']) ? (int) $_REQUEST['session_id'] : null; + if (empty($courseId)) { + exit; + } + $em = Database::getManager(); + $skills = $em->getRepository('ChamiloSkillBundle:SkillRelCourse')->findBy( + ['course' => $courseId, 'session' => $sessionId] + ); + + $returnSkills = []; + /** @var \Chamilo\SkillBundle\Entity\SkillRelCourse $skill */ + foreach ($skills as $skill) { + $returnSkills[] = [ + 'id' => $skill->getSkill()->getId(), + 'text' => $skill->getSkill()->getName(), + ]; + } echo json_encode([ 'items' => $returnSkills, ]); @@ -378,6 +400,7 @@ switch ($action) { $userId = isset($_REQUEST['user_id']) ? (int) $_REQUEST['user_id'] : 0; $courseId = isset($_REQUEST['course_id']) ? (int) $_REQUEST['course_id'] : 0; $sessionId = isset($_REQUEST['session_id']) ? (int) $_REQUEST['session_id'] : 0; + $resultId = isset($_REQUEST['result_id']) ? (int) $_REQUEST['result_id'] : 0; if (!empty($typeId) && !empty($itemId) && !empty($skillId) && !empty($userId) && !empty($courseId)) { $em = Database::getManager(); @@ -392,7 +415,6 @@ switch ($action) { } $session = $em->getRepository('ChamiloCoreBundle:Session')->find($sessionId); - /** @var \Chamilo\SkillBundle\Entity\SkillRelItem $skillRelItem */ $skillRelItem = $em->getRepository('ChamiloSkillBundle:SkillRelItem')->findOneBy( ['itemId' => $itemId, 'itemType' => $typeId, 'skill' => $skillId] @@ -413,6 +435,7 @@ switch ($action) { $skillRelItemRelUser ->setUser($user) ->setSkillRelItem($skillRelItem) + ->setResultId($resultId) ->setCreatedBy($creatorId) ->setUpdatedBy($creatorId) ; @@ -423,6 +446,72 @@ switch ($action) { echo Skill::getUserSkillStatusLabel($skillRelItem, $skillRelItemRelUser, false); } break; + case 'assign_user_to_skill': + $allowSkillInTools = api_get_configuration_value('allow_skill_rel_items'); + if (empty($allowSkillInTools)) { + exit; + } + + if (!api_is_allowed_to_edit()) { + exit; + } + + $skillId = isset($_REQUEST['skill_id']) ? (int) $_REQUEST['skill_id'] : 0; + $userId = isset($_REQUEST['user_id']) ? (int) $_REQUEST['user_id'] : 0; + $courseId = isset($_REQUEST['course_id']) ? (int) $_REQUEST['course_id'] : 0; + $sessionId = isset($_REQUEST['session_id']) ? (int) $_REQUEST['session_id'] : null; + + if (empty($skillId) || empty($userId)) { + exit; + } + + $em = Database::getManager(); + $skillRepo = $em->getRepository('ChamiloCoreBundle:Skill'); + $skill = $skillRepo->find($skillId); + $user = api_get_user_entity($userId); + + if (empty($skill) || empty($user)) { + exit; + } + + $skillUserRepo = $em->getRepository('ChamiloCoreBundle:SkillRelUser'); + $criteria = [ + 'user' => $user, + 'skill' => $skill, + ]; + $skillRelUsers = $skillUserRepo->findBy($criteria); + if (empty($skillRelUsers)) { + $skillUser = new \Chamilo\CoreBundle\Entity\SkillRelUser(); + $skillUser->setUser($user); + $skillUser->setSkill($skill); + /*if ($showLevels) { + $level = $skillLevelRepo->find(intval($values['acquired_level'])); + $skillUser->setAcquiredLevel($level); + }*/ + + $course = api_get_course_entity($courseId); + $skillUser->setCourse($course); + if (!empty($sessionId)) { + $session = $em->getRepository('ChamiloCoreBundle:Session')->find($sessionId); + $skillUser->setSession($session); + } + + $skillUser->setArgumentation(''); + $skillUser->setArgumentationAuthorId(api_get_user_id()); + $skillUser->setAcquiredSkillAt(new DateTime()); + $skillUser->setAssignedBy(0); + $em->persist($skillUser); + $em->flush(); + $result = 'success'; + } else { + foreach ($skillRelUsers as $skillRelUser) { + $em->remove($skillRelUser); + } + $em->flush(); + $result = 'danger'; + } + echo $result; + break; default: echo ''; } diff --git a/main/lp/aiccItem.class.php b/main/lp/aiccItem.class.php index da4814ef31..cfbd077a27 100755 --- a/main/lp/aiccItem.class.php +++ b/main/lp/aiccItem.class.php @@ -36,8 +36,8 @@ class aiccItem extends learnpathItem * Class constructor. Depending of the type of construction called ('db' or 'manifest'), will create a scormItem * object from database records or from the array given as second parameter. * - * @param string Type of construction needed ('db' or 'config', default = 'config') - * @param mixed Depending on the type given, DB id for the lp_item or parameters array + * @param string Type of construction needed ('db' or 'config', default = 'config') + * @param mixed Depending on the type given, DB id for the lp_item or parameters array */ public function __construct($type = 'config', $params = [], $course_id = null) { @@ -50,7 +50,6 @@ class aiccItem extends learnpathItem // no break case 'config': // Do the same as the default. default: - //if($first_item->type == XML_ELEMENT_NODE) this is already check prior to the call to this function foreach ($params as $a => $value) { switch ($a) { case 'system_id': @@ -109,10 +108,10 @@ class aiccItem extends learnpathItem /** * Builds a flat list with the current item and calls itself recursively on all children. * - * @param array Reference to the array to complete with the current item - * @param int Optional absolute order (pointer) of the item in this learning path - * @param int Optional relative order of the item at this level - * @param int Optional level. If not given, assumes it's level 0 + * @param array Reference to the array to complete with the current item + * @param int Optional absolute order (pointer) of the item in this learning path + * @param int Optional relative order of the item at this level + * @param int Optional level. If not given, assumes it's level 0 */ public function get_flat_list(&$list, &$abs_order, $rel_order = 1, $level = 0) { @@ -141,7 +140,7 @@ class aiccItem extends learnpathItem /** * Save function. Uses the parent save function and adds a layer for AICC. * - * @param bool Save from URL params (1) or from object attributes (0) + * @param bool Save from URL params (1) or from object attributes (0) */ public function save($from_outside = true, $prereqs_complete = false) { diff --git a/main/lp/aicc_hacp.php b/main/lp/aicc_hacp.php index 8d5c86e7b1..210ba2b50e 100755 --- a/main/lp/aicc_hacp.php +++ b/main/lp/aicc_hacp.php @@ -269,6 +269,7 @@ if (!empty($_REQUEST['command'])) { } Session::write('lpobject', serialize($oLP)); +Session::write('oLP', $oLP); session_write_close(); // Content type must be text/plain. header('Content-type: text/plain'); diff --git a/main/lp/learnpath.class.php b/main/lp/learnpath.class.php index 6f1eb0ce6d..05c9130b51 100755 --- a/main/lp/learnpath.class.php +++ b/main/lp/learnpath.class.php @@ -40,12 +40,11 @@ class learnpath public $default_status = 'not attempted'; public $encoding = 'UTF-8'; public $error = ''; - public $extra_information = ''; // This string can be used by proprietary SCORM contents to store data about the current learnpath. - public $force_commit = false; // For SCORM only - if set to true, will send a scorm LMSCommit() request on each LMSSetValue(). + public $force_commit = false; // For SCORM only- if true will send a scorm LMSCommit() request on each LMSSetValue() public $index; // The index of the active learnpath_item in $ordered_items array. public $items = []; public $last; // item_id of last item viewed in the learning path. - public $last_item_seen = 0; // In case we have already come in this learnpath, reuse the last item seen if authorized. + public $last_item_seen = 0; // In case we have already come in this lp, reuse the last item seen if authorized. public $license; // Which license this course has been given - not used yet on 20060522. public $lp_id; // DB iid for this learnpath. public $lp_view_id; // DB ID for lp_view @@ -98,15 +97,18 @@ class learnpath * Needs a database handler, a course code and a learnpath id from the database. * Also builds the list of items into $this->items. * - * @param string $course Course code + * @param string $course Course code * @param int $lp_id * @param int $user_id + * + * @throws \Doctrine\DBAL\DBALException */ public function __construct($course, $lp_id, $user_id) { + $debug = $this->debug; $this->encoding = api_get_system_encoding(); - if ($this->debug > 0) { - error_log('New LP - In learnpath::__construct('.$course.','.$lp_id.','.$user_id.')', 0); + if ($debug) { + error_log('In learnpath::__construct('.$course.','.$lp_id.','.$user_id.')'); } if (empty($course)) { $course = api_get_course_id(); @@ -131,8 +133,8 @@ class learnpath $lp_table = Database::get_course_table(TABLE_LP_MAIN); $sql = "SELECT * FROM $lp_table WHERE iid = $lp_id"; - if ($this->debug > 2) { - error_log('New LP - learnpath::__construct() '.__LINE__.' - Querying lp: '.$sql, 0); + if ($debug) { + error_log('learnpath::__construct() '.__LINE__.' - Querying lp: '.$sql, 0); } $res = Database::query($sql); if (Database::num_rows($res) > 0) { @@ -179,11 +181,11 @@ class learnpath if (empty($user_id)) { $this->error = 'User ID is empty'; } else { - $user_info = api_get_user_info($user_id); - if (!empty($user_info)) { - $this->user_id = $user_info['user_id']; + $userInfo = api_get_user_info($user_id); + if (!empty($userInfo)) { + $this->user_id = $userInfo['user_id']; } else { - $this->error = 'User ID does not exist in database ('.$sql.')'; + $this->error = 'User ID does not exist in database #'.$user_id; } } @@ -203,13 +205,13 @@ class learnpath $session ORDER BY view_count DESC"; $res = Database::query($sql); - if ($this->debug > 2) { - error_log('New LP - learnpath::__construct() '.__LINE__.' - querying lp_view: '.$sql, 0); + if ($debug) { + error_log('learnpath::__construct() '.__LINE__.' - querying lp_view: '.$sql, 0); } if (Database::num_rows($res) > 0) { - if ($this->debug > 2) { - error_log('New LP - learnpath::__construct() '.__LINE__.' - Found previous view'); + if ($debug) { + error_log('learnpath::__construct() '.__LINE__.' - Found previous view'); } $row = Database::fetch_array($res); $this->attempt = $row['view_count']; @@ -218,8 +220,8 @@ class learnpath $this->progress_db = $row['progress']; $this->lp_view_session_id = $row['session_id']; } elseif (!api_is_invitee()) { - if ($this->debug > 2) { - error_log('New LP - learnpath::__construct() '.__LINE__.' - NOT Found previous view'); + if ($debug) { + error_log('learnpath::__construct() '.__LINE__.' - NOT Found previous view'); } $this->attempt = 1; $params = [ @@ -230,6 +232,8 @@ class learnpath 'session_id' => $session_id, 'last_item' => 0, ]; + $this->last_item_seen = 0; + $this->lp_view_session_id = $session_id; $this->lp_view_id = Database::insert($lp_table, $params); if (!empty($this->lp_view_id)) { $sql = "UPDATE $lp_table SET id = iid @@ -245,8 +249,8 @@ class learnpath ORDER BY parent_item_id, display_order"; $res = Database::query($sql); - if ($this->debug > 2) { - error_log('New LP - learnpath::__construct() '.__LINE__.' - query lp items: '.$sql); + if ($debug) { + error_log('learnpath::__construct() '.__LINE__.' - query lp items: '.$sql); error_log('-- Start while--'); } @@ -263,9 +267,9 @@ class learnpath // Don't use reference here as the next loop will make the pointed object change. $this->items[$my_item_id] = $oItem; $this->refs_list[$oItem->ref] = $my_item_id; - if ($this->debug > 2) { + if ($debug) { error_log( - 'New LP - learnpath::__construct() - '. + 'learnpath::__construct() - '. 'aicc object with id '.$my_item_id. ' set in items[]', 0 @@ -282,20 +286,20 @@ class learnpath // Don't use reference here as the next loop will make the pointed object change. $this->items[$my_item_id] = $oItem; $this->refs_list[$oItem->ref] = $my_item_id; - if ($this->debug > 2) { - error_log('New LP - object with id '.$my_item_id.' set in items[]', 0); + if ($debug) { + error_log('object with id '.$my_item_id.' set in items[]'); } } break; case 1: default: - if ($this->debug > 2) { - error_log('New LP - learnpath::__construct() '.__LINE__.' - calling learnpathItem'); + if ($debug) { + error_log('learnpath::__construct() '.__LINE__.' - calling learnpathItem'); } $oItem = new learnpathItem($row['iid'], $user_id, $course_id, $row); - if ($this->debug > 2) { - error_log('New LP - learnpath::__construct() '.__LINE__.' - end calling learnpathItem'); + if ($debug) { + error_log('learnpath::__construct() '.__LINE__.' - end calling learnpathItem'); } if (is_object($oItem)) { $my_item_id = $oItem->get_id(); @@ -305,9 +309,9 @@ class learnpath // Don't use reference here as the next loop will make the pointed object change. $this->items[$my_item_id] = $oItem; $this->refs_list[$my_item_id] = $my_item_id; - if ($this->debug > 2) { + if ($debug) { error_log( - 'New LP - learnpath::__construct() '.__LINE__. + 'learnpath::__construct() '.__LINE__. ' - object with id '.$my_item_id.' set in items[]' ); } @@ -334,8 +338,8 @@ class learnpath } } - if ($this->debug > 2) { - error_log('New LP - learnpath::__construct() '.__LINE__.' ----- end while ----'); + if ($debug) { + error_log('learnpath::__construct() '.__LINE__.' ----- end while ----'); } if (!empty($lp_item_id_list)) { @@ -352,9 +356,9 @@ class learnpath lp_item_id IN ('".$lp_item_id_list_to_string."') ORDER BY view_count DESC "; - if ($this->debug > 2) { + if ($debug) { error_log( - 'New LP - learnpath::__construct() - Selecting item_views: '.$sql, + 'learnpath::__construct() - Selecting item_views: '.$sql, 0 ); } @@ -429,8 +433,9 @@ class learnpath } // TODO: Define the current item better. $this->first(); - if ($this->debug > 2) { - error_log('New LP - learnpath::__construct() '.__LINE__.' - End of learnpath constructor for learnpath '.$this->get_id(), 0); + if ($debug) { + error_log('lp_view_session_id '.$this->lp_view_session_id); + error_log('End of learnpath constructor for learnpath '.$this->get_id()); } } else { $this->error = 'Learnpath ID does not exist in database ('.$sql.')'; @@ -473,7 +478,7 @@ class learnpath * @param int $parent * @param int $previous * @param string $type - * @param int $id resource ID (ref) + * @param int $id resource ID (ref) * @param string $title * @param string $description * @param int $prerequisites @@ -481,6 +486,7 @@ class learnpath * @param int $userId * * @return int + * @throws \Doctrine\DBAL\DBALException */ public function add_item( $parent, @@ -495,7 +501,7 @@ class learnpath ) { $course_id = $this->course_info['real_id']; if ($this->debug > 0) { - error_log('New LP - In learnpath::add_item('.$parent.','.$previous.','.$type.','.$id.','.$title.')'); + error_log('In learnpath::add_item('.$parent.','.$previous.','.$type.','.$id.','.$title.')'); } if (empty($course_id)) { // Sometimes Oogie doesn't catch the course info but sets $this->cc @@ -561,6 +567,7 @@ class learnpath $id = intval($id); $typeCleaned = Database::escape_string($type); + $max_score = 100; if ($type == 'quiz') { $sql = 'SELECT SUM(ponderation) FROM '.Database::get_course_table(TABLE_QUIZ_QUESTION).' as quiz_question @@ -580,8 +587,6 @@ class learnpath $exercise->read($id); $exercise->disable(); $exercise->save(); - } else { - $max_score = 100; } $params = [ @@ -610,7 +615,7 @@ class learnpath $new_item_id = Database::insert($tbl_lp_item, $params); if ($this->debug > 2) { - error_log('New LP - Inserting dir/chapter: '.$new_item_id, 0); + error_log('Inserting dir/chapter: '.$new_item_id, 0); } if ($new_item_id) { @@ -724,18 +729,19 @@ class learnpath /** * Static admin function allowing addition of a learnpath to a course. * - * @param string Course code - * @param string Learnpath name - * @param string Learnpath description string, if provided - * @param string Type of learnpath (default = 'guess', others = 'dokeos', 'aicc',...) - * @param string Type of files origin (default = 'zip', others = 'dir','web_dir',...) - * @param string $zipname Zip file containing the learnpath or directory containing the learnpath + * @param $courseCode + * @param $name + * @param string $description + * @param string $learnpath + * @param string $origin + * @param string $zipname Zip file containing the learnpath or directory containing the learnpath * @param string $publicated_on * @param string $expired_on * @param int $categoryId * @param int $userId * * @return int The new learnpath ID on success, 0 on failure + * @throws \Doctrine\DBAL\DBALException */ public static function add_lp( $courseCode, @@ -912,7 +918,8 @@ class learnpath // if $item points to an object and there is a parent. if ($debug) { error_log( - 'Autocompleting parent of item '.$item.' "'.$currentItem->get_title().'" (item '.$parent_id.' "'.$parent->get_title().'") ', + 'Autocompleting parent of item '.$item.' '. + $currentItem->get_title().'" (item '.$parent_id.' "'.$parent->get_title().'") ', 0 ); } @@ -1000,18 +1007,6 @@ class learnpath } } - /** - * Auto saves the current results into the database for the whole learnpath. - * - * @todo: Add save operations for the learnpath itself. - */ - public function autosave() - { - if ($this->debug > 0) { - error_log('New LP - In learnpath::autosave()', 0); - } - } - /** * Closes the current resource. * @@ -1024,7 +1019,7 @@ class learnpath public function close() { if ($this->debug > 0) { - error_log('New LP - In learnpath::close()', 0); + error_log('In learnpath::close()', 0); } if (empty($this->lp_id)) { $this->error = 'Trying to close this learnpath but no ID is set'; @@ -1043,10 +1038,11 @@ class learnpath * Static admin function allowing removal of a learnpath. * * @param array $courseInfo - * @param int $id Learnpath ID - * @param string $delete Whether to delete data or keep it (default: 'keep', others: 'remove') + * @param int $id Learnpath ID + * @param string $delete Whether to delete data or keep it (default: 'keep', others: 'remove') * * @return bool True on success, false on failure (might change that to return number of elements deleted) + * @throws \Doctrine\DBAL\DBALException */ public function delete($courseInfo = null, $id = null, $delete = 'keep') { @@ -1102,7 +1098,7 @@ class learnpath if (Database::num_rows($res) > 0) { // Another learning path uses this directory, so don't delete it. if ($this->debug > 2) { - error_log('New LP - In learnpath::delete(), found other LP using path '.$path.', keeping directory', 0); + error_log('In learnpath::delete(), found other LP using path '.$path.', keeping directory', 0); } } else { // No other LP uses that directory, delete it. @@ -1110,7 +1106,7 @@ class learnpath $course_scorm_dir = api_get_path(SYS_COURSE_PATH).$course_rel_dir; // The absolute system path for this course. if ($delete == 'remove' && is_dir($course_scorm_dir.$path) && !empty($course_scorm_dir)) { if ($this->debug > 2) { - error_log('New LP - In learnpath::delete(), found SCORM, deleting directory: '.$course_scorm_dir.$path, 0); + error_log('In learnpath::delete(), found SCORM, deleting directory: '.$course_scorm_dir.$path, 0); } // Proposed by Christophe (clefevre). if (strcmp(substr($path, -2), "/.") == 0) { @@ -1167,12 +1163,13 @@ class learnpath * @param int $id Element ID of which children have to be removed * * @return int Total number of children removed + * @throws \Doctrine\DBAL\DBALException */ public function delete_children_items($id) { $course_id = $this->course_info['real_id']; if ($this->debug > 0) { - error_log('New LP - In learnpath::delete_children_items('.$id.')', 0); + error_log('In learnpath::delete_children_items('.$id.')', 0); } $num = 0; if (empty($id) || $id != strval(intval($id))) { @@ -1196,19 +1193,20 @@ class learnpath /** * Removes an item from the current learnpath. * - * @param int $id Elem ID (0 if first) - * @param int $remove Whether to remove the resource/data from the - * system or leave it (default: 'keep', others 'remove') + * @param int $id Elem ID (0 if first) + * @param string $remove Whether to remove the resource/data from the system + * or leave it (default: 'keep', others 'remove') * * @return int Number of elements moved * + * @throws \Doctrine\DBAL\DBALException * @todo implement resource removal */ public function delete_item($id, $remove = 'keep') { $course_id = api_get_course_int_id(); if ($this->debug > 0) { - error_log('New LP - In learnpath::delete_item()', 0); + error_log('In learnpath::delete_item()', 0); } // TODO: Implement the resource removal. if (empty($id) || $id != strval(intval($id))) { @@ -1230,12 +1228,12 @@ class learnpath // Delete children items. $num = $this->delete_children_items($id); if ($this->debug > 2) { - error_log('New LP - learnpath::delete_item() - deleted '.$num.' children of element '.$id, 0); + error_log('learnpath::delete_item() - deleted '.$num.' children of element '.$id, 0); } // Now delete the item. $sql_del = "DELETE FROM $lp_item WHERE iid = $id"; if ($this->debug > 2) { - error_log('New LP - Deleting item: '.$sql_del, 0); + error_log('Deleting item: '.$sql_del, 0); } Database::query($sql_del); // Now update surrounding items. @@ -1283,17 +1281,18 @@ class learnpath /** * Updates an item's content in place. * - * @param int $id Element ID - * @param int $parent Parent item ID - * @param int $previous Previous item ID - * @param string $title Item title - * @param string $description Item description - * @param string $prerequisites Prerequisites (optional) - * @param array $audio The array resulting of the $_FILES[mp3] element + * @param int $id Element ID + * @param int $parent Parent item ID + * @param int $previous Previous item ID + * @param string $title Item title + * @param string $description Item description + * @param string $prerequisites Prerequisites (optional) + * @param array $audio The array resulting of the $_FILES[mp3] element * @param int $max_time_allowed * @param string $url * * @return bool True on success, false on error + * @throws \Doctrine\DBAL\DBALException */ public function edit_item( $id, @@ -1310,7 +1309,7 @@ class learnpath $_course = api_get_course_info(); if ($this->debug > 0) { - error_log('New LP - In learnpath::edit_item()', 0); + error_log('In learnpath::edit_item()', 0); } if (empty($max_time_allowed)) { $max_time_allowed = 0; @@ -1538,12 +1537,13 @@ class learnpath /** * Updates an item's prereq in place. * - * @param int $id Element ID + * @param int $id Element ID * @param string $prerequisite_id Prerequisite Element ID - * @param int $mastery_score Prerequisite min score - * @param int $max_score Prerequisite max score + * @param int $mastery_score Prerequisite min score + * @param int $max_score Prerequisite max score * * @return bool True on success, false on error + * @throws \Doctrine\DBAL\DBALException */ public function edit_item_prereq( $id, @@ -1553,7 +1553,7 @@ class learnpath ) { $course_id = api_get_course_int_id(); if ($this->debug > 0) { - error_log('New LP - In learnpath::edit_item_prereq('.$id.','.$prerequisite_id.','.$mastery_score.','.$max_score.')', 0); + error_log('In learnpath::edit_item_prereq('.$id.','.$prerequisite_id.','.$mastery_score.','.$max_score.')', 0); } if (empty($id) || ($id != strval(intval($id))) || empty($prerequisite_id)) { @@ -1600,12 +1600,13 @@ class learnpath * @param int $id Item ID * * @return array A list of all the "brother items" (or an empty array on failure) + * @throws \Doctrine\DBAL\DBALException */ public function getSiblingDirectories($id) { $course_id = api_get_course_int_id(); if ($this->debug > 0) { - error_log('New LP - In learnpath::getSiblingDirectories()', 0); + error_log('In learnpath::getSiblingDirectories()', 0); } if (empty($id) || $id != strval(intval($id))) { @@ -1645,12 +1646,13 @@ class learnpath * @param int $id Item ID * * @return array A list of all the "brother items" (or an empty array on failure) + * @throws \Doctrine\DBAL\DBALException */ public function get_brother_items($id) { $course_id = api_get_course_int_id(); if ($this->debug > 0) { - error_log('New LP - In learnpath::get_brother_items('.$id.')', 0); + error_log('In learnpath::get_brother_items('.$id.')', 0); } if (empty($id) || $id != strval(intval($id))) { @@ -1715,7 +1717,7 @@ class learnpath public function get_complete_items_count($failedStatusException = false) { if ($this->debug > 0) { - error_log('New LP - In learnpath::get_complete_items_count()', 0); + error_log('In learnpath::get_complete_items_count()', 0); } $i = 0; $completedStatusList = [ @@ -1750,13 +1752,13 @@ class learnpath { $current = 0; if ($this->debug > 0) { - error_log('New LP - In learnpath::get_current_item_id()', 0); + error_log('In learnpath::get_current_item_id()', 0); } if (!empty($this->current)) { $current = $this->current; } if ($this->debug > 2) { - error_log('New LP - In learnpath::get_current_item_id() - Returning '.$current, 0); + error_log('In learnpath::get_current_item_id() - Returning '.$current, 0); } return $current; @@ -1785,7 +1787,7 @@ class learnpath public function get_total_items_count() { if ($this->debug > 0) { - error_log('New LP - In learnpath::get_total_items_count()', 0); + error_log('In learnpath::get_total_items_count()', 0); } return count($this->items); @@ -1799,7 +1801,7 @@ class learnpath public function getTotalItemsCountWithoutDirs() { if ($this->debug > 0) { - error_log('New LP - In learnpath::getTotalItemsCountWithoutDirs()', 0); + error_log('In learnpath::getTotalItemsCountWithoutDirs()', 0); } $total = 0; $typeListNotToCount = self::getChapterTypes(); @@ -1818,7 +1820,7 @@ class learnpath public function first() { if ($this->debug > 0) { - error_log('New LP - In learnpath::first()', 0); + error_log('In learnpath::first()', 0); error_log('$this->last_item_seen '.$this->last_item_seen); } @@ -1827,12 +1829,6 @@ class learnpath $this->index = 0; } - if ($this->debug > 0) { - if (isset($this->items[$this->last_item_seen])) { - $status = $this->items[$this->last_item_seen]->get_status(); - } - } - if (!empty($this->last_item_seen) && !empty($this->items[$this->last_item_seen]) && $this->items[$this->last_item_seen]->get_type() != 'dir' @@ -1840,7 +1836,7 @@ class learnpath //&& !$this->items[$this->last_item_seen]->is_done() ) { if ($this->debug > 2) { - error_log('New LP - In learnpath::first() - Last item seen is '.$this->last_item_seen.' of type '.$this->items[$this->last_item_seen]->get_type(), 0); + error_log('In learnpath::first() - Last item seen is '.$this->last_item_seen.' of type '.$this->items[$this->last_item_seen]->get_type(), 0); } $index = -1; foreach ($this->ordered_items as $myindex => $item_id) { @@ -1852,7 +1848,7 @@ class learnpath if ($index == -1) { // Index hasn't changed, so item not found - panic (this shouldn't happen). if ($this->debug > 2) { - error_log('New LP - Last item ('.$this->last_item_seen.') was found in items but not in ordered_items, panic!', 0); + error_log('Last item ('.$this->last_item_seen.') was found in items but not in ordered_items, panic!', 0); } return false; @@ -1863,7 +1859,7 @@ class learnpath } } else { if ($this->debug > 2) { - error_log('New LP - In learnpath::first() - No last item seen', 0); + error_log('In learnpath::first() - No last item seen', 0); } $index = 0; // Loop through all ordered items and stop at the first item that is @@ -1876,17 +1872,19 @@ class learnpath ) && $index < $this->max_ordered_items) { $index++; } + $this->last = $this->current; // current is $this->current = isset($this->ordered_items[$index]) ? $this->ordered_items[$index] : null; $this->index = $index; if ($this->debug > 2) { error_log('$index '.$index); - error_log('New LP - In learnpath::first() - No last item seen. New last = '.$this->last.'('.$this->ordered_items[$index].')', 0); + error_log('In learnpath::first() - No last item seen'); + error_log('New last = '.$this->last.'('.$this->ordered_items[$index].')'); } } if ($this->debug > 2) { - error_log('New LP - In learnpath::first() - First item is '.$this->get_current_item_id()); + error_log('In learnpath::first() - First item is '.$this->get_current_item_id()); } } @@ -1901,7 +1899,7 @@ class learnpath public function get_js_info($item_id = 0) { if ($this->debug > 0) { - error_log('New LP - In learnpath::get_js_info('.$item_id.')', 0); + error_log('In learnpath::get_js_info('.$item_id.')', 0); } $info = ''; @@ -1921,7 +1919,7 @@ class learnpath $info .= "top.set_flag_synchronized();"; $info .= ''; if ($this->debug > 2) { - error_log('New LP - in learnpath::get_js_info('.$item_id.') - returning: '.$info, 0); + error_log('in learnpath::get_js_info('.$item_id.') - returning: '.$info, 0); } return $info; @@ -1938,7 +1936,7 @@ class learnpath $info .= "top.set_flag_synchronized();"; $info .= ''; if ($this->debug > 2) { - error_log('New LP - in learnpath::get_js_info('.$item_id.') - returning: '.$info, 0); + error_log('in learnpath::get_js_info('.$item_id.') - returning: '.$info, 0); } return $info; @@ -1982,7 +1980,7 @@ class learnpath public function get_last() { if ($this->debug > 0) { - error_log('New LP - In learnpath::get_last()', 0); + error_log('In learnpath::get_last()', 0); } //This is just in case the lesson doesn't cointain a valid scheme, just to avoid "Notices" if (count($this->ordered_items) > 0) { @@ -2002,13 +2000,11 @@ class learnpath public function get_navigation_bar($idBar = null, $display = null) { if ($this->debug > 0) { - error_log('New LP - In learnpath::get_navigation_bar()', 0); + error_log('In learnpath::get_navigation_bar()', 0); } if (empty($idBar)) { $idBar = 'control-top'; } - - $navbar = ''; $lpId = $this->lp_id; $mycurrentitemid = $this->get_current_item_id(); @@ -2078,13 +2074,13 @@ class learnpath public function get_next_index() { if ($this->debug > 0) { - error_log('New LP - In learnpath::get_next_index()', 0); + error_log('In learnpath::get_next_index()', 0); } // TODO $index = $this->index; $index++; if ($this->debug > 2) { - error_log('New LP - Now looking at ordered_items['.($index).'] - type is '.$this->items[$this->ordered_items[$index]]->type, 0); + error_log('Now looking at ordered_items['.($index).'] - type is '.$this->items[$this->ordered_items[$index]]->type, 0); } while ( !empty($this->ordered_items[$index]) && ($this->items[$this->ordered_items[$index]]->get_type() == 'dir') && @@ -2103,7 +2099,7 @@ class learnpath return $this->index; } if ($this->debug > 2) { - error_log('New LP - index is now '.$index, 0); + error_log('index is now '.$index, 0); } return $index; @@ -2117,20 +2113,20 @@ class learnpath public function get_next_item_id() { if ($this->debug > 0) { - error_log('New LP - In learnpath::get_next_item_id()', 0); + error_log('In learnpath::get_next_item_id()', 0); } $new_index = $this->get_next_index(); if (!empty($new_index)) { if (isset($this->ordered_items[$new_index])) { if ($this->debug > 2) { - error_log('New LP - In learnpath::get_next_index() - Returning '.$this->ordered_items[$new_index], 0); + error_log('In learnpath::get_next_index() - Returning '.$this->ordered_items[$new_index], 0); } return $this->ordered_items[$new_index]; } } if ($this->debug > 2) { - error_log('New LP - In learnpath::get_next_index() - Problem - Returning 0', 0); + error_log('In learnpath::get_next_index() - Problem - Returning 0', 0); } return 0; @@ -2233,7 +2229,7 @@ class learnpath public function get_previous_index() { if ($this->debug > 0) { - error_log('New LP - In learnpath::get_previous_index()', 0); + error_log('In learnpath::get_previous_index()', 0); } $index = $this->index; if (isset($this->ordered_items[$index - 1])) { @@ -2248,7 +2244,7 @@ class learnpath } } else { if ($this->debug > 2) { - error_log('New LP - get_previous_index() - there was no previous index available, reusing '.$index, 0); + error_log('get_previous_index() - there was no previous index available, reusing '.$index, 0); } // There is no previous item. } @@ -2264,32 +2260,13 @@ class learnpath public function get_previous_item_id() { if ($this->debug > 0) { - error_log('New LP - In learnpath::get_previous_item_id()', 0); + error_log('In learnpath::get_previous_item_id()', 0); } $new_index = $this->get_previous_index(); return $this->ordered_items[$new_index]; } - /** - * Gets the progress value from the progress_db attribute. - * - * @return int Current progress value - * - * @deprecated This method does not seem to be used as of 20170514 - */ - public function get_progress() - { - if ($this->debug > 0) { - error_log('New LP - In learnpath::get_progress()', 0); - } - if (!empty($this->progress_db)) { - return $this->progress_db; - } - - return 0; - } - /** * Returns the HTML necessary to print a mediaplayer block inside a page. * @@ -2297,6 +2274,7 @@ class learnpath * @param string $autostart * * @return string The mediaplayer HTML + * @throws \Doctrine\DBAL\DBALException */ public function get_mediaplayer($lpItemId, $autostart = 'true') { @@ -2307,6 +2285,7 @@ class learnpath } $tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM); $tbl_lp_item_view = Database::get_course_table(TABLE_LP_ITEM_VIEW); + $lpItemId = (int) $lpItemId; // Getting all the information about the item. $sql = "SELECT * FROM $tbl_lp_item as lpi @@ -2413,12 +2392,13 @@ class learnpath * of its prerequisite is completed, considering the time availability and * the LP visibility. * - * @param int $lp_id - * @param int $student_id - * @param string Course code (optional) - * @param int $sessionId + * @param int $lp_id + * @param int $student_id + * @param null $courseCode + * @param int $sessionId * * @return bool + * @throws \Doctrine\DBAL\DBALException */ public static function is_lp_visible_for_student( $lp_id, @@ -2552,6 +2532,7 @@ class learnpath * @param int $sessionId * * @return int + * @throws \Doctrine\DBAL\DBALException */ public static function getProgress($lpId, $userId, $courseId, $sessionId = 0) { @@ -2626,23 +2607,23 @@ class learnpath public function get_progress_bar_text($mode = '', $add = 0) { if ($this->debug > 0) { - error_log('New LP - In learnpath::get_progress_bar_text()', 0); + error_log('In learnpath::get_progress_bar_text()', 0); } if (empty($mode)) { $mode = $this->progress_bar_mode; } $total_items = $this->getTotalItemsCountWithoutDirs(); if ($this->debug > 2) { - error_log('New LP - Total items available in this learnpath: '.$total_items, 0); + error_log('Total items available in this learnpath: '.$total_items, 0); } $completeItems = $this->get_complete_items_count(); if ($this->debug > 2) { - error_log('New LP - Items completed so far: '.$completeItems, 0); + error_log('Items completed so far: '.$completeItems, 0); } if ($add != 0) { $completeItems += $add; if ($this->debug > 2) { - error_log('New LP - Items completed so far (+modifier): '.$completeItems, 0); + error_log('Items completed so far (+modifier): '.$completeItems, 0); } } $text = ''; @@ -2677,7 +2658,7 @@ class learnpath public function get_progress_bar_mode() { if ($this->debug > 0) { - error_log('New LP - In learnpath::get_progress_bar_mode()', 0); + error_log('In learnpath::get_progress_bar_mode()', 0); } if (!empty($this->progress_bar_mode)) { return $this->progress_bar_mode; @@ -2686,23 +2667,6 @@ class learnpath } } - /** - * Gets the learnpath proximity (remote or local). - * - * @return string Learnpath proximity - */ - public function get_proximity() - { - if ($this->debug > 0) { - error_log('New LP - In learnpath::get_proximity()', 0); - } - if (!empty($this->proximity)) { - return $this->proximity; - } else { - return ''; - } - } - /** * Gets the learnpath theme (remote or local). * @@ -2711,7 +2675,7 @@ class learnpath public function get_theme() { if ($this->debug > 0) { - error_log('New LP - In learnpath::get_theme()', 0); + error_log('In learnpath::get_theme()', 0); } if (!empty($this->theme)) { return $this->theme; @@ -2728,7 +2692,7 @@ class learnpath public function get_lp_session_id() { if ($this->debug > 0) { - error_log('New LP - In learnpath::get_lp_session_id()', 0); + error_log('In learnpath::get_lp_session_id()', 0); } if (!empty($this->lp_session_id)) { return (int) $this->lp_session_id; @@ -2745,7 +2709,7 @@ class learnpath public function get_preview_image() { if ($this->debug > 0) { - error_log('New LP - In learnpath::get_preview_image()', 0); + error_log('In learnpath::get_preview_image()', 0); } if (!empty($this->preview_image)) { return $this->preview_image; @@ -2798,7 +2762,7 @@ class learnpath public function get_author() { if ($this->debug > 0) { - error_log('New LP - In learnpath::get_author()', 0); + error_log('In learnpath::get_author()', 0); } if (!empty($this->author)) { return $this->author; @@ -2824,14 +2788,14 @@ class learnpath * Prefix all item IDs that end-up in the prerequisites string by "ITEM_" to use the * same rule as the scorm_export() method. * - * @param int Item ID + * @param int Item ID * * @return string Prerequisites string ready for the export as SCORM */ public function get_scorm_prereq_string($item_id) { if ($this->debug > 0) { - error_log('New LP - In learnpath::get_scorm_prereq_string()'); + error_log('In learnpath::get_scorm_prereq_string()'); } if (!is_object($this->items[$item_id])) { return false; @@ -2905,8 +2869,8 @@ class learnpath /** * Returns the XML DOM document's node. * - * @param resource Reference to a list of objects to search for the given ITEM_* - * @param string The identifier to look for + * @param resource Reference to a list of objects to search for the given ITEM_* + * @param string The identifier to look for * * @return mixed The reference to the element found with that identifier. False if not found */ @@ -2939,7 +2903,7 @@ class learnpath public function get_items_status_list() { if ($this->debug > 0) { - error_log('New LP - In learnpath::get_items_status_list()', 0); + error_log('In learnpath::get_items_status_list()', 0); } $list = []; foreach ($this->ordered_items as $item_id) { @@ -2955,10 +2919,11 @@ class learnpath * Return the number of interactions for the given learnpath Item View ID. * This method can be used as static. * - * @param int Item View ID - * @param int course id + * @param int $lp_iv_id Item View ID + * @param int $course_id course id * - * @return int Number of interactions + * @return int + * @throws \Doctrine\DBAL\DBALException */ public static function get_interactions_count_from_db($lp_iv_id, $course_id) { @@ -2982,11 +2947,12 @@ class learnpath * Return the interactions as an array for the given lp_iv_id. * This method can be used as static. * - * @param int Learnpath Item View ID + * @param int Learnpath Item View ID * * @return array * - * @todo Transcode labels instead of switching to HTML (which requires to know the encoding of the LP) + * @throws \Doctrine\DBAL\DBALException + * @todo Transcode labels instead of switching to HTML (which requires to know the encoding of the LP) */ public static function get_iv_interactions_array($lp_iv_id) { @@ -3036,9 +3002,10 @@ class learnpath * Return the number of objectives for the given learnpath Item View ID. * This method can be used as static. * - * @param int Item View ID + * @param int Item View ID * * @return int Number of objectives + * @throws \Doctrine\DBAL\DBALException */ public static function get_objectives_count_from_db($lp_iv_id, $course_id) { @@ -3062,18 +3029,21 @@ class learnpath * Return the objectives as an array for the given lp_iv_id. * This method can be used as static. * - * @param int Learnpath Item View ID + * @param int $lpItemViewId Learnpath Item View ID * * @return array * - * @todo Translate labels + * @throws \Doctrine\DBAL\DBALException + * @todo Translate labels */ - public static function get_iv_objectives_array($lp_iv_id = 0) + public static function get_iv_objectives_array($lpItemViewId = 0) { $course_id = api_get_course_int_id(); + $lpItemViewId = (int) $lpItemViewId; + $table = Database::get_course_table(TABLE_LP_IV_OBJECTIVE); $sql = "SELECT * FROM $table - WHERE c_id = $course_id AND lp_iv_id = $lp_iv_id + WHERE c_id = $course_id AND lp_iv_id = $lpItemViewId ORDER BY order_id ASC"; $res = Database::query($sql); $num = Database::num_rows($res); @@ -3131,7 +3101,7 @@ class learnpath ]; } if ($this->debug > 2) { - error_log('New LP - In learnpath::get_toc() - TOC array: '.print_r($toc, true), 0); + error_log('In learnpath::get_toc() - TOC array: '.print_r($toc, true), 0); } return $toc; @@ -3143,19 +3113,19 @@ class learnpath * * @param string $varname * - * @return string A JS array vairiable construction + * @return string A JS array variable construction */ public function get_items_details_as_js($varname = 'olms.lms_item_types') { if ($this->debug > 0) { - error_log('New LP - In learnpath::get_items_details_as_js()', 0); + error_log('In learnpath::get_items_details_as_js()', 0); } $toc = $varname.' = new Array();'; foreach ($this->ordered_items as $item_id) { $toc .= $varname."['i$item_id'] = '".$this->items[$item_id]->get_type()."';"; } if ($this->debug > 2) { - error_log('New LP - In learnpath::get_items_details_as_js() - TOC array: '.print_r($toc, true), 0); + error_log('In learnpath::get_items_details_as_js() - TOC array: '.print_r($toc, true), 0); } return $toc; @@ -3172,13 +3142,13 @@ class learnpath { $res = false; if ($this->debug > 0) { - error_log('New LP - In learnpath::get_type()', 0); + error_log('In learnpath::get_type()', 0); } if (!empty($this->type) && (!$get_name)) { $res = $this->type; } if ($this->debug > 2) { - error_log('New LP - In learnpath::get_type() - Returning '.($res ? $res : 'false'), 0); + error_log('In learnpath::get_type() - Returning '.($res ? $res : 'false'), 0); } return $res; @@ -3190,6 +3160,7 @@ class learnpath * @param int $lp_id * * @return mixed Type ID or name, depending on the parameter + * @throws \Doctrine\DBAL\DBALException */ public static function get_type_static($lp_id = 0) { @@ -3213,12 +3184,14 @@ class learnpath * Gets a flat list of item IDs ordered for display (level by level ordered by order_display) * This method can be used as abstract and is recursive. * - * @param int Learnpath ID - * @param int Parent ID of the items to look for + * @param int $lp Learnpath ID + * @param int $parent Parent ID of the items to look for + * @param int $course_id * * @return array Ordered list of item IDs (empty array on error) + * @throws \Doctrine\DBAL\DBALException */ - public static function get_flat_ordered_items_list($lp, $parent = 0, $course_id = 0) + public static function get_flat_ordered_items_list($lp = 1, $parent = 0, $course_id = 0) { if (empty($course_id)) { $course_id = api_get_course_int_id(); @@ -3268,7 +3241,10 @@ class learnpath /** * Uses the table generated by get_toc() and returns an HTML-formattedstring ready to display. * - * @return string HTML TOC ready to display + * @param $tree + * + * @return array HTML TOC ready to display + * @throws \Doctrine\DBAL\DBALException */ public function getParentToc($tree) { @@ -3342,7 +3318,12 @@ class learnpath /** * Uses the table generated by get_toc() and returns an HTML-formattedstring ready to display. * - * @return string HTML TOC ready to display + * @param $tree + * @param $id + * @param bool $parent + * + * @return array HTML TOC ready to display + * @throws \Doctrine\DBAL\DBALException */ public function getChildrenToc($tree, $id, $parent = true) { @@ -3412,7 +3393,8 @@ class learnpath * * @param array $toc_list * - * @return string HTML TOC ready to display + * @return array HTML TOC ready to display + * @throws \Doctrine\DBAL\DBALException */ public function getListArrayToc($toc_list = []) { @@ -3503,10 +3485,10 @@ class learnpath */ public function get_teacher_toc_buttons() { - $is_allowed_to_edit = api_is_allowed_to_edit(null, true, false, false); - $hide_teacher_icons_lp = api_get_configuration_value('hide_teacher_icons_lp'); + $isAllow = api_is_allowed_to_edit(null, true, false, false); + $hideIcons = api_get_configuration_value('hide_teacher_icons_lp'); $html = ''; - if ($is_allowed_to_edit && $hide_teacher_icons_lp == false) { + if ($isAllow && $hideIcons == false) { if ($this->get_lp_session_id() == api_get_session_id()) { $html .= '