Adding grade model in the add course settings sse BT#4010

skala
Julio Montoya 13 years ago
parent 2492e6805f
commit 4114391a68
  1. 17
      main/admin/course_add.php
  2. 28
      main/gradebook/gradebook_edit_cat.php
  3. 1
      main/gradebook/index.php
  4. 84
      main/gradebook/lib/be/category.class.php
  5. 14
      main/gradebook/lib/gradebook_functions.inc.php
  6. 2
      main/inc/ajax/model.ajax.php
  7. 2
      main/inc/lib/add_course.lib.inc.php
  8. 8
      main/inc/lib/course.lib.php
  9. 2
      tests/main/inc/lib/add_course.lib.inc.test.php

@ -17,8 +17,8 @@ $this_section = SECTION_PLATFORM_ADMIN;
api_protect_admin_script(); api_protect_admin_script();
require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php'; require_once api_get_path(LIBRARY_PATH).'fileManage.lib.php';
require_once api_get_path(LIBRARY_PATH).'grade_model.lib.php';
$table_course = Database::get_main_table(TABLE_MAIN_COURSE);
$tool_name = get_lang('AddCourse'); $tool_name = get_lang('AddCourse');
$interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin')); $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
$interbreadcrumb[] = array('url' => 'course_list.php', 'name' => get_lang('CourseList')); $interbreadcrumb[] = array('url' => 'course_list.php', 'name' => get_lang('CourseList'));
@ -112,6 +112,20 @@ $form->addGroup($group,'', get_lang('Unsubscription'), '<br />');
$form->addElement('text','disk_quota',array(get_lang('CourseQuota'), null, get_lang('MB'))); $form->addElement('text','disk_quota',array(get_lang('CourseQuota'), null, get_lang('MB')));
$form->addRule('disk_quota', get_lang('ThisFieldShouldBeNumeric'), 'numeric'); $form->addRule('disk_quota', get_lang('ThisFieldShouldBeNumeric'), 'numeric');
//if (api_get_setting('gradebook'))
$obj = new GradeModel();
$grade_models = $obj->get_all();
$grade_model_options = array('-1' => get_lang('None'));
if (!empty($grade_models)) {
foreach ($grade_models as $item) {
$grade_model_options[$item['id']] = $item['name'];
}
}
$form->addElement('select', 'gradebook_model_id', get_lang('GradeModel'), $grade_model_options);
$form->add_progress_bar(); $form->add_progress_bar();
$form->addElement('style_submit_button', 'submit', get_lang('CreateCourse'), 'class="add"'); $form->addElement('style_submit_button', 'submit', get_lang('CreateCourse'), 'class="add"');
@ -136,7 +150,6 @@ $form->setDefaults($values);
// Validate the form // Validate the form
if ($form->validate()) { if ($form->validate()) {
$course = $form->exportValues(); $course = $form->exportValues();
$code = $course['visual_code'];
//$tutor_name = $teachers[$course['tutor_id']]; //$tutor_name = $teachers[$course['tutor_id']];
$teacher_id = $course['tutor_id']; $teacher_id = $course['tutor_id'];
$course_teachers = $course['course_teachers']; $course_teachers = $course['course_teachers'];

@ -118,34 +118,6 @@ if ($form->validate()) {
} }
$cat->set_visible($visible); $cat->set_visible($visible);
$cat->save(); $cat->save();
$parent_id = $cat->get_parent_id();
if ($parent_id == 0) {
//do something
if (isset($values['grade_model_id']) && !empty($values['grade_model_id'])) {
$obj = new GradeModel();
$components = $obj->get_components($values['grade_model_id']);
foreach ($components as $component) {
$gradebook = new Gradebook();
$params = array();
$params['name'] = $component['acronym'];
$params['description'] = $component['title'];
$params['user_id'] = api_get_user_id();
$params['parent_id'] = $cat->get_id();
$params['weight'] = $component['percentage']/100*$values['weight'];
$params['session_id'] = api_get_session_id();
$params['course_code'] = api_get_course_id();
$params['grade_model_id'] = api_get_session_id();
$gradebook->save($params);
}
}
}
header('Location: '.Security::remove_XSS($_SESSION['gradebook_dest']).'?editcat=&selectcat=' . $cat->get_parent_id()); header('Location: '.Security::remove_XSS($_SESSION['gradebook_dest']).'?editcat=&selectcat=' . $cat->get_parent_id());
exit; exit;
} }

