Fixing gradebook creation when creating a session

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

@ -10,9 +10,7 @@
*/
class Evaluation implements GradebookItem
{
// PROPERTIES
// PROPERTIES
private $id;
private $name;
private $description;
@ -23,9 +21,7 @@ class Evaluation implements GradebookItem
private $weight;
private $eval_max;
private $visible;
// CONSTRUCTORS
function __construct() {
}
@ -83,7 +79,7 @@ class Evaluation implements GradebookItem
return isset($this->locked) && $this->locked == 1 ? true : false ;
}
public function set_id ($id) {
public function set_id($id) {
$this->id = $id;
}
@ -131,7 +127,6 @@ class Evaluation implements GradebookItem
$this->locked = $locked;
}
// CRUD FUNCTIONS
/**
@ -226,7 +221,7 @@ class Evaluation implements GradebookItem
}
if (isset($this->category)) {
$sql .= ', category_id';
}
}
$sql .= ', created_at';
$sql .= ',type';
$sql .= ") VALUES ('".Database::escape_string($this->get_name())."'"
@ -242,10 +237,10 @@ class Evaluation implements GradebookItem
}
if (isset($this->category)) {
$sql .= ','.intval($this->get_category_id());
}
}
if (empty($this->type)) {
$this->type = 'evaluation';
}
}
$sql .= ", '".api_get_utc_datetime()."'";
$sql .= ',\''.Database::escape_string($this->type).'\'';
$sql .= ")";

@ -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();
}
$session_id = api_get_session_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)."' ";
@ -638,9 +641,8 @@ function create_default_course_gradebook($course_code = null, $gradebook_model_i
if (Database::num_rows($res)<1){
//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);
if (!empty($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']) {

@ -255,8 +255,7 @@ class Migration {
}
unset($dest_row[$details['dest']]);
}
}
}
if (!empty($table['dest_func'])) {
//error_log('Calling '.$table['dest_func'].' on data recovered: '.print_r($dest_row, 1));
@ -274,7 +273,7 @@ class Migration {
switch ($table['dest_table']) {
case 'course':
//Saving courses in array
if ($item_result) {
if ($item_result) {
//$this->data_list['courses'][$dest_row['uidIdCurso']] = $item_result;
} else {
error_log('Course Not FOUND');

@ -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']);
);*/
$course_data = CourseManager::create_course($data);
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']);
//error_log('create_session');
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