예제 #1
0
 /**
  * Gets the tools of a certain category. Returns an array expected
  * by show_tools_category()
  * @param string $course_tool_category	contains the category of tools to
  * display: "toolauthoring", "toolinteraction", "tooladmin", "tooladminplatform", "toolplugin"
  * @return array
  */
 public static function get_tools_category($course_tool_category)
 {
     $course_tool_table = Database::get_course_table(TABLE_TOOL_LIST);
     $is_platform_admin = api_is_platform_admin();
     $all_tools_list = array();
     // Condition for the session
     $session_id = api_get_session_id();
     $course_id = api_get_course_int_id();
     $condition_session = api_get_session_condition($session_id, true, true, 't.session_id');
     switch ($course_tool_category) {
         case TOOL_STUDENT_VIEW:
             $conditions = ' WHERE visibility = 1 AND (category = "authoring" OR category = "interaction" OR category = "plugin") ';
             if ((api_is_coach() || api_is_course_tutor()) && $_SESSION['studentview'] != 'studentview') {
                 $conditions = ' WHERE (visibility = 1 AND (category = "authoring" OR category = "interaction" OR category = "plugin") OR (name = "' . TOOL_TRACKING . '") )   ';
             }
             $sql = "SELECT *\n                        FROM {$course_tool_table} t\n                        {$conditions} AND\n                        c_id = {$course_id} {$condition_session}\n                        ORDER BY id";
             $result = Database::query($sql);
             break;
         case TOOL_AUTHORING:
             $sql = "SELECT * FROM {$course_tool_table} t\n                        WHERE category = 'authoring' AND c_id = {$course_id} {$condition_session}\n                        ORDER BY id";
             $result = Database::query($sql);
             break;
         case TOOL_INTERACTION:
             $sql = "SELECT * FROM {$course_tool_table} t\n                        WHERE category = 'interaction' AND c_id = {$course_id} {$condition_session}\n                        ORDER BY id";
             $result = Database::query($sql);
             break;
         case TOOL_ADMIN_VISIBLE:
             $sql = "SELECT * FROM {$course_tool_table} t\n                        WHERE category = 'admin' AND visibility ='1' AND c_id = {$course_id} {$condition_session}\n                        ORDER BY id";
             $result = Database::query($sql);
             break;
         case TOOL_ADMIN_PLATFORM:
             $sql = "SELECT * FROM {$course_tool_table} t\n                        WHERE category = 'admin' AND c_id = {$course_id} {$condition_session}\n                        ORDER BY id";
             $result = Database::query($sql);
             break;
         case TOOL_DRH:
             $sql = "SELECT * FROM {$course_tool_table} t\n                        WHERE name IN ('tracking') AND c_id = {$course_id} {$condition_session}\n                        ORDER BY id";
             $result = Database::query($sql);
             break;
         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\n                        WHERE category = 'plugin' AND c_id = {$course_id} {$condition_session}\n                        ORDER BY id";
             $result = Database::query($sql);
             break;
     }
     //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 = array();
     $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' and $line['selected_value'] == 'true') {
             $hide_list[] = $line['subkey'];
             $check = true;
         }
     }
     while ($temp_row = Database::fetch_assoc($result)) {
         $add = false;
         if ($check) {
             if (!in_array($temp_row['name'], $hide_list)) {
                 $add = true;
             }
         } else {
             $add = true;
         }
         if ($temp_row['image'] == 'scormbuilder.gif') {
             $lp_id = self::get_published_lp_id_from_link($temp_row['link']);
             $lp = new learnpath(api_get_course_id(), $lp_id, api_get_user_id());
             $path = $lp->get_preview_image_path(ICON_SIZE_BIG);
             $add = $lp->is_lp_visible_for_student($lp_id, api_get_user_id(), api_get_course_id(), api_get_session_id());
             if ($path) {
                 $temp_row['custom_image'] = $path;
             }
         }
         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($session_id, true, true, 'tip.session_id');
     switch ($course_tool_category) {
         case TOOL_AUTHORING:
             $sql_links = "SELECT tl.*, tip.visibility\n                    FROM {$course_link_table} tl\n                    LEFT JOIN {$course_item_property_table} tip\n                    ON tip.tool='link' AND tip.ref=tl.id\n                    WHERE\n                        tl.c_id = {$course_id} AND\n                        tip.c_id = {$course_id} AND\n                        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\n                    FROM {$course_link_table} tl\n                    LEFT JOIN {$course_item_property_table} tip\n                    ON tip.tool='link' AND tip.ref=tl.id\n                    WHERE\n                        tl.c_id \t\t= {$course_id} AND\n                        tip.c_id \t\t= {$course_id} AND\n                        tl.on_homepage\t='1' {$condition_session}";
             break;
         case TOOL_ADMIN:
             $sql_links = "SELECT tl.*, tip.visibility\n                    FROM {$course_link_table} tl\n                    LEFT JOIN {$course_item_property_table} tip\n                    ON tip.tool='link' AND tip.ref=tl.id\n                    WHERE\n                        tl.c_id = {$course_id} AND\n                        tip.c_id = {$course_id} AND\n                        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 = array();
                 $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)) {
         foreach ($tmp_all_tools_list as $tool) {
             if ($tool['image'] == 'blog.gif') {
                 // Init
                 $tbl_blogs_rel_user = Database::get_course_table(TABLE_BLOGS_REL_USER);
                 // Get blog id
                 $blog_id = substr($tool['link'], strrpos($tool['link'], '=') + 1, strlen($tool['link']));
                 // Get blog members
                 if ($is_platform_admin) {
                     $sql_blogs = "SELECT * FROM {$tbl_blogs_rel_user} blogs_rel_user\n                                      WHERE blog_id =" . $blog_id;
                 } else {
                     $sql_blogs = "SELECT * FROM {$tbl_blogs_rel_user} blogs_rel_user\n                                      WHERE blog_id =" . $blog_id . " AND user_id = " . api_get_user_id();
                 }
                 $result_blogs = Database::query($sql_blogs);
                 if (Database::num_rows($result_blogs) > 0) {
                     $all_tools_list[] = $tool;
                 }
             } else {
                 $all_tools_list[] = $tool;
             }
         }
     }
     return $all_tools_list;
 }
