protected function definition() { global $OUTPUT, $PAGE, $COURSE, $CFG, $USER; $mform =& $this->_form; $courseid = $this->_customdata['courseid']; $postid = !empty($this->_customdata['options']->postid) ? $this->_customdata['options']->postid : 0; // Update of save a post. $action = $postid > 0 ? 'updatepost' : 'savepost'; $context = context_course::instance($courseid); // ...get formparameters from cache. $cache = cache::make('format_socialwall', 'postformparams'); $formparams = $cache->get($courseid . '_' . $postid); $loadposteditor = optional_param('loadposteditor', -1, PARAM_INT); if ($loadposteditor != -1) { $formparams['loadposteditor'] = $loadposteditor; // ...remember this setting, if page is reloaded. $cache->set($courseid . '_' . $postid, $formparams); } // ...get errors from cache and set them to elements. $errorcache = cache::make('format_socialwall', 'postformerrors'); if ($errors = $errorcache->get($courseid)) { foreach ($errors as $element => $error) { $mform->setElementError($element, $error['message']); } } $errorcache->delete($courseid); // ... value of this element is set by javascript (postform.js) before submit. $mform->addElement('hidden', 'cmsequence', '', array('id' => 'cmsequence')); $mform->setType('cmsequence', PARAM_TEXT); $mform->setDefault('cmsequence', ''); // ... posttext. $buttongroup = array(); $buttongroup[] = $mform->createElement('submit', 'submitbutton', get_string($action, 'format_socialwall')); if ($action == 'updatepost') { $buttongroup[] = $mform->createElement('cancel'); } $mform->addGroup($buttongroup); // ... htmleditor/texarea to post text. $canposthtml = has_capability('format/socialwall:posthtml', $context); $showeditor = (!empty($formparams['loadposteditor']) and $canposthtml); $params = array('class' => 'sw-texarea', 'id' => 'posttext'); if ($showeditor) { $mform->addElement('editor', 'posttext', get_string('poststatusordnote', 'format_socialwall'), $params); $mform->setType('posttext', PARAM_RAW); if (isset($formparams['posttext'])) { $element = $mform->getElement('posttext'); $element->setValue(array('text' => $formparams['posttext'])); } } else { $mform->addElement('textarea', 'posttext', get_string('poststatusordnote', 'format_socialwall'), $params); $mform->setType('posttext', PARAM_TEXT); if (isset($formparams['posttext'])) { $mform->setDefault('posttext', $formparams['posttext']); } } $postoptions = array(); // ... Select group. $groupmode = groups_get_course_groupmode($COURSE); if ($groupmode == SEPARATEGROUPS and !has_capability('moodle/course:managegroups', $context)) { $allgroups = groups_get_all_groups($courseid, $USER->id); } else { $allgroups = groups_get_all_groups($courseid); } $groupsmenu = array(); $groupsmenu[0] = get_string('allparticipants'); foreach ($allgroups as $gid => $unused) { $groupsmenu[$gid] = format_string($allgroups[$gid]->name); } if (count($groupsmenu) > 0) { $postoptions[] = $mform->createElement('select', 'togroupid', '', $groupsmenu); if (isset($formparams['togroupid'])) { $mform->setDefault('togroupid', $formparams['togroupid']); } } // ... options group. $poststatusmenu = array(0 => get_string('poststatus', 'format_socialwall')); if (has_capability('format/socialwall:makesticky', $context)) { $poststatusmenu[1] = get_string('makesticky', 'format_socialwall'); } if (has_capability('format/socialwall:postprivate', $context)) { $poststatusmenu[2] = get_string('privatepost', 'format_socialwall'); } if ($PAGE->user_allowed_editing()) { $poststatusmenu[4] = get_string('makealert', 'format_socialwall'); } if (count($poststatusmenu) > 1) { $postoptions[] = $mform->createElement('select', 'poststatus', '', $poststatusmenu); if (isset($formparams['poststatus'])) { $mform->setDefault('poststatus', $formparams['poststatus']); } } // ...switch htmleditor on/off. if ($canposthtml) { $key = !empty($formparams['loadposteditor']) ? 'turneditoroff' : 'turneditoron'; $postoptions[] = $mform->createElement('submit', $key, get_string($key, 'format_socialwall')); } if (count($postoptions) > 0) { $mform->addGroup($postoptions); } // ... display the activites prepared for the next post only by a teacher. if ($PAGE->user_allowed_editing()) { if (!isset($USER->editing) or !$USER->editing) { $addstr = get_string('addactivityresource', 'format_socialwall'); $mform->addElement('submit', 'turneditingon', $addstr, array('id' => 'sw-addactivitylink')); } } else { $o = html_writer::tag('div', '', array('class' => 'clearfix')); $mform->addElement('html', $o); // ...upload options for all users, which cannot edit page. $attachgroup = array(); $course = course_get_format($COURSE)->get_course(); $canpostfile = has_capability('format/socialwall:postfile', $context) && !empty($course->enablestudentupload); if ($canpostfile) { $uploadfileicon = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('icon', 'resource'))); $linktext = $uploadfileicon . get_string('uploadafile', 'format_socialwall'); $url = new moodle_url('/course/view.php', array('id' => $courseid, 'loadfilemanager' => 1)); $link = html_writer::link($url, $linktext, array('id' => 'uploadfile')); $attachgroup[] = $mform->createElement('static', 'uploadfile', '', $link); } $canposturl = has_capability('format/socialwall:posturl', $context) && !empty($course->enablestudentupload); if ($canposturl) { $addlinkicon = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('icon', 'url'))); $at = html_writer::link('#', $addlinkicon . get_string('addalink', 'format_socialwall'), array('id' => 'addalink')); $attachgroup[] = $mform->createElement('static', 'addalink', '', $at); } if (!empty($attachgroup)) { $mform->addGroup($attachgroup); } $loadfilemanager = optional_param('loadfilemanager', 0, PARAM_INT); if ($canpostfile and $loadfilemanager == 1) { $mform->addElement('html', html_writer::start_div('', array('id' => 'fileswrapper'))); // ... filemanager. $filemanageroptions = array(); $filemanageroptions['accepted_types'] = '*'; $filemanageroptions['maxbytes'] = 0; $filemanageroptions['maxfiles'] = 1; $filemanageroptions['mainfile'] = true; $mform->addElement('filemanager', 'files', get_string('selectfiles'), array(), $filemanageroptions); $mform->addElement('html', html_writer::end_div()); $mform->addElement('hidden', 'loadfilemanager', '1', array('id' => 'loadfilemanager')); $mform->setType('loadfilemanager', PARAM_INT); } // ...external url. $style = isset($errors['externalurl']) ? 'display:auto' : 'display:none'; $mform->addElement('html', html_writer::start_div('', array('id' => 'externalurlwrapper', 'style' => $style))); $mform->addElement('url', 'externalurl', get_string('externalurl', 'url'), array('size' => '60'), array('usefilepicker' => true)); $mform->setType('externalurl', PARAM_URL); if (isset($errors['externalurl'])) { $mform->setDefault('externalurl', $errors['externalurl']['value']); } // ... get urlresource filter a try. $filters = filter_get_active_in_context($context); if (isset($filters['urlresource'])) { require_once $CFG->dirroot . '/filter/urlresource/lib.php'; filter_url_resource_helper::add_postformfields($mform, $courseid); } $mform->addElement('html', html_writer::end_div()); } // Id of post to remember the update option for further pageloads. $mform->addElement('hidden', 'id', 0, array('id' => 'id')); $mform->setType('id', PARAM_INT); $mform->setDefault('id', $postid); // Id of course we are in. $mform->addElement('hidden', 'courseid'); $mform->setType('courseid', PARAM_INT); $mform->setDefault('courseid', $courseid); $mform->addElement('hidden', 'action', $action); $mform->setType('action', PARAM_TEXT); $mform->disable_form_change_checker(); }