Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/course/moodleform_mod.php
Go to the documentation of this file.
00001 <?php
00002 require_once ($CFG->libdir.'/formslib.php');
00003 require_once($CFG->libdir.'/completionlib.php');
00004 
00009 abstract class moodleform_mod extends moodleform {
00011     protected $current;
00019     protected $_instance;
00026     protected $_section;
00033     protected $_cm;
00037     protected $_features;
00041     protected $_customcompletionelements;
00045     protected $_modname;
00047     protected $context;
00048 
00050     protected $_outcomesused;
00051 
00052     function moodleform_mod($current, $section, $cm, $course) {
00053         $this->current   = $current;
00054         $this->_instance = $current->instance;
00055         $this->_section  = $section;
00056         $this->_cm       = $cm;
00057         if ($this->_cm) {
00058             $this->context = get_context_instance(CONTEXT_MODULE, $this->_cm->id);
00059         } else {
00060             $this->context = get_context_instance(CONTEXT_COURSE, $course->id);
00061         }
00062 
00063         // Guess module name
00064         $matches = array();
00065         if (!preg_match('/^mod_([^_]+)_mod_form$/', get_class($this), $matches)) {
00066             debugging('Use $modname parameter or rename form to mod_xx_mod_form, where xx is name of your module');
00067             print_error('unknownmodulename');
00068         }
00069         $this->_modname = $matches[1];
00070         $this->init_features();
00071         parent::moodleform('modedit.php');
00072     }
00073 
00074     protected function init_features() {
00075         global $CFG;
00076 
00077         $this->_features = new stdClass();
00078         $this->_features->groups            = plugin_supports('mod', $this->_modname, FEATURE_GROUPS, true);
00079         $this->_features->groupings         = plugin_supports('mod', $this->_modname, FEATURE_GROUPINGS, false);
00080         $this->_features->groupmembersonly  = (!empty($CFG->enablegroupmembersonly) and plugin_supports('mod', $this->_modname, FEATURE_GROUPMEMBERSONLY, false));
00081         $this->_features->outcomes          = (!empty($CFG->enableoutcomes) and plugin_supports('mod', $this->_modname, FEATURE_GRADE_OUTCOMES, true));
00082         $this->_features->hasgrades         = plugin_supports('mod', $this->_modname, FEATURE_GRADE_HAS_GRADE, false);
00083         $this->_features->idnumber          = plugin_supports('mod', $this->_modname, FEATURE_IDNUMBER, true);
00084         $this->_features->introeditor       = plugin_supports('mod', $this->_modname, FEATURE_MOD_INTRO, true);
00085         $this->_features->defaultcompletion = plugin_supports('mod', $this->_modname, FEATURE_MODEDIT_DEFAULT_COMPLETION, true);
00086         $this->_features->rating            = plugin_supports('mod', $this->_modname, FEATURE_RATE, false);
00087         $this->_features->showdescription   = plugin_supports('mod', $this->_modname, FEATURE_SHOW_DESCRIPTION, false);
00088 
00089         $this->_features->gradecat          = ($this->_features->outcomes or $this->_features->hasgrades);
00090         $this->_features->advancedgrading   = plugin_supports('mod', $this->_modname, FEATURE_ADVANCED_GRADING, false);
00091     }
00092 
00098     function data_preprocessing(&$default_values){
00099         if (empty($default_values['scale'])) {
00100             $default_values['assessed'] = 0;
00101         }
00102 
00103         if (empty($default_values['assessed'])){
00104             $default_values['ratingtime'] = 0;
00105         } else {
00106             $default_values['ratingtime']=
00107                 ($default_values['assesstimestart'] && $default_values['assesstimefinish']) ? 1 : 0;
00108         }
00109     }
00110 
00114     function definition_after_data() {
00115         global $CFG, $COURSE;
00116         $mform =& $this->_form;
00117 
00118         if ($id = $mform->getElementValue('update')) {
00119             $modulename = $mform->getElementValue('modulename');
00120             $instance   = $mform->getElementValue('instance');
00121 
00122             if ($this->_features->gradecat) {
00123                 $gradecat = false;
00124                 if (!empty($CFG->enableoutcomes) and $this->_features->outcomes) {
00125                     $outcomes = grade_outcome::fetch_all_available($COURSE->id);
00126                     if (!empty($outcomes)) {
00127                         $gradecat = true;
00128                     }
00129                 }
00130 
00131                 $items = grade_item::fetch_all(array('itemtype'=>'mod', 'itemmodule'=>$modulename,'iteminstance'=>$instance, 'courseid'=>$COURSE->id));
00132                 //will be no items if, for example, this activity supports ratings but rating aggregate type == no ratings
00133                 if (!empty($items)) {
00134                     foreach ($items as $item) {
00135                         if (!empty($item->outcomeid)) {
00136                             $elname = 'outcome_'.$item->outcomeid;
00137                             if ($mform->elementExists($elname)) {
00138                                 $mform->hardFreeze($elname); // prevent removing of existing outcomes
00139                             }
00140                         }
00141                     }
00142 
00143                     foreach ($items as $item) {
00144                         if (is_bool($gradecat)) {
00145                             $gradecat = $item->categoryid;
00146                             continue;
00147                         }
00148                         if ($gradecat != $item->categoryid) {
00149                             //mixed categories
00150                             $gradecat = false;
00151                             break;
00152                         }
00153                     }
00154                 }
00155 
00156                 if ($gradecat === false) {
00157                     // items and outcomes in different categories - remove the option
00158                     // TODO: add a "Mixed categories" text instead of removing elements with no explanation
00159                     if ($mform->elementExists('gradecat')) {
00160                         $mform->removeElement('gradecat');
00161                         if ($this->_features->rating) {
00162                             //if supports ratings then the max grade dropdown wasnt added so the grade box can be removed entirely
00163                             $mform->removeElement('modstandardgrade');
00164                         }
00165                     }
00166                 }
00167             }
00168         }
00169 
00170         if ($COURSE->groupmodeforce) {
00171             if ($mform->elementExists('groupmode')) {
00172                 $mform->hardFreeze('groupmode'); // groupmode can not be changed if forced from course settings
00173             }
00174         }
00175 
00176         // Don't disable/remove groupingid if it is currently set to something,
00177         // otherwise you cannot turn it off at same time as turning off other
00178         // option (MDL-30764)
00179         if (empty($this->_cm) || !$this->_cm->groupingid) {
00180             if ($mform->elementExists('groupmode') and !$mform->elementExists('groupmembersonly') and empty($COURSE->groupmodeforce)) {
00181                 $mform->disabledIf('groupingid', 'groupmode', 'eq', NOGROUPS);
00182 
00183             } else if (!$mform->elementExists('groupmode') and $mform->elementExists('groupmembersonly')) {
00184                 $mform->disabledIf('groupingid', 'groupmembersonly', 'notchecked');
00185 
00186             } else if (!$mform->elementExists('groupmode') and !$mform->elementExists('groupmembersonly')) {
00187                 // groupings have no use without groupmode or groupmembersonly
00188                 if ($mform->elementExists('groupingid')) {
00189                     $mform->removeElement('groupingid');
00190                 }
00191             }
00192         }
00193 
00194         // Completion: If necessary, freeze fields
00195         $completion = new completion_info($COURSE);
00196         if ($completion->is_enabled()) {
00197             // If anybody has completed the activity, these options will be 'locked'
00198             $completedcount = empty($this->_cm)
00199                 ? 0
00200                 : $completion->count_user_data($this->_cm);
00201 
00202             $freeze = false;
00203             if (!$completedcount) {
00204                 if ($mform->elementExists('unlockcompletion')) {
00205                     $mform->removeElement('unlockcompletion');
00206                 }
00207                 // Automatically set to unlocked (note: this is necessary
00208                 // in order to make it recalculate completion once the option
00209                 // is changed, maybe someone has completed it now)
00210                 $mform->getElement('completionunlocked')->setValue(1);
00211             } else {
00212                 // Has the element been unlocked?
00213                 if ($mform->exportValue('unlockcompletion')) {
00214                     // Yes, add in warning text and set the hidden variable
00215                     $mform->insertElementBefore(
00216                         $mform->createElement('static', 'completedunlocked',
00217                             get_string('completedunlocked', 'completion'),
00218                             get_string('completedunlockedtext', 'completion')),
00219                         'unlockcompletion');
00220                     $mform->removeElement('unlockcompletion');
00221                     $mform->getElement('completionunlocked')->setValue(1);
00222                 } else {
00223                     // No, add in the warning text with the count (now we know
00224                     // it) before the unlock button
00225                     $mform->insertElementBefore(
00226                         $mform->createElement('static', 'completedwarning',
00227                             get_string('completedwarning', 'completion'),
00228                             get_string('completedwarningtext', 'completion', $completedcount)),
00229                         'unlockcompletion');
00230                     $freeze = true;
00231                 }
00232             }
00233 
00234             if ($freeze) {
00235                 $mform->freeze('completion');
00236                 if ($mform->elementExists('completionview')) {
00237                     $mform->freeze('completionview'); // don't use hardFreeze or checkbox value gets lost
00238                 }
00239                 if ($mform->elementExists('completionusegrade')) {
00240                     $mform->freeze('completionusegrade');
00241                 }
00242                 $mform->freeze($this->_customcompletionelements);
00243             }
00244         }
00245 
00246         // Availability conditions
00247         if (!empty($CFG->enableavailability) && $this->_cm) {
00248             $ci = new condition_info($this->_cm);
00249             $fullcm=$ci->get_full_course_module();
00250 
00251             $num=0;
00252             foreach($fullcm->conditionsgrade as $gradeitemid=>$minmax) {
00253                 $groupelements=$mform->getElement('conditiongradegroup['.$num.']')->getElements();
00254                 $groupelements[0]->setValue($gradeitemid);
00255                 // These numbers are always in the format 0.00000 - the rtrims remove any final zeros and,
00256                 // if it is a whole number, the decimal place.
00257                 $groupelements[2]->setValue(is_null($minmax->min)?'':rtrim(rtrim($minmax->min,'0'),'.'));
00258                 $groupelements[4]->setValue(is_null($minmax->max)?'':rtrim(rtrim($minmax->max,'0'),'.'));
00259                 $num++;
00260             }
00261 
00262             if ($completion->is_enabled()) {
00263                 $num=0;
00264                 foreach($fullcm->conditionscompletion as $othercmid=>$state) {
00265                     $groupelements=$mform->getElement('conditioncompletiongroup['.$num.']')->getElements();
00266                     $groupelements[0]->setValue($othercmid);
00267                     $groupelements[1]->setValue($state);
00268                     $num++;
00269                 }
00270             }
00271         }
00272     }
00273 
00274     // form verification
00275     function validation($data, $files) {
00276         global $COURSE, $DB;
00277         $errors = parent::validation($data, $files);
00278 
00279         $mform =& $this->_form;
00280 
00281         $errors = array();
00282 
00283         if ($mform->elementExists('name')) {
00284             $name = trim($data['name']);
00285             if ($name == '') {
00286                 $errors['name'] = get_string('required');
00287             }
00288         }
00289 
00290         $grade_item = grade_item::fetch(array('itemtype'=>'mod', 'itemmodule'=>$data['modulename'],
00291                      'iteminstance'=>$data['instance'], 'itemnumber'=>0, 'courseid'=>$COURSE->id));
00292         if ($data['coursemodule']) {
00293             $cm = $DB->get_record('course_modules', array('id'=>$data['coursemodule']));
00294         } else {
00295             $cm = null;
00296         }
00297 
00298         if ($mform->elementExists('cmidnumber')) {
00299             // verify the idnumber
00300             if (!grade_verify_idnumber($data['cmidnumber'], $COURSE->id, $grade_item, $cm)) {
00301                 $errors['cmidnumber'] = get_string('idnumbertaken');
00302             }
00303         }
00304 
00305         // Completion: Don't let them choose automatic completion without turning
00306         // on some conditions
00307         if (array_key_exists('completion', $data) && $data['completion']==COMPLETION_TRACKING_AUTOMATIC) {
00308             if (empty($data['completionview']) && empty($data['completionusegrade']) &&
00309                 !$this->completion_rule_enabled($data)) {
00310                 $errors['completion'] = get_string('badautocompletion', 'completion');
00311             }
00312         }
00313 
00314         // Conditions: Don't let them set dates which make no sense
00315         if (array_key_exists('availablefrom', $data) &&
00316             $data['availablefrom'] && $data['availableuntil'] &&
00317             $data['availablefrom'] >= $data['availableuntil']) {
00318             $errors['availablefrom'] = get_string('badavailabledates', 'condition');
00319         }
00320 
00321         // Conditions: Verify that the grade conditions are numbers, and make sense.
00322         if (array_key_exists('conditiongradegroup', $data)) {
00323             foreach ($data['conditiongradegroup'] as $i => $gradedata) {
00324                 if ($gradedata['conditiongrademin'] !== '' && !is_numeric($gradedata['conditiongrademin'])) {
00325                     $errors["conditiongradegroup[{$i}]"] = get_string('gradesmustbenumeric', 'condition');
00326                     continue;
00327                 }
00328                 if ($gradedata['conditiongrademax'] !== '' && !is_numeric($gradedata['conditiongrademax'])) {
00329                     $errors["conditiongradegroup[{$i}]"] = get_string('gradesmustbenumeric', 'condition');
00330                     continue;
00331                 }
00332                 if ($gradedata['conditiongrademin'] !== '' && $gradedata['conditiongrademax'] !== '' &&
00333                         $gradedata['conditiongrademax'] < $gradedata['conditiongrademin']) {
00334                     $errors["conditiongradegroup[{$i}]"] = get_string('badgradelimits', 'condition');
00335                     continue;
00336                 }
00337                 if ($gradedata['conditiongrademin'] === '' && $gradedata['conditiongrademax'] === '' &&
00338                         $gradedata['conditiongradeitemid']) {
00339                     $errors["conditiongradegroup[{$i}]"] = get_string('gradeitembutnolimits', 'condition');
00340                     continue;
00341                 }
00342                 if (($gradedata['conditiongrademin'] !== '' || $gradedata['conditiongrademax'] !== '') &&
00343                         !$gradedata['conditiongradeitemid']) {
00344                     $errors["conditiongradegroup[{$i}]"] = get_string('gradelimitsbutnoitem', 'condition');
00345                     continue;
00346                 }
00347             }
00348         }
00349 
00350         return $errors;
00351     }
00352 
00360     function set_data($default_values) {
00361         if (is_object($default_values)) {
00362             $default_values = (array)$default_values;
00363         }
00364 
00365         $this->data_preprocessing($default_values);
00366         parent::set_data($default_values);
00367     }
00368 
00372     function standard_coursemodule_elements(){
00373         global $COURSE, $CFG, $DB;
00374         $mform =& $this->_form;
00375 
00376         $this->_outcomesused = false;
00377         if ($this->_features->outcomes) {
00378             if ($outcomes = grade_outcome::fetch_all_available($COURSE->id)) {
00379                 $this->_outcomesused = true;
00380                 $mform->addElement('header', 'modoutcomes', get_string('outcomes', 'grades'));
00381                 foreach($outcomes as $outcome) {
00382                     $mform->addElement('advcheckbox', 'outcome_'.$outcome->id, $outcome->get_name());
00383                 }
00384             }
00385         }
00386 
00387 
00388         if ($this->_features->rating) {
00389             require_once($CFG->dirroot.'/rating/lib.php');
00390             $rm = new rating_manager();
00391 
00392             $mform->addElement('header', 'modstandardratings', get_string('ratings', 'rating'));
00393 
00394             $permission=CAP_ALLOW;
00395             $rolenamestring = null;
00396             if (!empty($this->_cm)) {
00397                 $context = get_context_instance(CONTEXT_MODULE, $this->_cm->id);
00398 
00399                 $rolenames = get_role_names_with_caps_in_context($context, array('moodle/rating:rate', 'mod/'.$this->_cm->modname.':rate'));
00400                 $rolenamestring = implode(', ', $rolenames);
00401             } else {
00402                 $rolenamestring = get_string('capabilitychecknotavailable','rating');
00403             }
00404             $mform->addElement('static', 'rolewarning', get_string('rolewarning','rating'), $rolenamestring);
00405             $mform->addHelpButton('rolewarning', 'rolewarning', 'rating');
00406 
00407             $mform->addElement('select', 'assessed', get_string('aggregatetype', 'rating') , $rm->get_aggregate_types());
00408             $mform->setDefault('assessed', 0);
00409             $mform->addHelpButton('assessed', 'aggregatetype', 'rating');
00410 
00411             $mform->addElement('modgrade', 'scale', get_string('scale'), false);
00412             $mform->disabledIf('scale', 'assessed', 'eq', 0);
00413 
00414             $mform->addElement('checkbox', 'ratingtime', get_string('ratingtime', 'rating'));
00415             $mform->disabledIf('ratingtime', 'assessed', 'eq', 0);
00416 
00417             $mform->addElement('date_time_selector', 'assesstimestart', get_string('from'));
00418             $mform->disabledIf('assesstimestart', 'assessed', 'eq', 0);
00419             $mform->disabledIf('assesstimestart', 'ratingtime');
00420 
00421             $mform->addElement('date_time_selector', 'assesstimefinish', get_string('to'));
00422             $mform->disabledIf('assesstimefinish', 'assessed', 'eq', 0);
00423             $mform->disabledIf('assesstimefinish', 'ratingtime');
00424         }
00425 
00426         //doing this here means splitting up the grade related settings on the lesson settings page
00427         //$this->standard_grading_coursemodule_elements();
00428 
00429         $mform->addElement('header', 'modstandardelshdr', get_string('modstandardels', 'form'));
00430         if ($this->_features->groups) {
00431             $options = array(NOGROUPS       => get_string('groupsnone'),
00432                              SEPARATEGROUPS => get_string('groupsseparate'),
00433                              VISIBLEGROUPS  => get_string('groupsvisible'));
00434             $mform->addElement('select', 'groupmode', get_string('groupmode', 'group'), $options, NOGROUPS);
00435             $mform->addHelpButton('groupmode', 'groupmode', 'group');
00436         }
00437 
00438         if ($this->_features->groupings or $this->_features->groupmembersonly) {
00439             //groupings selector - used for normal grouping mode or also when restricting access with groupmembersonly
00440             $options = array();
00441             $options[0] = get_string('none');
00442             if ($groupings = $DB->get_records('groupings', array('courseid'=>$COURSE->id))) {
00443                 foreach ($groupings as $grouping) {
00444                     $options[$grouping->id] = format_string($grouping->name);
00445                 }
00446             }
00447             $mform->addElement('select', 'groupingid', get_string('grouping', 'group'), $options);
00448             $mform->addHelpButton('groupingid', 'grouping', 'group');
00449             $mform->setAdvanced('groupingid');
00450         }
00451 
00452         if ($this->_features->groupmembersonly) {
00453             $mform->addElement('checkbox', 'groupmembersonly', get_string('groupmembersonly', 'group'));
00454             $mform->addHelpButton('groupmembersonly', 'groupmembersonly', 'group');
00455             $mform->setAdvanced('groupmembersonly');
00456         }
00457 
00458         $mform->addElement('modvisible', 'visible', get_string('visible'));
00459         if (!empty($this->_cm)) {
00460             $context = get_context_instance(CONTEXT_MODULE, $this->_cm->id);
00461             if (!has_capability('moodle/course:activityvisibility', $context)) {
00462                 $mform->hardFreeze('visible');
00463             }
00464         }
00465 
00466         if ($this->_features->idnumber) {
00467             $mform->addElement('text', 'cmidnumber', get_string('idnumbermod'));
00468             $mform->addHelpButton('cmidnumber', 'idnumbermod');
00469         }
00470 
00471         if (!empty($CFG->enableavailability)) {
00472             // Conditional availability
00473 
00474             // Available from/to defaults to midnight because then the display
00475             // will be nicer where it tells users when they can access it (it
00476             // shows only the date and not time).
00477             $date = usergetdate(time());
00478             $midnight = make_timestamp($date['year'], $date['mon'], $date['mday']);
00479 
00480             // From/until controls
00481             $mform->addElement('header', 'availabilityconditionsheader',
00482                     get_string('availabilityconditions', 'condition'));
00483             $mform->addElement('date_time_selector', 'availablefrom',
00484                     get_string('availablefrom', 'condition'),
00485                     array('optional' => true, 'defaulttime' => $midnight));
00486             $mform->addHelpButton('availablefrom', 'availablefrom', 'condition');
00487             $mform->addElement('date_time_selector', 'availableuntil',
00488                     get_string('availableuntil', 'condition'),
00489                     array('optional' => true, 'defaulttime' => $midnight));
00490 
00491             // Conditions based on grades
00492             $gradeoptions = array();
00493             $items = grade_item::fetch_all(array('courseid'=>$COURSE->id));
00494             $items = $items ? $items : array();
00495             foreach($items as $id=>$item) {
00496                 // Do not include grades for current item
00497                 if (!empty($this->_cm) && $this->_cm->instance == $item->iteminstance
00498                     && $this->_cm->modname == $item->itemmodule
00499                     && $item->itemtype == 'mod') {
00500                     continue;
00501                 }
00502                 $gradeoptions[$id] = $item->get_name();
00503             }
00504             asort($gradeoptions);
00505             $gradeoptions = array(0=>get_string('none','condition'))+$gradeoptions;
00506 
00507             $grouparray = array();
00508             $grouparray[] =& $mform->createElement('select','conditiongradeitemid','',$gradeoptions);
00509             $grouparray[] =& $mform->createElement('static', '', '',' '.get_string('grade_atleast','condition').' ');
00510             $grouparray[] =& $mform->createElement('text', 'conditiongrademin','',array('size'=>3));
00511             $grouparray[] =& $mform->createElement('static', '', '','% '.get_string('grade_upto','condition').' ');
00512             $grouparray[] =& $mform->createElement('text', 'conditiongrademax','',array('size'=>3));
00513             $grouparray[] =& $mform->createElement('static', '', '','%');
00514             $group = $mform->createElement('group','conditiongradegroup',
00515                 get_string('gradecondition', 'condition'),$grouparray);
00516 
00517             // Get version with condition info and store it so we don't ask
00518             // twice
00519             if(!empty($this->_cm)) {
00520                 $ci = new condition_info($this->_cm, CONDITION_MISSING_EXTRATABLE);
00521                 $this->_cm = $ci->get_full_course_module();
00522                 $count = count($this->_cm->conditionsgrade)+1;
00523             } else {
00524                 $count = 1;
00525             }
00526 
00527             $this->repeat_elements(array($group), $count, array(), 'conditiongraderepeats', 'conditiongradeadds', 2,
00528                                    get_string('addgrades', 'condition'), true);
00529             $mform->addHelpButton('conditiongradegroup[0]', 'gradecondition', 'condition');
00530 
00531             // Conditions based on completion
00532             $completion = new completion_info($COURSE);
00533             if ($completion->is_enabled()) {
00534                 $completionoptions = array();
00535                 $modinfo = get_fast_modinfo($COURSE);
00536                 foreach($modinfo->cms as $id=>$cm) {
00537                     // Add each course-module if it:
00538                     // (a) has completion turned on
00539                     // (b) is not the same as current course-module
00540                     if ($cm->completion && (empty($this->_cm) || $this->_cm->id != $id)) {
00541                         $completionoptions[$id]=$cm->name;
00542                     }
00543                 }
00544                 asort($completionoptions);
00545                 $completionoptions = array(0=>get_string('none','condition'))+$completionoptions;
00546 
00547                 $completionvalues=array(
00548                     COMPLETION_COMPLETE=>get_string('completion_complete','condition'),
00549                     COMPLETION_INCOMPLETE=>get_string('completion_incomplete','condition'),
00550                     COMPLETION_COMPLETE_PASS=>get_string('completion_pass','condition'),
00551                     COMPLETION_COMPLETE_FAIL=>get_string('completion_fail','condition'));
00552 
00553                 $grouparray = array();
00554                 $grouparray[] =& $mform->createElement('select','conditionsourcecmid','',$completionoptions);
00555                 $grouparray[] =& $mform->createElement('select','conditionrequiredcompletion','',$completionvalues);
00556                 $group = $mform->createElement('group','conditioncompletiongroup',
00557                     get_string('completioncondition', 'condition'),$grouparray);
00558 
00559                 $count = empty($this->_cm) ? 1 : count($this->_cm->conditionscompletion)+1;
00560                 $this->repeat_elements(array($group),$count,array(),
00561                     'conditioncompletionrepeats','conditioncompletionadds',2,
00562                     get_string('addcompletions','condition'),true);
00563                 $mform->addHelpButton('conditioncompletiongroup[0]', 'completioncondition', 'condition');
00564             }
00565 
00566             // Do we display availability info to students?
00567             $mform->addElement('select', 'showavailability', get_string('showavailability', 'condition'),
00568                     array(CONDITION_STUDENTVIEW_SHOW=>get_string('showavailability_show', 'condition'),
00569                     CONDITION_STUDENTVIEW_HIDE=>get_string('showavailability_hide', 'condition')));
00570             $mform->setDefault('showavailability', CONDITION_STUDENTVIEW_SHOW);
00571         }
00572 
00573         // Conditional activities: completion tracking section
00574         if(!isset($completion)) {
00575             $completion = new completion_info($COURSE);
00576         }
00577         if ($completion->is_enabled()) {
00578             $mform->addElement('header', 'activitycompletionheader', get_string('activitycompletion', 'completion'));
00579 
00580             // Unlock button for if people have completed it (will
00581             // be removed in definition_after_data if they haven't)
00582             $mform->addElement('submit', 'unlockcompletion', get_string('unlockcompletion', 'completion'));
00583             $mform->registerNoSubmitButton('unlockcompletion');
00584             $mform->addElement('hidden', 'completionunlocked', 0);
00585             $mform->setType('completionunlocked', PARAM_INT);
00586 
00587             $mform->addElement('select', 'completion', get_string('completion', 'completion'),
00588                 array(COMPLETION_TRACKING_NONE=>get_string('completion_none', 'completion'),
00589                 COMPLETION_TRACKING_MANUAL=>get_string('completion_manual', 'completion')));
00590             $mform->setDefault('completion', $this->_features->defaultcompletion
00591                 ? COMPLETION_TRACKING_MANUAL
00592                 : COMPLETION_TRACKING_NONE);
00593             $mform->addHelpButton('completion', 'completion', 'completion');
00594 
00595             // Automatic completion once you view it
00596             $gotcompletionoptions = false;
00597             if (plugin_supports('mod', $this->_modname, FEATURE_COMPLETION_TRACKS_VIEWS, false)) {
00598                 $mform->addElement('checkbox', 'completionview', get_string('completionview', 'completion'),
00599                     get_string('completionview_desc', 'completion'));
00600                 $mform->disabledIf('completionview', 'completion', 'ne', COMPLETION_TRACKING_AUTOMATIC);
00601                 $gotcompletionoptions = true;
00602             }
00603 
00604             // Automatic completion once it's graded
00605             if (plugin_supports('mod', $this->_modname, FEATURE_GRADE_HAS_GRADE, false)) {
00606                 $mform->addElement('checkbox', 'completionusegrade', get_string('completionusegrade', 'completion'),
00607                     get_string('completionusegrade_desc', 'completion'));
00608                 $mform->disabledIf('completionusegrade', 'completion', 'ne', COMPLETION_TRACKING_AUTOMATIC);
00609                 $mform->addHelpButton('completionusegrade', 'completionusegrade', 'completion');
00610                 $gotcompletionoptions = true;
00611             }
00612 
00613             // Automatic completion according to module-specific rules
00614             $this->_customcompletionelements = $this->add_completion_rules();
00615             foreach ($this->_customcompletionelements as $element) {
00616                 $mform->disabledIf($element, 'completion', 'ne', COMPLETION_TRACKING_AUTOMATIC);
00617             }
00618 
00619             $gotcompletionoptions = $gotcompletionoptions ||
00620                 count($this->_customcompletionelements)>0;
00621 
00622             // Automatic option only appears if possible
00623             if ($gotcompletionoptions) {
00624                 $mform->getElement('completion')->addOption(
00625                     get_string('completion_automatic', 'completion'),
00626                     COMPLETION_TRACKING_AUTOMATIC);
00627             }
00628 
00629             // Completion expected at particular date? (For progress tracking)
00630             $mform->addElement('date_selector', 'completionexpected', get_string('completionexpected', 'completion'), array('optional'=>true));
00631             $mform->addHelpButton('completionexpected', 'completionexpected', 'completion');
00632             $mform->disabledIf('completionexpected', 'completion', 'eq', COMPLETION_TRACKING_NONE);
00633         }
00634 
00635         $this->standard_hidden_coursemodule_elements();
00636     }
00637 
00647     function add_completion_rules() {
00648         return array();
00649     }
00650 
00659     function completion_rule_enabled(&$data) {
00660         return false;
00661     }
00662 
00663     function standard_hidden_coursemodule_elements(){
00664         $mform =& $this->_form;
00665         $mform->addElement('hidden', 'course', 0);
00666         $mform->setType('course', PARAM_INT);
00667 
00668         $mform->addElement('hidden', 'coursemodule', 0);
00669         $mform->setType('coursemodule', PARAM_INT);
00670 
00671         $mform->addElement('hidden', 'section', 0);
00672         $mform->setType('section', PARAM_INT);
00673 
00674         $mform->addElement('hidden', 'module', 0);
00675         $mform->setType('module', PARAM_INT);
00676 
00677         $mform->addElement('hidden', 'modulename', '');
00678         $mform->setType('modulename', PARAM_PLUGIN);
00679 
00680         $mform->addElement('hidden', 'instance', 0);
00681         $mform->setType('instance', PARAM_INT);
00682 
00683         $mform->addElement('hidden', 'add', 0);
00684         $mform->setType('add', PARAM_ALPHA);
00685 
00686         $mform->addElement('hidden', 'update', 0);
00687         $mform->setType('update', PARAM_INT);
00688 
00689         $mform->addElement('hidden', 'return', 0);
00690         $mform->setType('return', PARAM_BOOL);
00691     }
00692 
00693     public function standard_grading_coursemodule_elements() {
00694         global $COURSE, $CFG;
00695         $mform =& $this->_form;
00696 
00697         if ($this->_features->hasgrades) {
00698 
00699             if (!$this->_features->rating || $this->_features->gradecat) {
00700                 $mform->addElement('header', 'modstandardgrade', get_string('grade'));
00701             }
00702 
00703             //if supports grades and grades arent being handled via ratings
00704             if (!$this->_features->rating) {
00705                 $mform->addElement('modgrade', 'grade', get_string('grade'));
00706                 $mform->setDefault('grade', 100);
00707             }
00708 
00709             if ($this->_features->advancedgrading
00710                     and !empty($this->current->_advancedgradingdata['methods'])
00711                     and !empty($this->current->_advancedgradingdata['areas'])) {
00712 
00713                 if (count($this->current->_advancedgradingdata['areas']) == 1) {
00714                     // if there is just one gradable area (most cases), display just the selector
00715                     // without its name to make UI simplier
00716                     $areadata = reset($this->current->_advancedgradingdata['areas']);
00717                     $areaname = key($this->current->_advancedgradingdata['areas']);
00718                     $mform->addElement('select', 'advancedgradingmethod_'.$areaname,
00719                         get_string('gradingmethod', 'core_grading'), $this->current->_advancedgradingdata['methods']);
00720                     $mform->addHelpButton('advancedgradingmethod_'.$areaname, 'gradingmethod', 'core_grading');
00721 
00722                 } else {
00723                     // the module defines multiple gradable areas, display a selector
00724                     // for each of them together with a name of the area
00725                     $areasgroup = array();
00726                     foreach ($this->current->_advancedgradingdata['areas'] as $areaname => $areadata) {
00727                         $areasgroup[] = $mform->createElement('select', 'advancedgradingmethod_'.$areaname,
00728                             $areadata['title'], $this->current->_advancedgradingdata['methods']);
00729                         $areasgroup[] = $mform->createElement('static', 'advancedgradingareaname_'.$areaname, '', $areadata['title']);
00730                     }
00731                     $mform->addGroup($areasgroup, 'advancedgradingmethodsgroup', get_string('gradingmethods', 'core_grading'),
00732                         array(' ', '<br />'), false);
00733                 }
00734             }
00735 
00736             if ($this->_features->gradecat) {
00737                 $mform->addElement('select', 'gradecat',
00738                         get_string('gradecategoryonmodform', 'grades'),
00739                         grade_get_categories_menu($COURSE->id, $this->_outcomesused));
00740                 $mform->addHelpButton('gradecat', 'gradecategoryonmodform', 'grades');
00741             }
00742         }
00743     }
00744 
00745     function add_intro_editor($required=false, $customlabel=null) {
00746         if (!$this->_features->introeditor) {
00747             // intro editor not supported in this module
00748             return;
00749         }
00750 
00751         $mform = $this->_form;
00752         $label = is_null($customlabel) ? get_string('moduleintro') : $customlabel;
00753 
00754         $mform->addElement('editor', 'introeditor', $label, null, array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'noclean'=>true, 'context'=>$this->context));
00755         $mform->setType('introeditor', PARAM_RAW); // no XSS prevention here, users must be trusted
00756         if ($required) {
00757             $mform->addRule('introeditor', get_string('required'), 'required', null, 'client');
00758         }
00759 
00760         // If the 'show description' feature is enabled, this checkbox appears
00761         // below the intro.
00762         if ($this->_features->showdescription) {
00763             $mform->addElement('checkbox', 'showdescription', get_string('showdescription'));
00764             $mform->addHelpButton('showdescription', 'showdescription');
00765         }
00766     }
00767 
00776     function add_action_buttons($cancel=true, $submitlabel=null, $submit2label=null) {
00777         if (is_null($submitlabel)) {
00778             $submitlabel = get_string('savechangesanddisplay');
00779         }
00780 
00781         if (is_null($submit2label)) {
00782             $submit2label = get_string('savechangesandreturntocourse');
00783         }
00784 
00785         $mform = $this->_form;
00786 
00787         // elements in a row need a group
00788         $buttonarray = array();
00789 
00790         if ($submit2label !== false) {
00791             $buttonarray[] = &$mform->createElement('submit', 'submitbutton2', $submit2label);
00792         }
00793 
00794         if ($submitlabel !== false) {
00795             $buttonarray[] = &$mform->createElement('submit', 'submitbutton', $submitlabel);
00796         }
00797 
00798         if ($cancel) {
00799             $buttonarray[] = &$mform->createElement('cancel');
00800         }
00801 
00802         $mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
00803         $mform->setType('buttonar', PARAM_RAW);
00804         $mform->closeHeaderBefore('buttonar');
00805     }
00806 }
00807 
00808 
 All Data Structures Namespaces Files Functions Variables Enumerations