/** * Get the complete course tree of a specific category and for a specific * user. * Note that only the courses contained in the category and for which the * user is enrolled will be in the result. * * @param int user id * @param int category id * @return CourseTreeView */ public static function getUserCategoryCourseTreeView($userId, $categoryId) { // CourseListIterator $courseList = new UserCategoryCourseList($userId, $categoryId); $courseListIterator = $courseList->getIterator(); // User rights $privilegeList = new CourseUserPrivilegesList($userId); $privilegeList->load(); // Hot courses $notifiedCourseList = new NotifiedCourseList($userId); // User categories $userCategoryList = ClaroCategory::getUserCategories($userId); // Selected category $selectedCategoryId = isset($_REQUEST['viewCategory']) ? (int) $_REQUEST['viewCategory'] : null; // Course tree $courseTree = new CourseTree($courseListIterator); // View $courseTreeView = new CourseTreeView($courseTree->getRootNode(), $privilegeList, $notifiedCourseList, $userCategoryList, $selectedCategoryId, null); return $courseTreeView; }
/** * Returns a courses list for the current user. * * @return string list of courses (HTML format) * @deprecated use UserCourseList and CourseTreeView instead */ function render_user_course_list() { // Get the list of personnal courses marked as contening new events $date = Claroline::getInstance()->notification->get_notification_date(claro_get_current_user_id()); $modified_course = Claroline::getInstance()->notification->get_notified_courses($date, claro_get_current_user_id()); // Get all the user's courses $userCourseList = claro_get_user_course_list(); // Use the course id as array index, exclude disable courses // and flag hot courses $reorganizedUserCourseList = array(); $tempSessionCourses = array(); foreach ($userCourseList as $course) { // Do not include "disable", "pending", "trash" or "date" courses // (if we're not in the date limits) $curdate = claro_mktime(); $courseIsEnable = (bool) ($course['status'] == 'enable' || $course['status'] == 'date' && (!isset($course['creationDate']) || strtotime($course['creationDate']) <= $curdate) && (!isset($course['expirationDate']) || strtotime($course['expirationDate']) >= $curdate)); // Flag hot courses $course['hot'] = (bool) in_array($course['sysCode'], $modified_course); if (!isset($reorganizedUserCourseList[$course['courseId']]) && $courseIsEnable) { // If it's not a session course, include it in the final list if (empty($course['sourceCourseId'])) { $reorganizedUserCourseList[$course['courseId']] = $course; } else { $tempSessionCourses[$course['sourceCourseId']][] = $course; } } } unset($userCourseList); // Merge courses and their session courses (if any) foreach ($tempSessionCourses as $sourceCourseId => $sessionCourses) { /* * Sometimes, a session course could not find its associated source * course in the user course list. Simply because, for some reason, * this user isn't registered to the source course anymore, but is * still registered in the session course. */ if (!empty($reorganizedUserCourseList[$sourceCourseId])) { $reorganizedUserCourseList[$sourceCourseId]['sessionCourses'] = $sessionCourses; } else { foreach ($sessionCourses as $course) { $reorganizedUserCourseList[$course['courseId']] = $course; } } } unset($tempSessionCourses); // Now, $reorganizedUserCourseList contains all user's courses and, for // each course, its eventual session courses. // Display $out = ''; // Courses organized by categories if (get_conf('userCourseListGroupByCategories')) { // Get all the categories names (used to build trails) $categoryList = ClaroCategory::getAllCategories(0, 0, 1); // Get the categories informations for these courses $userCategoryList = ClaroCategory::getCoursesCategories($reorganizedUserCourseList); // Use the category id as array index $reorganizedUserCategoryList = array(); foreach ($userCategoryList as $category) { // Flag root courses and put it aside $reorganizedUserCourseList[$category['courseId']]['rootCourse'] = 0; if ($category['rootCourse']) { $reorganizedUserCourseList[$category['courseId']]['rootCourse'] = 1; } if (!isset($reorganizedUserCategoryList[$category['categoryId']])) { $reorganizedUserCategoryList[$category['categoryId']] = $category; //We won't need that key anymore unset($reorganizedUserCategoryList[$category['categoryId']]['courseId']); } // Initialise the category's course list $reorganizedUserCategoryList[$category['categoryId']]['courseList'] = array(); } // Place courses in the right categories and build categories' trails $currentCategoryId = null; foreach ($userCategoryList as $category) { // Build the full trail for each category (excepted root category) if ($category['categoryId'] == 0) { $trail = $category['name']; } else { $trail = build_category_trail($categoryList, $category['categoryId']); } $reorganizedUserCategoryList[$category['categoryId']]['trail'] = $trail; // Put root courses aside if ($reorganizedUserCourseList[$category['courseId']]['rootCourse']) { $reorganizedUserCategoryList[$category['categoryId']]['rootCourse'] = $reorganizedUserCourseList[$category['courseId']]; } else { // Do not include source courses (only display session courses) // (excepted if the user is manager of the course) if (!$reorganizedUserCourseList[$category['courseId']]['isSourceCourse'] || $reorganizedUserCourseList[$category['courseId']]['isCourseManager']) { $reorganizedUserCategoryList[$category['categoryId']]['courseList'][] = $reorganizedUserCourseList[$category['courseId']]; } } } unset($userCategoryList); if (count($reorganizedUserCategoryList) > 0) { $out .= '<dl class="courseList">'; foreach ($reorganizedUserCategoryList as $category) { if (!empty($category['courseList']) || !empty($category['rootCourse'])) { $out .= '<dt>' . "\n" . '<h4 id="' . $category['categoryId'] . '">' . $category['trail'] . (!empty($category['rootCourse']) ? ' [<a href="' . get_path('url') . '/claroline/course/index.php?cid=' . claro_htmlspecialchars($category['rootCourse']['sysCode']) . '">' . get_lang('Infos') . '</a>]' : '') . '</h4>' . "\n" . '</dt>' . "\n"; if (!empty($category['courseList'])) { foreach ($category['courseList'] as $course) { $out .= render_course_in_dl_list($course, $course['hot']); } } else { $out .= '<dt>' . get_lang('There are no courses in this category') . '</dt>'; } } } } $out .= '</dl>'; } else { if (count($reorganizedUserCourseList) > 0) { $out .= '<dl class="courseList">'; foreach ($reorganizedUserCourseList as $course) { $displayIconAccess = $course['isCourseManager'] || claro_is_platform_admin() ? true : false; $out .= render_course_in_dl_list($course, $course['hot'], $displayIconAccess); } $out .= '</dl>' . "\n"; } } return $out; }
} elseif (claro_failure::get_last_failure() == 'category_self_linked') { $dialogBox->error(get_lang('Category can\'t be its own parent')); } elseif (claro_failure::get_last_failure() == 'category_child_linked') { $dialogBox->error(get_lang('Category can\'t be linked to one of its own children')); } elseif (claro_failure::get_last_failure() == 'category_missing_field') { $dialogBox->error(get_lang('Some fields are missing')); } $dialogBox->form($category->displayForm()); } break; // Delete an existing category // Delete an existing category case 'exDelete': $category = new claroCategory(); if ($category->load($id)) { if (ClaroCategory::countSubCategories($category->id) > 0) { $dialogBox->error(get_lang('You cannot delete a category having sub categories')); } else { $category->delete(); $dialogBox->success(get_lang('Category deleted. Courses linked to this category have been linked to the root category.')); } } else { $dialogBox->error(get_lang('Category not found')); } break; // Shift or displace category (up) // Shift or displace category (up) case 'exMoveUp': $category = new claroCategory(); if ($category->load($id)) { $category->decreaseRank();
} else { $intitule = ""; } if (isset($_REQUEST['category'])) { $category = $_REQUEST['category']; } else { $category = ""; } if (isset($_REQUEST['searchLang'])) { $searchLang = $_REQUEST['searchLang']; } else { $searchLang = ""; } // Search needed info in db to create the right formulaire $arrayFaculty = course_category_get_list(); $category_array = ClaroCategory::getAllCategoriesFlat(); $language_list = claro_get_lang_flat_list(); $language_list = array_merge(array(get_lang('All') => ''), $language_list); // Structure the categories array as follow: array(category_label => category_value) $structuredCatArray = array(get_lang('All') => ''); // Default choice foreach ($category_array as $category) { $structuredCatArray[$category['path']] = $category['id']; } //---------------------------------- // DISPLAY //---------------------------------- $out = ''; //tool title $out .= claro_html_tool_title($nameTools . ' : '); $tpl = new CoreTemplate('advanced_course_search.tpl.php');
/** * If the course registration requires registration to the course category, * check if the user is register to the category * @return boolean */ protected function isAllowedToRegisterToCategory() { if ($this->isSuperUser) { return true; } if (get_conf('registrationRestrictedThroughCategories', false)) { if (!ClaroCategory::isRegistredToCategory($this->userAuthProfile->getUserId(), $this->categoryId)) { return false; } else { return true; } } else { return true; } }
/** * Return a list of categories associated to a list of courses * * @param int user id * @return array list of categories associated to the user */ public static function getUserCategoriesFlat($userId, $separator = '>') { // Get table name $tbl_mdb_names = claro_sql_get_main_tbl(); $tbl_course = $tbl_mdb_names['course']; $tbl_rel_course_user = $tbl_mdb_names['rel_course_user']; $tbl_category = $tbl_mdb_names['category']; $tbl_rel_course_category = $tbl_mdb_names['rel_course_category']; $sql = "SELECT ca.id, \n ca.name, \n ca.visible, \n ca.canHaveCoursesChild,\n ca.idParent\n\n FROM `{$tbl_category}` AS ca\n\n JOIN `{$tbl_rel_course_category}` AS rcc\n ON ca.id = rcc.categoryId\n\n JOIN `{$tbl_course}` AS co\n ON rcc.courseId = co.cours_id\n\n JOIN `{$tbl_rel_course_user}` AS rcu\n ON rcu.code_cours = co.code\n\n WHERE rcu.user_id = {$userId}\n\n GROUP BY ca.id"; $result = Claroline::getDatabase()->query($sql); $result->setFetchMode(Mysql_ResultSet::FETCH_ASSOC); return ClaroCategory::flatCategoryList($result, $separator); }