diff --git a/main/admin/dashboard_add_users_to_user.php b/main/admin/dashboard_add_users_to_user.php index 531a99c6f4..139196d385 100755 --- a/main/admin/dashboard_add_users_to_user.php +++ b/main/admin/dashboard_add_users_to_user.php @@ -40,6 +40,8 @@ $user_info = api_get_user_info($user_id); $user_anonymous = api_get_anonymous_id(); $current_user_id = api_get_user_id(); +$userStatus = api_get_user_status($user_id); + $firstLetterUser = isset($_POST['firstLetterUser']) ? $_POST['firstLetterUser'] : null; // setting the name of the tool @@ -47,6 +49,8 @@ if (UserManager::is_admin($user_id)) { $tool_name= get_lang('AssignUsersToPlatformAdministrator'); } else if ($user_info['status'] == SESSIONADMIN) { $tool_name= get_lang('AssignUsersToSessionsAdministrator'); +} else if ($user_info['status'] == STUDENT_BOSS) { + $tool_name= get_lang('AssignUsersToBoss'); } else { $tool_name= get_lang('AssignUsersToHumanResourcesManager'); } @@ -62,7 +66,7 @@ if (!api_is_platform_admin()) { function search_users($needle,$type) { - global $tbl_access_url_rel_user, $tbl_user, $user_anonymous, $current_user_id, $user_id; + global $tbl_access_url_rel_user, $tbl_user, $user_anonymous, $current_user_id, $user_id, $userStatus; $xajax_response = new XajaxResponse(); $return = ''; @@ -70,8 +74,17 @@ function search_users($needle,$type) // xajax send utf8 datas... datas in db can be non-utf8 datas $charset = api_get_system_encoding(); $needle = api_convert_encoding($needle, $charset, 'utf-8'); + $assigned_users_to_hrm = array(); + + switch ($userStatus) { + case DRH: + $assigned_users_to_hrm = UserManager::get_users_followed_by_drh($user_id); + break; + case STUDENT_BOSS: + $assigned_users_to_hrm = UserManager::getUsersFollowedByStudentBoss($user_id); + break; + } - $assigned_users_to_hrm = UserManager::get_users_followed_by_drh($user_id); $assigned_users_id = array_keys($assigned_users_to_hrm); $without_assigned_users = ''; @@ -92,7 +105,7 @@ function search_users($needle,$type) LEFT JOIN $tbl_access_url_rel_user au ON (au.user_id = user.user_id) WHERE ".(api_sort_by_first_name() ? 'firstname' : 'lastname')." LIKE '$needle%' AND - status NOT IN(".DRH.", ".SESSIONADMIN.") AND + status NOT IN(".DRH.", ".SESSIONADMIN.", " . STUDENT_BOSS . ") AND user.user_id NOT IN ($user_anonymous, $current_user_id, $user_id) $without_assigned_users AND access_url_id = ".api_get_current_access_url_id()." @@ -104,7 +117,7 @@ function search_users($needle,$type) FROM $tbl_user user WHERE ".(api_sort_by_first_name() ? 'firstname' : 'lastname')." LIKE '$needle%' AND - status NOT IN(".DRH.", ".SESSIONADMIN.") AND + status NOT IN(".DRH.", ".SESSIONADMIN.", " . STUDENT_BOSS . ") AND user_id NOT IN ($user_anonymous, $current_user_id, $user_id) $without_assigned_users $order_clause @@ -127,10 +140,19 @@ function search_users($needle,$type) username LIKE "'.$needle.'%" OR firstname LIKE "'.$needle.'%" OR lastname LIKE "'.$needle.'%" - ) AND - user.status<>6 AND user.status<>'.DRH.' '. - $order_clause. - ' LIMIT 11'; + ) AND '; + + switch ($userStatus) { + case DRH: + $sql .= " user.status <> 6 AND user.status <> " . DRH; + break; + case STUDENT_BOSS: + $sql .= " user.status <> 6 AND user.status <> " . STUDENT_BOSS; + break; + } + + $sql .= " $order_clause LIMIT 11"; + $rs = Database::query($sql); $i = 0; while ($user = Database :: fetch_array($rs)) { @@ -267,7 +289,18 @@ if (!empty($filters) && !empty($filterData)) { $msg = ''; if (isset($_POST['formSent']) && intval($_POST['formSent']) == 1) { $user_list = $_POST['UsersList']; - $affected_rows = UserManager::suscribe_users_to_hr_manager($user_id, $user_list); + + switch ($userStatus) { + case DRH: + $affected_rows = UserManager::suscribe_users_to_hr_manager($user_id, $user_list); + break; + case STUDENT_BOSS; + $affected_rows = UserManager::subscribeUsersToBoss($user_id, $user_list); + break; + default: + $affected_rows = 0; + } + if ($affected_rows) { $msg = get_lang('AssignedUsersHaveBeenUpdatedSuccessfully'); } @@ -278,11 +311,27 @@ Display::display_header($tool_name); // actions echo '
'; -echo ' -'. - Display::return_icon('course_add.gif', get_lang('AssignCourses'), array('style'=>'vertical-align:middle')).' '.get_lang('AssignCourses').' -'. - Display::return_icon('view_more_stats.gif', get_lang('AssignSessions'), array('style'=>'vertical-align:middle')).' '.get_lang('AssignSessions').''; + +if ($userStatus != STUDENT_BOSS) { + $actions = Display::url( + Display::return_icon('course_add.gif', get_lang('AssignCourses'), + array( + 'style' => 'vertical-align:middle' + )) . get_lang('AssignCourses'), "dashboard_add_courses_to_user.php?user=$user_id" + ); + + $actions .= Display::url( + Display::return_icon('view_more_stats.gif', get_lang('AssignSessions'), + array( + 'style' => 'vertical-align:middle' + )) . get_lang('AssignSessions'), "dashboard_add_sessions_to_user.php?user=$user_id" + ); + + echo Display::span($actions, array( + 'style' => 'float: right; margin: 0; paddingg: 0;' + )); +} + echo Display::url(get_lang('AdvancedSearch'), '#', array('class' => 'advanced_options', 'id' => 'advanced_search')); echo '
'; @@ -294,7 +343,15 @@ echo Display::page_header( sprintf(get_lang('AssignUsersToX'), api_get_person_name($user_info['firstname'], $user_info['lastname'])) ); -$assigned_users_to_hrm = UserManager::get_users_followed_by_drh($user_id); +switch ($userStatus) { + case DRH: + $assigned_users_to_hrm = UserManager::get_users_followed_by_drh($user_id); + break; + case STUDENT_BOSS; + $assigned_users_to_hrm = UserManager::getUsersFollowedByStudentBoss($user_id); + break; +} + $assigned_users_id = array_keys($assigned_users_to_hrm); $without_assigned_users = ''; if (count($assigned_users_id) > 0) { @@ -368,6 +425,8 @@ if(!empty($msg)) { echo get_lang('AssignedUsersListToPlatformAdministrator'); } else if ($user_info['status'] == SESSIONADMIN) { echo get_lang('AssignedUsersListToSessionsAdministrator'); + } else if ($user_info['status'] == STUDENT_BOSS) { + echo get_lang('AssignedUsersListToStudentBoss'); } else { echo get_lang('AssignedUsersListToHumanResourcesManager'); } diff --git a/main/admin/user_add.php b/main/admin/user_add.php index a92c0bf291..318cdc9fe6 100755 --- a/main/admin/user_add.php +++ b/main/admin/user_add.php @@ -198,6 +198,7 @@ $status[COURSEMANAGER] = get_lang('Teacher'); $status[STUDENT] = get_lang('Learner'); $status[DRH] = get_lang('Drh'); $status[SESSIONADMIN] = get_lang('SessionsAdmin'); +$status[STUDENT_BOSS] = get_lang('RoleStudentBoss'); $form->addElement('select', 'status', get_lang('Profile'), $status, array('id' => 'status_select', 'class'=>'chzn-select', 'onchange' => 'javascript: display_drh_list();')); diff --git a/main/admin/user_edit.php b/main/admin/user_edit.php index 93ac043d9a..86c8de9461 100755 --- a/main/admin/user_edit.php +++ b/main/admin/user_edit.php @@ -211,6 +211,7 @@ $status[COURSEMANAGER] = get_lang('Teacher'); $status[STUDENT] = get_lang('Learner'); $status[DRH] = get_lang('Drh'); $status[SESSIONADMIN] = get_lang('SessionsAdmin'); +$status[STUDENT_BOSS] = get_lang('RoleStudentBoss'); $form->addElement('select', 'status', get_lang('Profile'), $status, array('id' => 'status_select', 'onchange' => 'javascript: display_drh_list();','class'=>'chzn-select')); diff --git a/main/admin/user_list.php b/main/admin/user_list.php index 3abd4f7bef..d88b802efc 100755 --- a/main/admin/user_list.php +++ b/main/admin/user_list.php @@ -579,13 +579,35 @@ function modify_filter($user_id, $url_params, $row) { $result .= ''.Display::return_icon('view_more_stats.gif', get_lang('AssignSessions')).'  '; }*/ } else { - if ($current_user_status_label == $statusname[DRH] || UserManager::is_admin($user_id)) { - $result .= ''.Display::return_icon('user_subscribe_course.png', get_lang('AssignUsers'),'',ICON_SIZE_SMALL).''; - $result .= ''.Display::return_icon('course_add.gif', get_lang('AssignCourses')).'  '; - $result .= ''.Display::return_icon('view_more_stats.gif', get_lang('AssignSessions')).'  '; - } else if ($current_user_status_label == $statusname[SESSIONADMIN]) { - $result .= ''.Display::return_icon('view_more_stats.gif', get_lang('AssignSessions')).'  '; - } + if ($current_user_status_label == $statusname[SESSIONADMIN]) { + $result .= Display::url( + Display::return_icon('view_more_stats.gif', get_lang('AssignSessions')), + "dashboard_add_sessions_to_user.php?user={$user_id}" + ); + } else { + if ( + $current_user_status_label == $statusname[DRH] || + UserManager::is_admin($user_id) || + $current_user_status_label == $statusname[STUDENT_BOSS] + ) { + $result .= Display::url( + Display::return_icon('user_subscribe_course.png', get_lang('AssignUsers'), '', ICON_SIZE_SMALL), + "dashboard_add_users_to_user.php?user={$user_id}" + ); + } + + if ($current_user_status_label == $statusname[DRH] || UserManager::is_admin($user_id)) { + $result .= Display::url( + Display::return_icon('course_add.gif', get_lang('AssignCourses')), + "dashboard_add_courses_to_user.php?user={$user_id}" + ); + + $result .= Display::url( + Display::return_icon('view_more_stats.gif', get_lang('AssignSessions')), + "dashboard_add_sessions_to_user.php?user={$user_id}" + ); + } + } } if (api_is_platform_admin()) { diff --git a/main/auth/my_progress.php b/main/auth/my_progress.php index 1aaa3bfd79..561978902d 100755 --- a/main/auth/my_progress.php +++ b/main/auth/my_progress.php @@ -50,6 +50,9 @@ $user_id = api_get_user_id(); $course_user_list = CourseManager::get_courses_list_by_user_id($user_id); $dates = $issues = ''; +$sessionId = isset($_GET['session_id']) ? intval($_GET['session_id']) : 0; +$courseCode = isset($_GET['course']) ? Security::remove_XSS($_GET['course']) : null; + if (!empty($course_user_list)) { $items = MySpace::get_connections_from_course_list($user_id, $course_user_list); @@ -82,8 +85,10 @@ if (!empty($course_user_list)) { } } -$content .= Tracking::show_user_progress(api_get_user_id(), $_GET['session_id']); -$content .= Tracking::show_course_detail(api_get_user_id(), $_GET['course'], $_GET['session_id']); +$content = ''; + +$content .= Tracking::show_user_progress(api_get_user_id(), $sessionId); +$content .= Tracking::show_course_detail(api_get_user_id(), $courseCode, $sessionId); if (!empty($dates)) { if (!empty($content)) { @@ -104,11 +109,13 @@ if (!empty($dates)) { '; } +$message = null; + if (empty($content)) { $message = Display::return_message(get_lang('NoDataAvailable'), 'warning'); } -$tpl = new Template($tool_name); +$tpl = new Template($nameTools); $tpl->assign('message', $message); $tpl->assign('content', $content); diff --git a/main/exercice/exercise.class.php b/main/exercice/exercise.class.php index 1b554f97c4..2d70eceacb 100755 --- a/main/exercice/exercise.class.php +++ b/main/exercice/exercise.class.php @@ -2341,14 +2341,14 @@ class Exercise $choice[$ind] = 1; } - $studentChoice = $choice[$numAnswer]; + $studentChoice = isset($choice[$numAnswer]) ? $choice[$numAnswer] : null; $real_answers[$answerId] = (bool)$studentChoice; if ($studentChoice) { $questionScore +=$answerWeighting; } } else { - $studentChoice = $choice[$numAnswer]; + $studentChoice = isset($choice[$numAnswer]) ? $choice[$numAnswer] : null; $real_answers[$answerId] = (bool)$studentChoice; if (isset($studentChoice)) { diff --git a/main/exercice/exercise.lib.php b/main/exercice/exercise.lib.php index 6d36767778..327b44eb95 100755 --- a/main/exercice/exercise.lib.php +++ b/main/exercice/exercise.lib.php @@ -1198,7 +1198,7 @@ function get_exam_results_data( $course_code = api_get_course_id(); $sessionId = api_get_session_id(); - $is_allowedToEdit = api_is_allowed_to_edit(null,true) || api_is_allowed_to_edit(true) || api_is_drh(); + $is_allowedToEdit = api_is_allowed_to_edit(null,true) || api_is_allowed_to_edit(true) || api_is_drh() || api_is_student_boss(); $TBL_USER = Database :: get_main_table(TABLE_MAIN_USER); $TBL_EXERCICES = Database :: get_course_table(TABLE_QUIZ_TEST); @@ -1506,8 +1506,8 @@ function get_exam_results_data( Display :: return_icon('history.gif', get_lang('ViewHistoryChange')).''; } - // Admin can always delete the attempt - if ($locked == false || api_is_platform_admin()) { + //Admin can always delete the attempt + if (($locked == false || api_is_platform_admin()) && !api_is_student_boss()) { $ip = TrackingUserLog::get_ip_from_user_event($results[$i]['exe_user_id'], date('Y-m-d h:i:s'), false); $actions .= ''; diff --git a/main/exercice/exercise_report.php b/main/exercice/exercise_report.php index 7bdddc9f31..b277e990e3 100755 --- a/main/exercice/exercise_report.php +++ b/main/exercice/exercise_report.php @@ -46,7 +46,7 @@ $gradebook = isset($gradebook) ? $gradebook : null; $path = isset($_GET['path']) ? Security::remove_XSS($_GET['path']) : null; /* Constants and variables */ -$is_allowedToEdit = api_is_allowed_to_edit(null, true) || api_is_drh(); +$is_allowedToEdit = api_is_allowed_to_edit(null, true) || api_is_drh() || api_is_student_boss(); $is_tutor = api_is_allowed_to_edit(true); $TBL_QUESTIONS = Database :: get_course_table(TABLE_QUIZ_QUESTION); diff --git a/main/exercice/exercise_show.php b/main/exercice/exercise_show.php index 1a7bb54b20..01b677fa40 100755 --- a/main/exercice/exercise_show.php +++ b/main/exercice/exercise_show.php @@ -73,7 +73,7 @@ if (api_is_course_session_coach( } $maxEditors = isset($_configuration['exercise_max_fckeditors_in_page']) ? $_configuration['exercise_max_fckeditors_in_page'] : 0; -$is_allowedToEdit = api_is_allowed_to_edit(null, true) || $is_courseTutor || api_is_session_admin() || api_is_drh(); +$is_allowedToEdit = api_is_allowed_to_edit(null, true) || $is_courseTutor || api_is_session_admin() || api_is_drh() || api_is_student_boss(); //Getting results from the exe_id. This variable also contain all the information about the exercise $track_exercise_info = get_exercise_track_exercise_info($id); @@ -512,7 +512,7 @@ foreach ($questionList as $questionId) { $comnt = null; if ($show_results) { - if ($is_allowedToEdit && $locked == false && !api_is_drh()) { + if ($is_allowedToEdit && $locked == false && !api_is_drh() && !api_is_student_boss()) { $name = "fckdiv".$questionId; $marksname = "marksName".$questionId; if (in_array($answerType, array(FREE_ANSWER, ORAL_EXPRESSION))) { @@ -712,7 +712,7 @@ if (is_array($arrid) && is_array($arrmarks)) { $marksid = implode(",",$arrmarks); } -if ($is_allowedToEdit && $locked == false && !api_is_drh()) { +if ($is_allowedToEdit && $locked == false && !api_is_drh() && !api_is_student_boss()) { if (in_array($origin, array('tracking_course','user_course','correct_exercise_in_lp'))) { echo '
'; echo ''; diff --git a/main/gradebook/lib/be/category.class.php b/main/gradebook/lib/be/category.class.php index b704b148ff..0ffcb4b5c7 100755 --- a/main/gradebook/lib/be/category.class.php +++ b/main/gradebook/lib/be/category.class.php @@ -292,7 +292,6 @@ class Category implements GradebookItem // otherwise a special parameter is given to ask explicitely $sql .= " AND (session_id IS NULL OR session_id = 0) "; } else {*/ - if (empty($session_id)) { $sql .= ' AND (session_id IS NULL OR session_id = 0) '; } else { @@ -326,14 +325,15 @@ class Category implements GradebookItem $sql .= ' '.$order_by; } } + $result = Database::query($sql); - $allcat = array(); + $categories = array(); if (Database::num_rows($result) > 0) { - $allcat = Category::create_category_objects_from_sql_result($result); + $categories = Category::create_category_objects_from_sql_result($result); } - return $allcat; + return $categories; } /** @@ -731,7 +731,7 @@ class Category implements GradebookItem */ public function calc_score($stud_id = null, $course_code = '', $session_id = null) { - // get appropriate subcategories, evaluations and links + // Get appropriate subcategories, evaluations and links if (!empty($course_code)) { $cats = $this->get_subcategories($stud_id, $course_code, $session_id); $evals = $this->get_evaluations($stud_id, false, $course_code); @@ -782,10 +782,9 @@ class Category implements GradebookItem } if (!empty($links)) { - /** @var EvalLink $link */ + /** @var EvalLink|ExerciseLink $link */ foreach ($links as $link) { $linkres = $link->calc_score($stud_id); - if (!empty($linkres) && $link->get_weight() != 0) { $linkweight = $link->get_weight(); $link_res_denom = $linkres[1] == 0 ? 1 : $linkres[1]; @@ -1296,14 +1295,23 @@ class Category implements GradebookItem // 1 student if (isset($stud_id)) { - // special case: this is the root + // Special case: this is the root if ($this->id == 0) { return Category::get_root_categories_for_student($stud_id, $course_code, $session_id); } else { - return Category::load(null,null, $course_code, $this->id, api_is_allowed_to_edit() ? null : 1, $session_id, $order); + return Category::load( + null, + null, + $course_code, + $this->id, + api_is_allowed_to_edit() ? null : 1, + $session_id, + $order + ); } - } else {// all students - // course admin + } else { + // All students + // Course admin if (api_is_allowed_to_edit() && !api_is_platform_admin()) { // root if ($this->id == 0) { diff --git a/main/gradebook/lib/be/evallink.class.php b/main/gradebook/lib/be/evallink.class.php index 34484703cf..651e6da3ae 100755 --- a/main/gradebook/lib/be/evallink.class.php +++ b/main/gradebook/lib/be/evallink.class.php @@ -19,18 +19,26 @@ abstract class EvalLink extends AbstractLink parent::__construct(); } - // Functions implementing AbstractLink - + /** + * @return bool + */ public function has_results() { $eval = $this->get_evaluation(); + return $eval->has_results(); } - public function calc_score($stud_id = null) + /** + * @param int $userId + * + * @return array + */ + public function calc_score($userId = null) { $eval = $this->get_evaluation(); - return $eval->calc_score($stud_id); + + return $eval->calc_score($userId); } public function get_link() diff --git a/main/gradebook/lib/be/exerciselink.class.php b/main/gradebook/lib/be/exerciselink.class.php index b5d5db16b8..38e5161e50 100755 --- a/main/gradebook/lib/be/exerciselink.class.php +++ b/main/gradebook/lib/be/exerciselink.class.php @@ -221,7 +221,7 @@ class ExerciseLink extends AbstractLink if ($student_count == 0) { return null; } else { - return array ($sum , $student_count); + return array($sum, $student_count); } } } diff --git a/main/gradebook/lib/fe/flatviewtable.class.php b/main/gradebook/lib/fe/flatviewtable.class.php index 77a4e4f0d9..5319a22aad 100755 --- a/main/gradebook/lib/fe/flatviewtable.class.php +++ b/main/gradebook/lib/fe/flatviewtable.class.php @@ -47,6 +47,7 @@ class FlatViewTable extends SortableTable $mainCourseCategory = null ) { parent :: __construct('flatviewlist', null, null, (api_is_western_name_order() xor api_sort_by_first_name()) ? 1 : 0); + $this->selectcat = $selectcat; $this->datagen = new FlatViewDataGenerator( @@ -368,10 +369,13 @@ class FlatViewTable extends SortableTable } // retrieve sorting type + if ($is_western_name_order) { - $users_sorting = ($this->column == 0 ? FlatViewDataGenerator :: FVDG_SORT_FIRSTNAME : FlatViewDataGenerator :: FVDG_SORT_LASTNAME); + //$users_sorting = ($this->column == 0 ? FlatViewDataGenerator :: FVDG_SORT_FIRSTNAME : FlatViewDataGenerator :: FVDG_SORT_LASTNAME); + $users_sorting = FlatViewDataGenerator :: FVDG_SORT_FIRSTNAME; } else { - $users_sorting = ($this->column == 0 ? FlatViewDataGenerator :: FVDG_SORT_LASTNAME : FlatViewDataGenerator :: FVDG_SORT_FIRSTNAME); + //$users_sorting = ($this->column == 0 ? FlatViewDataGenerator :: FVDG_SORT_LASTNAME : FlatViewDataGenerator :: FVDG_SORT_FIRSTNAME); + $users_sorting = FlatViewDataGenerator :: FVDG_SORT_LASTNAME; } if ($this->direction == 'DESC') { $users_sorting |= FlatViewDataGenerator :: FVDG_SORT_DESC; @@ -382,16 +386,15 @@ class FlatViewTable extends SortableTable $header_names = $this->datagen->get_header_names($this->offset, $selectlimit); - $column = 0; - if ($is_western_name_order) { - $this->set_header($column++, $header_names[1]); - $this->set_header($column++, $header_names[0]); + $this->set_header(0, $header_names[1]); + $this->set_header(1, $header_names[0]); } else { - $this->set_header($column++, $header_names[0]); - $this->set_header($column++, $header_names[1]); + $this->set_header(0, $header_names[0]); + $this->set_header(1, $header_names[1]); } + $column = 2; while ($column < count($header_names)) { $this->set_header($column, $header_names[$column], false); $column++; diff --git a/main/gradebook/lib/flatview_data_generator.class.php b/main/gradebook/lib/flatview_data_generator.class.php index 736411a315..405d518b65 100755 --- a/main/gradebook/lib/flatview_data_generator.class.php +++ b/main/gradebook/lib/flatview_data_generator.class.php @@ -157,9 +157,11 @@ class FlatViewDataGenerator $session_id, 'ORDER BY id' ); + $evaluationsAdded = array(); if ($parent_id == 0 && !empty($allcat)) { // Means there are any subcategory + foreach ($allcat as $sub_cat) { $sub_cat_weight = round(100 * $sub_cat->get_weight() / $main_weight, 1); $add_weight = " $sub_cat_weight %"; @@ -216,7 +218,8 @@ class FlatViewDataGenerator $max = $score[0]; } } - return $max ; + + return $max; } /** @@ -389,7 +392,12 @@ class FlatViewDataGenerator $course_code = api_get_course_id(); $session_id = api_get_session_id(); - $allcat = $this->category->get_subcategories(null, $course_code, $session_id, 'ORDER BY id'); + $allcat = $this->category->get_subcategories( + null, + $course_code, + $session_id, + 'ORDER BY id' + ); $evaluationsAdded = array(); @@ -400,7 +408,7 @@ class FlatViewDataGenerator $real_score = $score; - $divide = ( ($score[1])==0 ) ? 1 : $score[1]; + $divide = $score[1] == 0 ? 1 : $score[1]; $sub_cat_percentage = $sum_categories_weight_array[$sub_cat->get_id()]; $item_value = $score[0]/$divide*$main_weight; @@ -410,10 +418,10 @@ class FlatViewDataGenerator $item_value = $percentage*$item_value; $item_total += $sub_cat->get_weight(); /* - if ($convert_using_the_global_weight) { - $score[0] = $score[0]/$main_weight*$sub_cat->get_weight(); - $score[1] = $main_weight ; - } + if ($convert_using_the_global_weight) { + $score[0] = $score[0]/$main_weight*$sub_cat->get_weight(); + $score[1] = $main_weight ; + } */ if (api_get_setting('gradebook_show_percentage_in_reports') == 'false') { //if (true) @@ -427,8 +435,7 @@ class FlatViewDataGenerator } if (!isset($this->params['only_total_category']) || - (isset($this->params['only_total_category']) && - $this->params['only_total_category'] == false) + (isset($this->params['only_total_category']) && $this->params['only_total_category'] == false) ) { if (!$show_all) { $row[] = $temp_score.' '; diff --git a/main/gradebook/lib/scoredisplay.class.php b/main/gradebook/lib/scoredisplay.class.php index 7881352c45..e46f7b8998 100755 --- a/main/gradebook/lib/scoredisplay.class.php +++ b/main/gradebook/lib/scoredisplay.class.php @@ -364,9 +364,11 @@ class ScoreDisplay return $this->display_as_div($score).' (' . $this->display_as_percent($score) . ')'.$custom; case SCORE_DIV_SIMPLE_WITH_CUSTOM : // X - Good! $custom = $this->display_custom($score); + if (!empty($custom)) { $custom = ' - '.$custom; } + return $this->display_simple_score($score).$custom; break; case SCORE_DIV_SIMPLE_WITH_CUSTOM_LETTERS: diff --git a/main/inc/ajax/model.ajax.php b/main/inc/ajax/model.ajax.php index 115471efd4..00b189eed4 100755 --- a/main/inc/ajax/model.ajax.php +++ b/main/inc/ajax/model.ajax.php @@ -658,7 +658,7 @@ switch ($action) { $course = api_get_course_info(); // Used inside get_exam_results_data() $documentPath = api_get_path(SYS_COURSE_PATH) . $course['path'] . "/document"; - if ($is_allowedToEdit) { + if ($is_allowedToEdit || api_is_student_boss()) { $columns = array( 'firstname', 'lastname', 'username', 'group_name', 'exe_duration', 'start_date', 'exe_date', 'score', 'status', 'lp', 'actions' ); diff --git a/main/inc/lib/banner.lib.php b/main/inc/lib/banner.lib.php index ba6868b27f..37a1e38b5b 100755 --- a/main/inc/lib/banner.lib.php +++ b/main/inc/lib/banner.lib.php @@ -59,7 +59,11 @@ function get_tabs() { $navigation['session_my_space']['url'] = api_get_path(WEB_CODE_PATH).'mySpace/'.(api_is_drh()?'session.php':''); $navigation['session_my_space']['title'] = get_lang('MySpace'); $navigation['session_my_space']['key'] = 'my-space'; - } else { + } else if (api_is_student_boss()) { + $navigation['session_my_space']['url'] = api_get_path(WEB_CODE_PATH) . 'mySpace/student.php'; + $navigation['session_my_space']['title'] = get_lang('MySpace'); + $navigation['session_my_space']['key'] = 'my-space'; + } else { // Link to my progress $navigation['session_my_progress']['url'] = api_get_path(WEB_CODE_PATH).'auth/my_progress.php'; $navigation['session_my_progress']['title'] = get_lang('MyProgress'); @@ -303,13 +307,13 @@ function return_navigation_array() { // Reporting if (api_get_setting('show_tabs', 'reporting') == 'true') { - if (api_is_allowed_to_create_course() || api_is_drh() || api_is_session_admin()) { + if (api_is_allowed_to_create_course() || api_is_drh() || api_is_session_admin() || api_is_student_boss()) { $navigation['session_my_space'] = $possible_tabs['session_my_space']; } else { $navigation['session_my_space'] = $possible_tabs['session_my_progress']; } } else { - if (api_is_allowed_to_create_course() || api_is_drh() || api_is_session_admin()) { + if (api_is_allowed_to_create_course() || api_is_drh() || api_is_session_admin() || api_is_student_boss()) { $menu_navigation['session_my_space'] = $possible_tabs['session_my_space']; } else { $menu_navigation['session_my_space'] = $possible_tabs['session_my_progress']; diff --git a/main/inc/lib/certificate.lib.php b/main/inc/lib/certificate.lib.php index 364925864c..b82c599449 100755 --- a/main/inc/lib/certificate.lib.php +++ b/main/inc/lib/certificate.lib.php @@ -167,8 +167,11 @@ class Certificate extends Model //If the gradebook is related to skills we added the skills to the user + $courseId = api_get_real_course_id(); + $sessionId = api_get_session_id(); + $skill = new Skill(); - $skill->add_skill_to_user($this->user_id, $this->certificate_data['cat_id']); + $skill->add_skill_to_user($this->user_id, $this->certificate_data['cat_id'], $courseId, $sessionId); if (is_dir($this->certification_user_path)) { if (!empty($this->certificate_data)) { diff --git a/main/inc/lib/main_api.lib.php b/main/inc/lib/main_api.lib.php index 4cef53afbb..66ee067cd7 100755 --- a/main/inc/lib/main_api.lib.php +++ b/main/inc/lib/main_api.lib.php @@ -43,6 +43,7 @@ define('SESSION_GENERAL_COACH', 13); define('COURSE_STUDENT', 14); //student subscribed in a course define('SESSION_STUDENT', 15); //student subscribed in a session course define('COURSE_TUTOR', 16); // student is tutor of a course (NOT in session) +define('STUDENT_BOSS', 17); // student is boss // Table of status $_status_list[COURSEMANAGER] = 'teacher'; // 1 @@ -325,6 +326,7 @@ define('USER_RELATION_TYPE_GOODFRIEND', 4); // should be deprecated is useless define('USER_RELATION_TYPE_ENEMY', 5); // should be deprecated is useless define('USER_RELATION_TYPE_DELETED', 6); define('USER_RELATION_TYPE_RRHH', 7); +define('USER_RELATION_TYPE_BOSS', 8); //Gradebook link constants //Please do not change existing values, they are used in the database ! @@ -1312,6 +1314,8 @@ function api_get_user_info_from_username($username = '') if (empty($username)) { return false; } + $username = trim($username); + $sql = "SELECT * FROM ".Database :: get_main_table(TABLE_MAIN_USER)." WHERE username='".Database::escape_string($username)."'"; $result = Database::query($sql); @@ -4669,7 +4673,8 @@ function api_get_status_langvars() { SESSIONADMIN => get_lang('SessionsAdmin', ''), DRH => get_lang('Drh', ''), STUDENT => get_lang('Student', ''), - ANONYMOUS => get_lang('Anonymous', '') + ANONYMOUS => get_lang('Anonymous', ''), + STUDENT_BOSS => get_lang('RoleStudentBoss', '') ); } @@ -7504,6 +7509,18 @@ function api_register_campus($listCampus = true) { // Reload the settings. } +/** + * Checks whether current user is a student boss + * @global array $_user + * @return boolean + */ +function api_is_student_boss () +{ + global $_user; + + return isset($_user['status']) && $_user['status'] == STUDENT_BOSS; +} + /** * Set the Site Use Cookie Warning for 1 year */ diff --git a/main/inc/lib/sessionmanager.lib.php b/main/inc/lib/sessionmanager.lib.php index e06e1ae969..4eacdf10e1 100755 --- a/main/inc/lib/sessionmanager.lib.php +++ b/main/inc/lib/sessionmanager.lib.php @@ -4763,7 +4763,7 @@ class SessionManager null, $active, $lastConnectionDate, - COURSEMANAGER, + api_is_student_boss() ? STUDENT_BOSS : COURSEMANAGER, $keyword ); } diff --git a/main/inc/lib/skill.lib.php b/main/inc/lib/skill.lib.php index bf0cf48ae8..d326b63555 100755 --- a/main/inc/lib/skill.lib.php +++ b/main/inc/lib/skill.lib.php @@ -335,7 +335,7 @@ class SkillRelGradebook extends Model */ class SkillRelUser extends Model { - public $columns = array('id', 'user_id', 'skill_id', 'acquired_skill_at', 'assigned_by'); + public $columns = array('id', 'user_id', 'skill_id', 'acquired_skill_at', 'assigned_by', 'course_id', 'session_id'); public function __construct() { @@ -602,21 +602,27 @@ class Skill extends Model return null; } - public function add_skill_to_user($user_id, $gradebook_id) + public function add_skill_to_user($user_id, $gradebook_id, $courseId = 0, $sessionId = 0) { + $courseId = intval($courseId); + $sessionId = intval($sessionId); + $skill_gradebook = new SkillRelGradebook(); $skill_rel_user = new SkillRelUser(); $skill_gradebooks = $skill_gradebook->get_all(array('where' => array('gradebook_id = ?' => $gradebook_id))); if (!empty($skill_gradebooks)) { foreach ($skill_gradebooks as $skill_gradebook) { - $user_has_skill = $this->user_has_skill($user_id, $skill_gradebook['skill_id']); + $user_has_skill = $this->user_has_skill($user_id, $skill_gradebook['skill_id'], $courseId, $sessionId); if (!$user_has_skill) { $params = array( 'user_id' => $user_id, 'skill_id' => $skill_gradebook['skill_id'], 'acquired_skill_at' => api_get_utc_datetime(), + 'course_id' => $courseId, + 'session_id' => $sessionId ); + $skill_rel_user->save($params); } } @@ -978,11 +984,24 @@ class Skill extends Model * * @return bool */ - public function user_has_skill($user_id, $skill_id) - { - $skills = $this->get_user_skills($user_id); - foreach ($skills as $my_skill_id) { - if ($my_skill_id == $skill_id) { + public function user_has_skill($user_id, $skill_id, $courseId = 0, $sessionId = 0) + { + $courseId = intval($courseId); + $sessionId = intval($sessionId); + + $whereConditions = array( + 'user_id = ? ' => $user_id, + 'AND skill_id = ? ' => $skill_id, + 'AND course_id = ? ' => $courseId, + 'AND session_id = ? ' => $sessionId + ); + + $result = Database::select('COUNT(1) AS qty', $this->table_skill_rel_user, array( + 'where' => $whereConditions + ), 'first'); + + if ($result != false) { + if ($result['qty'] > 0) { return true; } } @@ -1026,4 +1045,74 @@ class Skill extends Model return false; } + /** + * Get the achieved skills by course + * @param int $courseId The course id + * @return array The skills list + */ + public function listAchievedByCourse($courseId) + { + $courseId = intval($courseId); + + if ($courseId == 0) { + return array(); + } + + $list = array(); + + $sql = "SELECT course.id c_id, course.title c_name, course.directory c_directory, user.user_id, user.lastname, " + . "user.firstname, user.username, skill.id skill_id, skill.name skill_name, sru.acquired_skill_at " + . "FROM {$this->table_skill_rel_user} AS sru " + . "INNER JOIN {$this->table_course} " + . "ON sru.course_id = course.id " + . "INNER JOIN {$this->table_user} " + . "ON sru.user_id = user.user_id " + . "INNER JOIN {$this->table} " + . "ON sru.skill_id = skill.id " + . "WHERE course.id = $courseId"; + + $result = Database::query($sql); + + while ($row = Database::fetch_assoc($result)) { + $list[] = $row; + } + + return $list; + } + + /** + * Get the users list who achieved a skill + * @param int $skillId The skill id + * @return array The users list + */ + public function listUsersWhoAchieved($skillId) + { + $skillId = intval($skillId); + + if ($skillId == 0) { + return array(); + } + + $list = array(); + + $sql = "SELECT course.id c_id, course.title c_name, course.directory c_directory, user.user_id, user.lastname, " + . "user.firstname, user.username, skill.id skill_id, skill.name skill_name, sru.acquired_skill_at " + . "FROM {$this->table_skill_rel_user} AS sru " + . "INNER JOIN {$this->table_course} " + . "ON sru.course_id = course.id " + . "INNER JOIN {$this->table_user} " + . "ON sru.user_id = user.user_id " + . "INNER JOIN {$this->table} " + . "ON sru.skill_id = skill.id " + . "WHERE skill.id = $skillId "; + + $result = Database::query($sql); + + while ($row = Database::fetch_assoc($result)) { + $list[] = $row; + } + + return $list; + } + } diff --git a/main/inc/lib/sortable_table.class.php b/main/inc/lib/sortable_table.class.php index 3dc1880e19..0882a37eaa 100755 --- a/main/inc/lib/sortable_table.class.php +++ b/main/inc/lib/sortable_table.class.php @@ -244,7 +244,7 @@ class SortableTable extends HTML_Table public function return_table() { $empty_table = false; - $this->processHeaders(); + $content = $this->get_table_html(); if ($this->get_total_number_of_items() == 0) { @@ -574,6 +574,8 @@ class SortableTable extends HTML_Table $table_data = $this->get_table_data($from); + $this->processHeaders(); + if (is_array($table_data)) { $count = 1; foreach ($table_data as & $row) { @@ -697,6 +699,7 @@ class SortableTable extends HTML_Table public function processHeaders() { $counter = 0; + foreach ($this->headers as $column => $columnInfo) { $label = $columnInfo['label']; $sortable = $columnInfo['sortable']; @@ -743,7 +746,6 @@ class SortableTable extends HTML_Table $counter++; } - } /** diff --git a/main/inc/lib/usermanager.lib.php b/main/inc/lib/usermanager.lib.php index 8545c4e77a..5d39832263 100755 --- a/main/inc/lib/usermanager.lib.php +++ b/main/inc/lib/usermanager.lib.php @@ -4216,6 +4216,10 @@ class UserManager )" ; break; + case STUDENT_BOSS : + $drhConditions = " AND friend_user_id = $userId AND " + . "relation_type = " . USER_RELATION_TYPE_BOSS; + break; } $join = null; @@ -4282,51 +4286,65 @@ class UserManager * */ public static function suscribe_users_to_hr_manager($hr_dept_id, $users_id) { - // Database Table Definitions - $tbl_user_rel_user = Database::get_main_table(TABLE_MAIN_USER_REL_USER); - $tbl_user_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); + return self::subscribeUsersToUser($hr_dept_id, $users_id, USER_RELATION_TYPE_RRHH); + } - $hr_dept_id = intval($hr_dept_id); - $affected_rows = 0; + /** + * Add subscribed users to a user by relation type + * @param int $userId The user id + * @param array $subscribedUsersId The id of suscribed users + * @param action $relationType The relation type + */ + public static function subscribeUsersToUser($userId, $subscribedUsersId, $relationType) + { + $userRelUserTable = Database::get_main_table(TABLE_MAIN_USER_REL_USER); + $userRelAccessUrlTable = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); + + $userId = intval($userId); + $relationType = intval($relationType); + $affectedRows = 0; if (api_get_multiple_access_url()) { //Deleting assigned users to hrm_id - $sql = "SELECT s.user_id FROM $tbl_user_rel_user s - INNER JOIN $tbl_user_rel_access_url a - ON (a.user_id = s.user_id) - WHERE - friend_user_id = $hr_dept_id AND - relation_type = '".USER_RELATION_TYPE_RRHH."' AND - access_url_id = ".api_get_current_access_url_id().""; + $sql = "SELECT s.user_id FROM $userRelUserTable s " + . "INNER JOIN $userRelAccessUrlTable a ON (a.user_id = s.user_id) " + . "WHERE friend_user_id = $userId " + . "AND relation_type = $relationType " + . "AND access_url_id = " . api_get_current_access_url_id() . ""; } else { - $sql = "SELECT user_id FROM $tbl_user_rel_user - WHERE - friend_user_id = $hr_dept_id AND - relation_type = '".USER_RELATION_TYPE_RRHH."' "; + $sql = "SELECT user_id FROM $userRelUserTable " + . "WHERE friend_user_id = $userId " + . "AND relation_type = $relationType"; } + $result = Database::query($sql); + if (Database::num_rows($result) > 0) { while ($row = Database::fetch_array($result)) { - $sql = "DELETE FROM $tbl_user_rel_user - WHERE - user_id = '{$row['user_id']}' AND - friend_user_id = $hr_dept_id AND - relation_type = '".USER_RELATION_TYPE_RRHH."' "; + $sql = "DELETE FROM $userRelUserTable " + . "WHERE user_id = {$row['user_id']} " + . "AND friend_user_id = $userId " + . "AND relation_type = $relationType"; + Database::query($sql); } } // Inserting new user list - if (is_array($users_id)) { - foreach ($users_id as $user_id) { - $user_id = intval($user_id); - $sql = "INSERT IGNORE INTO $tbl_user_rel_user(user_id, friend_user_id, relation_type) - VALUES ('$user_id', $hr_dept_id, '".USER_RELATION_TYPE_RRHH."')"; + if (is_array($subscribedUsersId)) { + foreach ($subscribedUsersId as $subscribedUserId) { + $subscribedUserId = intval($subscribedUserId); + + $sql = "INSERT IGNORE INTO $userRelUserTable(user_id, friend_user_id, relation_type) " + . "VALUES ($subscribedUserId, $userId, $relationType)"; + Database::query($sql); - $affected_rows = Database::affected_rows(); + + $affectedRows = Database::affected_rows(); } } - return $affected_rows; + + return $affectedRows; } /** @@ -4943,6 +4961,51 @@ EOF; } } + /** + * Subscribe users to student boss + * @param int $bossId The boss id + * @param array $usersId The users array + * @return int Affected rows + */ + public static function subscribeUsersToBoss($bossId, $usersId) + { + return self::subscribeUsersToUser($bossId, $usersId, USER_RELATION_TYPE_BOSS); + } + + /** + * Get users followed by student boss + * @param int $userId + * @param int $userStatus (STUDENT, COURSEMANAGER, etc) + * @param bool $getOnlyUserId + * @param bool $getSql + * @param bool $getCount + * @param int $from + * @param int $numberItems + * @param int $column + * @param string $direction + * @param int $active + * @param string $lastConnectionDate + * @return array users + */ + public static function getUsersFollowedByStudentBoss( + $userId, + $userStatus = 0, + $getOnlyUserId = false, + $getSql = false, + $getCount = false, + $from = null, + $numberItems = null, + $column = null, + $direction = null, + $active = null, + $lastConnectionDate = null + ){ + return self::getUsersFollowedByUser( + $userId, $userStatus, $getOnlyUserId, $getSql, $getCount, $from, $numberItems, $column, $direction, + $active, $lastConnectionDate, STUDENT_BOSS + ); + } + /** * Get the teacher (users with COURSEMANGER status) list * @return array The list @@ -5005,4 +5068,5 @@ EOF; } return $users; } + } diff --git a/main/inc/lib/userportal.lib.php b/main/inc/lib/userportal.lib.php index 9ded8898de..0ae7ddc257 100755 --- a/main/inc/lib/userportal.lib.php +++ b/main/inc/lib/userportal.lib.php @@ -324,7 +324,7 @@ class IndexManager if (api_get_setting('allow_skills_tool') == 'true') { $content = '