Browse Source

More fixes in gradebook, now when dealing with certificates see BT#2848

Julio Montoya 13 years ago
parent
commit
460e110dce

+ 6 - 5
main/gradebook/gradebook_edit_cat.php

@@ -17,8 +17,8 @@ require_once 'lib/fe/catform.class.php';
 api_block_anonymous_users();
 block_students();
 
-$edit_cat= isset($_GET['editcat']) ? $_GET['editcat'] : '';
-$catedit = Category :: load($edit_cat);
+$edit_cat = isset($_REQUEST['editcat']) ? $_REQUEST['editcat'] : '';
+$catedit  = Category :: load($edit_cat);
 $form = new CatForm(CatForm :: TYPE_EDIT, $catedit[0], 'edit_cat_form');
 if ($form->validate()) {
 	$values = $form->exportValues();
@@ -34,7 +34,9 @@ if ($form->validate()) {
 	$cat->set_user_id($values['hid_user_id']);
 	$cat->set_parent_id($values['hid_parent_id']);
 	$cat->set_weight($values['weight']);
-	$cat->set_certificate_min_score($values['certif_min_score']);
+	if ($values['hid_parent_id'] == 0 ) {
+		$cat->set_certificate_min_score($values['certif_min_score']);
+	}
 	/*if (empty ($values['visible'])) {
 		$visible = 0;
 	} else {
@@ -49,6 +51,5 @@ $selectcat = isset($_GET['selectcat']) ? Security::remove_XSS($_GET['selectcat']
 $interbreadcrumb[] = array ('url' => Security::remove_XSS($_SESSION['gradebook_dest']).'?selectcat='.$selectcat,'name' => get_lang('Gradebook'));
 $this_section = SECTION_COURSES;
 Display :: display_header(get_lang('EditCategory'));
-echo '<div class="actions-message">'.get_lang('EditCategory').'</div>';
 $form->display();
-Display :: display_footer();
+Display :: display_footer();

+ 8 - 5
main/gradebook/index.php

@@ -696,9 +696,8 @@ if ($category != '0') {
 		//student
 		if (!api_is_allowed_to_edit()) {
 
-			// generating the total score for a course
-			
-			$cats_course     = Category :: load ($category_id, null, null, null, null, null, false);
+			// generating the total score for a course			
+			$cats_course     = Category :: load ($category_id, null, null, null, null, null, false);			
 			$alleval_course  = $cats_course[0]->get_evaluations($stud_id,true);
 			$alllink_course  = $cats_course[0]->get_links($stud_id,true);
 			
@@ -714,6 +713,10 @@ if ($category != '0') {
 				$item_value+=$score[0]/$score_denom*$item->get_weight();
 				$item_total+=$item->get_weight();
 			}			
+			if (!empty($allcat)) {
+				$count_categories = count($allcat);
+				$item_value = $item_value/$count_categories; 				
+			}
 			$item_value = number_format($item_value, 2, '.', ' ');
 			
 			$cattotal = Category :: load($category_id);
@@ -723,13 +726,13 @@ if ($category != '0') {
 			$my_score_in_gradebook =  round($scoretotal[0],2);
 			
 			//Show certificate
-			$certificate_min_score = $cats[0]->get_certificate_min_score();
+			$certificate_min_score = $cats[0]->get_certificate_min_score();			
 			$scoredisplay = ScoreDisplay :: instance();
 			$scoretotal_display = $scoredisplay->display_score($scoretotal,SCORE_DIV_PERCENT); //a student always sees only the teacher's repartition
 			
 			if (isset($certificate_min_score) && $item_value >= $certificate_min_score) {
 				$my_certificate = get_certificate_by_user_id($cats[0]->get_id(), api_get_user_id());
-
+								
 				if (empty($my_certificate)) {
 					register_user_info_about_certificate($category_id, api_get_user_id(), $my_score_in_gradebook, api_get_utc_datetime());
 					$my_certificate = get_certificate_by_user_id($cats[0]->get_id(), api_get_user_id());

+ 1 - 2
main/gradebook/lib/be/category.class.php

@@ -310,7 +310,7 @@ class Category implements GradebookItem
 			$sql .= 'null';
 		}
 		$sql .= ', certif_min_score = ';
-		if (isset ($this->certificate_min_score) && strcmp($this->certificate_min_score,'')!==0) {
+		if (isset($this->certificate_min_score) && !empty($this->certificate_min_score)) {
 			$sql .= Database::escape_string($this->get_certificate_min_score());
 		} else {
 			$sql .= 'null';
@@ -318,7 +318,6 @@ class Category implements GradebookItem
 		$sql .= ', weight = '.Database::escape_string($this->get_weight())
 			.', visible = '.intval($this->is_visible())
 			.' WHERE id = '.intval($this->id);
-
 		Database::query($sql);
 	}
 

+ 28 - 14
main/gradebook/lib/fe/catform.class.php

@@ -116,13 +116,13 @@ class CatForm extends FormValidator {
 	 */
    	protected function build_editing_form() {
    		$this->setDefaults(array(
-			'name' => $this->category_object->get_name(),
-    		'description' => $this->category_object->get_description(),
-    		'hid_user_id' => $this->category_object->get_user_id(),
-    		'hid_parent_id' => $this->category_object->get_parent_id(),
-   	 		'weight' => $this->category_object->get_weight(),
-   	 		'visible' => $this->category_object->is_visible(),
-   	 		'certif_min_score' => $this->category_object->get_certificate_min_score(),
+			'name' 				=> $this->category_object->get_name(),
+    		'description' 		=> $this->category_object->get_description(),
+    		'hid_user_id' 		=> $this->category_object->get_user_id(),
+    		'hid_parent_id' 	=> $this->category_object->get_parent_id(),
+   	 		'weight' 			=> $this->category_object->get_weight(),
+   	 		'visible' 			=> $this->category_object->is_visible(),
+   	 		'certif_min_score'  => $this->category_object->get_certificate_min_score(),
     		));
    		$this->addElement('hidden','hid_id', $this->category_object->get_id());
    		$this->addElement('hidden','course_code', $this->category_object->get_course_code());
@@ -133,6 +133,11 @@ class CatForm extends FormValidator {
 		$this->addElement('hidden', 'zero', 0);
 		$this->add_textfield('name', get_lang('CategoryName'), true,array('size'=>'54','maxlength'=>'50'));
 		$this->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
+		
+		if (isset($this->category_object) && $this->category_object->get_parent_id() == 0) {
+			//we can't change the root category
+			$this->freeze('name');
+		}
 		$models = api_get_settings_options('grading_model');
 		$course_grading_model_id = api_get_course_setting('course_grading_model');
 		$grading_model = '';
@@ -167,23 +172,32 @@ class CatForm extends FormValidator {
 		
 		$this->addElement('static', null, null, '<i>'.get_lang('TotalSumOfWeights').'</i>');
 		
-		$this->add_textfield('certif_min_score', get_lang('CertificateMinScore'),false,array('size'=>'4','maxlength'=>'5'));
-		$this->addRule('certif_min_score', get_lang('ThisFieldIsRequired'), 'required');
-		
+		if (isset($this->category_object) && $this->category_object->get_parent_id() == 0) {						
+			$this->add_textfield('certif_min_score', get_lang('CertificateMinScore'),false,array('size'=>'4','maxlength'=>'5'));
+			$this->addRule('certif_min_score', get_lang('ThisFieldIsRequired'), 'required');
+			$this->addRule('certif_min_score',get_lang('OnlyNumbers'),'numeric');
+			$this->addRule('certif_min_score',get_lang('NoDecimals'),'nopunctuation');
+			$this->addRule(array('certif_min_score', 'zero'), get_lang('NegativeValue'), 'compare', '>=');
+		}		
 		
    		$this->addElement('hidden','hid_user_id');
    		$this->addElement('hidden','hid_parent_id');
 		$this->addElement('textarea', 'description', get_lang('Description'),array('rows'=>'3','cols' => '34'));
 		$this->addElement('checkbox', 'visible',get_lang('Visible'));
-		$this->addElement('style_submit_button', null, get_lang('EditCategory'), 'class="save"');
+		if ($this->form_type == self :: TYPE_ADD) {
+			$this->addElement('style_submit_button', null, get_lang('AddCategory'), 'class="save"');
+		} else {
+			
+			$this->addElement('hidden','editcat', intval($_GET['editcat']));
+			$this->addElement('style_submit_button', null, get_lang('EditCategory'), 'class="save"');
+		}
+		
 		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', '>=');
 		}
-		$this->addRule('certif_min_score',get_lang('OnlyNumbers'),'numeric');
-		$this->addRule('certif_min_score',get_lang('NoDecimals'),'nopunctuation');
-		$this->addRule(array ('certif_min_score', 'zero'), get_lang('NegativeValue'), 'compare', '>=');
+		
    	}
 	/**
 	 * This function builds an 'select course' form in the add category process,

+ 2 - 1
main/gradebook/lib/fe/displaygradebook.php

@@ -365,6 +365,7 @@ class DisplayGradebook
 		}
 		$header .= '</div>';
 		echo $header;		
+		
 		/*
 		if (api_is_allowed_to_edit(null, true)) {
 			$weight = ((intval($catobj->get_weight())>0) ? $catobj->get_weight() : 0);
@@ -545,7 +546,7 @@ class DisplayGradebook
 			        
 					//Right icons
 					
-            		$modify_icons  = '<a href="gradebook_edit_cat.php?editcat=' . $catobj->get_id() . ' &amp;cidReq='.$catobj->get_course_code().'">'.Display::return_icon('edit.png', get_lang('Edit'),'','32').'</a>';
+            		$modify_icons  = '<a href="gradebook_edit_cat.php?editcat='.$catobj->get_id().'&amp;cidReq='.$catobj->get_course_code().'">'.Display::return_icon('edit.png', get_lang('Edit'),'','32').'</a>';
             		$modify_icons .= '<a href="../document/document.php?curdirpath=/certificates&'.$my_api_cidreq.'&origin=gradebook&selectcat=' . $catobj->get_id() . '">'.
             							Display::return_icon('certificate.png', get_lang('AttachCertificate'),'','32').'</a>';
             		

+ 26 - 23
main/gradebook/lib/flatview_data_generator.class.php

@@ -64,7 +64,7 @@ class FlatViewDataGenerator
 		
 		$count_categories = 1;
 		
-		if (isset($this->category)) {
+		if (isset($this->category) && !empty($this->category)) {
 			$categories = Category::load(null, null, null, $this->category->get_id());				
 			if (!empty($categories)) {
 				$count_categories = count($categories) ;
@@ -76,16 +76,16 @@ class FlatViewDataGenerator
 			$item = $this->evals_links [$count + $items_start];
 			
 			//$headers[] = $item->get_name().' <br /> '.get_lang('Max').' '.$this->get_max_result_by_link($count + $items_start).' ';
-			$weight = round($item->get_weight()/($count_categories*100), 2);
-			$headers[] = $item->get_name().' <br />'.$weight.' ';
+			$weight = round($item->get_weight()/($count_categories*100), 2)*100;
+			$headers[] = $item->get_name().' <br />'.$weight.'% ';
 			if ($show_detail) {
-				$headers[] = $item->get_name().' ('.get_lang('Detail').')';
+				//$headers[] = $item->get_name().' ('.get_lang('Detail').')';
 			}
 		}
 
 		$headers[] = get_lang('GradebookQualificationTotal');
 		if ($show_detail) {
-			$headers[] = get_lang('GradebookQualificationTotal').' ('.get_lang('Detail').')';
+			//$headers[] = get_lang('GradebookQualificationTotal').' ('.get_lang('Detail').')';
 		}
 		return $headers;
 	}
@@ -140,6 +140,7 @@ class FlatViewDataGenerator
 	public function get_data ($users_sorting = 0, $users_start = 0, $users_count = null,
 							  $items_start = 0, $items_count = null,
 							  $ignore_score_color = false, $show_all = false) {
+		
 		// do some checks on users/items counts, redefine if invalid values
 		if (!isset($users_count)) {
 			$users_count = count ($this->users) - $users_start;
@@ -184,10 +185,8 @@ class FlatViewDataGenerator
 		
 		$count_categories = 1;
 		
-		if (isset($this->category)) {
-			
-			$categories = Category::load(null, null, null, $this->category->get_id());
-			
+		if (isset($this->category) && !empty($this->category)) {			
+			$categories = Category::load(null, null, null, $this->category->get_id());			
 			if (!empty($categories)) {				
 				$count_categories = count($categories);				
 			}			
@@ -203,35 +202,39 @@ class FlatViewDataGenerator
 			$item_total=0;
 
 			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[0]);
-				$divide=( ($score[1])==0 ) ? 1 : $score[1];
-				$item_value+=round($score[0]/$divide*$item->get_weight(),2);
-				$item_total+=$item->get_weight();
+				$item  			= $this->evals_links [$count + $items_start];
+				$score 			= $item->calc_score($user[0]);
+				$divide			= ( ($score[1])==0 ) ? 1 : $score[1];
+				
+				$item_value		+= round($score[0]/$divide*$item->get_weight(),2);				
+				$item_total		+= $item->get_weight();
+				
 				if (!$show_all) {
 					//$row[] = $scoredisplay->display_score($score,SCORE_DIV_PERCENT);
-					if (in_array($item->get_type() , array(LINK_EXERCISE, LINK_DROPBOX, LINK_STUDENTPUBLICATION, LINK_LEARNPATH,LINK_FORUM_THREAD,  LINK_ATTENDANCE,LINK_SURVEY))) {																		
+					if (in_array($item->get_type() , array(LINK_EXERCISE, LINK_DROPBOX, LINK_STUDENTPUBLICATION, LINK_LEARNPATH, LINK_FORUM_THREAD,  LINK_ATTENDANCE,LINK_SURVEY))) {																		
 						$row[] = $score[0];
                         //$row[] = $scoredisplay->display_score($score,SCORE_DIV_PERCENT, SCORE_ONLY_SCORE);	
 					} else {
 						//$row[] = $scoredisplay->display_score($score,SCORE_DIV_PERCENT);
-                        $row[] = $score[0];                        
+                        $row[] = $score[0];                      
 					}					
 				} else {
-					$row[] = $scoredisplay->display_score($score, SCORE_DECIMAL);
-					$row[] = $scoredisplay->display_score($score, SCORE_DIV_PERCENT);
+					//$row[] = $scoredisplay->display_score($score, SCORE_DECIMAL);
+					$row[] = $score[0];
+					//$row[] = $scoredisplay->display_score($score, SCORE_DIV_PERCENT);
 				}
-			}
+			}		
 			
 			$item_value = round($item_value / $count_categories, 2);
 			$item_total = round($item_total / $count_categories, 2);
 			
 			$total_score = array($item_value, $item_total);
-			if (!$show_all) {
-				$row[] = $scoredisplay->display_score($total_score, SCORE_DIV_PERCENT_WITH_CUSTOM);
+			
+			if (!$show_all) {				
+				$row[] = $scoredisplay->display_score($total_score);
 			} else {
-				$row[] = $scoredisplay->display_score($total_score, SCORE_DECIMAL);
-				$row[] = $scoredisplay->display_score($total_score, SCORE_DIV_PERCENT);
+				$row[] = $scoredisplay->display_score($total_score, SCORE_DIV_PERCENT_WITH_CUSTOM);
+				//$row[] = $scoredisplay->display_score($total_score, SCORE_DIV_PERCENT);
 			}
 			unset($score);
 			$data[] = $row;

+ 1 - 1
main/gradebook/lib/gradebook_functions.inc.php

@@ -201,7 +201,7 @@ function build_edit_icons_cat($cat, $selectcat) {
 	if ($show_message===false) {
 		$visibility_icon= ($cat->is_visible() == 0) ? 'invisible' : 'visible';
 		$visibility_command= ($cat->is_visible() == 0) ? 'set_visible' : 'set_invisible';
-		$modify_icons= '<a href="gradebook_edit_cat.php?editcat=' . $cat->get_id() . ' &amp;cidReq='.$cat->get_course_code().'">'.Display::return_icon('edit.png', get_lang('Modify'),'','22').'</a>';
+		$modify_icons= '<a href="gradebook_edit_cat.php?editcat='.$cat->get_id().'&amp;cidReq='.$cat->get_course_code().'">'.Display::return_icon('edit.png', get_lang('Modify'),'','22').'</a>';
 		
 		$modify_icons .= '&nbsp;<a href="' . api_get_self() . '?visiblecat=' . $cat->get_id() . '&amp;' . $visibility_command . '=&amp;selectcat=' . $selectcat . ' ">'.Display::return_icon($visibility_icon.'.png', get_lang('Visible'),'','22').'</a>';