Browse Source

Adding new grading model see BT#4080 (with DB changes)

Julio Montoya 13 years ago
parent
commit
b61a15cc5b

+ 46 - 0
main/gradebook/index.php

@@ -36,6 +36,9 @@ require_once 'lib/fe/userform.class.php';
 require_once api_get_path(LIBRARY_PATH).'ezpdf/class.ezpdf.php';
 require_once api_get_path(LIBRARY_PATH).'document.lib.php';
 
+require_once api_get_path(LIBRARY_PATH).'grade_model.lib.php';
+require_once api_get_path(LIBRARY_PATH).'gradebook.lib.php';
+
 /*
 $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/jqplot/jquery.jqplot.min.css');
 $htmlHeadXtra[] = api_get_js('jqplot/jquery.jqplot.min.js');
@@ -870,6 +873,49 @@ if (isset($first_time) && $first_time==1 && api_is_allowed_to_edit(null,true)) {
 						Display::display_normal_message(get_lang('GradeModel').': '.$grading_string);
 					}
 				}		
+                $obj = new GradeModel();
+                $grade_models = $obj->get_all();                
+                $options = array(0 => get_lang('none'));
+                foreach ($grade_models as $item) {
+                    $options[$item['id']] = $item['name'];
+                }                
+                //$grade_model_id = $cat->get_grade_model_id();
+                //
+                //No children
+                if (empty($allcat)) {
+                    $form = new FormValidator('grade_model_settings');
+                    $form->addElement('select', 'grade_model', get_lang('SelectGradeModel'), $options);                
+                    $form->addElement('style_submit_button', 'submit', get_lang('Modify'), 'class="save"');                
+                    $form->display();     
+
+                    if ($form->validate()) {
+                        $value = $form->exportValue('grade_model');                    
+                        $gradebook = new Gradebook();
+                        $gradebook->update(array('id'=> $cat->get_id(), 'grade_model_id' => $value), true);                 
+
+                        //do something                        
+                        $obj = new GradeModel();                             
+                        $components = $obj->get_components($value);
+
+                        foreach ($components as $component) {
+                            $gradebook =  new Gradebook();
+                            $params = array();
+
+                            $params['name'] = $component['acronym'];
+                            $params['description'] = $component['title'];
+                            $params['user_id'] = api_get_user_id();
+                            $params['parent_id'] = $cat->get_id();
+                            $params['weight'] = $component['percentage'];
+                            $params['session_id'] = api_get_session_id();
+                            $params['course_code'] = api_get_course_id();
+                            $params['grade_model_id'] = api_get_session_id();
+
+                            $gradebook->save($params);
+
+
+                        }
+                    }
+                }
                 
 				$gradebooktable = new GradebookTable($cat, $allcat, $alleval, $alllink, $addparams);                
 				$gradebooktable->display();				

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

@@ -27,6 +27,7 @@ class Category implements GradebookItem
 	private $certificate_min_score;
     private $session_id;
     private $skills = array();
+    private $grade_model_id;
 
     function __construct() {
     }
@@ -114,6 +115,14 @@ class Category implements GradebookItem
 	public function set_visible ($visible) {
 		$this->visible = $visible;
 	}
+    
+    public function set_grade_model_id ($id) {
+		$this->grade_model_id = $id;
+	}
+    
+    public function get_grade_model_id () {
+		return $this->grade_model_id;
+	}
 	
 	public function get_type() {
 		return 'category';
@@ -164,7 +173,7 @@ class Category implements GradebookItem
 		}
 
 		$tbl_grade_categories = Database :: get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
-		$sql = 'SELECT id, name, description, user_id, course_code, parent_id, weight, visible, certif_min_score, session_id FROM '.$tbl_grade_categories;
+		$sql = 'SELECT id, name, description, user_id, course_code, parent_id, weight, visible, certif_min_score, session_id, grade_model_id FROM '.$tbl_grade_categories;
 		$paramcount = 0;
 		if (isset($id)) {
 			$id = Database::escape_string($id);
@@ -265,6 +274,7 @@ class Category implements GradebookItem
 			$cat->set_visible($data['visible']);
             $cat->set_session_id($data['session_id']);
 			$cat->set_certificate_min_score($data['certif_min_score']);
+            $cat->set_grade_model_id($data['grade_model_id']);
 			$allcat[]=$cat;
 		}
 		return $allcat;

+ 3 - 1
main/gradebook/lib/fe/gradebooktable.class.php

@@ -44,6 +44,8 @@ class GradebookTable extends SortableTable {
 		
 		$this->set_header($column++, get_lang('Type'),'','width="35px"');
 		$this->set_header($column++, get_lang('Name'), false);
+        
+        $this->set_header($column++, get_lang('Description'), false);
 
 		if (api_is_allowed_to_edit(null, true)) {
 			$this->set_header($column++, get_lang('Weight'),'','width="80px"');
@@ -171,7 +173,7 @@ class GradebookTable extends SortableTable {
             $main_categories[$item->get_id()]['weight'] = $item->get_weight();
             
 			//Description
-			//$row[] = $invisibility_span_open.$data[2] . $invisibility_span_close;			
+			$row[] = $invisibility_span_open.$data[2] . $invisibility_span_close;			
 			
 			//Weight
 			$row[] = $invisibility_span_open .Display::tag('h4', $data[3] .' / '.$this->currentcat->get_weight()).$invisibility_span_close;		

+ 18 - 1
main/inc/ajax/model.ajax.php

@@ -132,6 +132,11 @@ switch ($action) {
         $obj        = new Promotion();        
         $count      = $obj->get_count();   
         break;
+    case 'get_grade_models':        
+        require_once $libpath.'grade_model.lib.php';
+        $obj        = new GradeModel();
+        $count      = $obj->get_count();
+        break;
     case 'get_usergroups':
         require_once $libpath.'usergroup.lib.php';        
         $obj        = new UserGroup();        
@@ -284,6 +289,18 @@ switch ($action) {
         } 
         $result = $new_result;
         break;
+    case 'get_grade_models':
+        $columns = array('name', 'description', 'actions');
+        if(!in_array($sidx, $columns)) {
+            $sidx = 'name';
+        }                  
+        $result     = Database::select('*', "$obj->table ", array('order' =>"$sidx $sord", 'LIMIT'=> "$start , $limit"));
+        $new_result = array();
+        foreach($result as $item) {
+            $new_result[] = $item;
+        } 
+        $result = $new_result;        
+        break;
     case 'get_usergroups':
         $columns = array('name', 'users', 'courses','sessions','actions');
         $result     = Database::select('*', $obj->table, array('order'=>"name $sord", 'LIMIT'=> "$start , $limit"));
@@ -310,7 +327,7 @@ switch ($action) {
 //var_dump($result);
 
 $allowed_actions = array('get_careers', 'get_promotions', 'get_usergroups', 'get_gradebooks', 
-                         'get_sessions', 'get_exercise_results', 'get_work_user_list', 'get_timelines');
+                         'get_sessions', 'get_exercise_results', 'get_work_user_list', 'get_timelines', 'get_grade_models');
 //5. Creating an obj to return a json
 if (in_array($action, $allowed_actions)) {
     $response           = new stdClass();           

+ 1 - 1
main/inc/lib/career.lib.php

@@ -86,7 +86,7 @@ class Career extends Model {
             $header = get_lang('Modify');
         }
         
-        $form->addElement('header', '', $header);
+        $form->addElement('header', $header);
         $id = isset($_GET['id']) ? intval($_GET['id']) : '';
         $form->addElement('hidden', 'id', $id);
         

+ 5 - 1
main/inc/lib/database.constants.inc.php

@@ -329,4 +329,8 @@ define('TABLE_MAIN_SKILL_PROFILE',          'skill_profile');
 define('TABLE_MAIN_SKILL_REL_PROFILE',      'skill_rel_profile');
 
 define('TABLE_MAIN_CHAT',					'chat');
-define('TABLE_TIMELINE',                    'timeline');
+define('TABLE_TIMELINE',                    'timeline');
+
+//Gradebook model
+define('TABLE_GRADE_MODEL',                  'grade_model');
+define('TABLE_GRADE_MODEL_COMPONENTS',       'grade_components');

+ 1 - 1
main/inc/lib/database.lib.php

@@ -1166,7 +1166,7 @@ class Database {
         }
 
         $sql    = "SELECT $clean_columns FROM $table_name $conditions";
-        //var_dump($sql);
+        ///var_dump($sql);
         $result = self::query($sql);
         $array = array();
         //if (self::num_rows($result) > 0 ) {

+ 193 - 0
main/inc/lib/grade_model.lib.php

@@ -0,0 +1,193 @@
+<?php
+/* For licensing terms, see /license.txt */
+/**
+*	This class provides methods for the notebook management.
+*	Include/require it in your code to use its features.
+*	@package chamilo.library
+*/
+/**
+ * Code
+ */
+
+/**
+ * @package chamilo.library
+ */
+class GradeModel extends Model {
+    
+    var $table;
+    var $columns = array('id', 'name', 'description');
+    
+	public function __construct() {
+        $this->table =  Database::get_main_table(TABLE_GRADE_MODEL);
+	}    
+    
+    public function get_all($where_conditions = array()) {
+        return Database::select('*',$this->table, array('where'=>$where_conditions,'order' =>'name ASC'));
+    }    
+    
+    /**
+     * Displays the title + grid
+     */
+	public function display() {
+		// action links
+		echo '<div class="actions" style="margin-bottom:20px">';
+        echo '<a href="grade_models.php">'.Display::return_icon('back.png',get_lang('Back'),'','32').'</a>';     	
+		echo '<a href="'.api_get_self().'?action=add">'.Display::return_icon('add.png',get_lang('Add'),'','32').'</a>';        				
+		echo '</div>';   
+        echo Display::grid_html('grade_model');  
+	}
+    
+    /**
+     * Returns a Form validator Obj
+     * @todo the form should be auto generated
+     * @param   string  url
+     * @param   string  action add, edit
+     * @return  obj     form validator obj 
+     */
+    public function return_form($url, $action) {
+		
+		$oFCKeditor = new FCKeditor('description') ;
+		$oFCKeditor->ToolbarSet = 'grade_model';
+		$oFCKeditor->Width		= '100%';
+		$oFCKeditor->Height		= '200';
+		$oFCKeditor->Value		= '';
+		$oFCKeditor->CreateHtml();
+		
+        $form = new FormValidator('grades', 'post', $url);
+        // Settting the form elements
+        $header = get_lang('Add');        
+        if ($action == 'edit') {
+            $header = get_lang('Modify');
+        }
+        
+        $form->addElement('header', $header);
+        $id = isset($_GET['id']) ? intval($_GET['id']) : '';
+        $form->addElement('hidden', 'id', $id);
+        
+        $form->addElement('text', 'name', get_lang('Name'), array('size' => '70'));
+        $form->add_html_editor('description', get_lang('Description'), false, false, array('ToolbarSet' => 'careers','Width' => '100%', 'Height' => '250'));	   
+
+        $form->addElement('label', get_lang('Components'));
+        
+        //Get components
+        $nr_items = 10;
+        
+        $renderer = & $form->defaultRenderer();
+        
+        for ($i = 0; $i <= $nr_items;  $i++) {    
+            $counter = $i;
+            $form->addElement('text', 'components['.$i.'][percentage]', null, array('class' => 'span1'));                                        
+            $form->addElement('text', 'components['.$i.'][acronym]', null , array('class' => 'span1'));
+            $form->addElement('text', 'components['.$i.'][title]', null, array('class' => 'span3'));        
+            $form->addElement('hidden', 'components['.$i.'][id]', null , array('class' => 'span3'));
+            
+            $template_percentage =
+            '<div id=' . $i . ' style="display: '.(($i<=$nr_items)?'inline':'none').';" class="control-group">
+            <p><!-- BEGIN required --><span class="form_required">*</span> <!-- END required -->
+            <label class="control-label">{label}</label>
+            <div class="controls"><!-- BEGIN error --><span class="form_error">{error}</span><br /><!-- END error -->{element} % =';
+            
+            $template_acronym = '
+            <!-- BEGIN required --><span class="form_required">*</span> <!-- END required -->            
+            <!-- BEGIN error --><span class="form_error">{error}</span> <!-- END error -->{element} {label}';
+
+            $template_title =
+            '<!-- BEGIN error --><span class="form_error">{error}</span><br /><!-- END error -->&nbsp{element}
+            <a href="javascript:minItem(' . ($counter) . ')">
+                <img style="display: '.(($counter>=$nr_items)?'inline':'none').';" id="min-' . $counter . '" src="../img/delete.png" alt="'.get_lang('Delete').'" title="'.get_lang('Delete').'"></img>
+            </a>
+            <a href="javascript:plusItem(' . ($counter+1) . ')">
+                <img style="display: '.(($counter>=$nr_items)?'inline':'none').';" id="plus-' . ($counter+1) . '" src="../img/icons/22/add.png" alt="'.get_lang('Add').'" title="'.get_lang('Add').'"></img>
+            </a>
+            </div></p></div>';
+            
+            $renderer->setElementTemplate($template_title, 'components['.$i.'][title]');
+            $renderer->setElementTemplate($template_percentage ,  'components['.$i.'][percentage]');
+            $renderer->setElementTemplate($template_acronym , 'components['.$i.'][acronym]');
+            //$renderer->setElementTemplate($template_acronym , 'components['.$i.'][item_id]');
+        }
+        $form->addElement('advanced_settings', get_lang('AllMustWeight100'));
+        	            
+        if ($action == 'edit') {
+        	$form->addElement('style_submit_button', 'submit', get_lang('Modify'), 'class="save"');
+        } else {
+        	$form->addElement('style_submit_button', 'submit', get_lang('Add'), 'class="save"');
+        }
+        
+        // Setting the defaults
+        $defaults = $this->get($id);        
+        $components = $this->get_components($defaults['grade_model_id']);
+        
+        if (!empty($components)) {
+            $counter = 0;
+            foreach ($components as $component) {
+                foreach ($component as $key => $value) {
+                    $defaults['components['.$counter.']['.$key.']'] = $value;
+                }
+                $counter++;
+            }
+        }        
+        
+        $form->setDefaults($defaults);
+    
+        // Setting the rules
+        $form->addRule('name', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');               
+		return $form;                                
+    }
+    
+    public function get_components($id) {       
+        $obj = new GradeModelComponents();
+        return $obj->get_all(array('where'=> array('grade_model_id = ?' => $id)));                
+    }
+        
+    public function save($params) {        
+	    $id = parent::save($params);
+	    if (!empty($id)) {            
+            foreach ($params['components'] as $component) {                
+                if (!empty($component['title']) && !empty($component['percentage']) && !empty($component['acronym'])) {
+                    $obj = new GradeModelComponents();
+                    $component['grade_model_id'] = $id;
+                    $obj->save($component);
+                }
+            }                            
+        }
+        //event_system(LOG_CAREER_CREATE, LOG_CAREER_ID, $id, api_get_utc_datetime(), api_get_user_id());   		
+   		return $id;
+    }
+    
+    public function update($params) {
+        parent::update($params);
+        
+        if (!empty($params['id'])) {
+            foreach ($params['components'] as $component) {   
+                $obj = new GradeModelComponents();
+                $component['grade_model_id'] = $params['id'];
+                if (empty($component['title']) && empty($component['percentage']) && empty($component['acronym'])) {
+                    $obj->delete($component['id']);
+                } else {
+                    $obj->update($component);
+                }
+            }
+        }        
+        //$params['components']
+    }
+    
+    public function delete($id) {
+	    parent::delete($id);
+	    //event_system(LOG_CAREER_DELETE, LOG_CAREER_ID, $id, api_get_utc_datetime(), api_get_user_id());
+    }    
+}
+
+class GradeModelComponents extends Model {
+    var $table;
+    var $columns = array('id', 'title', 'percentage', 'acronym', 'grade_model_id');
+    
+	public function __construct() {
+        $this->table =  Database::get_main_table(TABLE_GRADE_MODEL_COMPONENTS);
+	}    
+    
+    public function save($params) {        
+	    $id = parent::save($params);  
+        return $id;
+    }
+}

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

@@ -10,7 +10,7 @@
  */
    
 class Gradebook extends Model {    
-    var $columns = array('id', 'name','description', 'course_code', 'parent_id');
+    var $columns = array('id', 'name', 'description', 'course_code', 'parent_id', 'grade_model_id', 'session_id', 'weight', 'user_id');
     
     public function __construct() {
         $this->table                        = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
@@ -28,6 +28,10 @@ class Gradebook extends Model {
         return $gradebooks;        
     }
     
+    public function update($params) {
+        return parent::update($params);
+    }
+    
     public function update_skills_to_gradebook($gradebook_id, $skill_list) {
         
         if (!empty($skill_list)) {

+ 1 - 0
main/inc/lib/userportal.lib.php

@@ -702,6 +702,7 @@ class IndexManager {
 	function display_login_form() {
 		$form = new FormValidator('formLogin', 'POST', null,  null, array('class'=>'form-vertical'));
         // 'placeholder'=>get_lang('UserName')
+        //'autocomplete'=>"off", 
 		$form->addElement('text', 'login', get_lang('UserName'), array('class' => 'span2','autofocus' => 'autofocus'));
 		$form->addElement('password', 'password', get_lang('Pass'), array('class' => 'span2'));
 		$form->addElement('style_submit_button','submitAuth', get_lang('LoginEnter'), array('class' => 'btn'));		

+ 21 - 1
main/install/db_main.sql

@@ -865,7 +865,7 @@ VALUES
 ('courses_default_creation_visibility', NULL, 'radio', 'Course', '2', 'CoursesDefaultCreationVisibilityTitle', 'CoursesDefaultCreationVisibilityComment', NULL, NULL, 1),
 ('allow_browser_sniffer', NULL, 'radio', 'Tuning', 'false', 'AllowBrowserSnifferTitle', 'AllowBrowserSnifferComment', NULL, NULL, 0),
 ('enable_wami_record',NULL,'radio','Tools','false','EnableWamiRecordTitle','EnableWamiRecordComment',NULL,NULL, 0),
-('chamilo_database_version',NULL,'textfield',NULL, '1.9.0.17054','DokeosDatabaseVersion','', NULL, NULL, 0);
+('chamilo_database_version',NULL,'textfield',NULL, '1.9.0.17471','DatabaseVersion','', NULL, NULL, 0);17470
 
 /*
 ('show_tabs', 'custom_tab_1', 'checkbox', 'Platform', 'true', 'ShowTabsTitle', 'ShowTabsComment', NULL, 'TabsCustom1', 1),
@@ -2972,3 +2972,23 @@ CREATE TABLE IF NOT EXISTS chat (
 
 ALTER TABLE chat ADD INDEX idx_chat_to_user (to_user);
 ALTER TABLE chat ADD INDEX idx_chat_from_user (from_user);
+
+-- Grade Model
+
+CREATE TABLE grade_model (
+  id INTEGER  NOT NULL AUTO_INCREMENT,
+  name VARCHAR(255)  NOT NULL,
+  description TEXT ,
+  PRIMARY KEY (id)
+);
+
+CREATE TABLE grade_components (
+  id INTEGER  NOT NULL AUTO_INCREMENT,
+  percentage VARCHAR(255)  NOT NULL,
+  title VARCHAR(255)  NOT NULL,
+  acronym VARCHAR(255)  NOT NULL,
+  grade_model_id INTEGER NOT NULL,
+  PRIMARY KEY (id)
+);
+
+ALTER TABLE gradebook_category ADD COLUMN grade_model_id INT DEFAULT 0;

+ 7 - 1
main/install/migrate-db-1.8.8-1.9.0-pre.sql

@@ -174,8 +174,14 @@ ALTER TABLE track_e_default  MODIFY COLUMN default_value TEXT;
 INSERT INTO user_field (field_type, field_variable, field_display_text, field_visible, field_changeable) VALUES (1, 'user_chat_status','User chat status', 0, 0);
 UPDATE settings_current SET selected_value = 'true' WHERE variable = 'more_buttons_maximized_mode';
 
+--Grade model
+CREATE TABLE grade_model (id INTEGER  NOT NULL AUTO_INCREMENT, name VARCHAR(255)  NOT NULL, description TEXT , PRIMARY KEY (id));
+CREATE TABLE grade_components (id INTEGER  NOT NULL AUTO_INCREMENT, percentage VARCHAR(255)  NOT NULL, title VARCHAR(255)  NOT NULL, acronym VARCHAR(255)  NOT NULL, grade_model_id INTEGER NOT NULL, PRIMARY KEY (id));
+ALTER TABLE gradebook_category ADD COLUMN grade_model_id INT DEFAULT 0;
+UPDATE settings_current SET title = 'DatabaseVersion' WHERE variable = 'chamilo_database_version';
+
 -- Do not move this query
-UPDATE settings_current SET selected_value = '1.9.0.17051' WHERE variable = 'chamilo_database_version';
+UPDATE settings_current SET selected_value = '1.9.0.17471' WHERE variable = 'chamilo_database_version';
 
 -- xxSTATSxx
 ALTER TABLE track_e_exercices ADD COLUMN questions_to_check TEXT NOT NULL DEFAULT '';