diff --git a/public/main/inc/lib/display.lib.php b/public/main/inc/lib/display.lib.php index fddd29160e..503a5d66df 100644 --- a/public/main/inc/lib/display.lib.php +++ b/public/main/inc/lib/display.lib.php @@ -127,10 +127,12 @@ class Display $url .= '?sid='.$sessionId; } - array_unshift( - $interbreadcrumb, - ['name' => $courseInfo['title'], 'url' => $url] - ); + if (!empty($interbreadcrumb)) { + array_unshift( + $interbreadcrumb, + ['name' => $courseInfo['title'], 'url' => $url] + ); + } } $params['legacy_javascript'] = $htmlHeadXtra; diff --git a/public/main/lp/LearnPathItemForm.php b/public/main/lp/LearnPathItemForm.php index 11c2baa712..0768e7326d 100644 --- a/public/main/lp/LearnPathItemForm.php +++ b/public/main/lp/LearnPathItemForm.php @@ -14,8 +14,8 @@ class LearnPathItemForm public static function setForm(FormValidator $form, $action, learnpath $lp, CLpItem $lpItem) { $arrLP = $lp->getItemsForForm(); - $lp->tree_array($arrLP); - $arrLP = $lp->arrMenu ?? []; + //$lp->tree_array($arrLP); + //$arrLP = $lp->arrMenu ?? []; switch ($action) { case 'add': @@ -60,7 +60,7 @@ class LearnPathItemForm $parentSelect->addOption($lp->name, $itemRoot->getIid()); /** @var CLpItem[] $sections */ $sections = $lpItemRepo->findBy(['itemType' => 'dir', 'lp' => $lp->get_id()]); - foreach ($sections as $key => $value) { + foreach ($sections as $value) { $parentSelect->addOption( str_repeat(' ', $value->getLvl()).Security::remove_XSS($value->getTitle()), $value->getIid() @@ -75,7 +75,7 @@ class LearnPathItemForm $arrHide = []; // Position - for ($i = 0; $i < $count; $i++) { + /*for ($i = 0; $i < $count; $i++) { if (($arrLP[$i]['parent_item_id'] == $parentItemId && $arrLP[$i]['id'] != $itemId) || TOOL_LP_FINAL_ITEM == $arrLP[$i]['item_type'] ) { @@ -105,11 +105,11 @@ class LearnPathItemForm if (is_array($arrLP)) { reset($arrLP); - } + }*/ if (TOOL_LP_FINAL_ITEM == $itemType) { $parentSelect->freeze(); - $position->freeze(); + //$position->freeze(); } // Content. diff --git a/public/main/lp/learnpath.class.php b/public/main/lp/learnpath.class.php index 9175b747f5..91cc117174 100644 --- a/public/main/lp/learnpath.class.php +++ b/public/main/lp/learnpath.class.php @@ -371,14 +371,6 @@ class learnpath } } - /** - * @return string - */ - public function getCourseCode() - { - return $this->cc; - } - /** * @return int */ @@ -3701,20 +3693,6 @@ class learnpath } return true; - - /*$action = 'visible'; - if (1 != $set_visibility) { - $action = 'invisible'; - self::toggle_publish($lp_id, 'i'); - } - - return api_item_property_update( - api_get_course_info(), - TOOL_LEARNPATH, - $lp_id, - $action, - api_get_user_id() - );*/ } /** @@ -3745,20 +3723,6 @@ class learnpath } return false; - /* - $action = 'visible'; - if (1 != $visibility) { - self::toggleCategoryPublish($id, 0); - $action = 'invisible'; - } - - return api_item_property_update( - api_get_course_info(), - TOOL_LEARNPATH_CATEGORY, - $id, - $action, - api_get_user_id() - );*/ } /** @@ -3792,88 +3756,6 @@ class learnpath } return true; - - /* - $course_id = api_get_course_int_id(); - $tbl_lp = Database::get_course_table(TABLE_LP_MAIN); - $lp_id = (int) $lp_id; - $sql = "SELECT * FROM $tbl_lp - WHERE iid = $lp_id"; - $result = Database::query($sql); - - if (Database::num_rows($result)) { - $row = Database::fetch_array($result); - $name = Database::escape_string($row['name']); - if ($set_visibility == 'i') { - $v = 0; - } - if ($set_visibility == 'v') { - $v = 1; - } - - $session_id = api_get_session_id(); - $session_condition = api_get_session_condition($session_id); - - $tbl_tool = Database::get_course_table(TABLE_TOOL_LIST); - $link = 'lp/lp_controller.php?action=view&lp_id='.$lp_id.'&id_session='.$session_id; - $oldLink = 'newscorm/lp_controller.php?action=view&lp_id='.$lp_id.'&id_session='.$session_id; - - $sql = "SELECT * FROM $tbl_tool - WHERE - c_id = $course_id AND - (link = '$link' OR link = '$oldLink') AND - image = 'scormbuilder.gif' AND - ( - link LIKE '$link%' OR - link LIKE '$oldLink%' - ) - $session_condition - "; - - $result = Database::query($sql); - $num = Database::num_rows($result); - if ($set_visibility == 'i' && $num > 0) { - $sql = "DELETE FROM $tbl_tool - WHERE - c_id = $course_id AND - (link = '$link' OR link = '$oldLink') AND - image='scormbuilder.gif' - $session_condition"; - Database::query($sql); - } elseif ($set_visibility == 'v' && $num == 0) { - $sql = "INSERT INTO $tbl_tool (category, c_id, name, link, image, visibility, admin, address, added_tool, session_id) VALUES - ('authoring', $course_id, '$name', '$link', 'scormbuilder.gif', '$v', '0','pastillegris.gif', 0, $session_id)"; - Database::query($sql); - $insertId = Database::insert_id(); - if ($insertId) { - $sql = "UPDATE $tbl_tool SET id = iid WHERE iid = $insertId"; - Database::query($sql); - } - } elseif ($set_visibility == 'v' && $num > 0) { - $sql = "UPDATE $tbl_tool SET - c_id = $course_id, - name = '$name', - link = '$link', - image = 'scormbuilder.gif', - visibility = '$v', - admin = '0', - address = 'pastillegris.gif', - added_tool = 0, - session_id = $session_id - WHERE - c_id = ".$course_id." AND - (link = '$link' OR link = '$oldLink') AND - image='scormbuilder.gif' - $session_condition - "; - Database::query($sql); - } else { - // Parameter and database incompatible, do nothing, exit. - return false; - } - } else { - return false; - }*/ } /** @@ -3928,16 +3810,8 @@ class learnpath return true; } - $repo = Container::getLpCategoryRepository(); $categoryVisibility = $category->isVisible($course, $session); - /*$categoryVisibility = api_get_item_visibility( - $courseInfo, - TOOL_LEARNPATH_CATEGORY, - $category->getId(), - $sessionId - );*/ - if (1 !== $categoryVisibility && -1 != $categoryVisibility) { return false; } @@ -4308,31 +4182,6 @@ class learnpath } } - /** - * Sets the JS lib setting in the database directly. - * This is the JavaScript library file this lp needs to load on startup. - * - * @param string $lib Proximity setting - * - * @return bool True on update success. False otherwise. - */ - public function set_jslib($lib = '') - { - $lp = $this->get_id(); - - if (0 != $lp) { - $tbl_lp = Database::get_course_table(TABLE_LP_MAIN); - $lib = Database::escape_string($lib); - $sql = "UPDATE $tbl_lp SET js_lib = '$lib' - WHERE iid = $lp"; - $res = Database::query($sql); - - return $res; - } - - return false; - } - /** * Set index specified prefix terms for all items in this path. * @@ -4424,27 +4273,6 @@ class learnpath $this->last = $id; } - /** - * Sets use_max_score. - * - * @param int $use_max_score Optional string giving the new location of this learnpath - * - * @return bool True on success / False on error - */ - public function set_use_max_score($use_max_score = 1) - { - $use_max_score = (int) $use_max_score; - $this->use_max_score = $use_max_score; - $table = Database::get_course_table(TABLE_LP_MAIN); - $lp_id = $this->get_id(); - $sql = "UPDATE $table SET - use_max_score = '".$this->use_max_score."' - WHERE iid = $lp_id"; - Database::query($sql); - - return true; - } - /** * Sets and saves the expired_on date. * @@ -5025,475 +4853,6 @@ class learnpath return $return; } - /** - * @param string $update_audio - * - * @return array - */ - public function processBuildMenuElements($update_audio = 'false') - { - $is_allowed_to_edit = api_is_allowed_to_edit(null, true); - $arrLP = $this->getItemsForForm(); - - $this->tree_array($arrLP); - $arrLP = $this->arrMenu ?? []; - $default_data = null; - $default_content = null; - $elements = []; - $return_audio = null; - $iconPath = api_get_path(SYS_PUBLIC_PATH).'img/'; - $mainUrl = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?'.api_get_cidreq(); - $countItems = count($arrLP); - - $upIcon = Display::return_icon( - 'up.png', - get_lang('Up'), - [], - ICON_SIZE_TINY - ); - - $disableUpIcon = Display::return_icon( - 'up_na.png', - get_lang('Up'), - [], - ICON_SIZE_TINY - ); - - $downIcon = Display::return_icon( - 'down.png', - get_lang('Down'), - [], - ICON_SIZE_TINY - ); - - $disableDownIcon = Display::return_icon( - 'down_na.png', - get_lang('Down'), - [], - ICON_SIZE_TINY - ); - - $show = api_get_configuration_value('show_full_lp_item_title_in_edition'); - - $pluginCalendar = 'true' === api_get_plugin_setting('learning_calendar', 'enabled'); - $plugin = null; - if ($pluginCalendar) { - $plugin = LearningCalendarPlugin::create(); - } - - for ($i = 0; $i < $countItems; $i++) { - $parent_id = $arrLP[$i]['parent_item_id']; - $title = $arrLP[$i]['title']; - $title_cut = $arrLP[$i]['title_raw']; - if (false === $show) { - $title_cut = cut($arrLP[$i]['title'], self::MAX_LP_ITEM_TITLE_LENGTH); - } - // Link for the documents - if ('document' === $arrLP[$i]['item_type'] || TOOL_READOUT_TEXT === $arrLP[$i]['item_type']) { - $url = $mainUrl.'&action=view_item&mode=preview_document&id='.$arrLP[$i]['id'].'&lp_id='.$this->lp_id; - $title_cut = Display::url( - $title_cut, - $url, - [ - 'class' => 'ajax moved', - 'data-title' => $title, - 'title' => $title, - ] - ); - } - - // Detect if type is FINAL_ITEM to set path_id to SESSION - if (TOOL_LP_FINAL_ITEM === $arrLP[$i]['item_type']) { - Session::write('pathItem', $arrLP[$i]['path']); - } - - $oddClass = 'row_even'; - if (0 == ($i % 2)) { - $oddClass = 'row_odd'; - } - $return_audio .= ''; - $icon_name = str_replace(' ', '', $arrLP[$i]['item_type']); - - if (file_exists($iconPath.'lp_'.$icon_name.'.png')) { - $icon = Display::return_icon('lp_'.$icon_name.'.png'); - } else { - if (file_exists($iconPath.'lp_'.$icon_name.'.gif')) { - $icon = Display::return_icon('lp_'.$icon_name.'.gif'); - } else { - if (TOOL_LP_FINAL_ITEM === $arrLP[$i]['item_type']) { - $icon = Display::return_icon('certificate.png'); - } else { - $icon = Display::return_icon('folder_document.png'); - } - } - } - - // The audio column. - $return_audio .= ''; - $audio = ''; - if (!$update_audio || 'true' != $update_audio) { - if (empty($arrLP[$i]['audio'])) { - $audio .= ''; - } - } else { - $types = self::getChapterTypes(); - if (!in_array($arrLP[$i]['item_type'], $types)) { - $audio .= ''; - if (!empty($arrLP[$i]['audio'])) { - $audio .= '
'.Security::remove_XSS($arrLP[$i]['audio']).'
- '.get_lang('Remove audio'); - } - } - } - - $return_audio .= Display::span($icon.' '.$title). - Display::tag( - 'td', - $audio, - ['style' => ''] - ); - $return_audio .= ''; - $move_icon = ''; - $move_item_icon = ''; - $edit_icon = ''; - $delete_icon = ''; - $audio_icon = ''; - $prerequisities_icon = ''; - $forumIcon = ''; - $previewIcon = ''; - $pluginCalendarIcon = ''; - $orderIcons = ''; - $pluginUrl = api_get_path(WEB_PLUGIN_PATH).'learning_calendar/start.php?'; - - if ($is_allowed_to_edit) { - if (!$update_audio || 'true' != $update_audio) { - if (TOOL_LP_FINAL_ITEM !== $arrLP[$i]['item_type']) { - $move_icon .= ''; - $move_icon .= Display::return_icon( - 'move_everywhere.png', - get_lang('Move'), - [], - ICON_SIZE_TINY - ); - $move_icon .= ''; - } - } - - // No edit for this item types - if (!in_array($arrLP[$i]['item_type'], ['sco', 'asset', 'final_item'])) { - if ('dir' != $arrLP[$i]['item_type']) { - $edit_icon .= ''; - $edit_icon .= Display::return_icon( - 'edit.png', - get_lang('Edit section description/name'), - [], - ICON_SIZE_TINY - ); - $edit_icon .= ''; - - if (!in_array($arrLP[$i]['item_type'], ['forum', 'thread'])) { - $forumThread = null; - if (isset($this->items[$arrLP[$i]['id']])) { - $forumThread = $this->items[$arrLP[$i]['id']]->getForumThread( - $this->course_int_id, - $this->lp_session_id - ); - } - if ($forumThread) { - $forumIconUrl = $mainUrl.'&'.http_build_query([ - 'action' => 'dissociate_forum', - 'id' => $arrLP[$i]['id'], - 'lp_id' => $this->lp_id, - ]); - $forumIcon = Display::url( - Display::return_icon( - 'forum.png', - get_lang('Dissociate the forum of this learning path item'), - [], - ICON_SIZE_TINY - ), - $forumIconUrl, - ['class' => 'btn btn-default lp-btn-dissociate-forum'] - ); - } else { - $forumIconUrl = $mainUrl.'&'.http_build_query([ - 'action' => 'create_forum', - 'id' => $arrLP[$i]['id'], - 'lp_id' => $this->lp_id, - ]); - $forumIcon = Display::url( - Display::return_icon( - 'forum.png', - get_lang('Associate a forum to this learning path item'), - [], - ICON_SIZE_TINY - ), - $forumIconUrl, - ['class' => 'btn btn-default lp-btn-associate-forum'] - ); - } - } - } else { - $edit_icon .= ''; - $edit_icon .= Display::return_icon( - 'edit.png', - get_lang('Edit section description/name'), - [], - ICON_SIZE_TINY - ); - $edit_icon .= ''; - } - } else { - if (TOOL_LP_FINAL_ITEM == $arrLP[$i]['item_type']) { - $edit_icon .= ''; - $edit_icon .= Display::return_icon( - 'edit.png', - get_lang('Edit'), - [], - ICON_SIZE_TINY - ); - $edit_icon .= ''; - } - } - - if ($pluginCalendar) { - $pluginLink = $pluginUrl. - '&action=toggle_visibility&lp_item_id='.$arrLP[$i]['id'].'&lp_id='.$this->lp_id; - $iconCalendar = Display::return_icon('agenda_na.png', get_lang('1 day'), [], ICON_SIZE_TINY); - $itemInfo = $plugin->getItemVisibility($arrLP[$i]['id']); - if ($itemInfo && 1 == $itemInfo['value']) { - $iconCalendar = Display::return_icon('agenda.png', get_lang('1 day'), [], ICON_SIZE_TINY); - } - $pluginCalendarIcon = Display::url( - $iconCalendar, - $pluginLink, - ['class' => 'btn btn-default'] - ); - } - - if ('final_item' != $arrLP[$i]['item_type']) { - $orderIcons = Display::url( - $upIcon, - 'javascript:void(0)', - ['class' => 'btn btn-default order_items', 'data-dir' => 'up', 'data-id' => $arrLP[$i]['id']] - ); - $orderIcons .= Display::url( - $downIcon, - 'javascript:void(0)', - ['class' => 'btn btn-default order_items', 'data-dir' => 'down', 'data-id' => $arrLP[$i]['id']] - ); - } - $delete_icon .= ' '; - $delete_icon .= Display::return_icon( - 'delete.png', - get_lang('Delete section'), - [], - ICON_SIZE_TINY - ); - $delete_icon .= ''; - - $url = $mainUrl.'&view=build&id='.$arrLP[$i]['id'].'&lp_id='.$this->lp_id; - $previewImage = Display::return_icon( - 'preview_view.png', - get_lang('Preview'), - [], - ICON_SIZE_TINY - ); - - switch ($arrLP[$i]['item_type']) { - case TOOL_DOCUMENT: - case TOOL_LP_FINAL_ITEM: - case TOOL_READOUT_TEXT: - $urlPreviewLink = $mainUrl.'&action=view_item&mode=preview_document&id='.$arrLP[$i]['id'].'&lp_id='.$this->lp_id; - $previewIcon = Display::url( - $previewImage, - $urlPreviewLink, - [ - 'target' => '_blank', - 'class' => 'btn btn-default', - 'data-title' => $arrLP[$i]['title'], - 'title' => $arrLP[$i]['title'], - ] - ); - break; - case TOOL_THREAD: - case TOOL_FORUM: - case TOOL_QUIZ: - case TOOL_STUDENTPUBLICATION: - case TOOL_LINK: - $class = 'btn btn-default'; - $target = '_blank'; - $link = self::rl_get_resource_link_for_learnpath( - $this->course_int_id, - $this->lp_id, - $arrLP[$i]['id'], - 0 - ); - $previewIcon = Display::url( - $previewImage, - $link, - [ - 'class' => $class, - 'data-title' => $arrLP[$i]['title'], - 'title' => $arrLP[$i]['title'], - 'target' => $target, - ] - ); - break; - default: - $previewIcon = Display::url( - $previewImage, - $url.'&action=view_item', - ['class' => 'btn btn-default', 'target' => '_blank'] - ); - break; - } - - if ('dir' != $arrLP[$i]['item_type']) { - $prerequisities_icon = Display::url( - Display::return_icon( - 'accept.png', - get_lang('Prerequisites'), - [], - ICON_SIZE_TINY - ), - $url.'&action=edit_item_prereq', - ['class' => 'btn btn-default'] - ); - if ('final_item' != $arrLP[$i]['item_type']) { - /*$move_item_icon = Display::url( - Display::return_icon( - 'move.png', - get_lang('Move'), - [], - ICON_SIZE_TINY - ), - $url.'&action=move_item', - ['class' => 'btn btn-default'] - );*/ - } - $audio_icon = Display::url( - Display::return_icon( - 'audio.png', - get_lang('Upload'), - [], - ICON_SIZE_TINY - ), - $url.'&action=add_audio', - ['class' => 'btn btn-default'] - ); - } - } - if ('true' != $update_audio) { - $row = $move_icon.' '.$icon. - Display::span($title_cut). - Display::tag( - 'div', - "
- $previewIcon - $audio - $edit_icon - $pluginCalendarIcon - $forumIcon - $prerequisities_icon - $move_item_icon - $audio_icon - $orderIcons - $delete_icon -
", - ['class' => 'btn-toolbar button_actions'] - ); - } else { - $row = - Display::span($title.$icon). - Display::span($audio, ['class' => 'button_actions']); - } - - $default_data[$arrLP[$i]['id']] = $row; - $default_content[$arrLP[$i]['id']] = $arrLP[$i]; - - if (empty($parent_id)) { - $elements[$arrLP[$i]['id']]['data'] = $row; - $elements[$arrLP[$i]['id']]['type'] = $arrLP[$i]['item_type']; - } else { - $parent_arrays = []; - if ($arrLP[$i]['depth'] > 1) { - // Getting list of parents - for ($j = 0; $j < $arrLP[$i]['depth']; $j++) { - foreach ($arrLP as $item) { - if ($item['id'] == $parent_id) { - if (0 == $item['parent_item_id']) { - $parent_id = $item['id']; - break; - } else { - $parent_id = $item['parent_item_id']; - if (empty($parent_arrays)) { - $parent_arrays[] = intval($item['id']); - } - $parent_arrays[] = $parent_id; - break; - } - } - } - } - } - - if (!empty($parent_arrays)) { - $parent_arrays = array_reverse($parent_arrays); - $val = '$elements'; - $x = 0; - foreach ($parent_arrays as $item) { - if ($x != count($parent_arrays) - 1) { - $val .= '["'.$item.'"]["children"]'; - } else { - $val .= '["'.$item.'"]["children"]'; - } - $x++; - } - $val .= ""; - $code_str = $val."[".$arrLP[$i]['id']."][\"load_data\"] = '".$arrLP[$i]['id']."' ; "; - eval($code_str); - } else { - $elements[$parent_id]['children'][$arrLP[$i]['id']]['data'] = $row; - $elements[$parent_id]['children'][$arrLP[$i]['id']]['type'] = $arrLP[$i]['item_type']; - } - } - } - - return [ - 'elements' => $elements, - 'default_data' => $default_data, - 'default_content' => $default_content, - 'return_audio' => $return_audio, - ]; - } - - /** - * @param string $updateAudio true/false strings - * - * @return string - */ - public function returnLpItemList($updateAudio) - { - $result = $this->processBuildMenuElements($updateAudio); - - $html = self::print_recursive( - $result['elements'], - $result['default_data'], - $result['default_content'] - ); - - if (!empty($html)) { - $html .= Display::return_message(get_lang('Drag and drop an element here')); - } - - return $html; - } - public function showBuildSideBar($updateAudio = false, $dropElementHere = false, $type = null) { $sureToDelete = trim(get_lang('Are you sure to delete?')); @@ -7017,10 +6376,6 @@ class learnpath * @param string $title * @param int $parentId * - * @throws \Doctrine\ORM\ORMException - * @throws \Doctrine\ORM\OptimisticLockException - * @throws \Doctrine\ORM\TransactionRequiredException - * * @return int */ public function createReadOutText($courseInfo, $content = '', $title = '', $parentId = 0) @@ -7774,10 +7129,6 @@ class learnpath { $course_id = api_get_course_int_id(); $session_id = api_get_session_id(); - $userInfo = api_get_user_info(); - - $tbl_quiz = Database::get_course_table(TABLE_QUIZ_TEST); - $condition_session = api_get_session_condition($session_id, true, true); $setting = 'true' === api_get_setting('lp.show_invisible_exercise_in_lp_toc'); //$activeCondition = ' active <> -1 '; @@ -7936,25 +7287,6 @@ class learnpath ICON_SIZE_TINY ); - /*$condition_session = api_get_session_condition( - $session_id, - true, - true, - 'link.session_id' - ); - - $sql = "SELECT - link.id as link_id, - link.title as link_title, - link.session_id as link_session_id, - link.category_id as category_id, - link_category.category_title as category_title - FROM $tbl_link as link - LEFT JOIN $linkCategoryTable as link_category - ON (link.category_id = link_category.id AND link.c_id = link_category.c_id) - WHERE link.c_id = $course_id $condition_session - ORDER BY link_category.category_title ASC, link.title ASC"; - $result = Database::query($sql);*/ $categorizedLinks = []; $categories = []; @@ -8058,12 +7390,6 @@ class learnpath { $return = '