Browse Source

Now we accept float values in the gradebook weight see BT#3004 (partial)

Julio Montoya 13 years ago
parent
commit
da7a59d082

+ 32 - 1
main/gradebook/gradebook_add_cat.php

@@ -98,6 +98,22 @@ if ($_in_course) {
 
 $catadd->set_course_code(api_get_course_id());
 
+$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');
+
+
+
+
 $form = new CatForm(CatForm :: TYPE_ADD, $catadd, 'add_cat_form', null, api_get_self() . '?selectcat='.$get_select_cat);
 
 if ($form->validate()) {
@@ -141,5 +157,20 @@ if ( !$_in_course ) {
 }
 $interbreadcrumb[]= array (	'url' =>'index.php','name' => get_lang('ToolGradebook'));
 Display :: display_header(get_lang('NewCategory'));
-$form->display();
+
+$display_form = true;
+
+if (!empty($grading_contents)) {
+    $count_items = count($grading_contents['items']);
+    $cats  = Category :: load(null, null, $course_code, null, null, $session_id, false); //already init
+    $cats_count = count($cats) - 1 ;         
+        
+    if ($cats_count >= $count_items) {
+        Display::display_warning_message(get_lang('CheckYourGradingModelValues'));
+        $display_form = false;
+    }
+}
+if ($display_form)
+    $form->display();
+
 Display :: display_footer();

+ 3 - 2
main/gradebook/gradebook_edit_link.php

@@ -18,11 +18,11 @@ api_block_anonymous_users();
 block_students();
 $tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
 //selected name of database
-$course_id 		= get_course_id_by_link_id(Security::remove_XSS($_GET['editlink']));
+$course_id 		= get_course_id_by_link_id($_GET['editlink']);
 $tbl_forum_thread 		= Database :: get_course_table(TABLE_FORUM_THREAD);
 $tbl_work 				= Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
 $tbl_attendance 		= Database :: get_course_table(TABLE_ATTENDANCE);
-$linkarray 				= LinkFactory :: load(Security::remove_XSS($_GET['editlink']));
+$linkarray 				= LinkFactory :: load($_GET['editlink']);
 $link = $linkarray[0];
 $linkcat  = isset($_GET['selectcat']) ? Security::remove_XSS($_GET['selectcat']):'';
 $linkedit = isset($_GET['editlink']) ? Security::remove_XSS($_GET['editlink']):'';
@@ -50,6 +50,7 @@ if ($form->validate()) {
 	$sql_t = 'UPDATE '.$tbl_forum_thread.' SET thread_weight='.$values['weight'].' 
 			  WHERE c_id = '.$course_id.' AND thread_id=(SELECT ref_id FROM '.$tbl_grade_links.' WHERE id='.intval($_GET['editlink']).' and type=5 AND c_id = '.$course_id.'  ) ';
 	Database::query($sql_t);
+    
 	//Update weight into student publication(work)
 	$sql_t = 'UPDATE '.$tbl_work.' SET weight='.$values['weight'].' 
 			  WHERE c_id = '.$course_id.' AND id = (SELECT ref_id FROM '.$tbl_grade_links.' WHERE c_id = '.$course_id.' AND id='.intval($_GET['editlink'] ).' AND  type=3 )';

+ 11 - 12
main/gradebook/lib/be/abstractlink.class.php

@@ -218,7 +218,7 @@ abstract class AbstractLink implements GradebookItem {
 					.','.intval($this->get_user_id())
 					.",'".Database::escape_string($this->get_course_code())."'"
 					.','.intval($this->get_category_id())
-					.','.intval($this->get_weight())
+					.",'".Database::escape_string($this->get_weight())."'"
 					.','.intval($this->is_visible());
 				$sql .= ','.'"'.$date_current=api_get_local_time().'"';
 				$sql .= ")";				
@@ -237,17 +237,18 @@ abstract class AbstractLink implements GradebookItem {
 		$this->save_linked_data();
 
 		$tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
-		$sql = 'UPDATE '.$tbl_grade_links
-			.' SET type = '.intval($this->get_type())
-				.', ref_id = '.intval($this->get_ref_id())
-				.', user_id = '.intval($this->get_user_id())
-				.", course_code = '".Database::escape_string($this->get_course_code())."'"
-				.', category_id = '.intval($this->get_category_id());
-		$sql .= ', weight = '.intval($this->get_weight())
-				.', visible = '.intval($this->is_visible())
-				.' WHERE id = '.intval($this->id);
+		$sql = "UPDATE $tbl_grade_links SET 
+                    type        = ".intval($this->get_type()).", 
+				    ref_id      = ".intval($this->get_ref_id()).", 
+				    user_id     = ".intval($this->get_user_id()).", 
+				    course_code = '".Database::escape_string($this->get_course_code())."', 
+				    category_id = ".intval($this->get_category_id()).", 
+		            weight      = '".Database::escape_string($this->get_weight())."', 
+				    visible     = ".intval($this->is_visible())."
+			     WHERE id = ".intval($this->id);
 	
 		AbstractLink::add_link_log($this->id);
+        
 		Database::query($sql);
 	}
 
@@ -275,9 +276,7 @@ abstract class AbstractLink implements GradebookItem {
 	 * Delete this link from the database
 	 */
 	public function delete() {
-
 		$this->delete_linked_data();
-
 		$tbl_grade_links = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
 		$sql = 'DELETE FROM '.$tbl_grade_links.' WHERE id = '.intval($this->id);
 		Database::query($sql);

+ 17 - 11
main/gradebook/lib/fe/catform.class.php

@@ -133,8 +133,9 @@ class CatForm extends FormValidator {
    	}
 
    	private function build_basic_form() {
+   	    
 		$this->addElement('hidden', 'zero', 0);
-		$this->add_textfield('name', get_lang('CategoryName'), true,array('size'=>'54','maxlength'=>'50'));
+		$this->add_textfield('name', get_lang('CategoryName'), true, array('size'=>'54','maxlength'=>'50'));
         
 		$this->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
 		
@@ -142,6 +143,7 @@ class CatForm extends FormValidator {
 			//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 = '';
@@ -163,9 +165,10 @@ class CatForm extends FormValidator {
 			///direct access to one evaluation
 			$cats  = Category :: load(null, null, $course_code, null, null, $session_id, false); //already init			
 			$count = count($cats) - 1;			
-			$value = intval($grading_contents['items'][$count]['percentage']);
-            if ($value == 0) {
-                //Display::display_warning_message(get_lang('GradingModelBlocks'));
+			$value = round((float)$grading_contents['items'][$count]['percentage'], 2);            
+            if ($value == 0) {                
+//                Display::display_warning_message(get_lang('GradingModelBlocks'));
+                //$this->freeze();
             }
 			
 			$this->add_textfield('weight', get_lang('TotalWeight'), true, array('value'=> $value,'size'=>'4','maxlength'=>'5'));
@@ -180,7 +183,7 @@ class CatForm extends FormValidator {
             //the magic should be here
             
             $skills = $this->category_object->get_skills();    
-            $this->addElement('select', 'skills', array(get_lang('SkillsAchievedWhenAchievingThisGradebook')), null, array('id'=>'skills', 'multiple'=>'multiple'));
+            $this->addElement('select', 'skills', array(get_lang('Skills'), get_lang('SkillsAchievedWhenAchievingThisGradebook')), null, array('id'=>'skills', 'multiple'=>'multiple'));
             $content = '';
             if (!empty($skills)) {
                 foreach($skills as $skill) {                    
@@ -192,29 +195,32 @@ class CatForm extends FormValidator {
             );
         }
         
-		if (isset($this->category_object) && $this->category_object->get_parent_id() == 0) {						
+		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('certif_min_score',get_lang('NoDecimals'),'nopunctuation');
 			$this->addRule(array('certif_min_score', 'zero'), get_lang('NegativeValue'), 'compare', '>=');
+		} else {
+		    $this->addElement('checkbox', 'visible', null, get_lang('Visible'));
 		}		
 		
    		$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', null, get_lang('Visible'));
+        
+		
+        
 		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('weight', get_lang('OnlyNumbers'), 'numeric');
+			//$this->addRule('weight',get_lang('NoDecimals'),'nopunctuation');
 			$this->addRule(array ('weight', 'zero'), get_lang('NegativeValue'), 'compare', '>=');
 		}
 		

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

@@ -450,7 +450,7 @@ class DisplayGradebook
                 $item_total_value   += $item_value;
 				//$row[] = $scoredisplay->display_score($score,SCORE_DIV_PERCENT);				
 			}
-            
+            $item_total = round($item_total);
 			$item_value = number_format($item_total_value, 2);
 			$total_score = array($item_value, $item_total);
 		

+ 7 - 5
main/gradebook/lib/fe/gradebooktable.class.php

@@ -47,7 +47,7 @@ class GradebookTable extends SortableTable {
 		$this->set_header($column++, get_lang('Name'), false);
 
 		if (api_is_allowed_to_edit(null, true)) {
-			$this->set_header($column++, get_lang('Weight'),'','width="50px"');
+			$this->set_header($column++, get_lang('Weight'),'','width="80px"');
 		} else {
 			$this->set_header($column++, get_lang('Weight'), false);
 			$this->set_header($column++, get_lang('Evaluation'), false);
@@ -173,7 +173,7 @@ class GradebookTable extends SortableTable {
             $category_weight = $item->get_weight();
             	
 			if (api_is_allowed_to_edit(null, true)) {
-				$weight_total_links += intval($data[3]);
+				$weight_total_links += $data[3];
 			} else {
 				$cattotal   = Category :: load($_GET['selectcat']);
                 $scoretotal = $cattotal[0]->calc_score(api_get_user_id());                    
@@ -251,7 +251,7 @@ class GradebookTable extends SortableTable {
 						$cattotal   = Category :: load($_GET['selectcat']);
 		                $scoretotal = $cattotal[0]->calc_score(api_get_user_id());                    
 		                $item_value = $scoretotal[0];
-		                $item_value = number_format($item_value, 2, '.', ' ');					   				  			   	
+		                $item_value = number_format($item_value, 2, '.', ' ');                        					   				  			   	
 					}
 					
 					//Date
@@ -288,16 +288,18 @@ class GradebookTable extends SortableTable {
 			if (isset($_GET['selectcat']) && $_GET['selectcat'] > 0 && $view <> 'presence') {
 				$id_cat = intval($_GET['selectcat']);
 				$category = Category :: load($id_cat);
+				//$weight_category = intval($this->build_weight($category[0]));
 				$weight_category = intval($this->build_weight($category[0]));
 				$course_code = $this->build_course_code($category[0]);
-
+                $weight_total_links  = round($weight_total_links);
+                //var_dump($weight_total_links);;
 				if ($weight_total_links > $weight_category) {
 				    
 					$warning_message = get_lang('TotalWeightMustNotBeMoreThan').'&nbsp;'.$weight_category;
 					Display::display_warning_message($warning_message,false);
 				}
 				
-				if ($weight_total_links < $weight_category) {
+				if ($weight_total_links < $weight_category ||$weight_total_links > $weight_category) {
 					$warning_message = sprintf(get_lang('TotalWeightMustBeX'), $weight_category);
 					Display::display_warning_message($warning_message,false);
 				}

+ 1 - 1
main/gradebook/lib/fe/linkaddeditform.class.php

@@ -66,7 +66,7 @@ class LinkAddEditForm extends FormValidator
 				}
 			}
 		} else {
-			$this->addElement('static','label',get_lang('Name'), $link->get_name().' ['.$link->get_type_name().']');
+			$this->addElement('static','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'));

+ 3 - 3
main/install/db_main.sql

@@ -854,7 +854,7 @@ VALUES
 ('enable_help_link', NULL, 'radio', 'Platform', 'true', 'EnableHelpLinkTitle', 'EnableHelpLinkTitle', NULL, NULL, 0),
 ('allow_teacher_change_gradebook_grading_model', NULL, 'radio', 'Gradebook', 'false', 'AllowTeacherChangeGradebookGradingModelTitle', 'AllowTeacherChangeGradebookGradingModelComment', NULL, NULL, 1),
 ('grading_model', 'grading_model', 'custom', 'Gradebook', 'false', 'GradingModelTitle', 'GradingModelComment', NULL, NULL, 1),
-('chamilo_database_version',NULL,'textfield',NULL, '1.9.0.16233','DokeosDatabaseVersion','', NULL, NULL, 0);
+('chamilo_database_version',NULL,'textfield',NULL, '1.9.0.16241','DokeosDatabaseVersion','', NULL, NULL, 0);
 
 /*
 ('use_custom_pages',NULL,'radio','Platform','false','UseCustomPages','useCustomPagesComment','platform',NULL,0),
@@ -1318,7 +1318,7 @@ CREATE TABLE gradebook_category (
   user_id int NOT NULL,
   course_code varchar(40) default NULL,
   parent_id int default NULL,
-  weight smallint NOT NULL,
+  weight float NOT NULL,
   visible tinyint NOT NULL,
   certif_min_score int DEFAULT NULL,
   session_id int DEFAULT NULL,
@@ -1350,7 +1350,7 @@ CREATE TABLE gradebook_link (
   course_code varchar(40) NOT NULL,
   category_id int NOT NULL,
   created_at DATETIME NOT NULL default '0000-00-00 00:00:00',
-  weight smallint NOT NULL,
+  weight float NOT NULL,
   visible tinyint NOT NULL,
   PRIMARY KEY  (id)
 );

+ 6 - 4
main/install/migrate-db-1.8.8-1.9.0-pre.sql

@@ -13,7 +13,6 @@
 -- This first part is for the main database
 
 -- xxMAINxx
-UPDATE settings_current SET selected_value = '1.9.0.16233' WHERE variable = 'chamilo_database_version';
 
 INSERT INTO settings_current (variable, subkey, type, category, selected_value, title, comment, scope, subkeytext, access_url_changeable) VALUES ('filter_terms', NULL, 'textarea', 'Security', '', 'FilterTermsTitle', 'FilterTermsComment', NULL, NULL, 0);
 
@@ -115,6 +114,12 @@ INSERT INTO settings_current (variable, subkey, type, category, selected_value,
 INSERT INTO settings_options (variable, value, display_text) VALUES ('enable_help_link', 'true', 'Yes');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('enable_help_link', 'false', 'No');
 
+ALTER TABLE gradebook_category MODIFY COLUMN weight FLOAT NOT NULL;
+ALTER TABLE gradebook_link MODIFY COLUMN weight FLOAT  NOT NULL;
+
+-- Do not move this query
+UPDATE settings_current SET selected_value = '1.9.0.16241' WHERE variable = 'chamilo_database_version';
+
 
 
 -- xxSTATSxx
@@ -134,9 +139,6 @@ INSERT INTO settings_current (variable, subkey, type, category, selected_value,
 INSERT INTO settings_options (variable, value, display_text) VALUES ('allow_hr_skills_management', 'true', 'Yes');
 INSERT INTO settings_options (variable, value, display_text) VALUES ('allow_hr_skills_management', 'false', 'No');
 
-
-
-
 -- xxUSERxx
 
 -- xxCOURSExx