"user.php", "name" => get_lang("ToolUser")); $interbreadcrumb[] = array("url" => "class.php", "name" => get_lang("Classes")); Display :: display_header($tool_name, "User"); echo Display::page_header($tool_name); if (isset($_GET['register'])) { ClassManager::subscribe_to_course($_GET['class_id'], $_course['sysCode']); Display::display_normal_message(get_lang('ClassesSubscribed')); } if (isset($_POST['action'])) { switch ($_POST['action']) { case 'subscribe' : if (is_array($_POST['class'])) { foreach ($_POST['class'] as $index => $class_id) { ClassManager::subscribe_to_course($class_id, $_course['sysCode']); } Display::display_normal_message(get_lang('ClassesSubscribed')); } break; } } /* SHOW LIST OF USERS */ /** * * Get the number of classes to display on the current page. */ function get_number_of_classes() { $em = Database::getManager(); $class_table = Database :: get_main_table(TABLE_MAIN_CLASS); $courseId = api_get_course_int_id(); $res = $em->getRepository('ChamiloCoreBundle:CourseRelClass')->findBy(['courseId' => $courseId]); $subscribed_classes = array(); foreach ($res as $obj) { $subscribed_classes[] = $obj->getClassId(); } $sql = "SELECT c.id FROM $class_table c WHERE 1 = 1"; if (isset($_GET['keyword'])) { $keyword = Database::escape_string(trim($_GET['keyword'])); $sql .= " AND (c.name LIKE '%" . $keyword . "%')"; } if (count($subscribed_classes) > 0) { $sql .= " AND c.id NOT IN ('" . implode("','", $subscribed_classes) . "')"; } $res = Database::query($sql); $result = Database::num_rows($res); return $result; } /** * Get the classes to display on the current page. */ function get_class_data($from, $number_of_items, $column, $direction) { $class_table = Database :: get_main_table(TABLE_MAIN_CLASS); $class_user_table = Database :: get_main_table(TABLE_MAIN_CLASS_USER); $courseId = api_get_course_int_id(); $em = Database::getManager(); $res = $em->getRepository('ChamiloCoreBundle:CourseRelClass')->findBy(['courseId' => $courseId]); $subscribed_classes = array(); foreach ($res as $obj) { $subscribed_classes[] = $obj->getClassId(); } $sql = "SELECT c.id AS col0, c.name AS col1, COUNT(cu.user_id) AS col2, c.id AS col3 FROM $class_table c "; $sql .= " LEFT JOIN $class_user_table cu ON cu.class_id = c.id"; $sql .= " WHERE 1 = 1"; if (isset($_GET['keyword'])) { $keyword = Database::escape_string(trim($_GET['keyword'])); $sql .= " AND (c.name LIKE '%" . $keyword . "%')"; } if (count($subscribed_classes) > 0) { $sql .= " AND c.id NOT IN ('" . implode("','", $subscribed_classes) . "')"; } $sql .= " GROUP BY c.id, c.name "; $sql .= " ORDER BY col$column $direction "; $sql .= " LIMIT $from,$number_of_items"; $res = Database::query($sql); $classes = array(); while ($class = Database::fetch_row($res)) { $classes[] = $class; } return $classes; } /** * Build the reg-column of the table * @param int $class_id The class id * @return string Some HTML-code */ function reg_filter($class_id) { $result = "" . get_lang("reg") . ""; return $result; } // Build search-form $form = new FormValidator('search_class', 'get', '', '', null, false); $form->addText('keyword', '', false); $form->addButtonSearch(get_lang('SearchButton')); // Build table $table = new SortableTable('users', 'get_number_of_classes', 'get_class_data', 1); $parameters['keyword'] = Security::remove_XSS($_GET['keyword']); $table->set_additional_parameters($parameters); $col = 0; $table->set_header($col++, '', false); $table->set_header($col++, get_lang('ClassName')); $table->set_header($col++, get_lang('NumberOfUsers')); $table->set_header($col++, get_lang('reg'), false); $table->set_column_filter($col - 1, 'reg_filter'); $table->set_form_actions(array('subscribe' => get_lang('reg')), 'class'); // Display form & table $form->display(); $table->display(); Display :: display_footer();