diff --git a/public/img/tools/agenda.png b/public/img/tools/agenda.png new file mode 100644 index 0000000000..48e8407c4c Binary files /dev/null and b/public/img/tools/agenda.png differ diff --git a/public/img/tools/agenda_na.png b/public/img/tools/agenda_na.png new file mode 100644 index 0000000000..47361b3573 Binary files /dev/null and b/public/img/tools/agenda_na.png differ diff --git a/public/img/tools/announcement.png b/public/img/tools/announcement.png new file mode 100644 index 0000000000..feba7acdb5 Binary files /dev/null and b/public/img/tools/announcement.png differ diff --git a/public/img/tools/announcement_na.png b/public/img/tools/announcement_na.png new file mode 100644 index 0000000000..7d5c3d5b07 Binary files /dev/null and b/public/img/tools/announcement_na.png differ diff --git a/public/img/tools/attendance.png b/public/img/tools/attendance.png new file mode 100644 index 0000000000..89713e42e4 Binary files /dev/null and b/public/img/tools/attendance.png differ diff --git a/public/img/tools/attendance_na.png b/public/img/tools/attendance_na.png new file mode 100644 index 0000000000..2d15743d8c Binary files /dev/null and b/public/img/tools/attendance_na.png differ diff --git a/public/img/tools/blog.png b/public/img/tools/blog.png new file mode 100644 index 0000000000..5efa9ced7b Binary files /dev/null and b/public/img/tools/blog.png differ diff --git a/public/img/tools/blog_na.png b/public/img/tools/blog_na.png new file mode 100644 index 0000000000..1915837992 Binary files /dev/null and b/public/img/tools/blog_na.png differ diff --git a/public/img/tools/chat.png b/public/img/tools/chat.png new file mode 100644 index 0000000000..96fd9ab0cd Binary files /dev/null and b/public/img/tools/chat.png differ diff --git a/public/img/tools/chat_na.png b/public/img/tools/chat_na.png new file mode 100644 index 0000000000..4c928800ca Binary files /dev/null and b/public/img/tools/chat_na.png differ diff --git a/public/img/tools/courese_description_na.png b/public/img/tools/courese_description_na.png new file mode 100644 index 0000000000..66c3317350 Binary files /dev/null and b/public/img/tools/courese_description_na.png differ diff --git a/public/img/tools/course_description.png b/public/img/tools/course_description.png new file mode 100644 index 0000000000..58c88bc19b Binary files /dev/null and b/public/img/tools/course_description.png differ diff --git a/public/img/tools/course_maintenance.png b/public/img/tools/course_maintenance.png new file mode 100644 index 0000000000..39ce73008c Binary files /dev/null and b/public/img/tools/course_maintenance.png differ diff --git a/public/img/tools/course_maintenance_na.png b/public/img/tools/course_maintenance_na.png new file mode 100644 index 0000000000..97345af60c Binary files /dev/null and b/public/img/tools/course_maintenance_na.png differ diff --git a/public/img/tools/course_progress.png b/public/img/tools/course_progress.png new file mode 100644 index 0000000000..d266b34016 Binary files /dev/null and b/public/img/tools/course_progress.png differ diff --git a/public/img/tools/course_progress_na.png b/public/img/tools/course_progress_na.png new file mode 100644 index 0000000000..b095d3e1ad Binary files /dev/null and b/public/img/tools/course_progress_na.png differ diff --git a/public/img/tools/course_setting.png b/public/img/tools/course_setting.png new file mode 100644 index 0000000000..77b5957ee8 Binary files /dev/null and b/public/img/tools/course_setting.png differ diff --git a/public/img/tools/course_setting_na.png b/public/img/tools/course_setting_na.png new file mode 100644 index 0000000000..6bba0a02fe Binary files /dev/null and b/public/img/tools/course_setting_na.png differ diff --git a/public/img/tools/document.png b/public/img/tools/document.png new file mode 100644 index 0000000000..2a40f0bedf Binary files /dev/null and b/public/img/tools/document.png differ diff --git a/public/img/tools/document_na.png b/public/img/tools/document_na.png new file mode 100644 index 0000000000..04a87dea8e Binary files /dev/null and b/public/img/tools/document_na.png differ diff --git a/public/img/tools/dropbox.png b/public/img/tools/dropbox.png new file mode 100644 index 0000000000..1b94a6c76d Binary files /dev/null and b/public/img/tools/dropbox.png differ diff --git a/public/img/tools/dropbox_na.png b/public/img/tools/dropbox_na.png new file mode 100644 index 0000000000..31e823bb3e Binary files /dev/null and b/public/img/tools/dropbox_na.png differ diff --git a/public/img/tools/forum.png b/public/img/tools/forum.png new file mode 100644 index 0000000000..17d4591a4f Binary files /dev/null and b/public/img/tools/forum.png differ diff --git a/public/img/tools/forum_na.png b/public/img/tools/forum_na.png new file mode 100644 index 0000000000..9524b4c065 Binary files /dev/null and b/public/img/tools/forum_na.png differ diff --git a/public/img/tools/glossary.png b/public/img/tools/glossary.png new file mode 100644 index 0000000000..9ae6531d9a Binary files /dev/null and b/public/img/tools/glossary.png differ diff --git a/public/img/tools/glossary_na.png b/public/img/tools/glossary_na.png new file mode 100644 index 0000000000..18c325580b Binary files /dev/null and b/public/img/tools/glossary_na.png differ diff --git a/public/img/tools/gradebook.png b/public/img/tools/gradebook.png new file mode 100644 index 0000000000..a7049c77f8 Binary files /dev/null and b/public/img/tools/gradebook.png differ diff --git a/public/img/tools/gradebook_na.png b/public/img/tools/gradebook_na.png new file mode 100644 index 0000000000..b32ec23ad7 Binary files /dev/null and b/public/img/tools/gradebook_na.png differ diff --git a/public/img/tools/group.png b/public/img/tools/group.png new file mode 100644 index 0000000000..e7a4d1005a Binary files /dev/null and b/public/img/tools/group.png differ diff --git a/public/img/tools/group_na.png b/public/img/tools/group_na.png new file mode 100644 index 0000000000..47d600e1c0 Binary files /dev/null and b/public/img/tools/group_na.png differ diff --git a/public/img/tools/learnpath.png b/public/img/tools/learnpath.png new file mode 100644 index 0000000000..718baa8c7a Binary files /dev/null and b/public/img/tools/learnpath.png differ diff --git a/public/img/tools/learnpath_na.png b/public/img/tools/learnpath_na.png new file mode 100644 index 0000000000..e3eff6c82d Binary files /dev/null and b/public/img/tools/learnpath_na.png differ diff --git a/public/img/tools/link.png b/public/img/tools/link.png new file mode 100644 index 0000000000..caff224c80 Binary files /dev/null and b/public/img/tools/link.png differ diff --git a/public/img/tools/links_na.png b/public/img/tools/links_na.png new file mode 100644 index 0000000000..3888beea5a Binary files /dev/null and b/public/img/tools/links_na.png differ diff --git a/public/img/tools/member.png b/public/img/tools/member.png new file mode 100644 index 0000000000..2286399175 Binary files /dev/null and b/public/img/tools/member.png differ diff --git a/public/img/tools/member_Na.png b/public/img/tools/member_Na.png new file mode 100644 index 0000000000..5f5b29ff80 Binary files /dev/null and b/public/img/tools/member_Na.png differ diff --git a/public/img/tools/notebook.png b/public/img/tools/notebook.png new file mode 100644 index 0000000000..b5e555b703 Binary files /dev/null and b/public/img/tools/notebook.png differ diff --git a/public/img/tools/notebook_na.png b/public/img/tools/notebook_na.png new file mode 100644 index 0000000000..ce7860946c Binary files /dev/null and b/public/img/tools/notebook_na.png differ diff --git a/public/img/tools/quiz.png b/public/img/tools/quiz.png new file mode 100644 index 0000000000..0f7ca9fd5d Binary files /dev/null and b/public/img/tools/quiz.png differ diff --git a/public/img/tools/quiz_na.png b/public/img/tools/quiz_na.png new file mode 100644 index 0000000000..22fa1826ba Binary files /dev/null and b/public/img/tools/quiz_na.png differ diff --git a/public/img/tools/statistics_na.png b/public/img/tools/statistics_na.png new file mode 100644 index 0000000000..50055541be Binary files /dev/null and b/public/img/tools/statistics_na.png differ diff --git a/public/img/tools/student_publication.png b/public/img/tools/student_publication.png new file mode 100644 index 0000000000..0d0b6b6f6b Binary files /dev/null and b/public/img/tools/student_publication.png differ diff --git a/public/img/tools/student_publication_na.png b/public/img/tools/student_publication_na.png new file mode 100644 index 0000000000..54e0c393eb Binary files /dev/null and b/public/img/tools/student_publication_na.png differ diff --git a/public/img/tools/survey.png b/public/img/tools/survey.png new file mode 100644 index 0000000000..843ea5f7c9 Binary files /dev/null and b/public/img/tools/survey.png differ diff --git a/public/img/tools/survey_na.png b/public/img/tools/survey_na.png new file mode 100644 index 0000000000..af1a4689ec Binary files /dev/null and b/public/img/tools/survey_na.png differ diff --git a/public/img/tools/tracking.png b/public/img/tools/tracking.png new file mode 100644 index 0000000000..575258d990 Binary files /dev/null and b/public/img/tools/tracking.png differ diff --git a/public/img/tools/wiki.png b/public/img/tools/wiki.png new file mode 100644 index 0000000000..bfafbcc6c3 Binary files /dev/null and b/public/img/tools/wiki.png differ diff --git a/public/img/tools/wiki_na.png b/public/img/tools/wiki_na.png new file mode 100644 index 0000000000..90f77f815a Binary files /dev/null and b/public/img/tools/wiki_na.png differ diff --git a/public/main/inc/lib/course_home.lib.php b/public/main/inc/lib/course_home.lib.php index 2e94b31cd0..b3d8e54397 100644 --- a/public/main/inc/lib/course_home.lib.php +++ b/public/main/inc/lib/course_home.lib.php @@ -1,8 +1,10 @@ getRepository('ChamiloCourseBundle:CTool'); + $qb = $repo->createQueryBuilder('tool'); + + $criteria = \Doctrine\Common\Collections\Criteria::create(); + switch ($course_tool_category) { case TOOL_STUDENT_VIEW: - $conditions = ' WHERE visibility = 1 AND - (category = "authoring" OR category = "interaction" OR category = "plugin") AND - t.name <> "notebookteacher" '; - if ((api_is_coach() || api_is_course_tutor() || api_is_platform_admin()) && !$studentView) { + $criteria + ->where(Criteria::expr()->eq('visibility', 1)) + ->andWhere(Criteria::expr()->in('category', ['authoring', 'interaction'])) + ; + + /*if ((api_is_coach() || api_is_course_tutor() || api_is_platform_admin()) && !$studentView) { $conditions = ' WHERE ( visibility = 1 AND ( - category = "authoring" OR - category = "interaction" OR + category = "authoring" OR + category = "interaction" OR category = "plugin" - ) OR (t.name = "'.TOOL_TRACKING.'") + ) OR (t.name = "'.TOOL_TRACKING.'") )'; - } - - // Add order if there are LPs - $sql = "SELECT t.* FROM $course_tool_table t - LEFT JOIN $lpTable l - ON (t.c_id = l.c_id AND link LIKE concat('%/lp_controller.php?action=view&lp_id=', l.id, '&%')) - LEFT JOIN $tblLpCategory lc - ON (t.c_id = lc.c_id AND l.category_id = lc.iid) - $conditions AND - t.c_id = $course_id $condition_session - ORDER BY - CASE WHEN l.category_id IS NULL THEN 0 ELSE 1 END, - CASE WHEN l.display_order IS NULL THEN 0 ELSE 1 END, - lc.position, - l.display_order, - t.id"; - $orderBy = ''; + }*/ break; case TOOL_AUTHORING: - $sql = "SELECT t.* FROM $course_tool_table t - LEFT JOIN $lpTable l - ON (t.c_id = l.c_id AND link LIKE concat('%/lp_controller.php?action=view&lp_id=', l.id, '&%')) - LEFT JOIN $tblLpCategory lc - ON (t.c_id = lc.c_id AND l.category_id = lc.iid) - WHERE - category = 'authoring' AND t.c_id = $course_id $condition_session - ORDER BY - CASE WHEN l.category_id IS NULL THEN 0 ELSE 1 END, - CASE WHEN l.display_order IS NULL THEN 0 ELSE 1 END, - lc.position, - l.display_order, - t.id"; - $orderBy = ''; + $criteria + ->where(Criteria::expr()->in('category', ['authoring'])) + ; break; case TOOL_INTERACTION: - $sql = "SELECT * FROM $course_tool_table t - WHERE category = 'interaction' AND c_id = $course_id $condition_session - "; + $criteria + ->where(Criteria::expr()->in('category', ['interaction'])) + ; break; case TOOL_ADMIN_VISIBLE: - $sql = "SELECT * FROM $course_tool_table t - WHERE category = 'admin' AND visibility ='1' AND c_id = $course_id $condition_session - "; + $criteria + ->where(Criteria::expr()->eq('visibility', 1)) + ->andWhere(Criteria::expr()->in('category', ['admin'])) + ; break; case TOOL_ADMIN_PLATFORM: - $sql = "SELECT * FROM $course_tool_table t - WHERE category = 'admin' AND c_id = $course_id $condition_session - "; + $criteria + ->andWhere(Criteria::expr()->in('category', ['admin'])) + ; break; case TOOL_DRH: - $sql = "SELECT * FROM $course_tool_table t - WHERE t.name IN ('tracking') AND c_id = $course_id $condition_session - "; + $criteria + ->andWhere(Criteria::expr()->in('tool.tool.name', ['tracking'])) + ; break; - case TOOL_COURSE_PLUGIN: + /*case TOOL_COURSE_PLUGIN: //Other queries recover id, name, link, image, visibility, admin, address, added_tool, target, category and session_id // but plugins are not present in the tool table, only globally and inside the course_settings table once configured $sql = "SELECT * FROM $course_tool_table t WHERE category = 'plugin' AND name <> 'courseblock' AND c_id = $course_id $condition_session - "; + ";*/ break; } - $sql .= $orderBy; - $result = Database::query($sql); - $tools = []; - while ($row = Database::fetch_assoc($result)) { - $tools[] = $row; - } - - // Get the list of hidden tools - this might imply performance slowdowns - // if the course homepage is loaded many times, so the list of hidden - // tools might benefit from a shared memory storage later on - $list = api_get_settings('Tools', 'list', api_get_current_access_url_id()); - $hide_list = []; - $check = false; - foreach ($list as $line) { - // Admin can see all tools even if the course_hide_tools configuration is set - if ($is_platform_admin) { - continue; - } - if ($line['variable'] == 'course_hide_tools' && $line['selected_value'] == 'true') { - $hide_list[] = $line['subkey']; - $check = true; - } - } - - $allowEditionInSession = api_get_configuration_value('allow_edit_tool_visibility_in_session'); - // If exists same tool (by name) from session in base course then avoid it. Allow them pass in other cases - $tools = array_filter($tools, function (array $toolToFilter) use ($sessionId, $tools) { - if (!empty($toolToFilter['session_id'])) { - foreach ($tools as $originalTool) { - if ($toolToFilter['name'] == $originalTool['name'] && empty($originalTool['session_id'])) { - return false; - } - } - } - return true; - }); + $criteria + ->andWhere(Criteria::expr()->eq('course', api_get_course_entity($courseId))) + ; - foreach ($tools as $temp_row) { - $add = false; - if ($check) { - if (!in_array($temp_row['name'], $hide_list)) { - $add = true; - } - } else { - $add = true; - } + //$condition_session = $condition_add." ( $session_field = $session_id OR $session_field = 0 OR $session_field IS NULL) "; + /*$criteria + ->andWhere(Criteria::expr()->eq('session', $courseId)) + ;*/ - if ($allowEditionInSession && !empty($sessionId)) { - // Checking if exist row in session - $criteria = [ - 'course' => $course_id, - 'name' => $temp_row['name'], - 'sessionId' => $sessionId, - ]; - /** @var CTool $toolObj */ - $toolObj = Database::getManager()->getRepository('ChamiloCourseBundle:CTool')->findOneBy($criteria); - if ($toolObj) { - if (api_is_allowed_to_edit() == false && $toolObj->getVisibility() == false) { - continue; - } - } - } + $qb->addCriteria($criteria); - switch ($temp_row['image']) { - case 'scormbuilder.gif': - $lpId = self::getPublishedLpIdFromLink($temp_row['link']); - $lp = new learnpath( - api_get_course_id(), - $lpId, - $userId - ); - $path = $lp->get_preview_image_path(ICON_SIZE_BIG); - - if (api_is_allowed_to_edit(null, true)) { - $add = true; - } else { - $add = learnpath::is_lp_visible_for_student( - $lpId, - $userId, - $courseInfo, - $sessionId - ); - } - if ($path) { - $temp_row['custom_image'] = $path; - } - break; - case 'lp_category.gif': - $lpCategory = self::getPublishedLpCategoryFromLink( - $temp_row['link'] - ); - $add = learnpath::categoryIsVisibleForStudent( - $lpCategory, - $user - ); - break; - } - - if ($add) { - $all_tools_list[] = $temp_row; - } - } - - // Grabbing all the links that have the property on_homepage set to 1 - $course_link_table = Database::get_course_table(TABLE_LINK); - $course_item_property_table = Database::get_course_table(TABLE_ITEM_PROPERTY); - $condition_session = api_get_session_condition( - $sessionId, - true, - true, - 'tip.session_id' - ); - - switch ($course_tool_category) { - case TOOL_AUTHORING: - $sql_links = "SELECT tl.*, tip.visibility - FROM $course_link_table tl - LEFT JOIN $course_item_property_table tip - ON tip.tool='link' AND tip.ref=tl.id - WHERE - tl.c_id = $course_id AND - tip.c_id = $course_id AND - tl.on_homepage='1' $condition_session"; - break; - case TOOL_INTERACTION: - $sql_links = null; - /* - $sql_links = "SELECT tl.*, tip.visibility - FROM $course_link_table tl - LEFT JOIN $course_item_property_table tip ON tip.tool='link' AND tip.ref=tl.id - WHERE tl.on_homepage='1' "; - */ - break; - case TOOL_STUDENT_VIEW: - $sql_links = "SELECT tl.*, tip.visibility - FROM $course_link_table tl - LEFT JOIN $course_item_property_table tip - ON tip.tool='link' AND tip.ref=tl.id - WHERE - tl.c_id = $course_id AND - tip.c_id = $course_id AND - tl.on_homepage ='1' $condition_session"; - break; - case TOOL_ADMIN: - $sql_links = "SELECT tl.*, tip.visibility - FROM $course_link_table tl - LEFT JOIN $course_item_property_table tip - ON tip.tool='link' AND tip.ref=tl.id - WHERE - tl.c_id = $course_id AND - tip.c_id = $course_id AND - tl.on_homepage='1' $condition_session"; - break; - default: - $sql_links = null; - break; - } - - // Edited by Kevin Van Den Haute (kevin@develop-it.be) for integrating Smartblogs - if ($sql_links != null) { - $result_links = Database::query($sql_links); - if (Database::num_rows($result_links) > 0) { - while ($links_row = Database::fetch_array($result_links, 'ASSOC')) { - $properties = []; - $properties['name'] = $links_row['title']; - $properties['session_id'] = $links_row['session_id']; - $properties['link'] = $links_row['url']; - $properties['visibility'] = $links_row['visibility']; - $properties['image'] = $links_row['visibility'] == '0' ? 'file_html.png' : 'file_html.png'; - $properties['adminlink'] = api_get_path(WEB_CODE_PATH).'link/link.php?action=editlink&id='.$links_row['id']; - $properties['target'] = $links_row['target']; - $tmp_all_tools_list[] = $properties; - } - } - } - - if (isset($tmp_all_tools_list)) { - $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER); - foreach ($tmp_all_tools_list as $tool) { - if ($tool['image'] == 'blog.gif') { - // Get blog id - $blog_id = substr($tool['link'], strrpos($tool['link'], '=') + 1, strlen($tool['link'])); - - // Get blog members - if ($is_platform_admin) { - $sql = "SELECT * FROM $tbl_blogs_rel_user blogs_rel_user - WHERE blog_id = ".$blog_id; - } else { - $sql = "SELECT * FROM $tbl_blogs_rel_user blogs_rel_user - WHERE blog_id = ".$blog_id." AND user_id = ".$userId; - } - $result = Database::query($sql); - if (Database::num_rows($result) > 0) { - $all_tools_list[] = $tool; - } - } else { - $all_tools_list[] = $tool; - } - } - } - - $list = self::filterPluginTools($all_tools_list, $course_tool_category); - - return $list; + return $qb->getQuery()->getResult(); } /** @@ -336,30 +127,13 @@ class CourseHome * * @return array */ - public static function show_tools_category($all_tools_list) + public static function show_tools_category($all_tools_list, ToolChain $toolChain) { - $_user = api_get_user_info(); - $theme = api_get_setting('homepage_view'); - - if ($theme === 'vertical_activity') { - //ordering by get_lang name - $order_tool_list = []; - if (is_array($all_tools_list) && count($all_tools_list) > 0) { - foreach ($all_tools_list as $key => $new_tool) { - $tool_name = self::translate_tool_name($new_tool); - $order_tool_list[$key] = $tool_name; - } - natsort($order_tool_list); - $my_temp_tool_array = []; - foreach ($order_tool_list as $key => $new_tool) { - $my_temp_tool_array[] = $all_tools_list[$key]; - } - $all_tools_list = $my_temp_tool_array; - } else { - $all_tools_list = []; - } + if (empty($all_tools_list)) { + return []; } - $web_code_path = api_get_path(WEB_CODE_PATH); + + $_user = api_get_user_info(); $session_id = api_get_session_id(); $is_platform_admin = api_is_platform_admin(); $allowEditionInSession = api_get_configuration_value('allow_edit_tool_visibility_in_session'); @@ -372,108 +146,52 @@ class CourseHome } } + $items = []; - $app_plugin = new AppPlugin(); - - if (isset($all_tools_list)) { - $lnk = ''; - foreach ($all_tools_list as &$tool) { - $item = []; - $studentview = false; - $tool['original_link'] = $tool['link']; - if ($tool['image'] === 'scormbuilder.gif') { - // Check if the published learnpath is visible for student - $lpId = self::getPublishedLpIdFromLink($tool['link']); - if (api_is_allowed_to_edit(null, true)) { - $studentview = true; + /** @var CTool $tool */ + foreach ($all_tools_list as $tool) { + $item = []; + $studentview = false; + $toolAdmin = false; + $toolModel = $toolChain->getToolFromName($tool->getTool()->getName()); + if ($is_allowed_to_edit) { + if (empty($session_id)) { + if ($tool->getVisibility() == '1' && $toolAdmin != '1') { + $link['name'] = Display::return_icon( + 'visible.png', + get_lang('Deactivate'), + ['id' => 'linktool_'.$tool->getIid()], + ICON_SIZE_SMALL, + false + ); } - if (!api_is_allowed_to_edit(null, true) && - !learnpath::is_lp_visible_for_student( - $lpId, - api_get_user_id(), - api_get_course_info(), - api_get_session_id() - ) - ) { - continue; + if ($tool->getVisibility() == '0' && $toolAdmin != '1') { + $link['name'] = Display::return_icon( + 'invisible.png', + get_lang('Activate'), + ['id' => 'linktool_'.$tool->getIid()], + ICON_SIZE_SMALL, + false + ); } - } - - if ($session_id != 0 && in_array($tool['name'], ['course_setting'])) { - continue; - } - - // This part displays the links to hide or remove a tool. - // These links are only visible by the course manager. - unset($lnk); - - $item['extra'] = null; - $toolAdmin = isset($tool['admin']) ? $tool['admin'] : ''; - - if ($is_allowed_to_edit) { - if (empty($session_id)) { - if (isset($tool['id'])) { - if ($tool['visibility'] == '1' && $toolAdmin != '1') { - $link['name'] = Display::return_icon( - 'visible.png', - get_lang('Deactivate'), - ['id' => 'linktool_'.$tool['iid']], - ICON_SIZE_SMALL, - false - ); - $link['cmd'] = 'hide=yes'; - $lnk[] = $link; - } - if ($tool['visibility'] == '0' && $toolAdmin != '1') { - $link['name'] = Display::return_icon( - 'invisible.png', - get_lang('Activate'), - ['id' => 'linktool_'.$tool['iid']], - ICON_SIZE_SMALL, - false - ); - $link['cmd'] = 'restore=yes'; - $lnk[] = $link; - } - } - } elseif ($allowEditionInSession) { - $criteria = [ - 'course' => api_get_course_int_id(), - 'name' => $tool['name'], - 'sessionId' => $session_id, - ]; - /** @var CTool $tool */ - $toolObj = Database::getManager()->getRepository('ChamiloCourseBundle:CTool')->findOneBy($criteria); - if ($toolObj) { - $visibility = (int) $toolObj->getVisibility(); - switch ($visibility) { - case '0': - $info = pathinfo($tool['image']); - $basename = basename($tool['image'], '.'.$info['extension']); - $tool['image'] = $basename.'_na.'.$info['extension']; - $link['name'] = Display::return_icon( - 'invisible.png', - get_lang('Activate'), - ['id' => 'linktool_'.$tool['iid']], - ICON_SIZE_SMALL, - false - ); - $link['cmd'] = 'restore=yes'; - $lnk[] = $link; - break; - case '1': - $link['name'] = Display::return_icon( - 'visible.png', - get_lang('Deactivate'), - ['id' => 'linktool_'.$tool['iid']], - ICON_SIZE_SMALL, - false - ); - $link['cmd'] = 'hide=yes'; - $lnk[] = $link; - break; - } - } else { + } elseif ($allowEditionInSession) { + $visibility = (int) $tool->getVisibility(); + switch ($visibility) { + case '0': + $info = pathinfo($tool['image']); + $basename = basename($tool['image'], '.'.$info['extension']); + $tool['image'] = $basename.'_na.'.$info['extension']; + $link['name'] = Display::return_icon( + 'invisible.png', + get_lang('Activate'), + ['id' => 'linktool_'.$tool['iid']], + ICON_SIZE_SMALL, + false + ); + $link['cmd'] = 'restore=yes'; + $lnk[] = $link; + break; + case '1': $link['name'] = Display::return_icon( 'visible.png', get_lang('Deactivate'), @@ -483,185 +201,76 @@ class CourseHome ); $link['cmd'] = 'hide=yes'; $lnk[] = $link; - } - } - if (!empty($tool['adminlink'])) { - $item['extra'] = ''. - Display::return_icon('edit.gif', get_lang('Edit')). - ''; - } - } - - // Both checks are necessary as is_platform_admin doesn't take student view into account - if ($is_platform_admin && $is_allowed_to_edit) { - if ($toolAdmin != '1') { - $link['cmd'] = 'hide=yes'; + break; } } + } - $item['visibility'] = ''; - if (isset($lnk) && is_array($lnk)) { - foreach ($lnk as $this_link) { - if (empty($tool['adminlink'])) { - $item['visibility'] .= - ''. - $this_link['name'].''; - } - } - } - - // NOTE : Table contains only the image file name, not full path - if (stripos($tool['link'], 'http://') === false && - stripos($tool['link'], 'https://') === false && - stripos($tool['link'], 'ftp://') === false - ) { - $tool['link'] = $web_code_path.$tool['link']; - } - - $class = ''; - if ($tool['visibility'] == '0' && $toolAdmin != '1') { - $class = 'text-muted'; - $info = pathinfo($tool['image']); - $basename = basename($tool['image'], '.'.$info['extension']); - $tool['image'] = $basename.'_na.'.$info['extension']; - } - - $qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&'; - - // If it's a link, we don't add the cidReq - if ($tool['image'] === 'file_html.png' || $tool['image'] === 'file_html_na.png') { - $tool['link'] = $tool['link']; - } else { - $tool['link'] = $tool['link'].$qm_or_amp.api_get_cidreq(); - } - - $toolIid = isset($tool['iid']) ? $tool['iid'] : null; - - //@todo this visio stuff should be removed - if (strpos($tool['name'], 'visio_') !== false) { - $tool_link_params = [ - 'id' => 'tooldesc_'.$toolIid, - 'href' => '"javascript: void(0);"', - 'class' => $class, - 'onclick' => 'javascript: window.open(\''.$tool['link'].'\',\'window_visio'.api_get_course_id().'\',config=\'height=\'+730+\', width=\'+1020+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')', - 'target' => $tool['target'], - ]; - } elseif (strpos($tool['name'], 'chat') !== false && - api_get_course_setting('allow_open_chat_window') - ) { - $tool_link_params = [ - 'id' => 'tooldesc_'.$toolIid, - 'class' => $class, - 'href' => 'javascript: void(0);', - 'onclick' => 'javascript: window.open(\''.$tool['link'].'\',\'window_chat'.api_get_course_id().'\',config=\'height=\'+600+\', width=\'+825+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')', //Chat Open Windows - 'target' => $tool['target'], - ]; - } else { - $tool_link_params = [ - 'id' => 'tooldesc_'.$toolIid, - 'href' => $tool['link'], - 'class' => $class, - 'target' => $tool['target'], - ]; + // Both checks are necessary as is_platform_admin doesn't take student view into account + if ($is_platform_admin && $is_allowed_to_edit) { + if ($toolAdmin != '1') { + $link['cmd'] = 'hide=yes'; } + } - $tool_name = self::translate_tool_name($tool); - - // Including Courses Plugins - // Creating title and the link - if (isset($tool['category']) && $tool['category'] == 'plugin') { - $plugin_info = $app_plugin->getPluginInfo($tool['name']); - if (isset($plugin_info) && isset($plugin_info['title'])) { - $tool_name = $plugin_info['title']; - } + $item['visibility'] = ''; - if (!file_exists(api_get_path(SYS_CODE_PATH).'img/'.$tool['image']) && - !file_exists(api_get_path(SYS_CODE_PATH).'img/icons/64/'.$tool['image'])) { - $tool['image'] = 'plugins.png'; - } - $tool_link_params['href'] = api_get_path(WEB_PLUGIN_PATH) - .$tool['original_link'].$qm_or_amp.api_get_cidreq(); - } + $class = ''; + if ($tool->getVisibility() == '0' && $toolAdmin != '1') { + $class = 'text-muted'; + $info = pathinfo($tool['image']); + $basename = basename($tool['image'], '.'.$info['extension']); + $tool['image'] = $basename.'_na.'.$info['extension']; + } - // Use in the course home - $icon = Display::return_icon( - $tool['image'], - $tool_name, - ['class' => 'tool-icon', 'id' => 'toolimage_'.$toolIid], - ICON_SIZE_BIG, - false - ); + $toolIid = $tool->getIid(); - // Used in the top bar - $iconMedium = Display::return_icon( - $tool['image'], - $tool_name, - ['class' => 'tool-icon', 'id' => 'toolimage_'.$toolIid], - ICON_SIZE_MEDIUM, - false - ); + $tool_link_params = [ + 'id' => 'tooldesc_'.$toolIid, + 'href' => $toolModel->getLink().'?'.api_get_cidreq(), + 'class' => $class, + ]; - // Used for vertical navigation - $iconSmall = Display::return_icon( - $tool['image'], - $tool_name, - ['class' => 'tool-img', 'id' => 'toolimage_'.$toolIid], - ICON_SIZE_SMALL, - false - ); + $tool_name = $tool->getTool()->getName(); - /*if (!empty($tool['custom_icon'])) { - $image = self::getCustomWebIconPath().$tool['custom_icon']; - $icon = Display::img( - $image, - $tool['description'], - array( - 'class' => 'tool-icon', - 'id' => 'toolimage_'.$tool['id'] - ) - ); - }*/ + $image = 'admin.png'; + // Use in the course home + $icon = Display::return_icon( + $image, + $tool_name, + ['class' => 'tool-icon', 'id' => 'toolimage_'.$toolIid], + ICON_SIZE_BIG, + false + ); - // Validation when belongs to a session + // Validation when belongs to a session + $session_img = ''; + if (!empty($tool->getSession())) { $session_img = api_get_session_image( - $tool['session_id'], + $tool->getSession()->getId(), !empty($_user['status']) ? $_user['status'] : '' ); - if ($studentview) { - $tool_link_params['href'] .= '&isStudentView=true'; - } - $item['url_params'] = $tool_link_params; - $item['icon'] = Display::url($icon, $tool_link_params['href'], $tool_link_params); - $item['only_icon'] = $icon; - $item['only_icon_medium'] = $iconMedium; - $item['only_icon_small'] = $iconSmall; - $item['only_href'] = $tool_link_params['href']; - $item['tool'] = $tool; - $item['name'] = $tool_name; - $tool_link_params['id'] = 'is'.$tool_link_params['id']; - $item['link'] = Display::url( - $tool_name.$session_img, - $tool_link_params['href'], - $tool_link_params - ); - $items[] = $item; } - } - - foreach ($items as &$item) { - $originalImage = self::getToolIcon($item, ICON_SIZE_BIG); - $item['tool']['only_icon_medium'] = self::getToolIcon($item, ICON_SIZE_MEDIUM, false); - $item['tool']['only_icon_small'] = self::getToolIcon($item, ICON_SIZE_SMALL, false); - if ($theme === 'activity_big') { - $item['tool']['image'] = Display::url( - $originalImage, - $item['url_params']['href'], - $item['url_params'] - ); + if ($studentview) { + $tool_link_params['href'] .= '&isStudentView=true'; } + $item['url_params'] = $tool_link_params; + $item['icon'] = Display::url($icon, $tool_link_params['href'], $tool_link_params); + $item['tool'] = $tool; + $item['name'] = $tool_name; + + $item['href'] = $tool_link_params['href']; + $tool_link_params['id'] = 'is'.$tool_link_params['id']; + $item['link'] = Display::url( + $tool_name.$session_img, + $tool_link_params['href'], + $tool_link_params + ); + $items[] = $item; } + return $items; } @@ -721,7 +330,7 @@ class CourseHome * * @return string returns the name of the corresponding tool */ - public static function translate_tool_name(&$tool) + public static function translate_tool_name(CTool $tool) { static $already_translated_icons = [ 'file_html.gif', @@ -736,7 +345,9 @@ class CourseHome 'external_na.gif', ]; - $toolName = Security::remove_XSS(stripslashes(strip_tags($tool['name']))); + $toolName = Security::remove_XSS(stripslashes(strip_tags($tool->getTool()->getName()))); + + return $toolName; if (isset($tool['image']) && in_array($tool['image'], $already_translated_icons)) { return $toolName; @@ -1101,33 +712,25 @@ class CourseHome /** * @return array */ - public static function getCourseAdminBlocks() + public static function getCourseAdminBlocks($toolChain) { $blocks = []; - $my_list = self::get_tools_category(TOOL_AUTHORING); - $blocks[] = [ 'title' => get_lang('Authoring'), 'class' => 'course-tools-author', - 'content' => self::show_tools_category($my_list), + 'content' => self::show_tools_category(self::get_tools_category(TOOL_AUTHORING), $toolChain), ]; - $list1 = self::get_tools_category(TOOL_INTERACTION); - $list2 = self::get_tools_category(TOOL_COURSE_PLUGIN); - $my_list = array_merge($list1, $list2); - $blocks[] = [ 'title' => get_lang('Interaction'), 'class' => 'course-tools-interaction', - 'content' => self::show_tools_category($my_list), + 'content' => self::show_tools_category(self::get_tools_category(TOOL_INTERACTION), $toolChain), ]; - $my_list = self::get_tools_category(TOOL_ADMIN_PLATFORM); - $blocks[] = [ 'title' => get_lang('Administration'), 'class' => 'course-tools-administration', - 'content' => self::show_tools_category($my_list), + 'content' => self::show_tools_category(self::get_tools_category(TOOL_ADMIN_PLATFORM), $toolChain), ]; return $blocks; @@ -1136,13 +739,13 @@ class CourseHome /** * @return array */ - public static function getCoachBlocks() + public static function getCoachBlocks(ToolChain $toolChain) { $blocks = []; $my_list = self::get_tools_category(TOOL_STUDENT_VIEW); $blocks[] = [ - 'content' => self::show_tools_category($my_list), + 'content' => self::show_tools_category($my_list, $toolChain), ]; $sessionsCopy = api_get_setting('allow_session_course_copy_for_teachers'); @@ -1161,7 +764,7 @@ class CourseHome $blocks[] = [ 'title' => get_lang('Administration'), - 'content' => self::show_tools_category($onlyMaintenanceList), + 'content' => self::show_tools_category($onlyMaintenanceList, $toolChain), ]; } @@ -1171,7 +774,7 @@ class CourseHome /** * @return array */ - public static function getStudentBlocks() + public static function getStudentBlocks(ToolChain $toolChain) { $blocks = []; $tools = self::get_tools_category(TOOL_STUDENT_VIEW); @@ -1208,12 +811,12 @@ class CourseHome } if (count($tools) > 0) { - $blocks[] = ['content' => self::show_tools_category($tools)]; + $blocks[] = ['content' => self::show_tools_category($tools, $toolChain)]; } if ($isDrhOfCourse) { $drhTool = self::get_tools_category(TOOL_DRH); - $blocks[] = ['content' => self::show_tools_category($drhTool)]; + $blocks[] = ['content' => self::show_tools_category($drhTool, $toolChain)]; } return $blocks; @@ -1222,16 +825,16 @@ class CourseHome /** * @return array */ - public static function getUserBlocks() + public static function getUserBlocks($toolChain) { $sessionId = api_get_session_id(); // Start of tools for CourseAdmins (teachers/tutors) if ($sessionId === 0 && api_is_course_admin() && api_is_allowed_to_edit(null, true)) { - $blocks = self::getCourseAdminBlocks(); + $blocks = self::getCourseAdminBlocks($toolChain); } elseif (api_is_coach()) { - $blocks = self::getCoachBlocks(); + $blocks = self::getCoachBlocks($toolChain); } else { - $blocks = self::getStudentBlocks(); + $blocks = self::getStudentBlocks($toolChain); } return $blocks; @@ -1293,53 +896,4 @@ class CourseHome return $dataIcons; } - - /** - * Find the tool icon when homepage_view is activity_big. - * - * @param int $iconSize - * @param bool $generateId - * - * @return string - */ - private static function getToolIcon(array $item, $iconSize, $generateId = true) - { - $image = str_replace('.gif', '.png', $item['tool']['image']); - $toolIid = isset($item['tool']['iid']) ? $item['tool']['iid'] : null; - - if (isset($item['tool']['custom_image'])) { - return Display::img( - $item['tool']['custom_image'], - $item['name'], - ['id' => 'toolimage_'.$toolIid] - ); - } - - if (isset($item['tool']['custom_icon']) && !empty($item['tool']['custom_icon'])) { - $customIcon = $item['tool']['custom_icon']; - - if ($item['tool']['visibility'] == '0') { - $customIcon = self::getDisableIcon($item['tool']['custom_icon']); - } - - return Display::img( - self::getCustomWebIconPath().$customIcon, - $item['name'], - ['id' => 'toolimage_'.$toolIid] - ); - } - - $id = ''; - if ($generateId) { - $id = 'toolimage_'.$toolIid; - } - - return Display::return_icon( - $image, - $item['name'], - ['id' => $id], - $iconSize, - false - ); - } } diff --git a/public/main/inc/lib/display.lib.php b/public/main/inc/lib/display.lib.php index e5786288ac..b4c9379b52 100644 --- a/public/main/inc/lib/display.lib.php +++ b/public/main/inc/lib/display.lib.php @@ -1538,6 +1538,7 @@ class Display if (empty($courseInfo)) { return ''; } + return ''; $t_track_e_access = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LASTACCESS); $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST); @@ -1567,7 +1568,7 @@ class Display c_id = $course_id AND access_user_id = '$user_id' AND access_session_id ='".$sessionId."' - ORDER BY access_date DESC + ORDER BY access_date DESC LIMIT 1 "; $result = Database::query($sql); @@ -1588,12 +1589,12 @@ class Display $hideTools = [TOOL_NOTEBOOK, TOOL_CHAT]; // Get current tools in course - $sql = "SELECT name, link, image - FROM $course_tool_table - WHERE - c_id = $course_id AND + $sql = "SELECT name + FROM $course_tool_table + WHERE + c_id = $course_id AND visibility = '1' AND - name NOT IN ('".implode("','", $hideTools)."') + name NOT IN ('".implode("','", $hideTools)." ') "; $result = Database::query($sql); $tools = Database::store_result($result); @@ -1613,7 +1614,7 @@ class Display $toolName = addslashes($toolName); - $sql = "SELECT * FROM $tool_edit_table + $sql = "SELECT * FROM $tool_edit_table WHERE c_id = $course_id AND $toolCondition @@ -2709,12 +2710,12 @@ class Display $ariaExpanded = $open ? 'true' : 'false'; $html = << -
- $title -
-
$content
+
+ $title +
+
$content
HTML; } else { @@ -2778,14 +2779,14 @@ HTML; $toolbar = '
'.$toolbar.'
'; } - return '
+ return '
-

'.$userInfo['complete_name'].'

-
+

'.$userInfo['complete_name'].'

+
'.$status.' '.$toolbar.' -
+

'; @@ -2881,7 +2882,7 @@ HTML; $.frameReady(function() { $(function () { $("video:not(.skip), audio:not(.skip)").mediaelementplayer({ - pluginPath: "'.$webPublicPath.'assets/mediaelement/plugins/", + pluginPath: "'.$webPublicPath.'assets/mediaelement/plugins/", features: [\''.$videoFeatures.'\'], success: function(mediaElement, originalNode, instance) { '.ChamiloApi::getQuizMarkersRollsJS().' @@ -2889,25 +2890,25 @@ HTML; vrPath: "'.$webPublicPath.'assets/vrview/build/vrview.js" }); }); - }, + }, "'.$frameName.'", [ {type:"script", src:"'.api_get_jquery_web_path().'", deps: [ {type:"script", src:"'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.highlight.js"}, {type:"script", src:"'.api_get_path(WEB_CODE_PATH).'glossary/glossary.js.php?'.api_get_cidreq().'"}, {type:"script", src:"'.api_get_jquery_ui_js_web_path().'"}, - {type:"script", src: "'.$webPublicPath.'build/libs/mediaelement/mediaelement-and-player.min.js", + {type:"script", src: "'.$webPublicPath.'build/libs/mediaelement/mediaelement-and-player.min.js", deps: [ {type:"script", src: "'.$webPublicPath.'build/libs/mediaelement/plugins/vrview/vrview.js"}, {type:"script", src: "'.$webPublicPath.'build/libs/mediaelement/plugins/markersrolls/markersrolls.js"}, '.$videoPluginFiles.' - ]}, + ]}, '.$translateHtml.' ]}, '.$videoPluginCssFiles.' {type:"script", src:"'.$webPublicPath.'build/libs/mathjax/MathJax.js?config=AM_HTMLorMML"}, {type:"stylesheet", src:"'.$webPublicPath.'assets/jquery-ui/themes/smoothness/jquery-ui.min.css"}, - {type:"stylesheet", src:"'.$webPublicPath.'assets/jquery-ui/themes/smoothness/theme.css"}, + {type:"stylesheet", src:"'.$webPublicPath.'assets/jquery-ui/themes/smoothness/theme.css"}, ]);'; return $frameReady; diff --git a/src/CoreBundle/Controller/CourseHomeController.php b/src/CoreBundle/Controller/CourseHomeController.php index 10e8aa3c9a..fda828542b 100644 --- a/src/CoreBundle/Controller/CourseHomeController.php +++ b/src/CoreBundle/Controller/CourseHomeController.php @@ -3,6 +3,7 @@ namespace Chamilo\CoreBundle\Controller; +use Chamilo\CoreBundle\ToolChain; use Chamilo\CourseBundle\Controller\ToolBaseController; use Chamilo\CourseBundle\Entity\CTool; use Chamilosession as Session; @@ -31,7 +32,7 @@ class CourseHomeController extends ToolBaseController * * @Entity("course", expr="repository.find(cid)") */ - public function indexAction(Request $request) + public function indexAction(Request $request, ToolChain $toolChain) { $course = $this->getCourse(); $result = $this->autoLaunch(); @@ -39,7 +40,6 @@ class CourseHomeController extends ToolBaseController $htmlHeadXtra[] = $js; $userId = $this->getUser()->getId(); - $courseCode = $course->getCode(); $courseId = $course->getId(); $sessionId = $this->getSessionId(); @@ -134,8 +134,8 @@ class CourseHomeController extends ToolBaseController if (!empty($session_id)) { $condition = api_get_session_condition($session_id); $sql = "SELECT id FROM $lp_table - WHERE c_id = $course_id AND autolaunch = 1 $condition - LIMIT 1"; + WHERE c_id = $course_id AND autolaunch = 1 $condition + LIMIT 1"; $result = Database::query($sql); // If we found nothing in the session we just called the session_id = 0 autolaunch if (Database::num_rows($result) == 0) { @@ -144,8 +144,8 @@ class CourseHomeController extends ToolBaseController } $sql = "SELECT id FROM $lp_table - WHERE c_id = $course_id AND autolaunch = 1 $condition - LIMIT 1"; + WHERE c_id = $course_id AND autolaunch = 1 $condition + LIMIT 1"; $result = Database::query($sql); if (Database::num_rows($result) > 0) { $lp_data = Database::fetch_array($result, 'ASSOC'); @@ -276,7 +276,6 @@ class CourseHomeController extends ToolBaseController ); } - //require 'activity.php'; // Activity start $id = isset($_GET['id']) ? (int) $_GET['id'] : null; $course_id = api_get_course_int_id(); @@ -288,9 +287,9 @@ class CourseHomeController extends ToolBaseController // visibility 0,1->2 if (!empty($_GET['askDelete'])) { $content .= '
'.get_lang('Do you really want to delete this link?').'
    - '.get_lang('No').' |  - '.get_lang('Yes').' -
'; + '.get_lang('No').' |  + '.get_lang('Yes').' +
'; } elseif (isset($_GET['delete']) && $_GET['delete']) { /* * Process hiding a tools from available tools. @@ -330,8 +329,7 @@ class CourseHomeController extends ToolBaseController } } - $blocks = CourseHome::getUserBlocks(); - // Activity end + $blocks = CourseHome::getUserBlocks($toolChain); // Get session-career diagram $diagram = ''; @@ -487,7 +485,7 @@ class CourseHomeController extends ToolBaseController $em = $this->getDoctrine()->getManager(); $repo = $this->getDoctrine()->getRepository('ChamiloCourseBundle:CTool'); - $sessionId = intval($request->get('id_session')); + $sessionId = (int) $request->get('id_session'); $itemsFromSession = []; if (!empty($sessionId)) { $query = $repo->createQueryBuilder('a'); @@ -670,177 +668,6 @@ class CourseHomeController extends ToolBaseController return $this->redirect($url); } - /** - * @param string $title - * @param string $content - * @param string $class - * - * @return string - */ - private function return_block($title, $content, $class = null) - { - $html = '
-
-
'.$title.'
-
-
-
'.$content.'
'; - - return $html; - } - - /** - * @return array - */ - private function renderActivityView() - { - $session_id = api_get_session_id(); - $urlGenerator = $this->get('router'); - $content = ''; - - $enabled = api_get_plugin_setting('courselegal', 'tool_enable'); - $pluginExtra = null; - if ($enabled === 'true') { - /*require_once api_get_path(SYS_PLUGIN_PATH).'courselegal/config.php'; - $plugin = CourseLegalPlugin::create(); - $pluginExtra = $plugin->getTeacherLink();*/ - } - - // Start of tools for CourseAdmins (teachers/tutors) - $totalList = []; - - // Start of tools for CourseAdmins (teachers/tutors) - if ($session_id === 0 && api_is_course_admin() && api_is_allowed_to_edit(null, true)) { - $content .= '
- - -
'; - - $content .= $pluginExtra; - - if (api_get_setting('show_session_data') == 'true' && $session_id > 0) { - $content .= ' -
-
- '.get_lang('Session\'s data').' - '. - CourseHome::show_session_data($session_id).' -
-
-
'; - } - - $my_list = CourseHome::get_tools_category(TOOL_AUTHORING); - - $blocks[] = [ - 'title' => get_lang('Authoring'), - 'class' => 'course-tools-author', - 'content' => CourseHome::show_tools_category($my_list), - ]; - - $list1 = CourseHome::get_tools_category(TOOL_INTERACTION); - $list2 = CourseHome::get_tools_category(TOOL_COURSE_PLUGIN); - $my_list = array_merge($list1, $list2); - - $blocks[] = [ - 'title' => get_lang('Interaction'), - 'class' => 'course-tools-interaction', - 'content' => CourseHome::show_tools_category($my_list), - ]; - - $my_list = CourseHome::get_tools_category(TOOL_ADMIN_PLATFORM); - - $blocks[] = [ - 'title' => get_lang('Administration'), - 'class' => 'course-tools-administration', - 'content' => CourseHome::show_tools_category($my_list), - ]; - } elseif (api_is_coach()) { - $content .= $pluginExtra; - if (api_get_setting('show_session_data') === 'true' && $session_id > 0) { - $content .= '
-
- '.get_lang('Session\'s data').' - '; - $content .= CourseHome::show_session_data($session_id); - $content .= '
'; - } - - $my_list = CourseHome::get_tools_category(TOOL_STUDENT_VIEW); - - $blocks[] = [ - 'content' => CourseHome::show_tools_category($my_list), - ]; - - $sessionsCopy = api_get_setting('allow_session_course_copy_for_teachers'); - if ($sessionsCopy === 'true') { - // Adding only maintenance for coaches. - $myList = CourseHome::get_tools_category(TOOL_ADMIN_PLATFORM); - $onlyMaintenanceList = []; - - foreach ($myList as $item) { - if ($item['name'] === 'course_maintenance') { - $item['link'] = 'course_info/maintenance_coach.php'; - - $onlyMaintenanceList[] = $item; - } - } - - $blocks[] = [ - 'title' => get_lang('Administration'), - 'content' => CourseHome::show_tools_category($onlyMaintenanceList), - ]; - } - } else { - $tools = CourseHome::get_tools_category(TOOL_STUDENT_VIEW); - - $isDrhOfCourse = \CourseManager::isUserSubscribedInCourseAsDrh( - api_get_user_id(), - api_get_course_info() - ); - - // Force user icon for DRH - if ($isDrhOfCourse) { - $addUserTool = true; - foreach ($tools as $tool) { - if ($tool['name'] === 'user') { - $addUserTool = false; - break; - } - } - - if ($addUserTool) { - $tools[] = [ - 'c_id' => api_get_course_int_id(), - 'name' => 'user', - 'link' => 'user/user.php', - 'image' => 'members.gif', - 'visibility' => '1', - 'admin' => '0', - 'address' => 'squaregrey.gif', - 'added_tool' => '0', - 'target' => '_self', - 'category' => 'interaction', - 'session_id' => api_get_session_id(), - ]; - } - } - - if (count($tools) > 0) { - $blocks[] = ['content' => CourseHome::show_tools_category($tools)]; - } - - if ($isDrhOfCourse) { - $drhTool = CourseHome::get_tools_category(TOOL_DRH); - $blocks[] = ['content' => CourseHome::show_tools_category($drhTool)]; - } - } - - return $blocks; - } /** * @return array diff --git a/src/CoreBundle/Controller/ResourceController.php b/src/CoreBundle/Controller/ResourceController.php index 6558c6229d..c5a6a23ad9 100644 --- a/src/CoreBundle/Controller/ResourceController.php +++ b/src/CoreBundle/Controller/ResourceController.php @@ -130,6 +130,7 @@ class ResourceController extends AbstractResourceController implements CourseCon // The group 'resource' is set in the @GRID\Source annotation in the entity. $source = new Entity($class, 'resource'); + /** @var ResourceNode $parentNode */ $parentNode = $repository->getResourceNodeRepository()->find($resourceNodeId); $this->denyAccessUnlessGranted( diff --git a/src/CoreBundle/Entity/Listener/CourseListener.php b/src/CoreBundle/Entity/Listener/CourseListener.php index 5b939efb04..19eda0df64 100644 --- a/src/CoreBundle/Entity/Listener/CourseListener.php +++ b/src/CoreBundle/Entity/Listener/CourseListener.php @@ -52,13 +52,14 @@ class CourseListener public function prePersist(Course $course, LifecycleEventArgs $args) { /** @var AccessUrlRelCourse $urlRelCourse */ + if ($course) { /*$urlRelCourse = $course->getUrls()->first(); $url = $urlRelCourse->getUrl();*/ //$url = $course->getCurrentUrl(); //$repo = $args->getEntityManager()->getRepository('ChamiloCoreBundle:Course'); ///$this->checkLimit($repo, $course, $url); - $this->toolChain->addToolsInCourse($course, $this->settingsManager); + $this->toolChain->addToolsInCourse($args->getEntityManager(), $course, $this->settingsManager); } } diff --git a/src/CoreBundle/Entity/Tool.php b/src/CoreBundle/Entity/Tool.php index a195c3c64e..ade0d0d8c7 100644 --- a/src/CoreBundle/Entity/Tool.php +++ b/src/CoreBundle/Entity/Tool.php @@ -19,7 +19,7 @@ class Tool /** * @var int * - * @ORM\Column(name="id", type="integer", nullable=false, unique=false) + * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue */ @@ -28,7 +28,7 @@ class Tool /** * @var string * - * @ORM\Column(name="name", type="string", nullable=false, unique=false) + * @ORM\Column(name="name", type="string", nullable=false, unique=true) */ protected $name; diff --git a/src/CoreBundle/Resources/config/tools.yml b/src/CoreBundle/Resources/config/tools.yml index aed5a35305..bf4137c4a7 100644 --- a/src/CoreBundle/Resources/config/tools.yml +++ b/src/CoreBundle/Resources/config/tools.yml @@ -47,8 +47,8 @@ services: arguments: - 'agenda' - 'authoring' - - 'calendar/agenda.php' - - chamilo_course.settings.agenda + - '/main/calendar/agenda.php' + - '@chamilo_course.settings.agenda' - events: repository: Chamilo\CourseBundle\Repository\CCalendarEventRepository @@ -64,7 +64,7 @@ services: arguments: - 'announcement' - 'authoring' - - 'announcements/announcements.php' + - '/main/announcements/announcements.php' - '@chamilo_course.settings.announcement' - announcements: @@ -80,8 +80,8 @@ services: arguments: - 'student_publication' - 'interaction' - - 'work/work.php' - - chamilo_course.settings.assignment + - '/main/work/work.php' + - '@chamilo_course.settings.assignment' - student_publications: repository: Chamilo\CourseBundle\Repository\CStudentPublicationRepository @@ -96,7 +96,7 @@ services: arguments: - 'attendance' - 'authoring' - - 'attendance/index.php' + - '/main/attendance/index.php' - '@chamilo_course.settings.attendance' - attendances: @@ -110,7 +110,7 @@ services: arguments: - 'blog' - 'admin' - - 'blog/blog_admin.php' + - '/main/blog/blog_admin.php' - '@chamilo_course.settings.blog' - blogs: @@ -122,9 +122,9 @@ services: chamilo_core.tool.course_description: class: Chamilo\CoreBundle\Tool\CourseDescription arguments: - - course_description - - authoring - - course_description/index.php + - 'course_description' + - 'authoring' + - '/main/course_description/index.php' - '@chamilo_course.settings.course_description' - course_descriptions: @@ -136,9 +136,9 @@ services: chamilo_core.tool.chat: class: Chamilo\CoreBundle\Tool\Chat arguments: - - chat - - interaction - - chat/chat.php + - 'chat' + - 'interaction' + - '/main/chat/chat.php' - '@chamilo_course.settings.chat' - ~ - 0 @@ -148,9 +148,9 @@ services: chamilo_core.tool.course_progress: class: Chamilo\CoreBundle\Tool\CourseProgress arguments: - - course_progress - - authoring - - course_progress/index.php + - 'course_progress' + - 'authoring' + - '/main/course_progress/index.php' - '@chamilo_course.settings.course_progress' - thematics: @@ -166,9 +166,9 @@ services: chamilo_core.tool.document: class: Chamilo\CoreBundle\Tool\Document arguments: - - document - - authoring - - document/document.php + - 'document' + - 'authoring' + - '/resources/document/files' - '@chamilo_course.settings.document' - files: @@ -180,9 +180,9 @@ services: chamilo_core.tool.dropbox: class: Chamilo\CoreBundle\Tool\Dropbox arguments: - - dropbox - - interaction - - dropbox/index.php + - 'dropbox' + - 'interaction' + - '/main/dropbox/index.php' - '@chamilo_course.settings.dropbox' - dropbox: @@ -194,9 +194,9 @@ services: chamilo_core.tool.exercise: class: Chamilo\CoreBundle\Tool\Exercise arguments: - - quiz - - authoring - - exercise/exercise.php + - 'quiz' + - 'authoring' + - '/main/exercise/exercise.php' - '@chamilo_course.settings.exercise' - exercises: @@ -214,9 +214,9 @@ services: chamilo_core.tool.forum: class: Chamilo\CoreBundle\Tool\Forum arguments: - - forum - - interaction - - forum/index.php + - 'forum' + - 'interaction' + - '/main/forum/index.php' - '@chamilo_course.settings.forum' - forums: @@ -236,9 +236,9 @@ services: chamilo_core.tool.glossary: class: Chamilo\CoreBundle\Tool\Glossary arguments: - - glossary - - authoring - - glossary/index.php + - 'glossary' + - 'authoring' + - '/main/glossary/index.php' - '@chamilo_course.settings.glossary' - glossaries: @@ -250,9 +250,9 @@ services: chamilo_core.tool.gradebook: class: Chamilo\CoreBundle\Tool\Gradebook arguments: - - gradebook - - authoring - - gradebook/index.php + - 'gradebook' + - 'authoring' + - '/main/gradebook/index.php' - '@chamilo_course.settings.gradebook' - gradebook_categories: @@ -271,7 +271,7 @@ services: arguments: - 'group' - 'interaction' - - 'group/group.php' + - '/main/group/group.php' - '@chamilo_course.settings.group' - groups: @@ -289,7 +289,7 @@ services: arguments: - 'learnpath' - 'authoring' - - 'lp/lp_controller.php' + - '/main/lp/lp_controller.php' - '@chamilo_course.settings.learning_path' - lps: @@ -305,7 +305,7 @@ services: arguments: - 'link' - 'authoring' - - 'link/link.php' + - '/main/link/link.php' - '@chamilo_course.settings.link' - links: @@ -327,7 +327,7 @@ services: arguments: - 'member' - 'interaction' - - 'user/user.php' + - '/main/user/user.php' - '@chamilo_course.settings.user' - ~ - 0 @@ -339,7 +339,7 @@ services: arguments: - 'course_maintenance' - 'admin' - - 'course_info/maintenance.php' + - '/main/course_info/maintenance.php' - '@chamilo_course.settings.maintenance' - ~ - 0 @@ -351,7 +351,7 @@ services: arguments: - 'notebook' - 'interaction' - - 'notebook/index.php' + - '/main/notebook/index.php' - '@chamilo_course.settings.notebook' - notebooks: @@ -364,8 +364,8 @@ services: class: Chamilo\CoreBundle\Tool\Settings arguments: - 'course_setting' - - admin - - course_info/infocours.php + - 'admin' + - '/main/course_info/infocours.php' - '@chamilo_course.settings.settings' - ~ - 0 @@ -378,7 +378,7 @@ services: arguments: - 'survey' - 'interaction' - - 'survey/survey_list.php' + - '/main/survey/survey_list.php' - '@chamilo_course.settings.survey' - surveys: @@ -392,9 +392,9 @@ services: chamilo_core.tool.tracking: class: Chamilo\CoreBundle\Tool\Tracking arguments: - - tracking - - admin - - tracking/courseLog.php + - 'tracking' + - 'admin' + - '/main/tracking/courseLog.php' - '@chamilo_course.settings.tracking' - ~ - 0 @@ -404,8 +404,8 @@ services: chamilo_core.tool.user: class: Chamilo\CoreBundle\Tool\User arguments: - - user - - interaction + - 'user' + - 'interaction' - ~ - ~ - @@ -418,9 +418,9 @@ services: chamilo_core.tool.wiki: class: Chamilo\CoreBundle\Tool\Wiki arguments: - - wiki - - interaction - - wiki/index.php + - 'wiki' + - 'interaction' + - '/main/wiki/index.php' - '@chamilo_course.settings.wiki' - wikis: diff --git a/src/CoreBundle/ToolChain.php b/src/CoreBundle/ToolChain.php index 90b03101d9..bb8209e8b8 100644 --- a/src/CoreBundle/ToolChain.php +++ b/src/CoreBundle/ToolChain.php @@ -12,6 +12,7 @@ use Chamilo\CoreBundle\Tool\AbstractTool; use Chamilo\CourseBundle\Entity\CTool; use Chamilo\SettingsBundle\Manager\SettingsManager; use Doctrine\Common\Persistence\ObjectManager; +use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\PropertyAccess\Exception\InvalidArgumentException; /** @@ -154,26 +155,30 @@ class ToolChain $tool->addToolResourceRight($toolResourceRightReader); } - public function addToolsInCourse(Course $course, SettingsManager $settingsManager): Course + public function addToolsInCourse(EntityManagerInterface $manager, Course $course, SettingsManager $settingsManager): Course { $tools = $this->getTools(); $toolVisibility = $settingsManager->getSetting('course.active_tools_on_create'); + /** @var AbstractTool $tool */ foreach ($tools as $tool) { - $toolEntity = new CTool(); - $visibility = in_array($tool->getName(), $toolVisibility); + $courseTool = new CTool(); + $visibility = in_array($tool->getName(), $toolVisibility, true); + $criteria = ['name' => $tool->getName()]; + $toolEntity = $manager->getRepository('ChamiloCoreBundle:Tool')->findOneBy($criteria); - $toolEntity + $courseTool + ->setTool($toolEntity) ->setCourse($course) - ->setImage($tool->getImage()) - ->setName($tool->getName()) + //->setImage($tool->getImage()) + //->setName($tool->getName()) ->setVisibility($visibility) - ->setLink($tool->getLink()) - ->setTarget($tool->getTarget()) + //->setLink($tool->getLink()) + //->setTarget($tool->getTarget()) ->setCategory($tool->getCategory()); - $course->addTools($toolEntity); + $course->addTools($courseTool); } return $course; diff --git a/src/CourseBundle/Entity/CTool.php b/src/CourseBundle/Entity/CTool.php index 534660e7cb..ff21ce4a2a 100644 --- a/src/CourseBundle/Entity/CTool.php +++ b/src/CourseBundle/Entity/CTool.php @@ -4,6 +4,8 @@ namespace Chamilo\CourseBundle\Entity; use Chamilo\CoreBundle\Entity\Course; +use Chamilo\CoreBundle\Entity\Session; +use Chamilo\CoreBundle\Entity\Tool; use Doctrine\ORM\Event\LifecycleEventArgs; use Doctrine\ORM\Mapping as ORM; @@ -22,8 +24,6 @@ use Doctrine\ORM\Mapping as ORM; */ class CTool { - protected $originalImage; - /** * @var int * @@ -40,27 +40,6 @@ class CTool */ protected $id; - /** - * @var string - * - * @ORM\Column(name="name", type="text", nullable=false) - */ - protected $name; - - /** - * @var string - * - * @ORM\Column(name="link", type="string", length=255, nullable=false) - */ - protected $link; - - /** - * @var string - * - * @ORM\Column(name="image", type="string", length=255, nullable=true) - */ - protected $image; - /** * @var bool * @@ -68,34 +47,6 @@ class CTool */ protected $visibility; - /** - * @var string - * - * @ORM\Column(name="admin", type="string", length=255, nullable=true) - */ - protected $admin; - - /** - * @var string - * - * @ORM\Column(name="address", type="string", length=255, nullable=true) - */ - protected $address; - - /** - * @var bool - * - * @ORM\Column(name="added_tool", type="boolean", nullable=true) - */ - protected $addedTool; - - /** - * @var string - * - * @ORM\Column(name="target", type="string", length=20, nullable=false) - */ - protected $target; - /** * @var string * @@ -104,33 +55,35 @@ class CTool protected $category; /** - * @var int + * @var string * - * @ORM\Column(name="session_id", type="integer", nullable=true) + * @ORM\Column(name="custom_icon", type="string", length=255, nullable=true) */ - protected $sessionId; + protected $customIcon; /** - * @var string + * @var Course * - * @ORM\Column(name="description", type="text", nullable=true) + * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Course", inversedBy="tools") + * @ORM\JoinColumn(name="c_id", referencedColumnName="id", nullable=false) */ - protected $description; + protected $course; /** - * @var string + * @var Session * - * @ORM\Column(name="custom_icon", type="string", length=255, nullable=true) + * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Session") + * @ORM\JoinColumn(name="session_id", referencedColumnName="id", nullable=true) */ - protected $customIcon; + protected $session; /** - * @var Course + * @var Tool * - * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Course", inversedBy="tools") - * @ORM\JoinColumn(name="c_id", referencedColumnName="id", nullable=false) + * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Tool") + * @ORM\JoinColumn(name="tool_id", referencedColumnName="id", nullable=false) */ - protected $course; + protected $tool; /** * Constructor. @@ -139,8 +92,6 @@ class CTool { // Default values $this->id = 0; - $this->sessionId = 0; - $this->address = 'squaregrey.gif'; } /** @@ -178,89 +129,37 @@ class CTool return $this->course; } - public static function loadValidatorMetadata(ClassMetadata $metadata) - { - $metadata->addPropertyConstraint( - 'customIcon', - new Assert\File(['mimeTypes' => ['image/png']]) - ); - $metadata->addPropertyConstraint( - 'customIcon', - new Assert\Image(['maxWidth' => 64, 'minHeight' => 64]) - ); - $metadata->addPropertyConstraint('cId', new Assert\NotBlank()); - } - - /** - * Set name. - * - * @param string $name - * - * @return CTool - */ - public function setName($name) - { - $this->name = $name; - - return $this; - } - - /** - * Get name. - * - * @return string - */ - public function getName() - { - return $this->name; - } - /** - * Set link. - * - * @param string $link - * - * @return CTool + * @return Session */ - public function setLink($link) + public function getSession(): ?Session { - $this->link = $link; - - return $this; + return $this->session; } /** - * Get link. - * - * @return string - */ - public function getLink() - { - return $this->link; - } - - /** - * Set image. - * - * @param string $image + * @param Session $session * * @return CTool */ - public function setImage($image) + public function setSession(Session $session = null): CTool { - $this->image = $image; + $this->session = $session; return $this; } - /** - * Get image. - * - * @return string - */ - public function getImage() + public static function loadValidatorMetadata(ClassMetadata $metadata) { - return $this->image; + /*$metadata->addPropertyConstraint( + 'customIcon', + new Assert\File(['mimeTypes' => ['image/png']]) + ); + $metadata->addPropertyConstraint( + 'customIcon', + new Assert\Image(['maxWidth' => 64, 'minHeight' => 64]) + ); + $metadata->addPropertyConstraint('cId', new Assert\NotBlank());*/ } /** @@ -287,102 +186,6 @@ class CTool return $this->visibility; } - /** - * Set admin. - * - * @param string $admin - * - * @return CTool - */ - public function setAdmin($admin) - { - $this->admin = $admin; - - return $this; - } - - /** - * Get admin. - * - * @return string - */ - public function getAdmin() - { - return $this->admin; - } - - /** - * Set address. - * - * @param string $address - * - * @return CTool - */ - public function setAddress($address) - { - $this->address = $address; - - return $this; - } - - /** - * Get address. - * - * @return string - */ - public function getAddress() - { - return $this->address; - } - - /** - * Set addedTool. - * - * @param bool $addedTool - * - * @return CTool - */ - public function setAddedTool($addedTool) - { - $this->addedTool = $addedTool; - - return $this; - } - - /** - * Get addedTool. - * - * @return bool - */ - public function getAddedTool() - { - return $this->addedTool; - } - - /** - * Set target. - * - * @param string $target - * - * @return CTool - */ - public function setTarget($target) - { - $this->target = $target; - - return $this; - } - - /** - * Get target. - * - * @return string - */ - public function getTarget() - { - return $this->target; - } - /** * Set category. * @@ -407,30 +210,6 @@ class CTool return $this->category; } - /** - * Set sessionId. - * - * @param int $sessionId - * - * @return CTool - */ - public function setSessionId($sessionId) - { - $this->sessionId = $sessionId; - - return $this; - } - - /** - * Get sessionId. - * - * @return int - */ - public function getSessionId() - { - return $this->sessionId; - } - /** * Set id. * @@ -458,39 +237,39 @@ class CTool /** * @return string */ - public function getDescription() + public function getCustomIcon() { - return $this->description; + return $this->customIcon; } /** - * @param string $description + * @param string $customIcon * * @return CTool */ - public function setDescription($description) + public function setCustomIcon($customIcon) { - $this->description = $description; + $this->customIcon = $customIcon; return $this; } /** - * @return string + * @return Tool */ - public function getCustomIcon() + public function getTool(): Tool { - return $this->customIcon; + return $this->tool; } /** - * @param string $customIcon + * @param Tool $tool * * @return CTool */ - public function setCustomIcon($customIcon) + public function setTool(Tool $tool): CTool { - $this->customIcon = $customIcon; + $this->tool = $tool; return $this; } diff --git a/src/ThemeBundle/Resources/views/Course/home.html.twig b/src/ThemeBundle/Resources/views/Course/home.html.twig index 638156551d..e775e5eca2 100644 --- a/src/ThemeBundle/Resources/views/Course/home.html.twig +++ b/src/ThemeBundle/Resources/views/Course/home.html.twig @@ -71,14 +71,19 @@ }); - {% if app.user.status != 5 %} + {% if app.user.status != 5 %}
{% for block in blocks %}
{% if block.title %}
- + {{ block.title }}
@@ -87,36 +92,27 @@
- {% if 'homepage_view'|api_get_setting == 'activity' %} - {% for item in block.content %} -
- {{ item.extra|raw }} - {{ item.visibility|raw }} - {{ item.icon|raw }} - {{ item.link|raw }} -
- {% endfor %} - {% endif %} - {% if 'homepage_view'|api_get_setting == 'activity_big' %} - {% for item in block.content %} -
-
-
- {{ item.tool.image|raw }} -
-
- {{ item.extra|raw }} - {{ item.link|raw }} - {% if item.visibility is not empty %} -
- {{ item.visibility|raw }} -
- {% endif %} -
+ {% for item in block.content %} +
+
+
+ + + +
+
+ + {{ item.tool.tool.name }} + + {% if item.visibility is not empty %} +
+{# {{ item.visibility|raw }}#} +
+ {% endif %}
- {% endfor %} - {% endif %} +
+ {% endfor %}
@@ -125,29 +121,24 @@ {% else %}
{% for block in blocks %} - {% if 'homepage_view'|api_get_setting == 'activity_big' %} - {% for item in block.content %} -
-
-
- {{ item.tool.image|raw }} -
-
- {{ item.extra|raw }} - {{ item.link|raw }} - {% if item.visibility is not empty %} -
- {{ item.visibility|raw }} -
- {% endif %} -
+ {% for item in block.content %} +
+ - {% endfor %} - {% endif %} +
+ {% endfor %} {% endfor %}
{% endif %} - {% endautoescape %} {% endblock %}