@ -859,7 +859,6 @@ if (isset($first_time) && $first_time==1 && api_is_allowed_to_edit(null,true)) {
$obj = new GradeModel(); $obj = new GradeModel();
$grade_models = $obj->get_all(); $grade_models = $obj->get_all();
$options = array('-1' => get_lang('None')); $options = array('-1' => get_lang('None'));
if (!empty($grade_models)) { if (!empty($grade_models)) {
foreach ($grade_models as $item) { foreach ($grade_models as $item) {
$options[$item['id']] = $item['name']; $options[$item['id']] = $item['name'];

@ -11,6 +11,7 @@
require_once api_get_path(LIBRARY_PATH).'skill.lib.php'; require_once api_get_path(LIBRARY_PATH).'skill.lib.php';
require_once api_get_path(LIBRARY_PATH).'gradebook.lib.php'; require_once api_get_path(LIBRARY_PATH).'gradebook.lib.php';
require_once api_get_path(LIBRARY_PATH).'grade_model.lib.php';
class Category implements GradebookItem class Category implements GradebookItem
{ {
@ -306,8 +307,6 @@ class Category implements GradebookItem
} }
if (isset($this->name) && isset($this->user_id)) { if (isset($this->name) && isset($this->user_id)) {
$tbl_grade_categories = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); $tbl_grade_categories = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
$sql = 'INSERT INTO '.$tbl_grade_categories.' (name,user_id,weight,visible'; $sql = 'INSERT INTO '.$tbl_grade_categories.' (name,user_id,weight,visible';
if (isset($this->description)) { if (isset($this->description)) {
@ -322,6 +321,11 @@ class Category implements GradebookItem
if (!empty($this->session_id)) { if (!empty($this->session_id)) {
$sql .= ', session_id'; $sql .= ', session_id';
} }
if (isset($this->grade_model_id)) {
$sql .= ', grade_model_id ';
}
$sql .= ") VALUES ('".Database::escape_string($this->get_name())."'" $sql .= ") VALUES ('".Database::escape_string($this->get_name())."'"
.','.intval($this->get_user_id()) .','.intval($this->get_user_id())
.','.Database::escape_string($this->get_weight()) .','.Database::escape_string($this->get_weight())
@ -336,15 +340,49 @@ class Category implements GradebookItem
$sql .= ','.intval($this->get_parent_id()); $sql .= ','.intval($this->get_parent_id());
} }
if (!empty($this->session_id)) { if (!empty($this->session_id)) {
$sql .= ', '.intval($this->get_session_id()); $sql .= ', '.intval($this->get_session_id());
}
if (isset($this->grade_model_id)) {
$sql .= ', '.intval($this->get_grade_model_id());
} }
$sql .= ')'; $sql .= ')';
Database::query($sql); Database::query($sql);
$id = Database::insert_id(); $id = Database::insert_id();
$this->set_id($id); $this->set_id($id);
if (!empty($id)) {
$parent_id = $this->get_parent_id();
$grade_model_id = $this->get_grade_model_id();
if ($parent_id == 0) {
//do something
if (isset($grade_model_id) && !empty($grade_model_id) && $grade_model_id != '-1') {
$obj = new GradeModel();
$components = $obj->get_components($grade_model_id);
$default_weight_setting = api_get_setting('gradebook_default_weight');
$default_weight = 100;
if (isset($default_weight_setting)) {
$default_weight = $default_weight_setting;
}
foreach ($components as $component) {
$gradebook = new Gradebook();
$params = array();
$params['name'] = $component['acronym'];
$params['description'] = $component['title'];
$params['user_id'] = api_get_user_id();
$params['parent_id'] = $id;
$params['weight'] = $component['percentage']/100*$default_weight;
$params['session_id'] = api_get_session_id();
$params['course_code'] = $this->get_course_code();
$gradebook->save($params);
}
}
}
}
$gradebook= new Gradebook(); $gradebook= new Gradebook();
$res = $gradebook->update_skills_to_gradebook($this->id, $this->get_skills(false)); $gradebook->update_skills_to_gradebook($this->id, $this->get_skills(false));
return $id; return $id;
} }
@ -389,6 +427,42 @@ class Category implements GradebookItem
Database::query($sql); Database::query($sql);
if (!empty($this->id)) {
$parent_id = $this->get_parent_id();
$grade_model_id = $this->get_grade_model_id();
if ($parent_id == 0) {
//do something
if (isset($grade_model_id) && !empty($grade_model_id) && $grade_model_id != '-1') {
$obj = new GradeModel();
$components = $obj->get_components($grade_model_id);
$default_weight_setting = api_get_setting('gradebook_default_weight');
$default_weight = 100;
if (isset($default_weight_setting)) {
$default_weight = $default_weight_setting;
}
$final_weight = $this->get_weight();
if (!empty($final_weight)) {
$default_weight = $this->get_weight();
}
foreach ($components as $component) {
$gradebook = new Gradebook();
$params = array();
$params['name'] = $component['acronym'];
$params['description'] = $component['title'];
$params['user_id'] = api_get_user_id();
$params['parent_id'] = $this->id;
$params['weight'] = $component['percentage']/100*$default_weight;
$params['session_id'] = api_get_session_id();
$params['course_code'] = $this->get_course_code();
$gradebook->save($params);
}
}
}
}
$gradebook= new Gradebook(); $gradebook= new Gradebook();
$gradebook->update_skills_to_gradebook($this->id, $this->get_skills(false)); $gradebook->update_skills_to_gradebook($this->id, $this->get_skills(false));
@ -1220,7 +1294,7 @@ class Category implements GradebookItem
function lock($locked) { function lock($locked) {
$table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); $table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
$sql = "UPDATE $table SET locked = '".intval($locked)."' WHERE id='".intval($this->id)."'"; $sql = "UPDATE $table SET locked = '".intval($locked)."' WHERE id='".intval($this->id)."'";
$rs = Database::query($sql); Database::query($sql);
} }
function lock_all_items($locked) { function lock_all_items($locked) {

@ -615,9 +615,11 @@ function get_user_certificate_content($user_id, $course_code, $is_preview = fals
return array('content' => $new_content_html, 'variables'=>$content_html['variables']); return array('content' => $new_content_html, 'variables'=>$content_html['variables']);
} }
function create_default_course_gradebook() { function create_default_course_gradebook( $course_code = null, $gradebook_model_id = 0) {
if (api_is_allowed_to_edit(true, true)) { if (api_is_allowed_to_edit(true, true)) {
$course_code = api_get_course_id(); if (!isset($course_code) || empty($course_code)) {
$course_code = api_get_course_id();
}
$session_id = api_get_session_id(); $session_id = api_get_session_id();
$t = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY); $t = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
@ -644,7 +646,13 @@ function create_default_course_gradebook() {
$cat->set_description(null); $cat->set_description(null);
$cat->set_user_id(api_get_user_id()); $cat->set_user_id(api_get_user_id());
$cat->set_parent_id(0); $cat->set_parent_id(0);
$cat->set_weight(100); $default_weight_setting = api_get_setting('gradebook_default_weight');
$default_weight = isset($default_weight_setting) && !empty($default_weight_setting) ? $default_weight_setting : 100;
$cat->set_weight($default_weight);
$cat->set_grade_model_id($gradebook_model_id);
$cat->set_visible(0); $cat->set_visible(0);
$cat->add(); $cat->add();
$category_id = $cat->get_id(); $category_id = $cat->get_id();

@ -291,7 +291,7 @@ switch ($action) {
break; break;
case 'get_grade_models': case 'get_grade_models':
$columns = array('name', 'description', 'actions'); $columns = array('name', 'description', 'actions');
if(!in_array($sidx, $columns)) { if (!in_array($sidx, $columns)) {
$sidx = 'name'; $sidx = 'name';
} }
$result = Database::select('*', "$obj->table ", array('order' =>"$sidx $sord", 'LIMIT'=> "$start , $limit")); $result = Database::select('*', "$obj->table ", array('order' =>"$sidx $sord", 'LIMIT'=> "$start , $limit"));

@ -2218,7 +2218,7 @@ function lang2db($string) {
* Fills the course database with some required content and example content. * Fills the course database with some required content and example content.
* @version 1.2 * @version 1.2
*/ */
function fill_Db_course($course_id, $course_repository, $language, $default_document_array = array(), $fill_with_exemplary_content = null) { function fill_db_course($course_id, $course_repository, $language, $default_document_array = array(), $fill_with_exemplary_content = null) {
if (is_null($fill_with_exemplary_content)) { if (is_null($fill_with_exemplary_content)) {
$fill_with_exemplary_content = api_get_setting('example_material_course_creation') != 'false'; $fill_with_exemplary_content = api_get_setting('example_material_course_creation') != 'false';
} }

@ -163,10 +163,14 @@ class CourseManager {
if (!empty($course_info)) { if (!empty($course_info)) {
prepare_course_repository($course_info['directory'], $course_info['code']); prepare_course_repository($course_info['directory'], $course_info['code']);
$pictures_array = fill_course_repository($course_info['directory'], $params['exemplary_content']); $pictures_array = fill_course_repository($course_info['directory'], $params['exemplary_content']);
fill_Db_course($course_id, $course_info['directory'], $course_info['course_language'], $pictures_array, $params['exemplary_content']); fill_db_course($course_id, $course_info['directory'], $course_info['course_language'], $pictures_array, $params['exemplary_content']);
self::update_course_ranking($course_info['real_id'], 0); self::update_course_ranking($course_info['real_id'], 0);
//Create gradebook_category for the new course and add a gradebook model for the course
if (isset($params['gradebook_model_id']) && !empty($params['gradebook_model_id']) && $params['gradebook_model_id'] != '-1') {
require_once api_get_path(SYS_CODE_PATH).'gradebook/lib/gradebook_functions.inc.php';
create_default_course_gradebook($course_info['code'], $params['gradebook_model_id']);
}
return $course_info; return $course_info;
} }
} }

@ -109,7 +109,7 @@ class TestAddCourse extends UnitTestCase {
$courseRepository = 'testcourse'; $courseRepository = 'testcourse';
$language = 'english'; $language = 'english';
$default_document_array ='testdocument'; $default_document_array ='testdocument';
$res = fill_Db_course($courseDbName, $courseRepository, $language,array()); $res = fill_db_course($courseDbName, $courseRepository, $language,array());
$this->assertTrue($res === 0); $this->assertTrue($res === 0);
} }

Loading…
Cancel
Save