Fixing gradebook creation when creating a session

skala
Julio Montoya 12 years ago
parent 9123b2a5cb
commit 786f9c659d
  1. 5
      main/gradebook/lib/be/evaluation.class.php
  2. 8
      main/gradebook/lib/gradebook_functions.inc.php
  3. 30
      main/inc/lib/sessionmanager.lib.php
  4. 1
      tests/migrate/migration.class.php
  5. 21
      tests/migrate/migration.custom.class.php
  6. 6
      tests/migrate/migration.mssql.class.php

@ -10,9 +10,7 @@
*/
class Evaluation implements GradebookItem
{
// PROPERTIES
private $id;
private $name;
private $description;
@ -24,8 +22,6 @@ class Evaluation implements GradebookItem
private $eval_max;
private $visible;
// CONSTRUCTORS
function __construct() {
}
@ -131,7 +127,6 @@ class Evaluation implements GradebookItem
$this->locked = $locked;
}
// CRUD FUNCTIONS
/**

@ -618,13 +618,16 @@ function get_user_certificate_content($user_id, $course_code, $is_preview = fals
return array('content' => $new_content_html, 'variables'=>$content_html['variables']);
}
function create_default_course_gradebook($course_code = null, $gradebook_model_id = 0) {
function create_default_course_gradebook($course_code = null, $gradebook_model_id = 0, $session_id = null) {
$category_id = null;
//if (api_is_allowed_to_edit(true, true)) {
if (!isset($course_code) || empty($course_code)) {
$course_code = api_get_course_id();
}
if (empty($session_id)) {
$session_id = api_get_session_id();
}
$t = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
$sql = "SELECT * FROM $t WHERE course_code = '".Database::escape_string($course_code)."' ";
@ -639,8 +642,7 @@ function create_default_course_gradebook($course_code = null, $gradebook_model_i
//there is no unique category for this course+session combination,
$cat = new Category();
if (!empty($session_id)) {
$my_session_id=api_get_session_id();
$s_name = api_get_session_name($my_session_id);
$s_name = api_get_session_name($session_id);
$cat->set_name($course_code.' - '.get_lang('Session').' '.$s_name);
$cat->set_session_id($session_id);
} else {

@ -88,6 +88,36 @@ class SessionManager {
if (isset($params['course_code'])) {
self::add_courses_to_session($session_id, array($params['course_code']));
//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) {
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']);
$eval->set_user_id($params['gradebook_params']['user_id']);
$eval->set_course_code($params['course_code']);
$eval->set_category_id($category_id);
$eval->set_weight($params['gradebook_params']['weight']);
$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";
$result = Database::query($sql);
if (Database::num_rows($result)) {
$gradebook_data = Database::fetch_array($result, 'ASSOC');
if (!empty($gradebook_data)) {
$sql = "UPDATE SET session_id = $session_id WHERE id = {$gradebook_data['id']}";
Database::query($sql);
}
}*/
}
}
} else {
if (isset($params['return_item_if_already_exists']) && $params['return_item_if_already_exists']) {

@ -257,7 +257,6 @@ class Migration {
}
}
if (!empty($table['dest_func'])) {
//error_log('Calling '.$table['dest_func'].' on data recovered: '.print_r($dest_row, 1));
$dest_row['return_item_if_already_exists'] = true;

@ -296,20 +296,22 @@ class MigrationCustom {
//Fixes wrong wanted codes
$data['wanted_code'] = str_replace(array('-', '_'), '000', $data['wanted_code']);
//Creates an evaluation
$data['create_gradebook_evaluation'] = true;
//Specific to ICPNA, set the default language to English
$data['language'] = 'english';
$data['visibility'] = COURSE_VISIBILITY_REGISTERED;
//Creates an evaluation
$data['create_gradebook_evaluation'] = false;
/*
$data['gradebook_params'] = array(
'name' => 'General evaluation',
'user_id' => self::default_admin_id,
'weight' => '20',
'max' => '20'
);
);*/
$course_data = CourseManager::create_course($data);
var_dump($course_data['code']);
return $course_data;
}
@ -318,9 +320,18 @@ class MigrationCustom {
* in db_matches.php
*/
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(
'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);
//error_log('create_session');
//error_log($data['course_code']);
if (!$session_id) {
//error_log($session_id);
error_log('failed create_session');

@ -35,15 +35,15 @@ class MigrationMSSQL extends Migration {
$top = null;
//$top = " TOP 1000 ";
if (in_array($table, array('Empleado', 'Alumno'))) {
//$top = " TOP 10000 ";
$top = " TOP 10000 ";
}
if (in_array($table, array('ProgramaAcademico', 'Matricula'))) {
$top = " TOP 1000 ";
$top = " TOP 100000 ";
}
//$top = null;
$top = " TOP 10 " ;
//$top = " TOP 10 " ;
$extra = null;
if (isset($options) && !empty($options['inner_join'])) {
$extra = ' '.$options['alias_orig_table'].' INNER JOIN '.$options['inner_join'].' '.$options['alias_join_table'].' ON '.$options['on'];

Loading…
Cancel
Save