Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/grade/report/grader/preferences_form.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00018 
00028 if (!defined('MOODLE_INTERNAL')) {
00029     die('Direct access to this script is forbidden.');    
00030 }
00031 
00032 require_once($CFG->libdir.'/formslib.php');
00033 
00038 class grader_report_preferences_form extends moodleform {
00039 
00040     function definition() {
00041         global $USER, $CFG;
00042 
00043         $mform    =& $this->_form;
00044         $course   = $this->_customdata['course'];
00045 
00046         $context = get_context_instance(CONTEXT_COURSE, $course->id);
00047         $systemcontext = get_context_instance(CONTEXT_SYSTEM);
00048 
00049         $canviewhidden = has_capability('moodle/grade:viewhidden', $context);
00050 
00051         $checkbox_default = array(GRADE_REPORT_PREFERENCE_DEFAULT => '*default*', 0 => get_string('no'), 1 => get_string('yes'));
00052 
00053         $advanced = array();
00055 //--------------------------------------------------------------------------------
00056         $preferences = array();
00057 
00058         // Initialise the preferences arrays with grade:manage capabilities
00059         if (has_capability('moodle/grade:manage', $context)) {
00060 
00061             $preferences['prefshow'] = array();
00062             $preferences['prefshow']['showcalculations']  = $checkbox_default;
00063             $preferences['prefshow']['showeyecons']       = $checkbox_default;
00064             if ($canviewhidden) {
00065                 $preferences['prefshow']['showaverages']  = $checkbox_default;
00066             }
00067             $preferences['prefshow']['showlocks']         = $checkbox_default;
00068 
00069             $preferences['prefrows'] = array(
00070                         'rangesdisplaytype'      => array(GRADE_REPORT_PREFERENCE_DEFAULT => '*default*',
00071                                                           GRADE_REPORT_PREFERENCE_INHERIT => get_string('inherit', 'grades'),
00072                                                           GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'),
00073                                                           GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'),
00074                                                           GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades')),
00075                         'rangesdecimalpoints'    => array(GRADE_REPORT_PREFERENCE_DEFAULT => '*default*',
00076                                                           GRADE_REPORT_PREFERENCE_INHERIT => get_string('inherit', 'grades'),
00077                                                           0=>0, 1=>1, 2=>2, 3=>3, 4=>4, 5=>5));
00078             $advanced = array_merge($advanced, array('rangesdisplaytype', 'rangesdecimalpoints'));
00079 
00080             if ($canviewhidden) {
00081                 $preferences['prefrows']['averagesdisplaytype'] = array(GRADE_REPORT_PREFERENCE_DEFAULT => '*default*',
00082                                                                         GRADE_REPORT_PREFERENCE_INHERIT => get_string('inherit', 'grades'),
00083                                                                         GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'),
00084                                                                         GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'),
00085                                                                         GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades'));
00086                 $preferences['prefrows']['averagesdecimalpoints'] = array(GRADE_REPORT_PREFERENCE_DEFAULT => '*default*',
00087                                                                           GRADE_REPORT_PREFERENCE_INHERIT => get_string('inherit', 'grades'),
00088                                                                           0=>0, 1=>1, 2=>2, 3=>3, 4=>4, 5=>5);
00089                 $preferences['prefrows']['meanselection']  = array(GRADE_REPORT_PREFERENCE_DEFAULT => '*default*',
00090                                                                    GRADE_REPORT_MEAN_ALL => get_string('meanall', 'grades'),
00091                                                                    GRADE_REPORT_MEAN_GRADED => get_string('meangraded', 'grades'));
00092 
00093                 $advanced = array_merge($advanced, array('averagesdisplaytype', 'averagesdecimalpoints'));
00094             }
00095         }
00096 
00097         // quickgrading and showquickfeedback are conditional on grade:edit capability
00098         if (has_capability('moodle/grade:edit', $context)) {
00099             $preferences['prefgeneral']['quickgrading'] = $checkbox_default;
00100             $preferences['prefgeneral']['showquickfeedback'] = $checkbox_default;
00101         }
00102 
00103         // View capability is the lowest permission. Users with grade:manage or grade:edit must also have grader:view
00104         if (has_capability('gradereport/grader:view', $context)) {
00105             $preferences['prefgeneral']['studentsperpage'] = 'text';
00106             $preferences['prefgeneral']['aggregationposition'] = array(GRADE_REPORT_PREFERENCE_DEFAULT => '*default*',
00107                                                                        GRADE_REPORT_AGGREGATION_POSITION_FIRST => get_string('positionfirst', 'grades'),
00108                                                                        GRADE_REPORT_AGGREGATION_POSITION_LAST => get_string('positionlast', 'grades'));
00109             $preferences['prefgeneral']['enableajax'] = $checkbox_default;
00110 
00111             $preferences['prefshow']['showuserimage'] = $checkbox_default;
00112             $preferences['prefshow']['showactivityicons'] = $checkbox_default;
00113             $preferences['prefshow']['showranges'] = $checkbox_default;
00114             $preferences['prefshow']['showanalysisicon'] = $checkbox_default;
00115 
00116             if ($canviewhidden) {
00117                 $preferences['prefrows']['shownumberofgrades'] = $checkbox_default;
00118             }
00119 
00120             $advanced = array_merge($advanced, array('aggregationposition'));
00121         }
00122 
00123 
00124         foreach ($preferences as $group => $prefs) {
00125             $mform->addElement('header', $group, get_string($group, 'grades'));
00126 
00127             foreach ($prefs as $pref => $type) {
00128                 // Detect and process dynamically numbered preferences
00129                 if (preg_match('/([^[0-9]+)([0-9]+)/', $pref, $matches)) {
00130                     $lang_string = $matches[1];
00131                     $number = ' ' . $matches[2];
00132                 } else {
00133                     $lang_string = $pref;
00134                     $number = null;
00135                 }
00136 
00137                 $full_pref  = 'grade_report_' . $pref;
00138 
00139                 $pref_value = get_user_preferences($full_pref);
00140 
00141                 $options = null;
00142                 if (is_array($type)) {
00143                     $options = $type;
00144                     $type = 'select';
00145                     // MDL-11478
00146                     // get default aggregationposition from grade_settings
00147                     $course_value = null;
00148                     if (!empty($CFG->{$full_pref})) {
00149                         $course_value = grade_get_setting($course->id, $pref, $CFG->{$full_pref});
00150                     }
00151 
00152                     if ($pref == 'aggregationposition') {
00153                         if (!empty($options[$course_value])) {
00154                             $default = $options[$course_value];
00155                         } else {
00156                             $default = $options[$CFG->grade_aggregationposition];
00157                         }
00158                     } elseif (isset($options[$CFG->{$full_pref}])) {
00159                         $default = $options[$CFG->{$full_pref}];
00160                     } else {
00161                         $default = '';
00162                     }
00163                 } else {
00164                     $default = $CFG->$full_pref;
00165                 }
00166 
00167                 // Replace the '*default*' value with the site default language string - 'default' might collide with custom language packs
00168                 if (!is_null($options) AND isset($options[GRADE_REPORT_PREFERENCE_DEFAULT]) && $options[GRADE_REPORT_PREFERENCE_DEFAULT] == '*default*') {
00169                     $options[GRADE_REPORT_PREFERENCE_DEFAULT] = get_string('reportdefault', 'grades', $default);
00170                 }
00171 
00172                 $label = get_string($lang_string, 'grades') . $number;
00173 
00174                 $mform->addElement($type, $full_pref, $label, $options);
00175                 if ($lang_string != 'showuserimage') {
00176                     $mform->addHelpButton($full_pref, $lang_string, 'grades');
00177                 }
00178                 $mform->setDefault($full_pref, $pref_value);
00179                 $mform->setType($full_pref, PARAM_ALPHANUM);
00180             }
00181         }
00182 
00183         foreach($advanced as $name) {
00184             $mform->setAdvanced('grade_report_'.$name);
00185         }
00186 
00187         $mform->addElement('hidden', 'id');
00188         $mform->setType('id', PARAM_INT);
00189         $mform->setDefault('id', $course->id);
00190 
00191         $this->add_action_buttons();
00192     }
00193 
00195     function validation($data, $files) {
00196         return parent::validation($data, $files);
00197     }
00198 }
00199 
 All Data Structures Namespaces Files Functions Variables Enumerations