Improving Userportal now you can filter by courses, courses with my personal categories, special courses, sessions, session in categories, also adding PageController class as a service and replacing calls see BT#4890

skala
Julio Montoya 12 years ago
parent c93bfb2fc4
commit 41dcf8a8c2
  1. 32
      main/admin/session_category_list.php
  2. 5
      main/inc/global.inc.php
  3. 2
      main/inc/lib/course.lib.php
  4. 367
      main/inc/lib/page.lib.php
  5. 13
      main/inc/lib/sessionmanager.lib.php
  6. 2
      main/inc/lib/template.lib.php
  7. 106
      main/inc/lib/usermanager.lib.php
  8. 22
      src/ChamiloLMS/Controller/IndexController.php
  9. 29
      src/ChamiloLMS/Controller/UserPortalController.php

@ -18,17 +18,17 @@ api_protect_admin_script(true);
// setting the section (for the tabs)
$this_section = SECTION_PLATFORM_ADMIN;
$htmlHeadXtra[] = '<script>
function selectAll(idCheck,numRows,action) {
for(i=0;i<numRows;i++) {
idcheck = document.getElementById(idCheck+"_"+i);
if (action == "true"){
idcheck.checked = true;
} else {
idcheck.checked = false;
}
}
}
</script>';
function selectAll(idCheck,numRows,action) {
for(i=0;i<numRows;i++) {
idcheck = document.getElementById(idCheck+"_"+i);
if (action == "true"){
idcheck.checked = true;
} else {
idcheck.checked = false;
}
}
}
</script>';
$tbl_session_category = Database::get_main_table(TABLE_MAIN_SESSION_CATEGORY);
$tbl_session = Database::get_main_table(TABLE_MAIN_SESSION);
@ -98,7 +98,6 @@ if (isset($_GET['search']) && $_GET['search'] == 'advanced') {
$nbr_results = sizeof($Sessions);
$tool_name = get_lang('ListSessionCategory');
Display::display_header($tool_name);
//api_display_tool_title($tool_name);
if (!empty($_GET['warn'])) {
Display::display_warning_message(urldecode($_GET['warn']), false);
@ -114,7 +113,7 @@ if (isset($_GET['search']) && $_GET['search'] == 'advanced') {
<?php
echo '<div style="float:right;">
<a href="'.api_get_path(WEB_CODE_PATH).'admin/session_category_add.php">'.Display::return_icon('new_folder.png', get_lang('AddSessionCategory'), '', ICON_SIZE_MEDIUM).'</a>
<a href="'.api_get_path(WEB_CODE_PATH).'admin/session_list.php">'.Display::return_icon('session.png', get_lang('ListSession'), '', ICON_SIZE_MEDIUM).'</a>
<a href="'.api_get_path(WEB_CODE_PATH).'session/session_list.php">'.Display::return_icon('session.png', get_lang('ListSession'), '', ICON_SIZE_MEDIUM).'</a>
</div>';
?>
<form method="POST" action="session_category_list.php">
@ -176,7 +175,7 @@ if (isset($_GET['search']) && $_GET['search'] == 'advanced') {
<tr class="<?php echo $i ? 'row_odd' : 'row_even'; ?>">
<td><input type="checkbox" id="idChecked_<?php echo $x; ?>" name="idChecked[]" value="<?php echo $enreg['id']; ?>"></td>
<td><?php echo api_htmlentities($enreg['name'], ENT_QUOTES, $charset); ?></td>
<td><?php echo "<a href=\"session_list.php?id_category=".$enreg['id']."\">".$nb_courses." Sesion(es) </a>"; ?></td>
<td><?php echo '<a href="'.api_get_path(WEB_CODE_PATH).'session/session_list.php?id_category='.$enreg['id'].'">'.$nb_courses.' '.get_lang('Sessions').'</a>'; ?></td>
<td><?php echo api_htmlentities($enreg['date_start'], ENT_QUOTES, $charset); ?></td>
<td><?php echo api_htmlentities($enreg['date_end'], ENT_QUOTES, $charset); ?></td>
<td>
@ -203,9 +202,7 @@ if (isset($_GET['search']) && $_GET['search'] == 'advanced') {
if ($num > $limit) {
if ($page) {
?>
<a href="<?php echo api_get_self(); ?>?page=<?php echo $page - 1; ?>&sort=<?php echo $sort; ?>&order=<?php echo Security::remove_XSS($_REQUEST['order']); ?>&keyword=<?php echo $_REQUEST['keyword']; ?><?php echo @$cond_url; ?>"><?php echo get_lang('Previous'); ?></a>
<?php
} else {
echo get_lang('Previous');
@ -238,4 +235,5 @@ if (isset($_GET['search']) && $_GET['search'] == 'advanced') {
<?php } ?>
</table>
<?php } Display::display_footer(); ?>
<?php }
Display::display_footer();

@ -434,6 +434,11 @@ class ChamiloServiceProvider implements ServiceProviderInterface
$template = new Template(null, $app);
return $template;
});
$app['page_controller'] = $app->share(function () use ($app) {
$pageController = new PageController($app);
return $pageController;
});
}
public function boot(Application $app)

@ -23,7 +23,7 @@ class CourseManager {
//This constant is used to show separate user names in the course list (userportal), footer, etc
CONST USER_SEPARATOR = ' |';
var $columns = array();
public $columns = array();
/**
* Creates a course

@ -10,12 +10,19 @@
/**
* Page controller
*/
use Silex\Application;
use Pagerfanta\Adapter\FixedAdapter;
use Pagerfanta\Pagerfanta;
use Pagerfanta\View\TwitterBootstrapView;
class PageController
{
public $app;
public $maxPerPage = 2;
function __construct(Application $app) {
$this->app = $app;
}
/**
* Returns an HTML block with the user picture (as a link in a <div>)
@ -26,7 +33,7 @@ class PageController
* @uses PageController::show_right_block() to include the image in a larger user block
* @assert (-1) === false
*/
static function return_user_image_block($user_id = null) {
public function return_user_image_block($user_id = null) {
if (empty($user_id)) {
$user_id = api_get_user_id();
}
@ -48,7 +55,7 @@ class PageController
$profile_content .='<a style="text-align:center" href="'.api_get_path(WEB_CODE_PATH).'auth/profile.php"><img title="'.get_lang('EditProfile').'" src="'.$img_array['file'].'" '.$img_array['style'].'></a>';
}
}
self::show_right_block(null, null, 'user_image_block', array('content' => $profile_content));
$this->show_right_block(null, null, 'user_image_block', array('content' => $profile_content));
}
/**
@ -58,7 +65,7 @@ class PageController
* @return string HTML <div> with links
* @assert () != ''
*/
static function return_course_block($filter = null) {
public function return_course_block($filter = null) {
$show_create_link = false;
$show_course_link = false;
@ -67,7 +74,6 @@ class PageController
} else {
$display_add_course_link = true;
}
//$display_add_course_link = api_is_allowed_to_create_course() && ($_SESSION['studentview'] != 'studentenview');
if ($display_add_course_link) {
$show_create_link = true;
@ -120,7 +126,7 @@ class PageController
);
}
}
self::show_right_block(get_lang('Courses'), $my_account_content, 'course_block');
$this->show_right_block(get_lang('Courses'), $my_account_content, 'course_block');
}
/**
@ -129,22 +135,18 @@ class PageController
* @return string HTML <div> block
* @assert () != ''
*/
static function return_profile_block() {
global $app;
// @todo Add a platform setting to add the user image.
public function return_profile_block() {
if (api_get_setting('allow_message_tool') == 'true') {
if (api_get_setting('allow_social_tool') == 'true') {
self::show_right_block(get_lang('Profile'), array(), 'profile_social_block');
$this->show_right_block(get_lang('Profile'), array(), 'profile_social_block');
} else {
self::show_right_block(get_lang('Profile'), array(), 'profile_block');
$this->show_right_block(get_lang('Profile'), array(), 'profile_block');
}
}
}
static function getSectionCourseBlock() {
//@todo use this class as a service
global $app;
function getSectionCourseBlock() {
$app = $this->app;
$courseURL = $app['url_generator']->generate('userportal', array('type' => 'courses'));
$sessionURL = $app['url_generator']->generate('userportal', array('type' => 'sessions'));
$myCourseCategoriesURL = $app['url_generator']->generate('userportal', array('type' => 'mycoursecategories'));
@ -159,7 +161,7 @@ class PageController
array('href' => $sessionCategoriesURL, 'title' => get_lang('SessionsCategories')),
);
self::show_right_block(get_lang('CourseSessionBlock'), $params, 'course_session_block');
$this->show_right_block(get_lang('CourseSessionBlock'), $params, 'course_session_block');
}
/**
@ -169,7 +171,7 @@ class PageController
* @return string HTML <div> with the most popular courses
* @assert () != ''
*/
static function return_hot_courses() {
public function return_hot_courses() {
return CourseManager::return_hot_courses();
}
@ -179,7 +181,7 @@ class PageController
* @return string HTML block
* @assert () != ''
*/
static function return_help() {
public function return_help() {
$home = api_get_home_path();
$user_selected_language = api_get_interface_language();
$sys_path = api_get_path(SYS_PATH);
@ -191,7 +193,7 @@ class PageController
$home_menu = @(string) file_get_contents($sys_path.$home.'home_menu_'.$user_selected_language.'.html');
if (!empty($home_menu)) {
$home_menu_content = api_to_system_encoding($home_menu, api_detect_encoding(strip_tags($home_menu)));
self::show_right_block(get_lang('MenuGeneral'), null, 'help_block', array('content' => $home_menu_content));
$this->show_right_block(get_lang('MenuGeneral'), null, 'help_block', array('content' => $home_menu_content));
}
}
@ -200,7 +202,7 @@ class PageController
* @return string HTML <div> block
* @assert () != ''
*/
static function return_skills_links() {
public function return_skills_links() {
if (api_get_setting('allow_skills_tool') == 'true') {
$content = array();
$content[]= array('title' => get_lang('MySkills'), 'href' => api_get_path(WEB_CODE_PATH).'social/skills_wheel.php');
@ -208,7 +210,7 @@ class PageController
if (api_get_setting('allow_hr_skills_management') == 'true' || api_is_platform_admin()) {
$content[]= array('title' => get_lang('ManageSkills'), 'href' => api_get_path(WEB_CODE_PATH).'admin/skills_wheel.php');
}
self::show_right_block(get_lang("Skills"), $content, 'skill_block');
$this->show_right_block(get_lang("Skills"), $content, 'skill_block');
}
}
@ -218,7 +220,7 @@ class PageController
* @return string HTML <div> block
* @assert () != ''
*/
static function return_notice() {
public function return_notice() {
$sys_path = api_get_path(SYS_PATH);
$user_selected_language = api_get_interface_language();
$home = api_get_home_path();
@ -233,7 +235,7 @@ class PageController
$home_notice = api_to_system_encoding($home_notice, api_detect_encoding(strip_tags($home_notice)));
$home_notice = Display::div($home_notice, array('class' => 'homepage_notice'));
self::show_right_block(get_lang('Notice'), null, 'notice_block', array('content' => $home_notice));
$this->show_right_block(get_lang('Notice'), null, 'notice_block', array('content' => $home_notice));
}
}
@ -248,9 +250,8 @@ class PageController
* @assert ('a','') != ''
* @todo use the template system
*/
static function show_right_block($title, $content, $id, $params = null) {
//@todo do not use global
global $app;
public function show_right_block($title, $content, $id, $params = null) {
$app = $this->app;
if (!empty($id)) {
$params['id'] = $id;
}
@ -269,7 +270,7 @@ class PageController
* @assert () != ''
* @version 1.1
*/
static function display_login_form() {
public function display_login_form() {
$form = new FormValidator('formLogin', 'POST', null, null, array('class' => 'form-vertical'));
// 'placeholder'=>get_lang('UserName')
//'autocomplete'=>"off",
@ -292,7 +293,7 @@ class PageController
* @return string HTML <div> block showing the search form, or an empty string if search not enabled
* @assert () !== false
*/
static function return_search_block() {
public function return_search_block() {
$html = '';
if (api_get_setting('search_enabled') == 'true') {
$html .= '<div class="searchbox">';
@ -302,7 +303,7 @@ class PageController
<input type="text" id="query" class="span2" name="query" value="" />
<button class="save" type="submit" name="submit" value="'.$search_btn.'" />'.$search_btn.' </button>
</form></div>';
$html .= self::show_right_block(get_lang('Search'), $search_content, 'search_block');
$html .= $this->show_right_block(get_lang('Search'), $search_content, 'search_block');
}
return $html;
}
@ -315,7 +316,7 @@ class PageController
* @assert () != ''
* @assert (1) != ''
*/
static function return_announcements($user_id = null, $show_slide = true) {
public function return_announcements($user_id = null, $show_slide = true) {
// Display System announcements
$announcement = isset($_GET['announcement']) ? intval($_GET['announcement']) : null;
@ -341,7 +342,7 @@ class PageController
* @return string The portal's homepage as an HTML string
* @assert () != ''
*/
static function return_home_page() {
public function return_home_page() {
// Including the page for the news
$html = null;
$home = api_get_home_path();
@ -391,14 +392,14 @@ class PageController
* @return string HTML block, or empty string if reservation tool is disabled
* @assert () == ''
*/
static function return_reservation_block() {
public function return_reservation_block() {
$html = '';
$booking_content = null;
if (api_get_setting('allow_reservation') == 'true' && api_is_allowed_to_create_course()) {
$booking_content .='<ul class="nav nav-list">';
$booking_content .='<a href="main/reservation/reservation.php">'.get_lang('ManageReservations').'</a><br />';
$booking_content .='</ul>';
$html .= self::show_right_block(get_lang('Booking'), $booking_content, 'reservation_block');
$html .= $this->show_right_block(get_lang('Booking'), $booking_content, 'reservation_block');
}
return $html;
}
@ -408,7 +409,7 @@ class PageController
* @return string A list of links to users classes tools, or an empty string if show_groups_to_users is disabled
* @assert () == ''
*/
static function return_classes_block() {
public function return_classes_block() {
$html = '';
if (api_get_setting('show_groups_to_users') == 'true') {
$usergroup = new Usergroup();
@ -426,7 +427,7 @@ class PageController
}
if (!empty($classes)) {
$classes = Display::tag('ul', $classes, array('class' => 'nav nav-list'));
$html .= self::show_right_block(get_lang('Classes'), $classes, 'classes_block');
$html .= $this->show_right_block(get_lang('Classes'), $classes, 'classes_block');
}
}
return $html;
@ -438,7 +439,7 @@ class PageController
* @return void Doesn't return anything but prepares and HTML block for use in templates
* @assert () !== 1
*/
static function return_exercise_block($personal_course_list, $tpl) {
public function return_exercise_block($personal_course_list, $tpl) {
require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php';
$exercise_list = array();
if (!empty($personal_course_list)) {
@ -472,7 +473,7 @@ class PageController
* @return string HTML <div> block
* @assert () == ''
*/
static function return_teacher_link() {
public function return_teacher_link() {
$user_id = api_get_user_id();
if (!empty($user_id)) {
@ -516,7 +517,7 @@ class PageController
}
}
}
self::show_right_block(get_lang('Courses'), $elements, 'teacher_block');
$this->show_right_block(get_lang('Courses'), $elements, 'teacher_block');
}
/**
@ -528,7 +529,7 @@ class PageController
* @author Julio Montoya <gugli100@gmail.com>, Beeznest template modifs
* @assert () !== 0
*/
static function return_courses_in_categories() {
public function return_courses_in_categories() {
$result = '';
$stok = Security::get_token();
@ -548,8 +549,7 @@ class PageController
ORDER BY title, UPPER(visual_code)";
// Showing only the courses of the current access_url_id.
global $_configuration;
if ($_configuration['multiple_access_urls']) {
if (api_is_multiple_url_enabled()) {
$url_access_id = api_get_current_access_url_id();
if ($url_access_id != -1) {
$tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
@ -591,7 +591,7 @@ class PageController
// Showing only the category of courses of the current access_url_id
if ($_configuration['multiple_access_urls']) {
if (api_is_multiple_url_enabled()) {
$url_access_id = api_get_current_access_url_id();
if ($url_access_id != -1) {
$tbl_url_rel_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
@ -614,7 +614,7 @@ class PageController
$htmlListCat .= '<ul>';
while ($catLine = Database::fetch_array($resCats)) {
if ($catLine['code'] != $category) {
$category_has_open_courses = self::category_has_open_courses($catLine['code']);
$category_has_open_courses = $this->category_has_open_courses($catLine['code']);
if ($category_has_open_courses) {
// The category contains courses accessible to anonymous visitors.
$htmlListCat .= '<li>';
@ -671,7 +671,7 @@ class PageController
$courses_list_string .= "<ul>";
if (api_get_user_id()) {
$courses_of_user = self::get_courses_of_user(api_get_user_id());
$courses_of_user = $this->get_courses_of_user(api_get_user_id());
}
foreach ($course_list as $course) {
@ -770,25 +770,24 @@ class PageController
return $result;
}
static function returnMyCourseCategories($user_id, $filter, $page) {
public function returnMyCourseCategories($user_id, $filter, $page) {
if (empty($user_id)) {
return false;
}
$loadDirs = api_get_setting('show_documents_preview') == 'true' ? true : false;
$maxPerPage = 2;
$start = ($page -1) * $maxPerPage;
$start = ($page -1) * $this->maxPerPage;
$nbResults = (int) CourseManager::displayPersonalCourseCategories($user_id, $filter, $loadDirs, true);
$html = CourseManager::displayPersonalCourseCategories($user_id, $filter, $loadDirs, false, $start, $maxPerPage);
$html = CourseManager::displayPersonalCourseCategories($user_id, $filter, $loadDirs, false, $start, $this->maxPerPage);
$adapter = new FixedAdapter($nbResults, array());
$pagerfanta = new Pagerfanta($adapter);
$pagerfanta->setMaxPerPage($maxPerPage); // 10 by default
$pagerfanta->setMaxPerPage($this->maxPerPage); // 10 by default
$pagerfanta->setCurrentPage($page); // 1 by default
$view = new TwitterBootstrapView();
global $app;
$app = $this->app;
//{type}/{category}/{filter}/{page}
$routeGenerator = function($page) use ($app, $filter) {
return $app['url_generator']->generate('userportal', array(
@ -808,27 +807,25 @@ class PageController
function returnSpecialCourses($user_id, $filter, $page)
{
global $app;
if (empty($user_id)) {
return false;
}
$loadDirs = api_get_setting('show_documents_preview') == 'true' ? true : false;
$maxPerPage = 2;
$start = ($page -1) * $maxPerPage;
$start = ($page -1) * $this->maxPerPage;
$nbResults = CourseManager::displaySpecialCourses($user_id, $filter, $loadDirs, true);
$html = CourseManager::displaySpecialCourses($user_id, $filter, $loadDirs, false, $start, $maxPerPage);
$html = CourseManager::displaySpecialCourses($user_id, $filter, $loadDirs, false, $start, $this->maxPerPage);
$adapter = new FixedAdapter($nbResults, array());
$pagerfanta = new Pagerfanta($adapter);
$pagerfanta->setMaxPerPage($maxPerPage); // 10 by default
$pagerfanta->setMaxPerPage($this->maxPerPage); // 10 by default
$pagerfanta->setCurrentPage($page); // 1 by default
$view = new TwitterBootstrapView();
$app = $this->app;
$routeGenerator = function($page) use ($app, $filter) {
return $app['url_generator']->generate('userportal', array(
'filter' => $filter,
@ -838,8 +835,8 @@ class PageController
};
$pagination = $view->render($pagerfanta, $routeGenerator, array(
'proximity' => 3,
));
'proximity' => 3,
));
return $html.$pagination;
}
@ -855,29 +852,28 @@ class PageController
*
*/
static function returnCourses($user_id, $filter, $page)
public function returnCourses($user_id, $filter, $page)
{
global $app;
if (empty($user_id)) {
return false;
}
$loadDirs = api_get_setting('show_documents_preview') == 'true' ? true : false;
$maxPerPage = 2;
$start = ($page -1) * $maxPerPage;
$start = ($page -1) * $this->maxPerPage;
$nbResults = CourseManager::displayCourses($user_id, $filter, $loadDirs, true);
$html = CourseManager::displayCourses($user_id, $filter, $loadDirs, false, $start, $maxPerPage);
$html = CourseManager::displayCourses($user_id, $filter, $loadDirs, false, $start, $this->maxPerPage);
$adapter = new FixedAdapter($nbResults, array());
$pagerfanta = new Pagerfanta($adapter);
$pagerfanta->setMaxPerPage($maxPerPage); // 10 by default
$pagerfanta->setMaxPerPage($this->maxPerPage); // 10 by default
$pagerfanta->setCurrentPage($page); // 1 by default
$view = new TwitterBootstrapView();
$app = $this->app;
$routeGenerator = function($page) use ($app, $filter) {
return $app['url_generator']->generate('userportal', array(
'filter' => $filter,
@ -893,25 +889,159 @@ class PageController
return $html.$pagination;
}
static function returnSessions($user_id, $filter, $page) {
public function returnSessionsCategories($user_id, $filter, $page)
{
if (empty($user_id)) {
return false;
}
$load_history = (isset($filter) && $filter == 'history') ? true : false;
$maxPerPage = 10;
$start = ($page -1) * $this->maxPerPage;
$nbResults = UserManager::getCategories($user_id, false, true, true);
$session_categories = UserManager::getCategories($user_id, false, false, true, $start, $this->maxPerPage);
$html = null;
//Showing history title
if ($load_history) {
$html .= Display::page_subheader(get_lang('HistoryTrainingSession'));
if (empty($session_categories)) {
$html .= get_lang('YouDoNotHaveAnySessionInItsHistory');
}
}
$load_directories_preview = api_get_setting('show_documents_preview') == 'true' ? true : false;
$sessions_with_category = $html;
if (is_array($session_categories)) {
foreach ($session_categories as $session_category) {
$session_category_id = $session_category['session_category']['id'];
// All sessions included in
$count_courses_session = 0;
$html_sessions = '';
foreach ($session_category['sessions'] as $session) {
$session_id = $session['session_id'];
// Don't show empty sessions.
if (count($session['courses']) < 1) {
continue;
}
$html_courses_session = '';
$count = 0;
foreach ($session['courses'] as $course) {
if (api_get_setting('hide_courses_in_sessions') == 'false') {
$html_courses_session .= CourseManager::get_logged_user_course_html($course, $session_id);
}
$count_courses_session++;
$count++;
}
$params = array();
if ($count > 0) {
$params['icon'] = Display::return_icon('window_list.png', $session['session_name'], array('id' => 'session_img_'.$session_id), ICON_SIZE_LARGE);
//Default session name
$session_link = $session['session_name'];
$params['link'] = null;
if (api_get_setting('session_page_enabled') == 'true' && !api_is_drh()) {
//session name with link
$session_link = Display::tag('a', $session['session_name'], array('href' => api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id));
$params['link'] = api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id;
}
$params['title'] = $session_link;
$moved_status = SessionManager::get_session_change_user_reason($session['moved_status']);
$moved_status = isset($moved_status) && !empty($moved_status) ? ' ('.$moved_status.')' : null;
$params['subtitle'] = isset($session['coach_info']) ? $session['coach_info']['complete_name'] : null.$moved_status;
$params['dates'] = $session['date_message'];
if (api_is_platform_admin()) {
$params['right_actions'] = '<a href="'.api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='.$session_id.'">'.Display::return_icon('edit.png', get_lang('Edit'), array('align' => 'absmiddle'), ICON_SIZE_SMALL).'</a>';
}
$html_sessions .= CourseManager::course_item_html($params, true).$html_courses_session;
}
}
if ($count_courses_session > 0) {
$params = array();
$params['icon'] = Display::return_icon('folder_blue.png', $session_category['session_category']['name'], array(), ICON_SIZE_LARGE);
if (api_is_platform_admin()) {
$params['right_actions'] = '<a href="'.api_get_path(WEB_CODE_PATH).'admin/session_category_edit.php?&id='.$session_category['session_category']['id'].'">'.Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>';
}
$params['title'] = $session_category['session_category']['name'];
if (api_is_platform_admin()) {
$params['link'] = api_get_path(WEB_CODE_PATH).'admin/session_category_edit.php?&id='.$session_category['session_category']['id'];
}
$session_category_start_date = $session_category['session_category']['date_start'];
$session_category_end_date = $session_category['session_category']['date_end'];
if (!empty($session_category_start_date) && $session_category_start_date != '0000-00-00' && !empty($session_category_end_date) && $session_category_end_date != '0000-00-00') {
$params['subtitle'] = sprintf(get_lang('FromDateXToDateY'), $session_category['session_category']['date_start'], $session_category['session_category']['date_end']);
} else {
if (!empty($session_category_start_date) && $session_category_start_date != '0000-00-00') {
$params['subtitle'] = get_lang('From').' '.$session_category_start_date;
}
if (!empty($session_category_end_date) && $session_category_end_date != '0000-00-00') {
$params['subtitle'] = get_lang('Until').' '.$session_category_end_date;
}
}
$sessions_with_category .= CourseManager::course_item_parent(CourseManager::course_item_html($params, true), $html_sessions);
}
}
}
$adapter = new FixedAdapter($nbResults, array());
$pagerfanta = new Pagerfanta($adapter);
$pagerfanta->setMaxPerPage($this->maxPerPage); // 10 by default
$pagerfanta->setCurrentPage($page); // 1 by default
$view = new TwitterBootstrapView();
$start = ($page -1) * $maxPerPage;
$app = $this->app;
$routeGenerator = function($page) use ($app, $filter) {
return $app['url_generator']->generate('userportal', array(
'filter' => $filter,
'type' => 'sessioncategories',
'page' => $page)
);
};
$pagination = $view->render($pagerfanta, $routeGenerator, array(
'proximity' => 3,
));
return $sessions_with_category.$pagination;
}
public function returnSessions($user_id, $filter, $page) {
if (empty($user_id)) {
return false;
}
$load_history = (isset($filter) && $filter == 'history') ? true : false;
$start = ($page -1) * $this->maxPerPage;
if ($load_history) {
//Load sessions in category in *history*
$nbResults = (int) UserManager::get_sessions_by_category($user_id, true, true, true);
$session_categories = UserManager::get_sessions_by_category($user_id, true, false, true, $start, $maxPerPage);
$nbResults = (int) UserManager::get_sessions_by_category($user_id, true, true, true, null, null, 'no_category');
$session_categories = UserManager::get_sessions_by_category($user_id, true, false, true, $start, $this->maxPerPage, 'no_category');
} else {
//Load sessions in category
$nbResults = (int) UserManager::get_sessions_by_category($user_id, false, true, false);
$session_categories = UserManager::get_sessions_by_category($user_id, false, false, false, $start, $maxPerPage);
$nbResults = (int) UserManager::get_sessions_by_category($user_id, false, true, false, null, null, 'no_category');
$session_categories = UserManager::get_sessions_by_category($user_id, false, false, false, $start, $this->maxPerPage, 'no_category');
}
$html = null;
@ -925,8 +1055,7 @@ class PageController
$load_directories_preview = api_get_setting('show_documents_preview') == 'true' ? true : false;
$sessions_with_category = $html;
$sessions_with_no_category = '';
$sessions_with_no_category = $html;
if (is_array($session_categories)) {
foreach ($session_categories as $session_category) {
@ -992,101 +1121,17 @@ class PageController
}
}
}
} else {
// All sessions included in
$count_courses_session = 0;
$html_sessions = '';
foreach ($session_category['sessions'] as $session) {
$session_id = $session['session_id'];
// Don't show empty sessions.
if (count($session['courses']) < 1) {
continue;
}
$html_courses_session = '';
$count = 0;
foreach ($session['courses'] as $course) {
if (api_get_setting('hide_courses_in_sessions') == 'false') {
$html_courses_session .= CourseManager::get_logged_user_course_html($course, $session_id);
}
$count_courses_session++;
$count++;
}
$params = array();
if ($count > 0) {
$params['icon'] = Display::return_icon('window_list.png', $session['session_name'], array('id' => 'session_img_'.$session_id), ICON_SIZE_LARGE);
//Default session name
$session_link = $session['session_name'];
$params['link'] = null;
if (api_get_setting('session_page_enabled') == 'true' && !api_is_drh()) {
//session name with link
$session_link = Display::tag('a', $session['session_name'], array('href' => api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id));
$params['link'] = api_get_path(WEB_CODE_PATH).'session/index.php?session_id='.$session_id;
}
$params['title'] .= $session_link;
$moved_status = SessionManager::get_session_change_user_reason($session['moved_status']);
$moved_status = isset($moved_status) && !empty($moved_status) ? ' ('.$moved_status.')' : null;
$params['subtitle'] = isset($session['coach_info']) ? $session['coach_info']['complete_name'] : null.$moved_status;
$params['dates'] = $session['date_message'];
if (api_is_platform_admin()) {
$params['right_actions'] .= '<a href="'.api_get_path(WEB_CODE_PATH).'admin/resume_session.php?id_session='.$session_id.'">'.Display::return_icon('edit.png', get_lang('Edit'), array('align' => 'absmiddle'), ICON_SIZE_SMALL).'</a>';
}
$html_sessions .= CourseManager::course_item_html($params, true).$html_courses_session;
}
}
if ($count_courses_session > 0) {
$params = array();
$params['icon'] = Display::return_icon('folder_blue.png', $session_category['session_category']['name'], array(), ICON_SIZE_LARGE);
if (api_is_platform_admin()) {
$params['right_actions'] .= '<a href="'.api_get_path(WEB_CODE_PATH).'admin/session_category_edit.php?&id='.$session_category['session_category']['id'].'">'.Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>';
}
$params['title'] .= $session_category['session_category']['name'];
if (api_is_platform_admin()) {
$params['link'] = api_get_path(WEB_CODE_PATH).'admin/session_category_edit.php?&id='.$session_category['session_category']['id'];
}
$session_category_start_date = $session_category['session_category']['date_start'];
$session_category_end_date = $session_category['session_category']['date_end'];
if (!empty($session_category_start_date) && $session_category_start_date != '0000-00-00' && !empty($session_category_end_date) && $session_category_end_date != '0000-00-00') {
$params['subtitle'] = sprintf(get_lang('FromDateXToDateY'), $session_category['session_category']['date_start'], $session_category['session_category']['date_end']);
} else {
if (!empty($session_category_start_date) && $session_category_start_date != '0000-00-00') {
$params['subtitle'] = get_lang('From').' '.$session_category_start_date;
}
if (!empty($session_category_end_date) && $session_category_end_date != '0000-00-00') {
$params['subtitle'] = get_lang('Until').' '.$session_category_end_date;
}
}
$sessions_with_category .= CourseManager::course_item_parent(CourseManager::course_item_html($params, true), $html_sessions);
}
}
}
}
$adapter = new FixedAdapter($nbResults, array());
$pagerfanta = new Pagerfanta($adapter);
$pagerfanta->setMaxPerPage($maxPerPage); // 10 by default
$pagerfanta->setMaxPerPage($this->maxPerPage); // 10 by default
$pagerfanta->setCurrentPage($page); // 1 by default
$view = new TwitterBootstrapView();
global $app;
$app = $this->app;
$routeGenerator = function($page) use ($app, $filter) {
return $app['url_generator']->generate('userportal', array(
'filter' => $filter,
@ -1098,7 +1143,7 @@ class PageController
$pagination = $view->render($pagerfanta, $routeGenerator, array(
'proximity' => 3,
));
return $sessions_with_category.$sessions_with_no_category.$pagination;
return $sessions_with_no_category.$pagination;
}
/**
@ -1108,7 +1153,7 @@ class PageController
* @return void
* @assert () === false
*/
static function return_welcome_to_course_block($tpl) {
public function return_welcome_to_course_block($tpl) {
if (empty($tpl)) {
return false;
}

@ -174,7 +174,7 @@ class SessionManager {
return $result['count'] > 0;
}
/**
* Gets the admin session list callback of the admin/session_list.php page
* Gets the admin session list callback of the session/session_list.php page
* @param array order and limit keys
* @param boolean Whether to get all the results or only the count
* @return mixed Integer for number of rows, or array of results
@ -452,7 +452,7 @@ class SessionManager {
return $num;
}
/**
* Gets the admin session list callback of the admin/session_list.php
* Gets the admin session list callback of the session/session_list.php
* page with all user/details in the right fomat
* @param array order and limit keys
* @result array Array of rows results
@ -2795,4 +2795,13 @@ class SessionManager {
);
return $return_array;
}
static function getSessionsByCategory($categoryId) {
$categoryId = intval($categoryId);
$tableSession = Database::get_main_table(TABLE_MAIN_SESSION);
$sql = "select * FROM $tableSession WHERE session_category_id = $categoryId";
$result = Database::query($sql);
return Database::store_result($result);
}
}

@ -850,7 +850,7 @@ class Template
$content .= '</li>';
}
$content .= '</ul>';
$html = PageController::show_right_block(get_lang('MainNavigation'), $content, 'navigation_link_block');
$html = $this->app['page_controller']->show_right_block(get_lang('MainNavigation'), $content, 'navigation_link_block');
}
return $html;
}

@ -2221,6 +2221,74 @@ class UserManager {
return $data;
}
static function getCategories($user_id, $is_time_over = false, $get_count = false, $reverse_order = false, $start = 0, $maxPerPage = null, $categoryFilter = null) {
$tableSessionCategory = Database :: get_main_table(TABLE_MAIN_SESSION_CATEGORY);
$tableSession = Database :: get_main_table(TABLE_MAIN_SESSION);
$tableSessionUser = Database :: get_main_table(TABLE_MAIN_SESSION_USER);
$tableSessionCourseUser = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
$select = " DISTINCT sc.id, sc.name ";
if ($get_count) {
$select = " COUNT(DISTINCT(sc.id)) as total";
}
$sql = "SELECT $select
FROM $tableSessionCategory sc
INNER JOIN $tableSession s ON (sc.id = s.session_category_id)
INNER JOIN (
(
SELECT DISTINCT id_session as sessionID FROM $tableSessionUser
WHERE id_user = $user_id AND relation_type <> ".SESSION_RELATION_TYPE_RRHH."
)
UNION
(
SELECT DISTINCT s.id
FROM $tableSession s
WHERE (id_coach = $user_id)
)
UNION
(
SELECT DISTINCT s.id
FROM $tableSessionUser su INNER JOIN $tableSession s
ON (su.id_session = s.id)
INNER JOIN $tableSessionCourseUser scu
ON (scu.id_session = s.id)
WHERE (scu.id_user = $user_id)
)
) as t ON (t.sessionId = sc.id)
";
if ($get_count) {
$result = Database::query($sql);
$row = Database::fetch_array($result);
return $row['total'];
}
$order = ' ORDER BY sc.name';
if ($reverse_order) {
$order = ' ORDER BY sc.name DESC ';
}
$sql .= $order;
if (isset($start) && isset($maxPerPage)) {
$start = intval($start);
$maxPerPage = intval($maxPerPage);
$limitCondition = " LIMIT $start, $maxPerPage";
$sql .= $limitCondition;
}
$result = Database::query($sql);
$sessionsCategories = array();
if (Database::num_rows($result)) {
while ($sessionCategory = Database::fetch_array($result, 'ASSOC')) {
$sessions = self::get_sessions_by_category($user_id, $is_time_over, false, $reverse_order, null, null, $sessionCategory['id']);
$sessionsCategories[$sessionCategory['id']] = $sessions[$sessionCategory['id']];
}
}
return $sessionsCategories;
}
/**
* Gives a list of [session_category][session_id] for the current user.
* @param integer $user_id
@ -2230,7 +2298,7 @@ class UserManager {
* @return array list of statuses [session_category][session_id]
* @todo ensure multiple access urls are managed correctly
*/
public static function get_sessions_by_category($user_id, $is_time_over = false, $get_count = false, $reverse_order = false, $start = 0, $maxPerPage = null) {
public static function get_sessions_by_category($user_id, $is_time_over = false, $get_count = false, $reverse_order = false, $start = 0, $maxPerPage = null, $categoryFilter = null) {
// Database Table Definitions
$tbl_session = Database :: get_main_table(TABLE_MAIN_SESSION);
$tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
@ -2249,13 +2317,12 @@ class UserManager {
$condition_date_end1 = null;
$condition_date_end2 = null;
// uncomment commented query lines to alter the query sorting
//$order = ' ORDER BY session_category_name, short_name ';
$order = ' ORDER BY session_category_name, name ';
$order = ' ORDER BY name ';
if ($reverse_order) {
//$order = ' ORDER BY session_category_name DESC, short_name DESC ';
$order = ' ORDER BY session_category_name DESC, name DESC ';
$order = ' ORDER BY name DESC ';
}
if ($is_time_over) {
$condition_date_end1 = " AND ((session.access_end_date < '$now' AND session.access_end_date != '0000-00-00 00:00:00') OR moved_to <> 0) ";
$condition_date_end2 = " AND ((session.access_end_date < '$now' AND session.access_end_date != '0000-00-00 00:00:00')) ";
@ -2309,19 +2376,41 @@ class UserManager {
ON su.id_session = session.id AND su.id_user = scu.id_user
WHERE scu.id_user = $user_id $condition_date_end1";
// select specific to session coaches
$select2 = " $select FROM $tbl_session as session LEFT JOIN $tbl_session_category session_category ON (session_category_id = session_category.id) ";
$sql2 = $select2 . " WHERE session.id_coach = $user_id $condition_date_end2 ";
if (isset($categoryFilter) && $categoryFilter != '') {
switch ($categoryFilter) {
case 'no_category':
$sql1 .= "AND session_category_id = 0";
$sql2 .= "AND session_category_id = 0";
break;
case 'with_category':
$sql1 .= "AND session_category_id <> 0";
$sql2 .= "AND session_category_id <> 0";
break;
default:
if (!empty($categoryFilter) && is_numeric($categoryFilter)) {
$categoryFilter = intval($categoryFilter);
$sql1 .= "AND session_category_id = $categoryFilter";
$sql2 .= "AND session_category_id = $categoryFilter";
}
break;
}
}
$sql3 = null;
if ($get_count) {
$sql3 = $sql1;
$sql3 = $sql2;
} else {
$sql1 .= $order;
$sql2 .= $order;
}
$sql3 = $select2 . " WHERE session.id_coach = $user_id $condition_date_end2 ";
//$sql3 = $sql2 . " AND session.id_coach = $user_id $condition_date_end2 ";
if (isset($start) && isset($maxPerPage)) {
$start = intval($start);
@ -2341,6 +2430,7 @@ class UserManager {
$row = Database::fetch_array($result3);
return $row['total_rows'];
} else {
$result1 = Database::query($sql1);
$result2 = Database::query($sql2);
}

@ -92,7 +92,7 @@ class IndexController// extends Controller
if (api_get_setting('display_categories_on_homepage') == 'true') {
$app['template']->assign('course_category_block', \PageController::return_courses_in_categories());
$app['template']->assign('course_category_block', $app['page_controller']->return_courses_in_categories());
}
// Facebook connexion, if activated
@ -103,13 +103,13 @@ class IndexController// extends Controller
$this->setLoginForm($app);
if (!api_is_anonymous()) {
\PageController::return_profile_block();
\PageController::return_user_image_block();
$app['page_controller']->return_profile_block();
$app['page_controller']->return_user_image_block();
if (api_is_platform_admin()) {
\PageController::return_course_block();
$app['page_controller']->return_course_block();
} else {
\PageController::return_teacher_link();
$app['page_controller']->return_teacher_link();
}
}
@ -120,16 +120,16 @@ class IndexController// extends Controller
// When loading a chamilo page do not include the hot courses and news
if (!isset($_REQUEST['include'])) {
if (api_get_setting('show_hot_courses') == 'true') {
$hotCourses = \PageController::return_hot_courses();
$hotCourses = $app['page_controller']->return_hot_courses();
}
$announcementsBlock = \PageController::return_announcements();
$announcementsBlock = $app['page_controller']->return_announcements();
}
$app['template']->assign('hot_courses', $hotCourses);
$app['template']->assign('announcements_block', $announcementsBlock);
//Homepage
$app['template']->assign('home_page_block', \PageController::return_home_page());
$app['template']->assign('home_page_block', $app['page_controller']->return_home_page());
//Navigation links
$navLinks = $app['template']->returnNavigationLinks();
@ -137,11 +137,11 @@ class IndexController// extends Controller
$app['template']->assign('navigation_course_links', $navLinks);
$app['template']->assign('main_navigation_block', $navLinks);
\PageController::return_notice();
\PageController::return_help();
$app['page_controller']->return_notice();
$app['page_controller']->return_help();
if (api_is_platform_admin() || api_is_drh()) {
\PageController::return_skills_links();
$app['page_controller']->return_skills_links();
}
$response = $app['template']->render_layout('layout_2_col.tpl');

@ -34,40 +34,39 @@ class UserPortalController
switch ($type) {
case 'sessions':
$items = \PageController::returnSessions(api_get_user_id(), $filter, $page);
$items = $app['page_controller']->returnSessions(api_get_user_id(), $filter, $page);
break;
case 'sessioncategories':
$items = \PageController::returnSessionsCategories(api_get_user_id(), $filter, $page);
$items = $app['page_controller']->returnSessionsCategories(api_get_user_id(), $filter, $page);
break;
case 'courses':
$items = \PageController::returnCourses(api_get_user_id(), $filter, $page);
$items = $app['page_controller']->returnCourses(api_get_user_id(), $filter, $page);
break;
case 'mycoursecategories':
$items = \PageController::returnMyCourseCategories(api_get_user_id(), $filter, $page);
$items = $app['page_controller']->returnMyCourseCategories(api_get_user_id(), $filter, $page);
break;
case 'specialcourses':
$items = \PageController::returnSpecialCourses(api_get_user_id(), $filter, $page);
$items = $app['page_controller']->returnSpecialCourses(api_get_user_id(), $filter, $page);
break;
}
//Show the chamilo mascot
if (empty($items) && empty($filter)) {
\PageController::return_welcome_to_course_block($app['template']);
$app['page_controller']->return_welcome_to_course_block($app['template']);
}
$app['template']->assign('content', $items);
\PageController::getSectionCourseBlock();
\PageController::return_profile_block();
\PageController::return_user_image_block();
\PageController::return_course_block($filter);
$app['page_controller']->getSectionCourseBlock();
$app['page_controller']->return_profile_block();
$app['page_controller']->return_user_image_block();
$app['page_controller']->return_course_block($filter);
$app['template']->assign('navigation_course_links', $app['template']->returnNavigationLinks());
\PageController::return_reservation_block();
$app['template']->assign('search_block', \PageController::return_search_block());
$app['template']->assign('classes_block', \PageController::return_classes_block());
\PageController::return_skills_links();
$app['page_controller']->return_reservation_block();
$app['template']->assign('search_block', $app['page_controller']->return_search_block());
$app['template']->assign('classes_block', $app['page_controller']->return_classes_block());
$app['page_controller']->return_skills_links();
// Deleting the session_id.
Session::erase('session_id');

Loading…
Cancel
Save