function definition() { global $CFG; $mform =& $this->_form; $add = optional_param('add', 0, PARAM_ALPHA); $return = optional_param('return', 0, PARAM_BOOL); //return to course/view.php if false or mod/modname/view.php if true $type = optional_param('type', '', PARAM_ALPHANUM); $section = required_param('section', PARAM_INT); $course = required_param('course', PARAM_INT); $mform->addElement('header', 'searchheader', get_string('searchheader', 'taoresource')); $plugins = taoresource_get_plugins(); // let the plugins see the form definition foreach ($plugins as $plugin) { $rc = $plugin->search_definition($mform); if (!$rc) { break; } } $this->add_action_buttons(true, get_string('searchtaoresource', 'taoresource')); if (!($course = get_record("course", "id", $course))) { error("This course doesn't exist"); } $context = get_context_instance(CONTEXT_COURSE, $course->id); if (has_capability('moodle/course:manageactivities', $context)) { $mform->addElement('header', 'addheader', get_string('addheader', 'taoresource')); $addbutton = $mform->addElement('submit', 'addtaoresource', get_string('addtaoresource', 'taoresource')); $buttonattributes = array('title' => get_string('addtaoresource', 'taoresource'), 'onclick' => "location.href = '" . $CFG->wwwroot . "/mod/taoresource/edit.php?course={$course->id}§ion={$section}&type={$type}&add={$add}&return={$return}&mode=add'; return false;"); $addbutton->updateAttributes($buttonattributes); } }
/** * Check all the plugins to see if they specify the extra screen */ function taoresource_extra_resource_screen() { $plugins = taoresource_get_plugins(); $extra = false; foreach ($plugins as $plugin) { $extra = $plugin->taoresource_entry_extra_form_required(); if ($extra) { break; } } return $extra; }
function validation($data, $files) { $errors = parent::validation($data, $files); // let the plugins see the form validation $plugins = taoresource_get_plugins(); foreach ($plugins as $plugin) { $rc = $plugin->taoresource_entry_extra_validation($data, $files, $errors, $this->taoresource_entry_mode); if (!$rc) { break; } } return $errors; }
function validation($data, $files) { $errors = parent::validation($data, $files); if ($this->taoresource_entry_mode == 'add') { // make sure that either the file or the URL are supplied if (empty($data['url']) && $_FILES['taoresourcefile']['size'] <= 0) { $errors['url'] = get_string('missingresource', 'taoresource'); } // if file is uploaded - check that there was no problem if (empty($data['url']) && $_FILES['taoresourcefile']['error'] != 0) { // error - physical upload of file failed $errors['taoresourcefile'] = get_string('fileuploadfailed', 'taoresource'); } // check that this resource signature does not allready exist if (!empty($data['url'])) { $hash = sha1($data['url']); $result = count_records('taoresource_entry', 'identifier', $hash) + count_records('taoresource_entry', 'url', $data['url']); if ($result > 0) { $errors['url'] = get_string('resourceexists', 'taoresource'); } } else { $tempfile = $_FILES['taoresourcefile']['tmp_name']; $hash = taoresource_sha1file($tempfile); $taoresource_entry->identifier = $hash; $uri = $hash . '-' . $_FILES['taoresourcefile']['name']; $result = count_records('taoresource_entry', 'identifier', $hash) + count_records('taoresource_entry', 'url', $uri); if ($result > 0) { $errors['taoresourcefile'] = get_string('resourceexists', 'taoresource'); } } } // let the plugins see the form validation $plugins = taoresource_get_plugins(); foreach ($plugins as $plugin) { $rc = $plugin->taoresource_entry_validation($data, $files, $errors, $this->taoresource_entry_mode); if (!$rc) { break; } } return $errors; }
/** * Internal method that processes the plugins for the after update * interface. * * @return bool, returns true. */ function after_update() { // get the plugins $plugins = taoresource_get_plugins(); // process each plugins before_save function - there is a default called local foreach ($plugins as $plugin) { // if we get a positive return then we don't use any more plugins $rc = $plugin->after_update($this); if (!$rc) { break; } } return true; }