Fixing bug when adding a link or an evaluation into a gradebook

skala
Julio Montoya 13 years ago
parent 332698052d
commit bd733771e6
  1. 15
      main/gradebook/index.php
  2. 1
      main/gradebook/lib/be/abstractlink.class.php
  3. 29
      main/gradebook/lib/be/category.class.php
  4. 5
      main/gradebook/lib/be/evaluation.class.php
  5. 70
      main/gradebook/lib/fe/catform.class.php
  6. 81
      main/gradebook/lib/fe/evalform.class.php
  7. 17
      main/gradebook/lib/fe/gradebooktable.class.php
  8. 57
      main/gradebook/lib/fe/linkaddeditform.class.php
  9. 2
      main/gradebook/lib/fe/linkform.class.php
  10. 6
      main/gradebook/lib/gradebook_data_generator.class.php

@ -665,6 +665,7 @@ if (isset ($_GET['studentoverview'])) {
} else {
$stud_id = $stud_id;
}
$allcat = $cats[0]->get_subcategories($stud_id, $course_code, $session_id);
$alleval = $cats[0]->get_evaluations($stud_id);
$alllink = $cats[0]->get_links($stud_id);
@ -792,8 +793,8 @@ if (isset($first_time) && $first_time==1 && api_is_allowed_to_edit(null,true)) {
echo '<meta http-equiv="refresh" content="0;url='.api_get_self().'?cidReq='.$course_code.'" />';
} else {
$cats = Category :: load(null, null, $course_code, null, null, $session_id, false); //already init
if (!empty($cats)) {
if (!empty($cats)) {
if (api_is_allowed_to_edit(null, true)) {
//Getting grade models
@ -845,10 +846,10 @@ if (isset($first_time) && $first_time==1 && api_is_allowed_to_edit(null,true)) {
}
}
$i = 0;
foreach ($cats as $cat) {
$allcat = $cat->get_subcategories($stud_id, $course_code, $session_id);
$i = 0;
foreach ($cats as $cat) {
$allcat = $cat->get_subcategories($stud_id, $course_code, $session_id);
$alleval = $cat->get_evaluations($stud_id);
$alllink = $cat->get_links($stud_id);
@ -864,7 +865,7 @@ if (isset($first_time) && $first_time==1 && api_is_allowed_to_edit(null,true)) {
if (!empty($grade_models[$grade_model_id])) {
Display::display_normal_message(get_lang('GradeModel').': '.$grade_models[$grade_model_id]['name']);
}
}
}
$gradebooktable = new GradebookTable($cat, $allcat, $alleval, $alllink, $addparams);
$gradebooktable->display();
}

@ -213,7 +213,6 @@ abstract class AbstractLink implements GradebookItem {
*/
public function add() {
$this->add_linked_data();
if (isset($this->type) && isset($this->ref_id) && isset($this->user_id) && isset($this->course_code) && isset($this->category) && isset($this->weight) && isset($this->visible)) {
$tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
$sql_testing="SELECT count(*) FROM ".$tbl_grade_links." WHERE ref_id=".$this->get_ref_id()." AND category_id = ".$this->category." AND type = ".$this->type." ;";

@ -1077,33 +1077,28 @@ class Category implements GradebookItem
if (isset($stud_id) && !empty($stud_id)) {
// special case: this is the root
if ($this->id == 0) {
$evals = Evaluation::get_evaluations_with_result_for_student(0,$stud_id);
$evals = Evaluation::get_evaluations_with_result_for_student(0,$stud_id);
} else {
$evals = Evaluation::load(null,null,$course_code,$this->id, api_is_allowed_to_edit() ? null : 1);
$evals = Evaluation::load(null,null, $course_code, $this->id, api_is_allowed_to_edit() ? null : 1);
}
} else {// all students
// course admin
// course admin
if ((api_is_allowed_to_edit() || api_is_drh() || api_is_session_admin()) && !api_is_platform_admin()) {
// root
// root
if ($this->id == 0) {
$evals = Evaluation::load(null, api_get_user_id(), null, $this->id, null);
}
// inside a course
elseif (isset($this->course_code) && !empty($this->course_code)) {
} elseif (isset($this->course_code) && !empty($this->course_code)) {
// inside a course
$evals = Evaluation::load(null, null, $course_code, $this->id, null);
}else { // course independent
} else {
// course independent
$evals = Evaluation::load(null, api_get_user_id(), null, $this->id, null);
}
} elseif (api_is_platform_admin()) {
//platform admin
$evals = Evaluation::load(null, null, $course_code, $this->id, null);
}
//platform admin
elseif (api_is_platform_admin()) {
$evals = Evaluation::load(null, null, $course_code, $this->id, null);
}
}
if ($recursive) {

@ -139,7 +139,7 @@ class Evaluation implements GradebookItem
*/
public function load ($id = null, $user_id = null, $course_code = null, $category_id = null, $visible = null, $locked = null) {
$tbl_grade_evaluations = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
$sql='SELECT id,name,description,user_id,course_code,category_id,created_at,weight,max,visible,type,locked FROM '.$tbl_grade_evaluations;
$sql = 'SELECT id,name,description,user_id,course_code,category_id,created_at,weight,max,visible,type,locked FROM '.$tbl_grade_evaluations;
$paramcount = 0;
if (isset ($id)) {
$sql.= ' WHERE id = '.intval($id);
@ -174,8 +174,7 @@ class Evaluation implements GradebookItem
else $sql .= ' WHERE';
$sql .= ' visible = '.intval($locked);
$paramcount ++;
}
//var_dump($sql);
}
$result = Database::query($sql);
$alleval = Evaluation::create_evaluation_objects_from_sql_result($result);
return $alleval;

@ -120,8 +120,12 @@ class CatForm extends FormValidator {
$session_id = api_get_session_id();
//Freeze or not
$test_cats = Category :: load(null, null, $course_code, null, null, $session_id, false); //already init
$links = $test_cats[0]->get_links();
$links = null;
if (isset($test_cats[0])) {
$links = $test_cats[0]->get_links();
}
$grade_model_id = $this->category_object->get_grade_model_id();
if (empty($links)) {
$grade_model_id = 0;
}
@ -151,47 +155,17 @@ class CatForm extends FormValidator {
if (isset($this->category_object) && $this->category_object->get_parent_id() == 0) {
//we can't change the root category
$this->freeze('name');
}
}
$global_weight = api_get_setting('gradebook_default_weight');
if (isset($global_weight)) {
$value = $global_weight;
} else {
$value = 100;
}
$this->add_textfield('weight', array(get_lang('TotalWeight'), get_lang('TotalSumOfWeights')), true, array('value'=>$value, 'size'=>'4','maxlength'=>'5'));
$this->addRule('weight',get_lang('ThisFieldIsRequired'),'required');
/*$models = api_get_settings_options('grading_model');
$course_grading_model_id = api_get_course_setting('course_grading_model');
$grading_model = '';
if (!empty($course_grading_model_id)) {
foreach($models as $option) {
if (intval($option['id']) == $course_grading_model_id) {
$grading_model = $option['value'];
}
}
}
$grading_contents = api_grading_model_functions($grading_model, 'to_array');
*/
if (0) {
/*$course_code = api_get_course_id();
$session_id = api_get_session_id();
///direct access to one evaluation
$cats = Category :: load(null, null, $course_code, null, null, $session_id, false); //already init
$count = count($cats) - 1;
$value = round((float)$grading_contents['items'][$count]['percentage'], 2);
if ($value == 0) {
//$this->freeze();
}
$this->add_textfield('weight', get_lang('TotalWeight'), true, array('value'=> $value,'size'=>'4','maxlength'=>'5'));
//$this->addRule('weight',get_lang('ThisFieldIsRequired'),'required');
$this->freeze('weight'); */
} else {
$global_weight = api_get_setting('gradebook_default_weight');
if (isset($global_weight)) {
$value = $global_weight;
} else {
$value = 100;
}
$this->add_textfield('weight', array(get_lang('TotalWeight'), get_lang('TotalSumOfWeights')), true, array('value'=>$value, 'size'=>'4','maxlength'=>'5'));
$this->addRule('weight',get_lang('ThisFieldIsRequired'),'required');
}
if (api_is_platform_admin() || api_is_drh()) {
//the magic should be here
$skills = $this->category_object->get_skills();
@ -202,8 +176,7 @@ class CatForm extends FormValidator {
$content .= Display::tag('li', $skill['name'].'<a id="deleteskill_'.$skill['id'].'" class="closebutton" href="#"></a>', array('id'=>'skill_'.$skill['id'], 'class'=>'bit-box'));
}
}
$this->addElement('label', null, Display::tag('ul', $content, array('class'=>'holder holder_simple')));
$this->addElement('label', null, Display::tag('ul', $content, array('class'=>'holder holder_simple')));
}
if (isset($this->category_object) && $this->category_object->get_parent_id() == 0) {
@ -234,7 +207,10 @@ class CatForm extends FormValidator {
$course_code = api_get_course_id();
$session_id = api_get_session_id();
$test_cats = Category :: load(null, null, $course_code, null, null, $session_id, false); //already init
$links = $test_cats[0]->get_links();
$links = null;
if (!empty($test_cats[0])) {
$links = $test_cats[0]->get_links();
}
if (count($test_cats) > 1 || !empty($links)) {
$this->freeze('grade_model_id');
@ -248,11 +224,11 @@ class CatForm extends FormValidator {
$this->addElement('style_submit_button', null, get_lang('EditCategory'), 'class="save"');
}
if (!empty($grading_contents)) {
//if (!empty($grading_contents)) {
$this->addRule('weight', get_lang('OnlyNumbers'), 'numeric');
//$this->addRule('weight',get_lang('NoDecimals'),'nopunctuation');
$this->addRule(array ('weight', 'zero'), get_lang('NegativeValue'), 'compare', '>=');
}
//}
}
/**
@ -283,4 +259,4 @@ class CatForm extends FormValidator {
function setDefaults($defaults = array ()) {
parent :: setDefaults($defaults);
}
}
}

@ -418,50 +418,51 @@ class EvalForm extends FormValidator
$this->addElement('header', $form_title);
$this->addElement('hidden', 'zero', 0);
$this->addElement('hidden', 'hid_user_id');
//$this->addElement('hidden', 'hid_category_id');
$this->addElement('hidden', 'hid_course_code');
$this->add_textfield('name', get_lang('EvaluationName'), true, array (
'size' => '54',
'class' => 'span3',
'maxlength' => '50',
'id' => 'evaluation_title'
));
$this->evaluation_object->get_category_id();
$select_gradebook = $this->addElement('select', 'hid_category_id', get_lang('SelectGradebook'), array(), array('id' => 'hid_category_id'));
$session_id = api_get_session_id();
$cat_id = $this->evaluation_object->get_category_id();
$session_id = api_get_session_id();
$course_code = api_get_course_id();
$all_categories = Category :: load(null, null, $course_code, null, null, $session_id, false);
if (count($all_categories) == 1) {
$this->addElement('hidden', 'hid_category_id', $cat_id);
} else {
$select_gradebook = $this->addElement('select', 'hid_category_id', get_lang('SelectGradebook'), array(), array('id' => 'hid_category_id'));
$this->addRule('hid_category_id', get_lang('ThisFieldIsRequired'), 'nonzero');
//$all_categories = Category :: load();
$all_categories = Category :: load(null, null, $course_code, null, null, $session_id, false);
// load ($id = null, $user_id = null, $course_code = null, $parent_id = null, $visible = null, $session = null, $show_session_categories = true) {
$default_weight = 0;
if (!empty($all_categories)) {
foreach ($all_categories as $my_cat) {
if ($my_cat->get_course_code() == api_get_course_id()) {
$grade_model_id = $my_cat->get_grade_model_id();
if (empty($grade_model_id)) {
if ($my_cat->get_parent_id() == 0) {
$default_weight = $my_cat->get_weight();
$select_gradebook->addoption(get_lang('Default'), $my_cat->get_id());
$cats_added[] = $my_cat->get_id();
$default_weight = 0;
if (!empty($all_categories)) {
foreach ($all_categories as $my_cat) {
if ($my_cat->get_course_code() == api_get_course_id()) {
$grade_model_id = $my_cat->get_grade_model_id();
if (empty($grade_model_id)) {
if ($my_cat->get_parent_id() == 0) {
$default_weight = $my_cat->get_weight();
$select_gradebook->addoption(get_lang('Default'), $my_cat->get_id());
$cats_added[] = $my_cat->get_id();
} else {
$select_gradebook->addoption($my_cat->get_name(), $my_cat->get_id());
$cats_added[] = $my_cat->get_id();
}
} else {
$select_gradebook->addoption($my_cat->get_name(), $my_cat->get_id());
$cats_added[] = $my_cat->get_id();
$select_gradebook->addoption(get_lang('Select'), 0);
}
} else {
$select_gradebook->addoption(get_lang('Select'), 0);
}
if ($this->evaluation_object->get_category_id() == $my_cat->get_id()) {
$default_weight = $my_cat->get_weight();
}
}
if ($this->evaluation_object->get_category_id() == $my_cat->get_id()) {
$default_weight = $my_cat->get_weight();
}
}
}
}
}
$global_weight = api_get_setting('gradebook_default_weight');
$this->add_textfield('weight_mask', array(get_lang('Weight'), null, ' [0 .. '.$global_weight.'] '), true, array (
@ -480,32 +481,38 @@ class EvalForm extends FormValidator
if ($edit) {
if (!$this->evaluation_object->has_results()) {
$this->add_textfield('max', get_lang('QualificationNumeric'), true, array (
'size' => '4',
'class' => 'span1',
'maxlength' => '5'
));
} else {
$this->add_textfield('max', array(get_lang('QualificationNumeric'), get_lang('CannotChangeTheMaxNote')), false, array (
'size' => '4',
'class' => 'span1',
'maxlength' => '5',
'disabled' => 'disabled'
));
}
} else {
$this->add_textfield('max', get_lang('QualificationNumeric'), true, array (
'size' => '4',
'class' => 'span1',
'maxlength' => '5'
));
}
$this->addElement('textarea', 'description', get_lang('Description'), array (
'rows' => '3',
'cols' => '34'
'class' => 'span3',
));
//var_dump(HTML_QuickForm::getRegisteredRules() );
$this->addRule('hid_category_id', get_lang('ThisFieldIsRequired'), 'required');
$this->addElement('checkbox', 'visible', null, get_lang('Visible'));
$this->addRule('weight_mask', get_lang('OnlyNumbers'), 'numeric');
$this->addRule(array ('weight_mask', 'zero'), get_lang('NegativeValue'), 'compare', '>=');
$this->addRule(array('weight_mask', 'zero'), get_lang('NegativeValue'), 'compare', '>=');
$this->addRule('max', get_lang('OnlyNumbers'), 'numeric');
$this->addRule(array ('max', 'zero'), get_lang('NegativeValue'), 'compare', '>=');
$this->addRule(array('max', 'zero'), get_lang('NegativeValue'), 'compare', '>=');
}
function display() {

@ -27,12 +27,13 @@ class GradebookTable extends SortableTable {
* Constructor
*/
function GradebookTable ($currentcat, $cats = array(), $evals = array(), $links = array(), $addparams = null) {
$status = CourseManager::get_user_in_course_status(api_get_user_id(), api_get_course_id());
//$status = CourseManager::get_user_in_course_status(api_get_user_id(), api_get_course_id());
parent :: __construct ('gradebooklist', null, null, (api_is_allowed_to_edit()?1:0));
$this->evals_links = array_merge($evals, $links);
$this->currentcat = $currentcat;
$this->datagen = new GradebookDataGenerator($cats, $evals, $links);
if (isset($addparams)) {
$this->set_additional_parameters($addparams);
}
@ -54,11 +55,11 @@ class GradebookTable extends SortableTable {
$this->set_header($column++, get_lang('Result'), false);
}
if (api_is_allowed_to_edit(null, true)) {
/*if (api_is_allowed_to_edit(null, true)) {
//$this->set_header($column++, get_lang('CreationDate'),true, 'width="100px"');
} elseif (($status<>1) && !api_is_allowed_to_edit() && (!isset($_GET['selectcat']) || $_GET['selectcat']==0)) {
//$this->set_header($column++, get_lang('Date'),true, 'width="100px"');
}
}*/
//admins get an edit column
if (api_is_allowed_to_edit(null, true)) {
@ -84,7 +85,6 @@ class GradebookTable extends SortableTable {
return $this->datagen;
}
/**
* Function used by SortableTable to get total number of items in the table
*/
@ -132,10 +132,10 @@ class GradebookTable extends SortableTable {
}
//status of user in course
$user_id = api_get_user_id();
$course_code = api_get_course_id();
$session_id = api_get_session_id();
$status_user = api_get_status_of_user_in_course($user_id, $course_code);
$user_id = api_get_user_id();
$course_code = api_get_course_id();
$session_id = api_get_session_id();
$status_user = api_get_status_of_user_in_course($user_id, $course_code);
$data_array = $this->datagen->get_data($sorting, $from, $this->per_page);
@ -146,6 +146,7 @@ class GradebookTable extends SortableTable {
$main_categories = array();
$main_cat = Category :: load(null, null, $course_code, null, null, $session_id, false);
foreach ($data_array as $data) {
// list of items inside the gradebook (exercises, lps, forums, etc)

@ -20,8 +20,7 @@ require_once api_get_path(LIBRARY_PATH) . 'groupmanager.lib.php';
*/
class LinkAddEditForm extends FormValidator
{
const TYPE_ADD = 1;
const TYPE_ADD = 1;
const TYPE_EDIT = 2;
/**
@ -61,26 +60,39 @@ class LinkAddEditForm extends FormValidator
} else {
$this->addElement('label',get_lang('Name'), '<span class="freeze">'.$link->get_name().' ['.$link->get_type_name().']</span>');
$this->addElement('hidden','name_link',$link->get_name(),array('id'=>'name_link'));
}
$select_gradebook = $this->addElement('select', 'select_gradebook', get_lang('SelectGradebook'), array(), array('id' => 'hide_category_id'));
}
$default_weight = 0;
if (!empty($category_object)) {
foreach ($category_object as $my_cat) {
if ($my_cat->get_course_code() == api_get_course_id()) {
if ($my_cat->get_parent_id() == 0 ) {
$default_weight = $my_cat->get_weight();
$select_gradebook->addoption(get_lang('Default'), $my_cat->get_id());
} else {
$select_gradebook->addoption($my_cat->get_name(), $my_cat->get_id());
}
if ($link->get_category_id() == $my_cat->get_id()) {
$default_weight = $my_cat->get_weight();
}
}
if (count($category_object) == 1) {
$this->addElement('hidden', 'select_gradebook', $category_object[0]->get_id());
} else {
$select_gradebook = $this->addElement('select', 'select_gradebook', get_lang('SelectGradebook'), array(), array('id' => 'hide_category_id'));
$this->addRule('select_gradebook', get_lang('ThisFieldIsRequired'), 'nonzero');
$default_weight = 0;
if (!empty($category_object)) {
foreach ($category_object as $my_cat) {
if ($my_cat->get_course_code() == api_get_course_id()) {
$grade_model_id = $my_cat->get_grade_model_id();
if (empty($grade_model_id)) {
if ($my_cat->get_parent_id() == 0 ) {
$default_weight = $my_cat->get_weight();
$select_gradebook->addoption(get_lang('Default'), $my_cat->get_id());
} else {
$select_gradebook->addoption($my_cat->get_name(), $my_cat->get_id());
}
} else {
$select_gradebook->addoption(get_lang('Select'), 0);
}
if ($link->get_category_id() == $my_cat->get_id()) {
$default_weight = $my_cat->get_weight();
}
}
}
}
}
$global_weight = api_get_setting('gradebook_default_weight');
@ -90,6 +102,9 @@ class LinkAddEditForm extends FormValidator
'maxlength' => '5',
'class' => 'span1'
));
$this->addElement('hidden', 'weight');
/*
// ELEMENT: weight
@ -124,7 +139,6 @@ class LinkAddEditForm extends FormValidator
if ($form_type == self :: TYPE_EDIT) {
$defaults['max'] = $link->get_max();
}
}
// ELEMENT: date
@ -159,6 +173,5 @@ class LinkAddEditForm extends FormValidator
// set default values
$this->setDefaults($defaults);
}
}

@ -100,4 +100,4 @@ class LinkForm extends FormValidator
$this->setDefaults(array('select_link' => $this->extra));
}
}
}
}

@ -34,7 +34,7 @@ class GradebookDataGenerator
$allevals = (isset($evals) ? $evals : array());
$alllinks = (isset($links) ? $links : array());
// merge categories, evaluations and links
$this->items = array_merge($allcats, $allevals, $alllinks);
$this->items = array_merge($allcats, $allevals, $alllinks);
$this->evals_links = array_merge($allevals, $alllinks);
}
@ -56,7 +56,7 @@ class GradebookDataGenerator
* 5: student's score (if student logged in)
*/
public function get_data($sorting = 0, $start = 0, $count = null, $ignore_score_color = false) {
$status = CourseManager::get_user_in_course_status(api_get_user_id(), api_get_course_id());
//$status = CourseManager::get_user_in_course_status(api_get_user_id(), api_get_course_id());
// do some checks on count, redefine if invalid value
if (!isset($count)) {
$count = count ($this->items) - $start;
@ -64,6 +64,7 @@ class GradebookDataGenerator
if ($count < 0) {
$count = 0;
}
$allitems = $this->items;
// sort array
if ($sorting & self :: GDG_SORT_TYPE) {
@ -90,6 +91,7 @@ class GradebookDataGenerator
$status_user = api_get_status_of_user_in_course($user_id, $course_code);
// generate the data to display
$data = array();
foreach ($visibleitems as $item) {
$row = array ();
$row[] = $item;

Loading…
Cancel
Save