function definition() { global $CFG; $mform =& $this->_form; if ($this->is_adding_equella_resource()) { return; } $mform->addElement('header', 'general', get_string('general', 'form')); $mform->addElement('text', 'name', get_string('name'), array('size' => '48')); $mform->setType('name', PARAM_TEXT); $mform->addRule('name', null, 'required', null, 'client'); if (method_exists($this, 'standard_intro_elements')) { $this->standard_intro_elements(); } else { $this->add_intro_editor(); } $mform->addElement('text', 'url', get_string('location'), array('size' => '80')); $mform->setType('url', PARAM_URL); $mform->addElement('hidden', 'activation', ''); $mform->setType('activation', PARAM_TEXT); $mform->addElement('header', 'optionssection', get_string('option.pagewindow.header', 'equella')); $woptions = array(0 => get_string('option.pagewindow.same', 'equella'), 1 => get_string('option.pagewindow.new', 'equella')); $mform->addElement('select', 'windowpopup', get_string('option.pagewindow', 'equella'), $woptions); $mform->setDefault('windowpopup', !empty($CFG->resource_popup)); foreach (equella_get_window_options() as $option => $value) { $label = get_string('option.popup.' . $option, 'equella'); if ($option == 'height' or $option == 'width') { $mform->addElement('text', $option, $label, array('size' => '4')); $mform->setType($option, PARAM_INT); } else { $mform->addElement('checkbox', $option, $label); } if (isset($CFG->{"resource_popup" . $option})) { $mform->setDefault($option, $CFG->{"resource_popup" . $option}); } $mform->disabledIf($option, 'windowpopup', 'eq', 0); $mform->setAdvanced($option); } $this->standard_coursemodule_elements(); $this->add_action_buttons(); }
/** * Validate and process EQUELLA options * * @param stdClass $resource * @return stdClass */ function equella_postprocess($resource) { if (!empty($resource->windowpopup)) { $optionlist = array(); foreach (equella_get_window_options() as $option => $value) { if (($option == 'width' or $option == 'height') and empty($resource->{$option})) { $resource->{$option} = $value; } if (isset($resource->{$option})) { $optionlist[] = $option . "=" . $resource->{$option}; unset($resource->{$option}); } else { $optionlist[] = $option . "=" . $value; } } $resource->popup = implode(',', $optionlist); unset($resource->windowpopup); } else { $resource->popup = ''; } $pattern = "/(?P<uuid>[\\w]{8}-[\\w]{4}-[\\w]{4}-[\\w]{4}-[\\w]{12})\\/(?P<version>[0-9]*)\\/(?P<path>.*)/"; $url = $resource->url; preg_match($pattern, $url, $matches); if (!empty($matches['uuid'])) { $resource->uuid = $matches['uuid']; } // version could be 0, so don't test it with !empty() if (isset($matches['version'])) { $resource->version = $matches['version']; } if (!empty($matches['path'])) { $resource->path = $matches['path']; } return $resource; }