/** * Hydrate a taoresource_entry object reading by id * * @param id int, internal id of taoresource_entry object * @return taoresource_entry object */ static function get_by_id($entry_id) { return taoresource_entry::read_by_id($entry_id); }
/** * TODO document */ function setup_elements(&$mform) { global $CFG, $USER, $TAORESOURCE_WINDOW_OPTIONS; $taoresource_entry; $add = optional_param('add', 0, PARAM_ALPHA); $update = optional_param('update', 0, PARAM_INT); $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 = optional_param('section', PARAM_INT); $course = optional_param('course', PARAM_INT); if (!empty($add)) { $entry_id = optional_param('entry_id', false, PARAM_INT); // Have we selected a resource yet ? if (empty($entry_id)) { redirect($CFG->wwwroot . "/mod/taoresource/search.php?course={$course}§ion={$section}&type={$type}&add={$add}&return={$return}"); } else { if (!($taoresource_entry = taoresource_entry::read_by_id($entry_id))) { error('Invalid taoresource_entry::id supplied: ' . $entry_id); } } } else { if (!empty($update)) { if (!($cm = get_coursemodule_from_id('taoresource', $update))) { error('Course Module ID was incorrect'); } if (!($resource = get_record('taoresource', 'id', $cm->instance))) { error('Resource ID was incorrect'); } if (!($taoresource_entry = taoresource_entry::read($resource->identifier))) { error('Invalid taoresource_entry::identifier supplied: ' . $resource->identifier); } } } $this->set_parameters(); // set the parameter array for the form $mform->addElement('hidden', 'entry_id', $taoresource_entry->id); $mform->addElement('hidden', 'identifier', $taoresource_entry->identifier); $mform->setDefault('name', stripslashes_safe($taoresource_entry->title)); $mform->setDefault('description', stripslashes_safe($taoresource_entry->description)); $location = $mform->addElement('static', 'origtitle', get_string('title', 'taoresource') . ': ', stripslashes_safe($taoresource_entry->title)); $strpreview = get_string('preview', 'taoresource'); $link = "<a href=\"{$CFG->wwwroot}/mod/taoresource/view.php?identifier={$taoresource_entry->identifier}&inpopup=true\" " . "onclick=\"this.target='resource{$taoresource_entry->id}'; return openpopup('/mod/taoresource/view.php?inpopup=true&identifier={$taoresource_entry->identifier}', " . "'resource{$taoresource_entry->id}','resizable=1,scrollbars=1,directories=1,location=0,menubar=0,toolbar=0,status=1,width=800,height=600');\">(" . $strpreview . ")</a>"; $location = $mform->addElement('static', 'url', get_string('location', 'taoresource') . ': ', $link); $searchbutton = $mform->addElement('submit', 'searchtaoresource', get_string('searchtaoresource', 'taoresource')); $buttonattributes = array('title' => get_string('searchtaoresource', 'taoresource'), 'onclick' => " window.location.href ='" . $CFG->wwwroot . "/mod/taoresource/search.php?course={$this->course->id}§ion={$section}&type={$type}&add={$add}&return={$return}" . "'; return false;"); $searchbutton->updateAttributes($buttonattributes); $mform->addElement('header', 'displaysettings', get_string('display', 'resource')); $mform->addElement('checkbox', 'forcedownload', get_string('forcedownload', 'resource')); $mform->setHelpButton('forcedownload', array('forcedownload', get_string('forcedownload', 'resource'), 'resource')); $mform->disabledIf('forcedownload', 'windowpopup', 'eq', 1); $woptions = array(0 => get_string('pagewindow', 'resource'), 1 => get_string('newwindow', 'resource')); $mform->addElement('select', 'windowpopup', get_string('display', 'resource'), $woptions); $mform->setDefault('windowpopup', empty($CFG->taoresource_popup) ? 1 : 0); $mform->disabledIf('windowpopup', 'forcedownload', 'checked'); $mform->addElement('checkbox', 'framepage', get_string('keepnavigationvisible', 'resource')); $mform->setHelpButton('framepage', array('frameifpossible', get_string('keepnavigationvisible', 'resource'), 'resource')); $mform->setDefault('framepage', 0); $mform->disabledIf('framepage', 'windowpopup', 'eq', 1); $mform->disabledIf('framepage', 'forcedownload', 'checked'); $mform->setAdvanced('framepage'); foreach ($TAORESOURCE_WINDOW_OPTIONS as $option) { if ($option == 'height' or $option == 'width') { $mform->addElement('text', $option, get_string('new' . $option, 'resource'), array('size' => '4')); $mform->setDefault($option, $CFG->{'taoresource_popup' . $option}); $mform->disabledIf($option, 'windowpopup', 'eq', 0); } else { $mform->addElement('checkbox', $option, get_string('new' . $option, 'resource')); $mform->setDefault($option, $CFG->{'taoresource_popup' . $option}); $mform->disabledIf($option, 'windowpopup', 'eq', 0); } $mform->setAdvanced($option); } $mform->addElement('header', 'parameters', get_string('parameters', 'resource')); $options = array(); $options['-'] = get_string('chooseparameter', 'resource') . '...'; $optgroup = ''; foreach ($this->parameters as $pname => $param) { if ($param['value'] == '/optgroup') { $optgroup = ''; continue; } if ($param['value'] == 'optgroup') { $optgroup = $param['langstr']; continue; } $options[$pname] = $optgroup . ' - ' . $param['langstr']; } for ($i = 0; $i < $this->maxparameters; $i++) { $parametername = "parameter{$i}"; $parsename = "parse{$i}"; $group = array(); $group[] =& $mform->createElement('text', $parsename, '', array('size' => '12')); //TODO: accessiblity $group[] =& $mform->createElement('select', $parametername, '', $options); //TODO: accessiblity $mform->addGroup($group, 'pargroup' . $i, get_string('variablename', 'resource') . '=' . get_string('parameter', 'resource'), ' ', false); $mform->setAdvanced('pargroup' . $i); $mform->setDefault($parametername, '-'); } }