From 95e5aaf2baa18b0fa1f4dc9b71398def9f0df979 Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Mon, 29 Oct 2012 15:04:00 +0100 Subject: [PATCH] Disabling creation of an evaluation when creating a gradebook see BT#4878 --- main/course_progress/thematic.php | 2 +- main/gradebook/lib/be/evaluation.class.php | 34 ++++++----- main/inc/lib/gradebook.lib.php | 4 +- main/inc/lib/model.lib.php | 4 ++ main/inc/lib/sessionmanager.lib.php | 6 +- main/inc/lib/thematic.lib.php | 2 +- tests/migrate/migration.custom.class.php | 70 +++++++++++++++------- 7 files changed, 80 insertions(+), 42 deletions(-) diff --git a/main/course_progress/thematic.php b/main/course_progress/thematic.php index 234da14772..600ed60f9e 100644 --- a/main/course_progress/thematic.php +++ b/main/course_progress/thematic.php @@ -75,7 +75,7 @@ if ($action == 'thematic_list') { if (!empty($thematic_data)) { // display progress - echo '

'.get_lang('Progress').': '.$total_average_of_advances.' %

'; + echo '

'.get_lang('Progress').': '.$total_average_of_advances.' %

'; echo ''; echo ''; diff --git a/main/gradebook/lib/be/evaluation.class.php b/main/gradebook/lib/be/evaluation.class.php index 6bb93521bf..2c210da74e 100644 --- a/main/gradebook/lib/be/evaluation.class.php +++ b/main/gradebook/lib/be/evaluation.class.php @@ -20,7 +20,8 @@ class Evaluation implements GradebookItem private $created_at; private $weight; private $eval_max; - private $visible; + private $visible; + private $evaluation_type_id; function __construct() { } @@ -127,6 +128,14 @@ class Evaluation implements GradebookItem $this->locked = $locked; } + public function get_evaluation_type_id() { + return isset($this->evaluation_type_id) ? $this->evaluation_type_id : 0; + } + + public function set_evaluation_type_id($id) { + $this->evaluation_type_id = intval($id); + } + // CRUD FUNCTIONS /** @@ -222,7 +231,9 @@ class Evaluation implements GradebookItem if (isset($this->category)) { $sql .= ', category_id'; } - $sql .= ', created_at'; + $sql .= ', created_at'; + $sql .= ', evaluation_type_id'; + $sql .= ',type'; $sql .= ") VALUES ('".Database::escape_string($this->get_name())."'" .','.intval($this->get_user_id()) @@ -237,13 +248,16 @@ class Evaluation implements GradebookItem } if (isset($this->category)) { $sql .= ','.intval($this->get_category_id()); - } + } + + $sql .= ','.intval($this->get_evaluation_type_id()); if (empty($this->type)) { $this->type = 'evaluation'; } $sql .= ", '".api_get_utc_datetime()."'"; $sql .= ',\''.Database::escape_string($this->type).'\''; - $sql .= ")"; + $sql .= ")"; + Database::query($sql); $this->set_id(Database::insert_id()); } else { @@ -492,9 +506,7 @@ class Evaluation implements GradebookItem } $this->save(); } - - - + /** * Retrieve evaluations where a student has results for * and return them as an array of Evaluation objects @@ -523,8 +535,6 @@ class Evaluation implements GradebookItem return $alleval; } - - /** * Get a list of students that do not have a result record for this evaluation */ @@ -546,7 +556,6 @@ class Evaluation implements GradebookItem return $db_users; } - /** * Find evaluations by name * @param string $name_mask search string @@ -565,10 +574,7 @@ class Evaluation implements GradebookItem return $foundevals; } - - -// Other methods implementing GradebookItem - + // Other methods implementing GradebookItem public function get_item_type() { return 'E'; } diff --git a/main/inc/lib/gradebook.lib.php b/main/inc/lib/gradebook.lib.php index d1e28aed32..2a8d5f878e 100644 --- a/main/inc/lib/gradebook.lib.php +++ b/main/inc/lib/gradebook.lib.php @@ -19,7 +19,6 @@ class Gradebook extends Model { $this->table_skill = Database::get_main_table(TABLE_MAIN_SKILL); $this->table_skill_rel_gradebook = Database::get_main_table(TABLE_MAIN_SKILL_REL_GRADEBOOK); } - /** * Returns true if the gradebook is active and visible in a course, false @@ -150,8 +149,7 @@ class Gradebook extends Model { $result = Database::query($sql); $result = Database::store_result($result,'ASSOC'); return $result; - } - + } /** * Displays the title + grid diff --git a/main/inc/lib/model.lib.php b/main/inc/lib/model.lib.php index 1c890ddb22..bcc9211943 100644 --- a/main/inc/lib/model.lib.php +++ b/main/inc/lib/model.lib.php @@ -98,6 +98,10 @@ class Model { return Database::select('*', $this->table, $options); } + public function get_first($options = null) { + return Database::select('*', $this->table, $options, 'first'); + } + public function get_all_for_export($options = null) { return Database::select('name, description', $this->table, $options); } diff --git a/main/inc/lib/sessionmanager.lib.php b/main/inc/lib/sessionmanager.lib.php index 2d47ea49ab..8df663c70d 100644 --- a/main/inc/lib/sessionmanager.lib.php +++ b/main/inc/lib/sessionmanager.lib.php @@ -91,10 +91,10 @@ class SessionManager { //Update default course gradebook to the session if exists $create_gradebook_evaluation = isset($params['create_gradebook_evaluation']) ? $params['create_gradebook_evaluation'] : false; - if ($create_gradebook_evaluation) { - + if ($create_gradebook_evaluation) { require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php'; $category_id = create_default_course_gradebook($params['course_code'], false, $session_id); + /* if ($category_id && isset($params['gradebook_params'])) { $eval = new Evaluation(); $eval->set_name($params['gradebook_params']['name']); @@ -105,7 +105,7 @@ class SessionManager { $eval->set_max($params['gradebook_params']['max']); $eval->set_visible(0); $eval->add(); - } + }*/ /*$tbl_gradebook_category = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION); $sql = "SELECT id FROM $tbl_gradebook_category WHERE course_code = {$params['course_code']} AND session_id = 0 LIMIT 1"; diff --git a/main/inc/lib/thematic.lib.php b/main/inc/lib/thematic.lib.php index f1bfed6e94..47b8be5b01 100644 --- a/main/inc/lib/thematic.lib.php +++ b/main/inc/lib/thematic.lib.php @@ -286,7 +286,7 @@ class Thematic WHERE c_id = $course_id AND session_id = $session_id AND title = $title AND - active = 1"; + active = 1"; $result = Database::query($sql); if (Database::num_rows($result)) { return Database::fetch_array($result, 'ASSOC'); diff --git a/tests/migrate/migration.custom.class.php b/tests/migrate/migration.custom.class.php index 4607f5f234..a38cfaa262 100644 --- a/tests/migrate/migration.custom.class.php +++ b/tests/migrate/migration.custom.class.php @@ -322,12 +322,12 @@ class MigrationCustom { static function create_session($data) { //Hack to add the default gradebook course to the session course $data['create_gradebook_evaluation'] = true; - $data['gradebook_params'] = array( + /*$data['gradebook_params'] = array( 'name' => 'General evaluation', 'user_id' => self::default_admin_id, 'weight' => '20', 'max' => '20' - ); + );*/ //Here the $data variable has $data['course_code'] that will be added when creating the session $session_id = SessionManager::add($data); @@ -403,12 +403,13 @@ class MigrationCustom { $link_to_gradebook = false; //$attendance->category_id = $_POST['category_id']; $attendance_id = $attendance->attendance_add($link_to_gradebook, self::default_admin_id); - error_log("Attendance added course code: {$course['code']} session_id: $session_id"); - //only 1 course per session + error_log("Attendance added course code: {$course['code']} - session_id: $session_id"); + //only 1 course per session } else { $attendance_data = current($attendance_list); $attendance_id = $attendance_data['id']; - } + error_log("Attendance found in attendance_id = $attendance_id - course code: {$course['code']} - session_id: $session_id"); + } if ($attendance_id) { //Attendance date exists? @@ -438,7 +439,7 @@ class MigrationCustom { } static function create_thematic($data) { - error_log('create_attendance'); + error_log('create_thematic'); $session_id = $data['session_id']; if (!empty($session_id)) { @@ -447,37 +448,43 @@ class MigrationCustom { if (!empty($course_list)) { $course_data = current($course_list); $course_info = api_get_course_info($course_data['code']); - + if (!empty($course_data)) { $thematic = new Thematic(); $thematic->set_course_int_id($course_info['real_id']); - $thematic->set_session_id($session_id); + $thematic->set_session_id($session_id); $thematic_info = $thematic->get_thematic_by_title($data['thematic']); if (empty($thematic_info)) { $thematic->set_thematic_attributes(null, $data['thematic'], null, $session_id); - $thematic_id = $thematic->thematic_save(); + $thematic_id = $thematic->thematic_save(); + error_log("Thematic added to course code: {$course_info['code']} - session_id: $session_id"); } else { - $thematic_id = isset($thematic_info['id']) ? $thematic_info['id'] : null; + $thematic_id = isset($thematic_info['id']) ? $thematic_info['id'] : null; + error_log("Thematic id #$thematic_id found in course: {$course_info['code']} - session_id: $session_id"); } if ($thematic_id) { $thematic->set_thematic_plan_attributes($thematic_id, $data['thematic_plan'], null, 6); $thematic->thematic_plan_save(); + error_log("Saving plan attributes: {$data['thematic_plan']}"); } - - error_log("Adding thematic id : $thematic_id to session: $session_id to course: {$course_data['code']} real_id: {$course_data['real_id']}"); + error_log("Adding thematic id : $thematic_id to session: $session_id to course: {$course_info['code']} real_id: {$course_info['real_id']}"); if ($thematic_id) { error_log("Thematic saved: $thematic_id"); } else { error_log("Thematic NOT saved"); } - } + } + + if ($course_info['code'] != 'B05') { + //exit; + } } else { error_log("No courses in session $session_id "); } - } + } } static function add_evaluation_type($params) { @@ -502,8 +509,8 @@ class MigrationCustom { return false; } - static function create_gradebook_links($data){ - error_log('create_gradebook_links'); + static function create_gradebook_evaluation($data){ + error_log('create_gradebook_evaluation'); $session_id = isset($data['session_id']) ? $data['session_id'] : null; if (!empty($session_id)) { @@ -513,12 +520,35 @@ class MigrationCustom { if (isset($course_data['code'])) { //Get gradebook $gradebook = new Gradebook(); - $gradebooks = $gradebook->get_all(array('where' => array('course_code = ? AND session_id = ?' => array($course_data['code'], $session_id)))); - var_dump($course_data['code'], $session_id); - print_r($gradebooks); + $gradebook = $gradebook->get_first(array('where' => array('course_code = ? AND session_id = ?' => array($course_data['code'], $session_id)))); + error_log("Looking gradebook in course code: {$course_data['code']} - session_id: $session_id"); + if (!empty($gradebook)) { + error_log("Gradebook exists"); + echo 'parameters'; + var_dump($data); + + + $eval = new Evaluation(); + $eval->set_name($data['gradebook_description']); + $eval->set_description($data['gradebook_description']); + $eval->set_evaluation_type_id($data['gradebook_evaluation_type_id']); + $eval->set_user_id(self::default_admin_id); + $eval->set_course_code($course_data['code']); + $eval->set_category_id($gradebook['id']); + + //harcoded values + $eval->set_weight(10); + $eval->set_max(20); + $eval->set_visible(1); + $eval->add(); + + } else { + error_log("Gradebook does not exists"); + } + exit; } else { - error_log("Something is wrong with the course "); + error_log("Something is wrong with the course "); } exit; } else {
'.get_lang('Thematic').''.get_lang('ThematicPlan').''.get_lang('ThematicAdvance').'