diff --git a/main/gradebook/gradebook.php b/main/gradebook/gradebook.php index 2286df9e6a..4b16dff5df 100755 --- a/main/gradebook/gradebook.php +++ b/main/gradebook/gradebook.php @@ -576,7 +576,7 @@ if (((empty ($allcat)) && (empty ($alleval)) && (empty ($alllink)) && (!$is_plat } // Here we are in a sub category if ($category != '0') { - DisplayGradebook:: display_header_gradebook( + DisplayGradebook:: header( $cats[0], 1, $_GET['selectcat'], @@ -586,7 +586,7 @@ if ($category != '0') { ); } else { // This is the root category - DisplayGradebook:: display_header_gradebook( + DisplayGradebook:: header( $cats[0], (((count($allcat) == '0') && (!isset ($_GET['search']))) ? 0 : 1), 0, diff --git a/main/gradebook/index.php b/main/gradebook/index.php index f292f718c2..054bbfa58a 100755 --- a/main/gradebook/index.php +++ b/main/gradebook/index.php @@ -96,6 +96,7 @@ $filter_confirm_msg = true; $filter_warning_msg = true; $cats = Category :: load(null, null, $course_code, null, null, $session_id, false); + $first_time = null; if (empty($cats)) { @@ -151,7 +152,7 @@ if ((isset($_GET['selectcat']) && $_GET['selectcat']>0) && // ACTIONS //this is called when there is no data for the course admin -if (isset ($_GET['createallcategories'])) { +if (isset($_GET['createallcategories'])) { GradebookUtils::block_students(); $coursecat= Category :: get_not_created_course_categories($stud_id); if (!count($coursecat) == 0) { @@ -173,13 +174,13 @@ if (isset ($_GET['createallcategories'])) { } //show logs evaluations -if (isset ($_GET['visiblelog'])) { +if (isset($_GET['visiblelog'])) { header('Location: ' . api_get_self().'/gradebook_showlog_eval.php'); exit; } //move a category -if (isset ($_GET['movecat'])) { +if (isset($_GET['movecat'])) { GradebookUtils::block_students(); $cats= Category :: load($_GET['movecat']); if (!isset ($_GET['targetcat'])) { @@ -196,7 +197,7 @@ if (isset ($_GET['movecat'])) { exit; } } else { - $targetcat= Category :: load($_GET['targetcat']); + $targetcat = Category :: load($_GET['targetcat']); $course_to_crsind = ($cats[0]->get_course_code() != null && $targetcat[0]->get_course_code() == null); if (!($course_to_crsind && !isset($_GET['confirm']))) { @@ -210,7 +211,7 @@ if (isset ($_GET['movecat'])) { } //move an evaluation -if (isset ($_GET['moveeval'])) { +if (isset($_GET['moveeval'])) { GradebookUtils::block_students(); $evals= Evaluation :: load($_GET['moveeval']); if (!isset ($_GET['targetcat'])) { @@ -244,7 +245,7 @@ if (isset ($_GET['moveeval'])) { } //move a link -if (isset ($_GET['movelink'])) { +if (isset($_GET['movelink'])) { GradebookUtils::block_students(); $link= LinkFactory :: load($_GET['movelink']); $move_form = new LinkForm( @@ -266,7 +267,7 @@ if (isset ($_GET['movelink'])) { } //parameters for categories -if (isset ($_GET['visiblecat'])) { +if (isset($_GET['visiblecat'])) { GradebookUtils::block_students(); if (isset ($_GET['set_visible'])) { @@ -274,7 +275,7 @@ if (isset ($_GET['visiblecat'])) { } else { $visibility_command= 0; } - $cats= Category :: load($_GET['visiblecat']); + $cats = Category :: load($_GET['visiblecat']); $cats[0]->set_visible($visibility_command); $cats[0]->save(); $cats[0]->apply_visibility_to_children(); @@ -302,8 +303,9 @@ if (isset($_GET['deletecat'])) { $confirmation_message = get_lang('CategoryDeleted'); $filter_confirm_msg = false; } + //parameters for evaluations -if (isset ($_GET['visibleeval'])) { +if (isset($_GET['visibleeval'])) { GradebookUtils::block_students(); if (isset ($_GET['set_visible'])) { $visibility_command= 1; @@ -322,6 +324,7 @@ if (isset ($_GET['visibleeval'])) { $filter_confirm_msg = false; } } + //parameters for evaluations if (isset($_GET['lockedeval'])) { GradebookUtils::block_students(); @@ -339,9 +342,9 @@ if (isset($_GET['lockedeval'])) { } $filter_confirm_msg = false; - } -if (isset ($_GET['deleteeval'])) { + +if (isset($_GET['deleteeval'])) { GradebookUtils::block_students(); $eval= Evaluation :: load($_GET['deleteeval']); if ($eval[0] != null) { @@ -350,8 +353,9 @@ if (isset ($_GET['deleteeval'])) { $confirmation_message = get_lang('GradebookEvaluationDeleted'); $filter_confirm_msg = false; } + //parameters for links -if (isset ($_GET['visiblelink'])) { +if (isset($_GET['visiblelink'])) { GradebookUtils::block_students(); if (isset ($_GET['set_visible'])) { $visibility_command= 1; @@ -441,7 +445,7 @@ switch ($action) { } //actions on the sortabletable -if (isset ($_POST['action'])) { +if (isset($_POST['action'])) { GradebookUtils::block_students(); $number_of_selected_items= count($_POST['id']); @@ -450,8 +454,7 @@ if (isset ($_POST['action'])) { $filter_warning_msg = false; } else { switch ($_POST['action']) { - - case 'deleted' : + case 'deleted': $number_of_deleted_categories= 0; $number_of_deleted_evaluations= 0; $number_of_deleted_links= 0; @@ -486,10 +489,10 @@ if (isset ($_POST['action'])) { $confirmation_message = get_lang('DeletedCategories') . ' : ' . $number_of_deleted_categories . '
' . get_lang('DeletedEvaluations') . ' : ' . $number_of_deleted_evaluations . '
' . get_lang('DeletedLinks') . ' : ' . $number_of_deleted_links . '

' . get_lang('TotalItems') . ' : ' . $number_of_selected_items . ''; $filter_confirm_msg = false; break; - case 'setvisible' : + case 'setvisible': foreach ($_POST['id'] as $indexstr) { if (substr($indexstr, 0, 4) == 'CATE') { - $cats= Category :: load(substr($indexstr, 4)); + $cats = Category :: load(substr($indexstr, 4)); $cats[0]->set_visible(1); $cats[0]->save(); $cats[0]->apply_visibility_to_children(); @@ -508,10 +511,10 @@ if (isset ($_POST['action'])) { $confirmation_message = get_lang('ItemsVisible'); $filter_confirm_msg = false; break; - case 'setinvisible' : + case 'setinvisible': foreach ($_POST['id'] as $indexstr) { if (substr($indexstr, 0, 4) == 'CATE') { - $cats= Category :: load(substr($indexstr, 4)); + $cats = Category :: load(substr($indexstr, 4)); $cats[0]->set_visible(0); $cats[0]->save(); $cats[0]->apply_visibility_to_children(); @@ -609,15 +612,15 @@ $is_course_admin = api_is_allowed_to_edit(null, true); //load data for category, evaluation and links if (empty($_GET['selectcat'])) { - $category= 0; + $category = 0; } else { - $category= $_GET['selectcat']; + $category = $_GET['selectcat']; } $simple_search_form=''; if (isset($_GET['studentoverview'])) { //@todo this code also seems to be deprecated ... - $cats= Category :: load($category); + $cats = Category :: load($category); $stud_id= (api_is_allowed_to_edit() ? null : $stud_id); $allcat= array (); $alleval= $cats[0]->get_evaluations($stud_id, true); @@ -656,6 +659,7 @@ if (isset($_GET['studentoverview'])) { //if $category = 0 (which happens when GET['selectcat'] is undefined) // then Category::load() will create a new 'root' category with empty // course and session fields in memory (Category::create_root_category()) + if ($_in_course === true) { // When *inside* a course, we want to make sure there is one (and only // one) category for this course or for this session. @@ -671,7 +675,7 @@ if (isset($_GET['studentoverview'])) { $cats = Category :: load(null, null, $course_code, null, null, $session_id, false); if (empty($cats)) { // There is no category for this course+session, so create one - $cat= new Category(); + $cat = new Category(); if (!empty($session_id)) { $s_name = api_get_session_name($session_id); $cat->set_name($course_code.' - '.get_lang('Session').' '.$s_name); @@ -690,10 +694,11 @@ if (isset($_GET['studentoverview'])) { if ($can_edit) { $cat->add(); } - unset ($cat); + unset($cat); } unset($cats); } + $cats = Category::load($category, null, null, null, null, null, false); //with this fix the teacher only can view 1 gradebook @@ -706,19 +711,17 @@ if (isset($_GET['studentoverview'])) { $allcat = $cats[0]->get_subcategories($stud_id, $course_code, $session_id); $alleval = $cats[0]->get_evaluations($stud_id); $alllink = $cats[0]->get_links($stud_id); - //whether we found a category or not, we now have a category object with - // empty or full subcats } // add params to the future links (in the table shown) -$addparams = array ('selectcat' => $cats[0]->get_id()); +$addparams = array('selectcat' => $cats[0]->get_id()); -if (isset ($_GET['studentoverview'])) { +if (isset($_GET['studentoverview'])) { $addparams['studentoverview'] = ''; } //$addparams['cidReq']=''; if (isset($_GET['cidReq']) && $_GET['cidReq']!='') { - $addparams['cidReq']=Security::remove_XSS($_GET['cidReq']); + $addparams['cidReq'] = Security::remove_XSS($_GET['cidReq']); } else { $addparams['cidReq']=''; } @@ -849,8 +852,7 @@ if (isset($first_time) && $first_time==1 && api_is_allowed_to_edit(null,true)) { } else { // This is the father // Create gradebook/add gradebook links. - - DisplayGradebook::display_header_gradebook( + DisplayGradebook::header( $cat, 0, $cat->get_id(), diff --git a/main/gradebook/lib/be/category.class.php b/main/gradebook/lib/be/category.class.php index 89e17a6daf..0a1f990ec1 100755 --- a/main/gradebook/lib/be/category.class.php +++ b/main/gradebook/lib/be/category.class.php @@ -807,7 +807,12 @@ class Category implements GradebookItem */ public function is_certificate_available($user_id) { - $score = $this->calc_score($user_id, null, $this->course_code); + $score = $this->calc_score( + $user_id, + null, + $this->course_code, + $this->session_id + ); if (isset($score) && isset($score[0])) { // Get a percentage score to compare to minimum certificate score @@ -1487,13 +1492,15 @@ class Category implements GradebookItem * @param int $stud_id student id (default: all students) * @param boolean $recursive process subcategories (default: no recursion) * @param string $course_code + * @param int $sessionId * * @return array */ public function get_evaluations( $stud_id = null, $recursive = false, - $course_code = '' + $course_code = '', + $sessionId = 0 ) { $evals = array(); @@ -1501,18 +1508,30 @@ class Category implements GradebookItem $course_code = api_get_course_id(); } + if (empty($sessionId)) { + $sessionId = api_get_session_id(); + } + // 1 student if (isset($stud_id) && !empty($stud_id)) { // Special case: this is the root if ($this->id == 0) { $evals = Evaluation::get_evaluations_with_result_for_student(0, $stud_id); } else { - $evals = Evaluation::load(null,null, $course_code, $this->id, api_is_allowed_to_edit() ? null : 1); + $evals = Evaluation::load( + null, + null, + $course_code, + $this->id, + api_is_allowed_to_edit() ? null : 1 + ); } } else { // All students // course admin - if ((api_is_allowed_to_edit() || api_is_drh() || api_is_session_admin()) && !api_is_platform_admin()) { + if ((api_is_allowed_to_edit() || api_is_drh() || api_is_session_admin()) && + !api_is_platform_admin() + ) { // root if ($this->id == 0) { $evals = Evaluation::load(null, api_get_user_id(), null, $this->id, null); @@ -1529,11 +1548,11 @@ class Category implements GradebookItem } if ($recursive) { - $subcats = $this->get_subcategories($stud_id, $course_code); + $subcats = $this->get_subcategories($stud_id, $course_code, $sessionId); + if (!empty($subcats)) { foreach ($subcats as $subcat) { $subevals = $subcat->get_evaluations($stud_id, true, $course_code); - //$this->debugprint($subevals); $evals = array_merge($evals, $subevals); } } @@ -1555,7 +1574,7 @@ class Category implements GradebookItem $stud_id = null, $recursive = false, $course_code = '', - $sessionId = null + $sessionId = 0 ) { $links = array(); @@ -1737,6 +1756,7 @@ class Category implements GradebookItem */ public static function register_user_certificate($category_id, $user_id) { + $sessionId = api_get_session_id(); // Generating the total score for a course $cats_course = Category::load( $category_id, @@ -1744,19 +1764,21 @@ class Category implements GradebookItem null, null, null, - api_get_session_id(), + $sessionId, false ); + /** @var Category $category */ $category = $cats_course[0]; if (!$category->getGenerateCetificates()) { + $skill = new Skill(); $skill->add_skill_to_user( $user_id, $category_id, api_get_course_int_id(), - api_get_session_id() + $sessionId ); return false; @@ -1792,7 +1814,11 @@ class Category implements GradebookItem return false; } - $my_certificate = GradebookUtils::get_certificate_by_user_id($cats_course[0]->get_id(), $user_id); + $my_certificate = GradebookUtils::get_certificate_by_user_id( + $cats_course[0]->get_id(), + $user_id + ); + if (empty($my_certificate)) { GradebookUtils::register_user_info_about_certificate( $category_id, @@ -1800,8 +1826,12 @@ class Category implements GradebookItem $my_score_in_gradebook, api_get_utc_datetime() ); - $my_certificate = GradebookUtils::get_certificate_by_user_id($cats_course[0]->get_id(), $user_id); + $my_certificate = GradebookUtils::get_certificate_by_user_id( + $cats_course[0]->get_id(), + $user_id + ); } + $html = array(); if (!empty($my_certificate)) { $certificate_obj = new Certificate($my_certificate['id']); @@ -1809,6 +1839,7 @@ class Category implements GradebookItem if (!empty($fileWasGenerated)) { $url = api_get_path(WEB_PATH) . 'certificates/index.php?id=' . $my_certificate['id']; + $certificates = Display::url( ' '.get_lang('DownloadCertificate'), $url, @@ -1817,6 +1848,7 @@ class Category implements GradebookItem 'class' => 'btn' ) ); + $exportToPDF = Display::url( Display::return_icon( 'pdf.png', @@ -1826,6 +1858,7 @@ class Category implements GradebookItem ), "$url&action=export" ); + $html = array( 'certificate_link' => $certificates, 'pdf_link' => $exportToPDF diff --git a/main/gradebook/lib/fe/displaygradebook.php b/main/gradebook/lib/fe/displaygradebook.php index df43c18ee4..b2d3df5d9c 100755 --- a/main/gradebook/lib/fe/displaygradebook.php +++ b/main/gradebook/lib/fe/displaygradebook.php @@ -341,8 +341,10 @@ class DisplayGradebook $my_course_id = api_get_course_id(); $my_file = substr($_SESSION['gradebook_dest'], 0, 5); - $header .= '' . Display::return_icon('stats.png', get_lang('FlatView'), '', ICON_SIZE_MEDIUM) . ''; - $header .= '' . Display::return_icon('certificate_list.png', get_lang('GradebookSeeListOfStudentsCertificates'), '', ICON_SIZE_MEDIUM) . ''; + $header .= '' . + Display::return_icon('stats.png', get_lang('FlatView'), '', ICON_SIZE_MEDIUM) . ''; + $header .= '' . + Display::return_icon('certificate_list.png', get_lang('GradebookSeeListOfStudentsCertificates'), '', ICON_SIZE_MEDIUM) . ''; $visibility_icon = ($catobj->is_visible() == 0) ? 'invisible' : 'visible'; $visibility_command = ($catobj->is_visible() == 0) ? 'set_visible' : 'set_invisible'; @@ -380,7 +382,7 @@ class DisplayGradebook * where we have only one calification per course or session) * @return void Everything is printed on screen upon closing */ - static function display_header_gradebook( + static function header( $catobj, $showtree, $selectcat, @@ -391,8 +393,22 @@ class DisplayGradebook $show_add_link = true, $certificateLinkInfo = null ) { + + $userId = api_get_user_id(); + $courseCode = api_get_course_id(); + $sessionId = api_get_session_id(); + // Student. - $status = CourseManager::get_user_in_course_status(api_get_user_id(), api_get_course_id()); + $status = CourseManager::get_user_in_course_status($userId, $courseCode); + + if (!empty($sessionId)) { + $sessionStatus = SessionManager::get_user_status_in_course_session( + $userId, + $courseCode, + $sessionId + ); + } + $objcat = new Category(); $course_id = CourseManager::get_course_by_category($selectcat); $message_resource = $objcat->show_message_resource_delete($course_id); @@ -403,7 +419,15 @@ class DisplayGradebook $sum_categories_weight_array = array(); if (isset($catobj) && !empty($catobj)) { - $categories = Category::load(null, null, null, $catobj->get_id()); + $categories = Category::load( + null, + null, + null, + $catobj->get_id(), + null, + $sessionId + ); + if (!empty($categories)) { foreach ($categories as $category) { $sum_categories_weight_array[$category->get_id()] = $category->get_weight(); @@ -413,23 +437,15 @@ class DisplayGradebook } } - if (!$is_course_admin && $status <> 1 && $selectcat <> 0) { - $user_id = api_get_user_id(); + if (!$is_course_admin && ($status <> 1 || $sessionStatus == 0) && $selectcat <> 0) { $catcourse = Category::load($catobj->get_id()); - $main_weight = $catcourse[0]->get_weight(); + /** @var Category $category */ + $category = $catcourse[0]; + $main_weight = $category->get_weight(); $scoredisplay = ScoreDisplay :: instance(); - //$categories = Category::getCategories($catcourse[0]->get_id()); - // generating the total score for a course - /*if (count($categories) > 0) { - foreach ($categories as $category) { - $allevals = $category->get_evaluations($user_id, true); - $alllinks = $category->get_links($user_id, true); - $catEvalsLinks = array_merge($allevals, $alllinks); - } - }*/ - $allevals = $catcourse[0]->get_evaluations($user_id, true); - $alllinks = $catcourse[0]->get_links($user_id, true); + $allevals = $category->get_evaluations($userId, true); + $alllinks = $category->get_links($userId, true); $allEvalsLinks = array_merge($allevals, $alllinks); @@ -438,13 +454,10 @@ class DisplayGradebook for ($count = 0; $count < count($allEvalsLinks); $count++) { $item = $allEvalsLinks[$count]; - $score = $item->calc_score($user_id); + $score = $item->calc_score($userId); if (!empty($score)) { $divide = $score[1] == 0 ? 1 : $score[1]; - //$sub_cat_percentage = $sum_categories_weight_array[$item->get_category_id()]; - //$item_value = $score[0] / $divide * $item->get_weight() / $sub_cat_percentage * $sub_cat_percentage / $main_weight * $main_weight; $item_value = $score[0] / $divide * $item->get_weight(); - //var_dump($score[0], $divide, $item->get_weight(), $sub_cat_percentage, $main_weight, $item_value); $item_value_total += $item_value; } } @@ -600,8 +613,6 @@ class DisplayGradebook if ($isDrhOfCourse) { $header .= '' . Display::return_icon('stats.png', get_lang('FlatView'), '', ICON_SIZE_MEDIUM) . ''; - /*$header .= '' . - Display::return_icon('certificate_list.png', get_lang('GradebookSeeListOfStudentsCertificates'), '', ICON_SIZE_MEDIUM) . '';*/ } $header .= ''; @@ -609,7 +620,7 @@ class DisplayGradebook echo $header; if (api_is_allowed_to_edit(null, true)) { - $weight = ((intval($catobj->get_weight()) > 0) ? $catobj->get_weight() : 0); + $weight = intval($catobj->get_weight()) > 0 ? $catobj->get_weight() : 0; $weight = get_lang('TotalWeight') . ' : ' . $weight; $min_certification = (intval($catobj->get_certificate_min_score() > 0) ? $catobj->get_certificate_min_score() : 0); diff --git a/main/gradebook/lib/fe/gradebooktable.class.php b/main/gradebook/lib/fe/gradebooktable.class.php index 37e20ecf08..7935e9fb9c 100755 --- a/main/gradebook/lib/fe/gradebooktable.class.php +++ b/main/gradebook/lib/fe/gradebooktable.class.php @@ -221,7 +221,7 @@ class GradebookTable extends SortableTable $row[] = $invisibility_span_open.$data[2].$invisibility_span_close; // Weight. - $average = $scoredisplay->display_score( + $weight = $scoredisplay->display_score( array( $data['3'], $this->currentcat->get_weight() @@ -231,11 +231,10 @@ class GradebookTable extends SortableTable true ); - // Weight if (api_is_allowed_to_edit(null, true)) { - $row[] = $invisibility_span_open .Display::tag('h4', $average).$invisibility_span_close; + $row[] = $invisibility_span_open .Display::tag('h4', $weight).$invisibility_span_close; } else { - $row[] = $invisibility_span_open .$average.$invisibility_span_close; + $row[] = $invisibility_span_open .$weight.$invisibility_span_close; } $category_weight = $item->get_weight(); @@ -270,7 +269,8 @@ class GradebookTable extends SortableTable } // Students get the results and certificates columns - if (count($this->evals_links) > 0 && $status_user != 1) { + //if (count($this->evals_links) > 0 && $status_user != 1) { + if ($status_user != 1) { $value_data = isset($data[4]) ? $data[4] : null; $best = isset($data['best']) ? $data['best'] : null; $average = isset($data['average']) ? $data['average'] : null;