Should fix weight bugs see #5168

skala
Julio Montoya 13 years ago
parent 0d5f41a0a0
commit fef1af2a9d
  1. 15
      main/gradebook/gradebook_edit_cat.php
  2. 5
      main/gradebook/gradebook_edit_eval.php
  3. 7
      main/gradebook/gradebook_edit_link.php
  4. 3
      main/gradebook/lib/be/abstractlink.class.php
  5. 32
      main/gradebook/lib/be/category.class.php
  6. 2
      main/gradebook/lib/be/exerciselink.class.php
  7. 14
      main/gradebook/lib/be/forumthreadlink.class.php
  8. 14
      main/gradebook/lib/be/studentpublicationlink.class.php
  9. 42
      main/gradebook/lib/fe/displaygradebook.php
  10. 15
      main/gradebook/lib/fe/gradebooktable.class.php
  11. 12
      main/gradebook/lib/fe/linkaddeditform.class.php
  12. 43
      main/gradebook/lib/flatview_data_generator.class.php
  13. 2
      main/gradebook/lib/gradebook_functions.inc.php

@ -87,13 +87,19 @@ $form = new CatForm(CatForm :: TYPE_EDIT, $catedit[0], 'edit_cat_form');
if ($form->validate()) {
$values = $form->getSubmitValues();
if (isset($values['skills'])) {
//$res = $gradebook->update_skills_to_gradebook($values['hid_id'], $values['skills']);
$cat = new Category();
if (!empty($values['hid_id'])) {
$cat = $cat->load($values['hid_id']);
if (isset($cat[0])) {
$cat = $cat[0];
}
}
$cat = new Category();
$cat->set_id($values['hid_id']);
$cat->set_name($values['name']);
if (empty ($values['course_code'])) {
$cat->set_course_code(null);
}else {
@ -105,6 +111,9 @@ if ($form->validate()) {
$cat->set_skills($values['skills']);
$cat->set_user_id($values['hid_user_id']);
$cat->set_parent_id($values['hid_parent_id']);
//$cat->update_children_weight($values['weight']);
$cat->set_weight($values['weight']);
if ($values['hid_parent_id'] == 0 ) {

@ -33,14 +33,15 @@ if ($form->validate()) {
$parent_cat = Category :: load($values['hid_category_id']);
$final_weight = null;
/*$final_weight = null;
if ($parent_cat[0]->get_parent_id() == 0) {
$final_weight = $values['weight_mask'];
} else {
$cat = Category :: load($parent_cat[0]->get_parent_id());
$global_weight = $cat[0]->get_weight();
$final_weight = $values['weight_mask']/$global_weight*$parent_cat[0]->get_weight();
}
}*/
$final_weight = $values['weight_mask'];
$eval->set_weight($final_weight);

@ -41,13 +41,16 @@ if ($form->validate()) {
$parent_cat = Category :: load($values['select_gradebook']);
$final_weight = null;
/*
if ($parent_cat[0]->get_parent_id() == 0) {
$final_weight = $values['weight_mask'];
$final_weight = $values['weight_mask'];
} else {
$cat = Category :: load($parent_cat[0]->get_parent_id());
$global_weight = $cat[0]->get_weight();
$final_weight = $values['weight_mask']/$global_weight*$parent_cat[0]->get_weight();
}
}*/
$final_weight = $values['weight_mask'];
$link->set_weight($final_weight);

@ -437,6 +437,5 @@ abstract class AbstractLink implements GradebookItem {
$table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
$sql = "UPDATE $table SET locked = '".intval($locked)."' WHERE id='".$this->id."'";
Database::query($sql);
}
}
}

@ -387,12 +387,14 @@ class Category implements GradebookItem
return $id;
}
}
/**
* Update the properties of this category in the database
* @todo fix me
*/
public function save() {
$tbl_grade_categories = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
$sql = 'UPDATE '.$tbl_grade_categories." SET name = '".Database::escape_string($this->get_name())."'".', description = ';
if (isset($this->description)) {
$sql .= "'".Database::escape_string($this->get_description())."'";
@ -407,7 +409,7 @@ class Category implements GradebookItem
$sql .= 'null';
}
$sql .= ', parent_id = ';
if (isset ($this->parent)) {
if (isset($this->parent)) {
$sql .= intval($this->get_parent_id());
} else {
$sql .= 'null';
@ -427,11 +429,11 @@ class Category implements GradebookItem
Database::query($sql);
if (!empty($this->id)) {
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);
@ -461,12 +463,36 @@ class Category implements GradebookItem
}
}
}
$gradebook= new Gradebook();
$gradebook->update_skills_to_gradebook($this->id, $this->get_skills(false));
}
/**
* Update link weights see #5168
* @param type $new_weight
*/
function update_children_weight($new_weight) {
//$evals = $this->get_evaluations();
$links = $this->get_links();
$old_weight = $this->get_weight();
if (!empty($links)) {
foreach ($links as $link_item) {
if (isset($link_item)) {
$new_item_weight = $new_weight * $link_item->get_weight() / $old_weight;
$link_item->set_weight($new_item_weight);
$link_item->save();
}
}
}
}
/**
* Delete this evaluation from the database

@ -228,7 +228,7 @@ class ExerciseLink extends AbstractLink
/**
* Lazy load function to get the database table of the exercise
*/
private function get_exercise_table () {
private function get_exercise_table() {
$this->exercise_table = Database :: get_course_table(TABLE_QUIZ_TEST);
return $this->exercise_table;
}

@ -258,9 +258,21 @@ class ForumThreadLink extends AbstractLink
return 'forum';
}
function save_linked_data() {
$weight = (float)$this->get_weight();
$ref_id = $this->get_ref_id();
if (!empty($ref_id)) {
$sql = 'UPDATE '.$this->get_forum_thread_table().' SET thread_weight='.$weight.'
WHERE c_id = '.$this->course_id.' AND thread_id= '.$ref_id;
Database::query($sql);
}
}
function delete_linked_data() {
$ref_id = $this->get_ref_id();
if (!empty($ref_id)) {
if (!empty($ref_id)) {
//Cleans forum
$sql = 'UPDATE '.$this->get_forum_thread_table().' SET thread_qualify_max=0,thread_weight=0,thread_title_qualify=""
WHERE c_id = '.$this->course_id.' AND thread_id= '.$ref_id;

@ -275,6 +275,18 @@ class StudentPublicationLink extends AbstractLink
return 'studentpublication';
}
function save_linked_data() {
$weight = (float)$this->get_weight();
$ref_id = $this->get_ref_id();
if (!empty($ref_id)) {
//Cleans works
$sql = 'UPDATE '.$this->get_studpub_table().' SET weight= '.$weight.'
WHERE c_id = '.$this->course_id.' AND id ='.$ref_id;
Database::query($sql);
}
}
function delete_linked_data() {
$ref_id = $this->get_ref_id();
if (!empty($ref_id)) {
@ -284,4 +296,4 @@ class StudentPublicationLink extends AbstractLink
Database::query($sql);
}
}
}
}

@ -361,16 +361,16 @@ class DisplayGradebook
$status = CourseManager::get_user_in_course_status(api_get_user_id(), api_get_course_id());
$objcat = new Category();
$course_id = Database::get_course_by_category($selectcat);
$message_resource=$objcat->show_message_resource_delete($course_id);
$message_resource = $objcat->show_message_resource_delete($course_id);
$grade_model_id = $catobj->get_grade_model_id();
//@todo move these in a function
$sum_categories_weight_array = array();
//@todo move these in a function
$sum_categories_weight_array = array();
if (isset($catobj) && !empty($catobj)) {
$categories = Category::load(null, null, null, $catobj->get_id());
if (!empty($categories)) {
foreach($categories as $category) {
foreach ($categories as $category) {
$sum_categories_weight_array[$category->get_id()] = $category->get_weight();
}
} else {
@ -380,38 +380,38 @@ class DisplayGradebook
if (!$is_course_admin && $status<>1 && $selectcat<>0) {
$user_id = api_get_user_id();
$catcourse = Category::load($catobj->get_id());
$catcourse = Category::load($catobj->get_id());
$main_weight = $catcourse[0]->get_weight();
$scoredisplay = ScoreDisplay :: instance();
// generating the total score for a course
$allevals= $catcourse[0]->get_evaluations($user_id,true);
$alllinks= $catcourse[0]->get_links($user_id,true);
$evals_links = array_merge($allevals, $alllinks);
$item_value=0;
$item_total=0;
$item_total_value = 0;
$item_value =0;
$item_total = 0;
$item_total_value = 0;
//var_dump($sum_categories_weight_array);
for ($count=0; $count < count($evals_links); $count++) {
$item = $evals_links[$count];
$score = $item->calc_score($user_id);
$my_score_denom =($score[1]==0) ? 1 : $score[1];
$divide = ( ($score[1])==0 ) ? 1 : $score[1];
$item_value = $score[0]/$my_score_denom * $item->get_weight();
$sub_item_total = $item->get_weight();
$sub_cat_percentage = $sum_categories_weight_array[$item->get_category_id()];
/*$item_value = $item_value*$catcourse[0]->get_weight();
$sub_item_total = $item->get_weight()*$catcourse[0]->get_weight();
*/
//var_dump($item_value.' - '.$sub_item_total);
$item_total += $sub_item_total;
$item_total_value += $item_value;
$item_value = round($score[0]/$divide, 2);
//$item_value = $item_value*$item->get_weight();
$item_value =round($score[0]/$divide*$item->get_weight(),2)*$sub_cat_percentage/$main_weight;
//var_dump($score[0].' '.$divide.' '.$item->get_weight().' - '.$item_value.' '.$sub_cat_percentage);
$item_value_total +=$item_value;
}
$item_total = $main_weight;
$item_total = round($item_total);
//$item_value = number_format($item_total_value, api_get_setting('gradebook_number_decimals'));
$item_value = number_format($item_total_value, 2);
$total_score = array($item_value, $item_total);
$total_score = array($item_value_total, $item_total);
$scorecourse_display = $scoredisplay->display_score($total_score, SCORE_DIV_PERCENT);
if ((!$catobj->get_id() == '0') && (!isset ($_GET['studentoverview'])) && (!isset ($_GET['search']))) {

@ -239,6 +239,7 @@ class GradebookTable extends SortableTable {
$course_code = api_get_course_id();
$session_id = api_get_session_id();
$parent_id = $item->get_id();
$cats = Category :: load ($parent_id, null, null, null, null, null);
$allcat = $cats[0]->get_subcategories($stud_id, $course_code, $session_id);
@ -273,12 +274,18 @@ class GradebookTable extends SortableTable {
//Description
$row[] = $invisibility_span_open.$data[2].$invisibility_span_close;
//Weight
//$row[] = $invisibility_span_open . $data[3] .' / '.$category_weight.$invisibility_span_close;
$weight = $data[3]/$category_weight*$main_cat[0]->get_weight();
//Weight
//$weight = $data[3]/$category_weight*$main_cat[0]->get_weight();
/*$weight = $category_weight * $data[3] / $main_cat[0]->get_weight();
$weight = $main_cat[0]->get_weight()*$weight/$category_weight;*/
$weight = $data[3];
//$extra = " - $data[3] $category_weight -".$main_cat[0]->get_weight();
$total_weight += $weight;
$row[] = $invisibility_span_open.$weight.$invisibility_span_close;
$row[] = $invisibility_span_open.$weight.$extra.$invisibility_span_close;
if (api_is_allowed_to_edit(null, true)) {
//$weight_total_links += intval($data[3]);

@ -118,8 +118,18 @@ class LinkAddEditForm extends FormValidator
$values['weight'] = $link->get_weight();
} else {
$cat = Category :: load($parent_cat[0]->get_parent_id());
$global_weight = $cat[0]->get_weight();
$global_weight = $cat[0]->get_weight();
$values['weight'] = $link->get_weight()/$parent_cat[0]->get_weight()*$global_weight;
/*
* 33 -> 100
* x -> 25
*/
//100 33 25
//var_dump($global_weight, $link->get_weight(), $parent_cat[0]->get_weight());
$weight = $parent_cat[0]->get_weight()* $link->get_weight() / $global_weight;
//$values['weight'] = $weight;
$values['weight'] = $link->get_weight() ;
}
$defaults['weight_mask'] = $values['weight'] ;

@ -97,13 +97,13 @@ class FlatViewDataGenerator
//@todo move these in a function
$sum_categories_weight_array = array();
if (isset($this->category) && !empty($this->category)) {
$categories = Category::load(null, null, null, $this->category->get_id());
$categories = Category::load(null, null, null, $this->category->get_id());
if (!empty($categories)) {
foreach ($categories as $category) {
$sum_categories_weight_array[$category->get_id()] = $category->get_weight();
}
} else {
$sum_categories_weight_array[$this->category->get_id()] = $this->category->get_weight();
$sum_categories_weight_array[$this->category->get_id()] = $this->category->get_weight();
}
}
@ -125,7 +125,8 @@ class FlatViewDataGenerator
for ($count=0; ($count < $items_count ) && ($items_start + $count < count($this->evals_links)); $count++) {
$item = $this->evals_links[$count + $items_start];
$sub_cat_percentage = $sum_categories_weight_array[$item->get_category_id()];
$weight = round($item->get_weight()/($sub_cat_percentage)*$sub_cat_percentage/$this->category->get_weight() *100, 2);
//$weight = round($item->get_weight()/($sub_cat_percentage)*$sub_cat_percentage/$this->category->get_weight() *100, 2);
$weight = 100*$item->get_weight()/$main_weight;
$headers[] = $item->get_name().' '.$weight.' % ';
}
}
@ -317,7 +318,8 @@ class FlatViewDataGenerator
$item_total += $sub_cat->get_weight();
if ($convert_using_the_global_weight) {
$score[0] = $main_weight*$score[0]/$sub_cat->get_weight();
//$score[0] = $main_weight*$score[0]/$sub_cat->get_weight();
$score[0] = $score[0]/$main_weight*$sub_cat->get_weight();
$score[1] = $main_weight ;
}
@ -340,29 +342,32 @@ class FlatViewDataGenerator
for ($count=0; ($count < $items_count ) && ($items_start + $count < count($this->evals_links)); $count++) {
$item = $this->evals_links[$count + $items_start];
$score = $item->calc_score($user_id);
$divide = ( ($score[1])==0 ) ? 1 : $score[1];
$divide = ( ($score[1])==0 ) ? 1 : $score[1];
//sub cat weight
$sub_cat_percentage = $sum_categories_weight_array[$item->get_category_id()];
$item_value = round($score[0]/$divide,2);
$item_value = round($score[0]/$divide, 2);
//Fixing total when using one or multiple gradebooks
if ($this->category->get_parent_id() == 0 ) {
$item_value = $item_value;
if ($this->category->get_parent_id() == 0 ) {
$item_value =round($score[0]/$divide*$item->get_weight(),2);
} else {
$item_value = $item_value*$item->get_weight();
$item_value = $main_weight*$item_value/$item->get_weight();
}
} else {
$item_value = $item_value*$item->get_weight();
//var_dump($item_value.' - '.$item->get_weight());
//$item_value = $main_weight*$item_value/$item->get_weight();
//$item_value = $item_value*100/$item->get_weight();
}
$item_total += $item->get_weight();
$temp_score = $scoredisplay->display_score($score, SCORE_DIV_PERCENT, SCORE_ONLY_SCORE);
//$temp_score = $scoredisplay->display_score($score, SCORE_DIV_SIMPLE_WITH_CUSTOM);
//$temp_score = $scoredisplay->display_score($score, SCORE_DIV_PERCENT, SCORE_ONLY_SCORE);
//$temp_score = $item_value.' - '.$scoredisplay->display_score($score, SCORE_DIV_PERCENT, SCORE_ONLY_SCORE);
$temp_score = $item_value;
if (!isset($this->params['only_total_category']) || (isset($this->params['only_total_category']) && $this->params['only_total_category'] == false)) {
if (!$show_all) {
if (in_array($item->get_type() , array(LINK_EXERCISE, LINK_DROPBOX, LINK_STUDENTPUBLICATION,
LINK_LEARNPATH, LINK_FORUM_THREAD, LINK_ATTENDANCE,LINK_SURVEY))) {
LINK_LEARNPATH, LINK_FORUM_THREAD, LINK_ATTENDANCE,LINK_SURVEY))) {
if (!empty($score[0])) {
$row[] = $temp_score.' ';
} else {
@ -374,14 +379,14 @@ class FlatViewDataGenerator
} else {
$row[] = $temp_score;
}
}
$item_value_total +=$item_value;
}
$item_value_total +=$item_value;
}
$item_total = $main_weight;
}
$item_total = round($item_total);
$total_score = array($item_value_total, $item_total);
$total_score = array($item_value_total, $item_total);
if (!$show_all) {
if ($export_to_pdf) {

@ -192,8 +192,6 @@ function build_edit_icons_cat($cat, $selectcat) {
if (api_is_allowed_to_edit(null, true)) {
//Locking button
if (api_get_setting('gradebook_locking_enabled') == 'true') {

Loading…
Cancel
Save