예제 #2
0
 /**
  * Displays the tools of a certain category.
  * @param Symfony\Component\Routing\RouterInterface $urlGenerator
  * @param array List of tools as returned by get_tools_category()
  * @param bool rows
  * @return string
  */
 public static function show_tools_category($urlGenerator, $toolList, $rows = false)
 {
     $rowDiv = '<div class="row">';
     $theme = api_get_setting('homepage_view');
     if ($theme == 'vertical_activity') {
         //ordering by get_lang name
         $order_tool_list = array();
         if (is_array($toolList) && count($toolList) > 0) {
             foreach ($toolList 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 = array();
             foreach ($order_tool_list as $key => $new_tool) {
                 $my_temp_tool_array[] = $toolList[$key];
             }
             $toolList = $my_temp_tool_array;
         } else {
             $toolList = array();
         }
     }
     $courseInfo = api_get_course_info();
     $web_code_path = api_get_path(WEB_CODE_PATH);
     $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
     $is_platform_admin = api_is_platform_admin();
     $session_id = api_get_session_id();
     $items = array();
     $app_plugin = new AppPlugin();
     if (isset($toolList)) {
         $lnk = '';
         foreach ($toolList as &$tool) {
             $item = array();
             $tool['admin'] = isset($tool['admin']) ? $tool['admin'] : null;
             $tool['id'] = isset($tool['id']) ? $tool['id'] : null;
             $tool['target'] = isset($tool['target']) ? $tool['target'] : null;
             if (isset($tool['link_id'])) {
                 $tool['original_link'] = api_get_path(WEB_CODE_PATH) . 'link/link_goto.php?link_id=' . $tool['link_id'] . '&' . api_get_cidreq();
                 $tool['link'] = $tool['original_link'];
             } else {
                 $tool['original_link'] = $tool['link'];
             }
             // Re-writing URL for new tools
             $newTools = array(TOOL_CURRICULUM);
             $toolName = isset($tool['name']) ? $tool['name'] : null;
             if (in_array($toolName, $newTools)) {
                 $tool['link'] = $courseInfo['course_web_public_url'] . $tool['name'] . '/';
             }
             if ($tool['image'] == 'scormbuilder.gif') {
                 // Check if the published learnpath is visible for student
                 $published_lp_id = self::get_published_lp_id_from_link($tool['link']);
                 if (!api_is_allowed_to_edit(null, true) && !learnpath::is_lp_visible_for_student($published_lp_id, api_get_user_id())) {
                     continue;
                 }
             }
             if ($session_id != 0 && in_array($tool['name'], array('course_maintenance', 'course_setting'))) {
                 continue;
             }
             if ($tool['name'] == 'course_description') {
                 $tool['link'] = 'course_description/index.php';
             }
             // 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;
             if ($is_allowed_to_edit && !api_is_coach()) {
                 if (empty($session_id)) {
                     if ($tool['visibility'] == '1' && $tool['admin'] != '1') {
                         $link['name'] = Display::return_icon('visible.gif', get_lang('Deactivate'), array('id' => 'linktool_' . $tool['id']), ICON_SIZE_MEDIUM, false);
                         if (!empty($tool['id'])) {
                             $link['cmd'] = $urlGenerator->generate('course_home.controller:hideIconAction', array('course' => api_get_course_id(), 'iconId' => $tool['id']));
                         }
                         $lnk[] = $link;
                     }
                     if ($tool['visibility'] == '0' && $tool['admin'] != '1') {
                         $link['name'] = Display::return_icon('invisible.gif', get_lang('Activate'), array('id' => 'linktool_' . $tool['id']), ICON_SIZE_MEDIUM, false);
                         if (!empty($tool['id'])) {
                             $link['cmd'] = $urlGenerator->generate('course_home.controller:showIconAction', array('course' => api_get_course_id(), 'iconId' => $tool['id']));
                         }
                         $lnk[] = $link;
                     }
                 }
                 if (!empty($tool['adminlink'])) {
                     $item['extra'] = '<a href="' . $tool['adminlink'] . '">' . Display::return_icon('edit.gif', get_lang('Edit')) . '</a>';
                 }
             }
             // Both checks are necessary as is_platform_admin doesn't take student view into account
             if ($is_platform_admin && $is_allowed_to_edit) {
                 if ($tool['admin'] != '1') {
                     $link['cmd'] = 'hide=yes';
                 }
             }
             $item['visibility'] = null;
             if (isset($lnk) && is_array($lnk)) {
                 foreach ($lnk as $this_link) {
                     if (empty($tool['adminlink'])) {
                         $item['visibility'] .= '<a class="make_visible_and_invisible" href="' . $this_link['cmd'] . '">' . $this_link['name'] . '</a>';
                     }
                 }
             } else {
                 $item['visibility'] .= null;
             }
             // 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'];
             }
             if (!empty($tool['custom_icon'])) {
                 $tool['image'] = self::getCustomIconPath($courseInfo) . $tool['custom_icon'];
             }
             if ($tool['visibility'] == '0' && $tool['admin'] != '1') {
                 $class = 'invisible';
                 $info = pathinfo($tool['image']);
                 $dirName = null;
                 if ($info['dirname'] != '.') {
                     $dirName = $info['dirname'] . '/';
                 }
                 $basename = basename($tool['image'], '.' . $info['extension']);
                 // $file is set to "index"
                 $tool['image'] = $dirName . $basename . '_na.' . $info['extension'];
             } else {
                 $class = '';
             }
             $qm_or_amp = strpos($tool['link'], '?') === false ? '?' : '&';
             // If it's a link, we don't add the cidReq
             if ($tool['image'] == 'file_html.gif' || $tool['image'] == 'file_html_na.gif') {
                 $tool['link'] = $tool['link'] . $qm_or_amp;
             } else {
                 $tool['link'] = $tool['link'] . $qm_or_amp . api_get_cidreq();
             }
             $tool_link_params = array();
             //@todo this visio stuff should be removed
             if (strpos($tool['name'], 'visio_') !== false) {
                 $tool_link_params = array('id' => 'tooldesc_' . $tool["id"], 'href' => '"javascript: void(0);"', 'class' => $class, 'onclick' => 'javascript: window.open(\'' . $tool['link'] . '\',\'window_visio' . $_SESSION['_cid'] . '\',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 = array('id' => 'tooldesc_' . $tool["id"], 'class' => $class, 'href' => 'javascript: void(0);', 'onclick' => 'javascript: window.open(\'' . $tool['link'] . '\',\'window_chat' . $_SESSION['_cid'] . '\',config=\'height=\'+380+\', width=\'+625+\', left=2, top=2, toolbar=no, menubar=no, scrollbars=yes, resizable=yes, location=no, directories=no, status=no\')', 'target' => $tool['target']);
             } else {
                 if (count(explode('type=classroom', $tool['link'])) == 2 || count(explode('type=conference', $tool['link'])) == 2) {
                     $tool_link_params = array('id' => 'tooldesc_' . $tool["id"], 'href' => $tool['link'], 'class' => $class, 'target' => '_blank');
                 } else {
                     $tool_link_params = array('id' => 'tooldesc_' . $tool["id"], 'href' => $tool['link'], 'class' => $class, 'target' => $tool['target']);
                 }
             }
             $tool_name = self::translate_tool_name($tool);
             $toolTip = $tool_name;
             if (!empty($tool['description'])) {
                 $toolTip = $tool['description'];
             }
             $tool_link_params['data-original-title'] = $toolTip;
             $tool_link_params['data-toggle'] = 'tooltip';
             //$tool_link_params['title'] = $toolTip;
             // Including Courses Plugins
             // Creating title and the link
             if (isset($tool['category']) && $tool['category'] == 'plugin') {
                 $plugin_info = $app_plugin->get_plugin_info($tool['name']);
                 if (isset($plugin_info) && isset($plugin_info['title'])) {
                     $tool_name = $plugin_info['title'];
                 }
                 $tool_link_params['href'] = api_get_path(WEB_PLUGIN_PATH) . $tool['original_link'] . '?' . api_get_cidreq();
             }
             if (!empty($tool['custom_icon'])) {
                 //self::getCustomIconPath($courseInfo)
                 $icon = Display::img($tool['image'], null, array('class' => 'tool-icon', 'id' => 'toolimage_' . $tool['id']));
             } else {
                 $image = substr($tool['image'], 0, strpos($tool['image'], '.')) . '.png';
                 $icon = Display::return_icon($image, null, array('class' => 'tool-icon', 'id' => 'toolimage_' . $tool['id']), ICON_SIZE_BIG, false);
             }
             $userInfo = api_get_user_info();
             $userStatus = isset($userInfo['status']) ? $userInfo['status'] : null;
             // Validation when belongs to a session
             $session_img = api_get_session_image($tool['session_id'], $userStatus);
             $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;
             $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;
         }
         // end of foreach
     }
     $i = 0;
     $html = '';
     $counter = 0;
     if (!empty($items)) {
         foreach ($items as $item) {
             switch ($theme) {
                 case 'activity_big':
                     $data = '';
                     if ($counter == 0) {
                         $html .= $rowDiv;
                     }
                     $html .= '<div class="col-xs-4 col-md-4 course-tool">';
                     $image = substr($item['tool']['image'], 0, strpos($item['tool']['image'], '.')) . '.png';
                     if (!empty($item['tool']['custom_icon'])) {
                         $original_image = Display::img($item['tool']['image'], null, array('id' => 'toolimage_' . $item['tool']['id']));
                     } else {
                         $original_image = Display::return_icon($image, null, array('id' => 'toolimage_' . $item['tool']['id']), ICON_SIZE_BIG, false);
                     }
                     switch ($image) {
                         case 'scormbuilder.png':
                             if (api_is_allowed_to_edit(null, true)) {
                                 $item['url_params']['href'] .= '&isStudentView=true';
                             }
                             $image = $original_image;
                             $lp_id = self::get_published_lp_id_from_link($item['link']);
                             if ($lp_id) {
                                 $lp = new learnpath(api_get_course_id(), $lp_id, api_get_user_id());
                                 $path = $lp->get_preview_image_path(64);
                                 if ($path) {
                                     $image = '<img src="' . $path . '">';
                                 }
                             }
                             break;
                         default:
                             $image = $original_image;
                     }
                     $data .= Display::url($image, $item['url_params']['href'], $item['url_params']);
                     $html .= Display::div($data, array('class' => 'big_icon'));
                     //box-image reflection
                     $html .= Display::div('<h4>' . $item['visibility'] . $item['extra'] . $item['link'] . '</h4>', array('class' => 'content'));
                     $html .= '</div>';
                     if ($counter == 2) {
                         $html .= '</div>';
                         $counter = -1;
                     }
                     $counter++;
                     break;
                 case 'activity':
                     if ($counter == 0) {
                         $html .= $rowDiv;
                     }
                     $html .= '<div class="col-md-6 course-tool">';
                     $content = $item['extra'];
                     $content .= $item['visibility'];
                     $content .= $item['icon'];
                     $content .= $item['link'];
                     $html .= Display::div($content, array('class' => 'activity_content'));
                     $html .= '</div>';
                     if ($counter == 1) {
                         $html .= '</div>';
                         $counter = -1;
                     }
                     $counter++;
                     break;
                 case 'vertical_activity':
                     if ($i == 0) {
                         $html .= '<ul>';
                     }
                     $html .= '<li class="course-tool">';
                     $html .= $item['extra'];
                     $html .= $item['visibility'];
                     $html .= $item['icon'];
                     $html .= $item['link'];
                     $html .= '</li>';
                     if ($i == count($items) - 1) {
                         $html .= '</ul>';
                     }
                     break;
             }
             $i++;
         }
     }
     return array('content' => $html, 'tool_list' => $items);
 }