Selaa lähdekoodia

Now admin can set a common ranking system - file changes see BT#4080

Julio Montoya 13 vuotta sitten
vanhempi
commit
3f247ac867

+ 10 - 1
main/admin/settings.lib.php

@@ -1224,7 +1224,16 @@ function generate_settings_form($settings, $settings_by_access_list) {
                 $form->addElement('select', $row['variable'], array(get_lang($row['title']), get_lang($row['comment'])), call_user_func('select_'.$row['variable']), $hideme);
                 $default_values[$row['variable']] = $row['selected_value'];
                 break;
-            case 'custom_gradebook':
+            case 'gradebook_ranking':
+                $value = explode('::', $row['selected_value']);
+                
+                $form->addElement('text', 'gradebook_display['.$row['variable'].'][text]',  array(get_lang($row['title']), get_lang($row['comment'])), array('class' => 'span1', 'value' => $value[0]), $hideme);
+                $form->addElement('text', 'gradebook_display['.$row['variable'].'][score]', array(get_lang($row['title']), get_lang($row['comment'])), array('class' => 'span3','value' => $value[1]), $hideme);
+                
+                $renderer = $form -> defaultRenderer();
+                $renderer->setElementTemplate(' {label}<div class="controls"> {element} %= ', 'gradebook_display['.$row['variable'].'][text]');
+                $renderer->setElementTemplate(' {element}</div><br />', 'gradebook_display['.$row['variable'].'][score]');                
+                break;
             case 'custom':
             	/*$values = api_get_settings_options($row['variable']);
             	

+ 12 - 3
main/admin/settings.php

@@ -127,6 +127,7 @@ if (!empty($_GET['category']) && !in_array($_GET['category'], array('Plugins', '
     
     if ($form->validate()) {       
         $values = $form->exportValues();         
+        
         $pdf_export_watermark_path = $_FILES['pdf_export_watermark_path'];
          
         if (isset($pdf_export_watermark_path) && !empty($pdf_export_watermark_path['name'])) {       
@@ -178,12 +179,20 @@ if (!empty($_GET['category']) && !in_array($_GET['category'], array('Plugins', '
                
         foreach ($values as $key => $value) {
             if (in_array($key, $settings_to_avoid)) { continue; }
-                      	
+                                	                                         
+            //Gradebook fix
+            if ($key == 'gradebook_display') {
+                foreach ($value as $new_key => $item) {                    
+                    $final_value = $item['text'].'::'.$item['score'];
+                    $result = api_set_setting($new_key, $final_value, 'ranking', null, $_configuration['access_url']);	
+                } 
+            }
+            //
             // Treat gradebook values in separate function.
             //if (strpos($key, 'gradebook_score_display_custom_values') === false) {
                 if (!is_array($value)) {
-                    $old_value = api_get_setting($key);                    
-                    switch ($key) {                    	
+                    $old_value = api_get_setting($key);                                        
+                    switch ($key) {                            
                     	case 'header_extra_content':
                     		file_put_contents(api_get_path(SYS_PATH).api_get_home_path().'/header_extra_content.txt', $value);                    		
                     		$value = api_get_home_path().'/header_extra_content.txt';

+ 18 - 26
main/gradebook/gradebook_scoring_system.php

@@ -14,13 +14,17 @@ require_once 'lib/be.inc.php';
 require_once 'lib/gradebook_functions.inc.php';
 require_once 'lib/fe/scoredisplayform.class.php';
 require_once 'lib/scoredisplay.class.php';
+
 api_block_anonymous_users();
 //api_protect_admin_script();
 
+if (api_get_setting('teachers_can_change_score_settings') != 'true') {
+    api_not_allowed();
+}
+
 $htmlHeadXtra[]= '
-  <script language="JavaScript">
-  function plusItem(item)
-  {
+  <script>
+  function plusItem(item) {
 		document.getElementById(item).style.display = "inline";
     	document.getElementById("plus-"+item).style.display = "none";
    	 	document.getElementById("min-"+(item-1)).style.display = "none";
@@ -30,10 +34,8 @@ $htmlHeadXtra[]= '
 	 	document.getElementById("txta-"+(item-1)).value = "";
   }
 
-  function minItem(item)
-   {
-    if (item != 1)
-	{
+  function minItem(item) {
+    if (item != 1) {
      document.getElementById(item).style.display = "none";
 	 document.getElementById("txta-"+item).value = "";
 	 document.getElementById("txtb-"+item).value = "";
@@ -42,12 +44,11 @@ $htmlHeadXtra[]= '
 	 document.getElementById("txta-"+(item-1)).value = "100";
 
 	}
-	if (item = 1)
-	{
+	if (item = 1) {
 		document.getElementById("min-"+(item)).style.display = "none";
 	}
-  }
- </script>';
+    }
+</script>';
 
 $interbreadcrumb[] = array ('url' => $_SESSION['gradebook_dest'].'?selectcat=1', 'name' => get_lang('ToolGradebook'));
 
@@ -63,8 +64,8 @@ if ($scoreform->validate()) {
 	$value_export=isset($value_export) ? $scoreform->exportValues(): '';
 	$values= $value_export;
 
-        // create new array of custom display settings
-        // this loop also checks if all score ranges are unique
+    // create new array of custom display settings
+    // this loop also checks if all score ranges are unique
 
 	$scoringdisplay= array ();
 	$ranges_ok = true;
@@ -80,7 +81,7 @@ if ($scoreform->validate()) {
                     $ranges_ok = false;
                 }
             }
-        $scoringdisplay[]= $setting;
+            $scoringdisplay[]= $setting;
         }
     }
 
@@ -89,20 +90,11 @@ if ($scoreform->validate()) {
 		exit;
 	}
 
-	// update color settings
-	$val_enablescorecolor=isset($values['enablescorecolor']) ? $values['enablescorecolor'] : null;
-	$displayscore->set_coloring_enabled(($val_enablescorecolor == '1') ? true : false);
 	$scorecolpercent = 0;
-        if ($displayscore->is_coloring_enabled()) {
-		//$displayscore->set_color_split_value($values['scorecolpercent']);
-                $scorecolpercent = $values['scorecolpercent'];
+    if ($displayscore->is_coloring_enabled()) {		
+        $scorecolpercent = $values['scorecolpercent'];
 	}
-	// update custom display settings
-	$val_enablescore=isset($values['enablescore']) ? $values['enablescore'] : null;
-	$val_includeupperlimit=isset($values['includeupperlimit']) ? $values['includeupperlimit'] : null;
-
-	$displayscore->set_custom(($val_enablescore == '1') ? true : false);
-	$displayscore->set_upperlimit_included(($val_includeupperlimit == '1') ? true : false);
+	    
 	if ($displayscore->is_custom() && !empty($scoringdisplay)) {
 		$displayscore->update_custom_score_display_settings($scoringdisplay, $scorecolpercent);
 	}

+ 5 - 13
main/gradebook/lib/fe/displaygradebook.php

@@ -322,12 +322,8 @@ class DisplayGradebook
 					//Right icons
 					$modify_icons  = '<a href="gradebook_edit_cat.php?editcat='.$catobj->get_id().'&cidReq='.$catobj->get_course_code().'">'.Display::return_icon('edit.png', get_lang('Edit'),'',ICON_SIZE_MEDIUM).'</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'),'',ICON_SIZE_MEDIUM).'</a>';
-		
-					//$modify_icons .= '<a href="gradebook_edit_all.php?id_session='.intval($_SESSION['id_session']).'&amp;'.$my_api_cidreq.'&selectcat=' . $catobj->get_id() . '">'.Display::return_icon('percentage.png', get_lang('EditAllWeights'),'',ICON_SIZE_MEDIUM).'</a>';
-		
-					//$modify_icons .= '<a href="gradebook_scoring_system.php?'.$my_api_cidreq.'&selectcat=' . $catobj->get_id() .'">'.Display::return_icon('ranking.png', get_lang('ScoreEdit'),'',ICON_SIZE_MEDIUM).'</a>';
-		
+					Display::return_icon('certificate.png', get_lang('AttachCertificate'),'',ICON_SIZE_MEDIUM).'</a>';	
+	
 					//hide or delete are not options available
 					//$modify_icons .= '&nbsp;<a  href="' . api_get_self() . '?visiblecat=' . $catobj->get_id() . '&amp;' . $visibility_command . '=&amp;selectcat=0 ">'.Display::return_icon($visibility_icon.'.png', get_lang('Visible'),'',ICON_SIZE_MEDIUM).'</a>';
 					if ($catobj->get_name() != api_get_course_id()) {
@@ -530,13 +526,9 @@ class DisplayGradebook
                     if (empty($categories)) {
                         $modify_icons .= '<a href="gradebook_edit_all.php?id_session='.api_get_session_id().'&amp;'.$my_api_cidreq.'&selectcat=' . $catobj->get_id() . '">'.Display::return_icon('percentage.png', get_lang('EditAllWeights'),'',ICON_SIZE_MEDIUM).'</a>';
                     }
-            		
-            		$modify_icons .= '<a href="gradebook_scoring_system.php?'.$my_api_cidreq.'&selectcat=' . $catobj->get_id() .'">'.Display::return_icon('ranking.png', get_lang('ScoreEdit'),'',ICON_SIZE_MEDIUM).'</a>';
-            		
-            		//hide or delete are not options available
-            		//$modify_icons .= '&nbsp;<a  href="' . api_get_self() . '?visiblecat=' . $catobj->get_id() . '&amp;' . $visibility_command . '=&amp;selectcat=0 ">'.Display::return_icon($visibility_icon.'.png', get_lang('Visible'),'',ICON_SIZE_MEDIUM).'</a>';
-            		//$modify_icons .= '&nbsp;<a  href="' . api_get_self() . '?deletecat=' . $catobj->get_id() . '&amp;selectcat=0&amp;cidReq='.$catobj->get_course_code().'" onclick="return confirmation();">'.Display::return_icon('delete.png', get_lang('DeleteAll'),'',ICON_SIZE_MEDIUM).'</a>';
-            			
+            		if (api_get_setting('teachers_can_change_score_settings') == 'true') {
+                        $modify_icons .= '<a href="gradebook_scoring_system.php?'.$my_api_cidreq.'&selectcat=' . $catobj->get_id() .'">'.Display::return_icon('ranking.png', get_lang('ScoreEdit'),'',ICON_SIZE_MEDIUM).'</a>';
+                    }
             		$header .= Display::div($modify_icons, array('class'=>'right'));
 					
                 }

+ 6 - 12
main/gradebook/lib/fe/scoredisplayform.class.php

@@ -24,11 +24,8 @@ class ScoreDisplayForm extends FormValidator
 		$displayscore= ScoreDisplay :: instance();
 		$customdisplays= $displayscore->get_custom_score_display_settings();
 		$nr_items =(count($customdisplays)!='0')?count($customdisplays):'1';
-		$this->setDefaults(array (
-            'enablescorecolor' => $displayscore->is_coloring_enabled(),
-            'scorecolpercent' => $displayscore->get_color_split_value(),
-            'enablescore' => $displayscore->is_custom(),
-            'includeupperlimit' => $displayscore->is_upperlimit_included()
+		$this->setDefaults(array (            
+            'scorecolpercent' => $displayscore->get_color_split_value()                
 		));
 		$this->addElement('hidden', 'maxvalue', '100');
 		$this->addElement('hidden', 'minvalue', '0');
@@ -49,8 +46,7 @@ class ScoreDisplayForm extends FormValidator
 
 		//settings for the colored score
 		$this->addElement('header', '', get_lang('ScoreEdit'));
-		$this->addElement('html', '<b>' . get_lang('ScoreColor') . '</b>');
-		$this->addElement('checkbox', 'enablescorecolor', null, get_lang('EnableScoreColor'), null);
+		$this->addElement('html', '<b>' . get_lang('ScoreColor') . '</b>');		
 		$this->addElement('text', 'scorecolpercent', array(get_lang('Below'), get_lang('WillColorRed'), '%'), array (
 			'size' => 5,
 			'maxlength' => 5,
@@ -64,10 +60,10 @@ class ScoreDisplayForm extends FormValidator
 		//settings for the scoring system
 
 		$this->addElement('html', '<br /><b>' . get_lang('ScoringSystem') . '</b>');
-		$this->addElement('checkbox', 'enablescore', null, get_lang('EnableScoringSystem'), null);
+		//$this->addElement('checkbox', 'enablescore', null, get_lang('EnableScoringSystem'), null);
 
 		if ($displayscore->is_custom()) {
-			$this->addElement('checkbox', 'includeupperlimit', null, get_lang('IncludeUpperLimit'), null);
+			//$this->addElement('checkbox', 'includeupperlimit', null, get_lang('IncludeUpperLimit'), null);
 			$this->addElement('static', null, null, get_lang('ScoreInfo'));
 			$scorenull[]= & $this->CreateElement('static', null, null, get_lang('Between'));
 			$this->setDefaults(array (
@@ -114,9 +110,7 @@ class ScoreDisplayForm extends FormValidator
 				$this->addRule(array ('endscore[' . $counter . ']', 'maxvalue'), get_lang('Over100'), 'compare', '<=');
 				$this->addRule(array ('endscore[' . $counter . ']', 'minvalue'), get_lang('UnderMin'), 'compare', '>');
 			}
-		}
-		$this->setDefaults(array (
-		'enablescore' => $displayscore->is_custom(), 'includeupperlimit' => $displayscore->is_upperlimit_included()));
+		}		
 		$this->addElement('style_submit_button', 'submit', get_lang('Ok'),'class="save"');
 	}
 	function validate() {

+ 24 - 52
main/gradebook/lib/scoredisplay.class.php

@@ -23,8 +23,6 @@ define('SCORE_DIV_PERCENT_WITH_CUSTOM',  9);    // X / Y (XX %) - Good!
 define('SCORE_CUSTOM',                  10);    // Good!
 define('SCORE_DIV_SIMPLE_WITH_CUSTOM',  11);    // X - Good!
 
-
-
 define('SCORE_BOTH',1);
 define('SCORE_ONLY_DEFAULT',2);
 define('SCORE_ONLY_CUSTOM',3);
@@ -52,7 +50,7 @@ class ScoreDisplay
 	}
 
 
-// Static methods
+    // Static methods
 
 	/**
 	 * Compare the custom display of 2 scores, can be useful in sorting
@@ -91,25 +89,27 @@ class ScoreDisplay
             $this->category_id = $category_id;
         }
         
-        //Loading portal settings
+        //Loading portal settings + using standard functions
         
         $value = api_get_setting('gradebook_score_display_coloring');
         $value = $value['my_display_coloring'];        
-        $this->coloring_enabled = $value == 'true' ? true : false;    
+        
+        //Settting coloring
+        $this->coloring_enabled = $value == 'true' ? true : false;
 
         if ($this->coloring_enabled) {
             $value = api_get_setting('gradebook_score_display_colorsplit');
-            if (isset($value)) {    		
-                $this->color_split_value = $this->get_score_color_percent();
+            if (isset($value)) {  		
+                $this->color_split_value = $value;
             }
         }
         
+        //Setting custom enabled
         $value = api_get_setting('gradebook_score_display_custom');
         $value = $value['my_display_custom'];   
         $this->custom_enabled  = $value;
         
-        if ($this->custom_enabled) {
-            //$this->custom_display = $this->get_custom_displays();        
+        if ($this->custom_enabled) {             
             
             $params = array('category = ? AND subkey = ?' =>  array('Gradebook', 'ranking'));
             $displays = api_get_settings_params($params);
@@ -131,20 +131,20 @@ class ScoreDisplay
             }
     	}
         
+        //If teachers can override the portal parameters
+        
         if (api_get_setting('teachers_can_change_score_settings') == 'true') {
             //Load course settings
-            //
-            $this->custom_display = $this->get_custom_displays();    
-            if (count($this->custom_display)>0) {
-                $value = api_get_setting('gradebook_score_display_upperlimit');
-                $value = $value['my_display_upperlimit'];        
-                $this->upperlimit_included  = $value == 'true' ? true : false;    
-                $this->custom_display_conv = $this->convert_displays($this->custom_display);                
+            if ($this->custom_enabled) {
+                $this->custom_display = $this->get_custom_displays();    
+                if (count($this->custom_display)> 0) {               
+                    $this->custom_display_conv = $this->convert_displays($this->custom_display);                
+                }            
+            }
+            if ($this->coloring_enabled) {
+                $this->color_split_value = $this->get_score_color_percent();
             }
-            
         }
-        
-    	
     }
     
 	/**
@@ -156,8 +156,7 @@ class ScoreDisplay
 	/**
 	 * Is custom score display enabled ?
 	 */
-	public function is_custom ()
-	{
+	public function is_custom() {
 		return $this->custom_enabled;
 	}
 	/**
@@ -255,7 +254,7 @@ class ScoreDisplay
 	 * 				(only taken into account if custom score display is enabled and for course/platform admin)
 	 */
 	public function display_score($score, $type = SCORE_DIV_PERCENT, $what = SCORE_BOTH, $no_color = false) {	  
-		$my_score = ($score==0) ? 1 : $score;		
+		$my_score = ($score==0) ? 1 : $score;		        
 		if ($this->custom_enabled && isset($this->custom_display_conv)) {		    
 	        $display = $this->display_default($my_score, $type);	        
 		} else {
@@ -273,6 +272,7 @@ class ScoreDisplay
 	
     // Internal functions
 	private function display_default ($score, $type) {
+        
 		switch ($type) {
 			case SCORE_DIV :			                // X / Y
 				return $this->display_as_div($score);
@@ -360,30 +360,7 @@ class ScoreDisplay
 			}
 		}
 	}
-	private function load_bool_setting ($property, $default = 0) {
-		$value = $this->load_int_setting($property, $default);
-		return ($value == 'true' ? true : false);
-	}
-
-	private function load_int_setting ($property, $default = 0) {
-    	$tbl_setting = Database::get_main_table(TABLE_MAIN_SETTINGS_CURRENT);
-        $property    = Database::escape_string($property);
-        $default     = Database::escape_string($default);
-		$sql = "SELECT selected_value FROM $tbl_setting WHERE category = 'Gradebook' AND variable = '".$property."'";
-		$result = Database::query($sql);
-
-		if ($data = Database::fetch_row($result)) {
-			return $data[0];
-		} else {
-			// if not present, add default setting into table...
-			$sql = "INSERT INTO ".$tbl_setting
-					." (variable, selected_value, category)"
-					." VALUES ('".$property."', '".$default."','Gradebook')";
-			Database::query($sql);
-			// ...and return default value
-			return $default;
-		}
-	}
+	
 
     /**
      * Get score color percent by category
@@ -391,9 +368,7 @@ class ScoreDisplay
      * @return  int Score
      */
     private function get_score_color_percent($category_id = null) {
-
         $tbl_display = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_SCORE_DISPLAY);
-
         if (isset($category_id)) {
             $category_id = intval($category_id);
         } else {
@@ -406,8 +381,6 @@ class ScoreDisplay
         if (Database::num_rows($result) > 0) {
             $row = Database::fetch_row($result);
             $score = $row[0];
-        } else {
-            $score = $this->load_int_setting('gradebook_score_display_colorsplit',50);
         }
         return $score;
     }
@@ -427,8 +400,7 @@ class ScoreDisplay
 		$sql = 'SELECT * FROM '.$tbl_display.' WHERE category_id = '.$category_id.' ORDER BY score';
 		$result = Database::query($sql);
 		return Database::store_result($result,'ASSOC');
-	}
-    
+	}   
  
 
 	/**