From e014bc9f72e98e20b8e12c92b156b765521798ab Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 13 Jan 2014 13:11:31 -0500 Subject: [PATCH 1/4] Fixing problem when adding categories in sessions -refs #5962 --- main/gradebook/gradebook_add_link.php | 7 ++++-- main/gradebook/gradebook_edit_link.php | 7 +++++- main/gradebook/index.php | 28 +++++++++++++++++++----- main/gradebook/lib/be/category.class.php | 24 ++++++++++++++------ 4 files changed, 51 insertions(+), 15 deletions(-) diff --git a/main/gradebook/gradebook_add_link.php b/main/gradebook/gradebook_add_link.php index 60497d866b..8618e577d4 100644 --- a/main/gradebook/gradebook_add_link.php +++ b/main/gradebook/gradebook_add_link.php @@ -27,8 +27,11 @@ $tbl_forum_thread = Database :: get_course_table(TABLE_FORUM_THREAD); $tbl_link = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK); $session_id = api_get_session_id(); -$all_categories = Category :: load(null, null, api_get_course_id(), null, null, $session_id); - +if ($session_id == 0) { + $all_categories = Category :: load(null, null, api_get_course_id(), null, null, $session_id); +} else { + $all_categories = Category :: load_session_categories(null,$session_id); +} $category = Category :: load($_GET['selectcat']); $url = api_get_self().'?selectcat='.Security::remove_XSS($_GET['selectcat']).'&newtypeselected='.(isset($_GET['typeselected']) ? Security::remove_XSS($_GET['typeselected']) : '').'&course_code='.api_get_course_id(); $typeform = new LinkForm(LinkForm :: TYPE_CREATE, $category[0], null, 'create_link', null, $url, $_GET['typeselected']); diff --git a/main/gradebook/gradebook_edit_link.php b/main/gradebook/gradebook_edit_link.php index 8113265c7e..09635cc16c 100644 --- a/main/gradebook/gradebook_edit_link.php +++ b/main/gradebook/gradebook_edit_link.php @@ -33,7 +33,12 @@ if ($link->is_locked() && !api_is_platform_admin()) { $linkcat = isset($_GET['selectcat']) ? Security::remove_XSS($_GET['selectcat']):''; $linkedit = isset($_GET['editlink']) ? Security::remove_XSS($_GET['editlink']):''; -$cats = Category :: load(null, null, $course_code, null, null, $session_id, false); //already init +$session_id = api_get_session_id(); +if ($session_id == 0) { + $cats = Category :: load(null, null, $course_code, null, null, $session_id, false); //already init +} else { + $cats = Category :: load_session_categories(null,$session_id); +} $form = new LinkAddEditForm(LinkAddEditForm :: TYPE_EDIT, $cats, null, $link, 'edit_link_form', api_get_self() . '?selectcat=' . $linkcat. '&editlink=' . $linkedit); if ($form->validate()) { diff --git a/main/gradebook/index.php b/main/gradebook/index.php index ca1c4c9c57..1c56543dca 100644 --- a/main/gradebook/index.php +++ b/main/gradebook/index.php @@ -119,11 +119,19 @@ $filter_confirm_msg = true; $filter_warning_msg = true; ///direct access to one evaluation -$cats = Category :: load(null, null, $course_code, null, null, $session_id, false); //already init +$catsResult = array(); +if ( api_get_session_id() != 0) { + $session_id = api_get_session_id(); + $cats = Category :: load_session_categories(null, $session_id); //already init + $catsResult = $cats; +} else { + $cats = Category :: load(null, null, $course_code, null, null, null, false); +} $first_time = null; + if (empty($cats)) { $cats = Category :: load(0, null, $course_code, null, null, $session_id, false);//first time - $first_time=1; + $first_time=1; } $_GET['selectcat'] = $cats[0]->get_id(); @@ -817,10 +825,20 @@ if (isset($first_time) && $first_time==1 && api_is_allowed_to_edit(null,true)) { } $i = 0; - + $allcat = array(); foreach ($cats as $cat) { - $allcat = $cat->get_subcategories($stud_id, $course_code, $session_id); - $alleval = $cat->get_evaluations($stud_id); + if ($session_id != 0) { + $allcatSession = $catsResult; + foreach ($allcatSession as $catSession) { + if($catSession->get_parent_id() == 0) { + continue; + } + $allcat[] = $catSession; + } + } else { + $allcat = $cat->get_subcategories($stud_id, $course_code, $session_id); + } + $alleval = $cat->get_evaluations($stud_id); $alllink = $cat->get_links($stud_id,true); if ($cat->get_parent_id() != 0 ) { diff --git a/main/gradebook/lib/be/category.class.php b/main/gradebook/lib/be/category.class.php index d1223fcf9d..7d86d598b8 100644 --- a/main/gradebook/lib/be/category.class.php +++ b/main/gradebook/lib/be/category.class.php @@ -169,18 +169,28 @@ class Category implements GradebookItem $cats[] = Category::create_root_category(); return $cats; } - $cat = array(); + $courseCode = api_get_course_info(api_get_course_id()); + $courseCode = $courseCode['code']; + $cats = array(); if (!empty ($session_id)) { $tbl_grade_categories = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); - $sql_session = 'SELECT id FROM '.$tbl_grade_categories. ' WHERE session_id = '.$session_id; + $sql_session = 'SELECT id, course_code FROM '.$tbl_grade_categories. ' WHERE session_id = '.(int) $session_id; $result_session = Database::query($sql_session); if (Database::num_rows($result_session) > 0) { - $data_session = Database::fetch_array($result_session); - $parent_id = $data_session['id']; - $cat = Category::load($parent_id); - $cats = Category::load(null, null, null, $parent_id, null, null, $order); - return array_merge($cat,$cats); + $cat = array(); + while ($data_session = Database::fetch_array($result_session)) { + + $parent_id = $data_session['id']; + if ($data_session['course_code'] == $courseCode) { + $cat = Category::load($parent_id); + $cats = Category::load(null,null,null,$parent_id,null,null,null); + //$cat = array_merge($cat,$cats); + } + } + + + return array_merge($cat,$cats); } } } From f472175466fad43cd83e24abecbfbf16dae7d7f6 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 13 Jan 2014 13:27:26 -0500 Subject: [PATCH 2/4] Minor indentation corrections --- main/gradebook/index.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main/gradebook/index.php b/main/gradebook/index.php index 1c56543dca..90d31a7b67 100644 --- a/main/gradebook/index.php +++ b/main/gradebook/index.php @@ -131,7 +131,7 @@ $first_time = null; if (empty($cats)) { $cats = Category :: load(0, null, $course_code, null, null, $session_id, false);//first time - $first_time=1; + $first_time = 1; } $_GET['selectcat'] = $cats[0]->get_id(); @@ -825,7 +825,7 @@ if (isset($first_time) && $first_time==1 && api_is_allowed_to_edit(null,true)) { } $i = 0; - $allcat = array(); + $allcat = array(); foreach ($cats as $cat) { if ($session_id != 0) { $allcatSession = $catsResult; From 315d475ddbf4af8732585f5910a16a747b882884 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 13 Jan 2014 13:29:35 -0500 Subject: [PATCH 3/4] minor spaces corrections --- main/gradebook/gradebook_add_link.php | 2 +- main/gradebook/gradebook_edit_link.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/main/gradebook/gradebook_add_link.php b/main/gradebook/gradebook_add_link.php index 8618e577d4..59369eeca5 100644 --- a/main/gradebook/gradebook_add_link.php +++ b/main/gradebook/gradebook_add_link.php @@ -30,7 +30,7 @@ $session_id = api_get_session_id(); if ($session_id == 0) { $all_categories = Category :: load(null, null, api_get_course_id(), null, null, $session_id); } else { - $all_categories = Category :: load_session_categories(null,$session_id); + $all_categories = Category :: load_session_categories(null, $session_id); } $category = Category :: load($_GET['selectcat']); $url = api_get_self().'?selectcat='.Security::remove_XSS($_GET['selectcat']).'&newtypeselected='.(isset($_GET['typeselected']) ? Security::remove_XSS($_GET['typeselected']) : '').'&course_code='.api_get_course_id(); diff --git a/main/gradebook/gradebook_edit_link.php b/main/gradebook/gradebook_edit_link.php index 09635cc16c..b6a826f80b 100644 --- a/main/gradebook/gradebook_edit_link.php +++ b/main/gradebook/gradebook_edit_link.php @@ -37,7 +37,7 @@ $session_id = api_get_session_id(); if ($session_id == 0) { $cats = Category :: load(null, null, $course_code, null, null, $session_id, false); //already init } else { - $cats = Category :: load_session_categories(null,$session_id); + $cats = Category :: load_session_categories(null, $session_id); } $form = new LinkAddEditForm(LinkAddEditForm :: TYPE_EDIT, $cats, null, $link, 'edit_link_form', api_get_self() . '?selectcat=' . $linkcat. '&editlink=' . $linkedit); From 3eb54707cd0d771ca6abcaa466db789efb507337 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 13 Jan 2014 13:32:02 -0500 Subject: [PATCH 4/4] Minor indentation corrections --- main/gradebook/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/gradebook/index.php b/main/gradebook/index.php index 90d31a7b67..d29b1e2e3d 100644 --- a/main/gradebook/index.php +++ b/main/gradebook/index.php @@ -825,7 +825,7 @@ if (isset($first_time) && $first_time==1 && api_is_allowed_to_edit(null,true)) { } $i = 0; - $allcat = array(); + $allcat = array(); foreach ($cats as $cat) { if ($session_id != 0) { $allcatSession = $catsResult;