/**
  * Defines forms elements
  */
 public function definition()
 {
     global $CFG;
     $mform = $this->_form;
     $gallery = $this->_customdata['gallery'];
     $tags = $this->_customdata['tags'];
     $item = $this->_customdata['item'];
     // General settings.
     $mform->addElement('header', 'general', get_string('general', 'form'));
     $mform->addElement('text', 'caption', get_string('caption', 'mediagallery'), array('size' => '64'));
     $mform->setType('caption', PARAM_TEXT);
     $mform->addRule('caption', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
     $mform->addHelpButton('caption', 'caption', 'mediagallery');
     $options = array('collapsed' => true, 'maxfiles' => 0, 'return_types' => null);
     $mform->addElement('editor', 'description', get_string('description'), null, $options);
     $mform->addElement('selectyesno', 'display', get_string('itemdisplay', 'mediagallery'));
     $mform->setDefault('display', 1);
     $mform->addHelpButton('display', 'itemdisplay', 'mediagallery');
     $mform->addElement('selectyesno', 'thumbnail', get_string('gallerythumbnail', 'mediagallery'));
     $default = $this->_customdata['firstitem'] ? 1 : 0;
     $mform->setDefault('thumbnail', $default);
     $mform->addHelpButton('thumbnail', 'gallerythumbnail', 'mediagallery');
     $mform->addElement('static', 'filecheck', '', get_string('choosecontent', 'mediagallery'));
     if ($gallery->mode == 'standard') {
         $mform->addElement('uploader_standard', 'content', get_string('content', 'mediagallery'), '0', mediagallery_filepicker_options($gallery));
         $mform->addHelpButton('content', 'content', 'mediagallery');
         $fpoptions = mediagallery_filepicker_options($gallery);
         $fpoptions['accepted_types'] = array('web_image');
         $fpoptions['return_types'] = FILE_INTERNAL;
         $mform->addElement('filepicker', 'customthumbnail', get_string('thumbnail', 'mediagallery'), '0', $fpoptions);
         $mform->addHelpButton('customthumbnail', 'thumbnail', 'mediagallery');
     } else {
         if ($gallery->mode == 'youtube') {
             $mform->addElement('limitedurl', 'externalurl', get_string('youtubeurl', 'mediagallery'), array('size' => '60'), array('usefilepicker' => true, 'repo' => 'youtube'));
             $mform->setType('externalurl', PARAM_TEXT);
             $mform->addHelpButton('externalurl', 'externalurl', 'mediagallery');
         } else {
             if ($gallery->mode == 'thebox') {
                 if (empty($item->objectid)) {
                     $mform->addElement('uploader', 'content', get_string('content', 'mediagallery'), '0', array('maxfiles' => 1, 'return_types' => FILE_REFERENCE, 'repo' => 'thebox'));
                     $mform->addHelpButton('content', 'content', 'mediagallery');
                 } else {
                     $mform->removeElement('filecheck');
                     $mform->addElement('static', 'contentlinked', get_string('content', 'mediagallery'), get_string('contentlinkedinfo', 'mediagallery', $item->get_file()->get_filename()));
                     $mform->addHelpButton('contentlinked', 'contentlinked', 'mediagallery');
                 }
             }
         }
     }
     $lockfields = $item && !$item->user_can_edit() ? true : false;
     mediagallery_add_tag_field($mform, $tags, false, !$lockfields);
     if ($lockfields) {
         $mform->hardFreeze('caption');
         $mform->hardFreeze('description');
         $mform->hardFreeze('tags');
     }
     // Advanced settings.
     $mform->addElement('header', 'advanced', get_string('advanced'));
     mediagallery_add_metainfo_fields($mform);
     $mform->addElement('hidden', 'g', $gallery->id);
     $mform->setType('g', PARAM_INT);
     $mform->addElement('hidden', 'id');
     $mform->setType('id', PARAM_INT);
     $mform->addElement('hidden', 'source', 'moodle');
     $mform->setType('source', PARAM_ALPHA);
     $mform->hardFreeze('source');
     $mform->addElement('hidden', 'extpath', '');
     $mform->setType('extpath', PARAM_RAW);
     $mform->addElement('hidden', 'theme_id', '');
     $mform->setType('theme_id', PARAM_ALPHANUMEXT);
     $mform->addElement('hidden', 'copyright_id', '');
     $mform->setType('copyright_id', PARAM_ALPHANUMEXT);
     $mform->addElement('hidden', 'objectid', '');
     $mform->setType('objectid', PARAM_ALPHANUMEXT);
     $this->add_action_buttons();
 }
Example #2
0
}
$PAGE->set_url($pageurl);
$PAGE->set_title(format_string($mediagallery->name));
$PAGE->set_heading(format_string($course->fullname));
$PAGE->set_context($context);
$PAGE->add_body_class('mediagallery-mode-' . $gallery->mode);
if ($gallery) {
    $pageurl = new moodle_url('/mod/mediagallery/view.php', array('g' => $g));
    $navnode = $PAGE->navigation->find($cm->id, navigation_node::TYPE_ACTIVITY);
    if (empty($navnode)) {
        $navnode = $PAGE->navbar;
    }
    $node = $navnode->add(format_string($gallery->name), $pageurl);
    $node->make_active();
}
$fmoptions = mediagallery_filepicker_options($gallery);
$formclass = $bulk ? 'mod_mediagallery_item_bulk_form' : 'mod_mediagallery_item_form';
$tags = \mod_mediagallery\item::get_tags_possible();
$mform = new $formclass(null, array('gallery' => $gallery, 'firstitem' => !$gallery->has_items(), 'tags' => $tags, 'item' => $item));
$fs = get_file_storage();
if ($mform->is_cancelled()) {
    redirect(new moodle_url('/mod/mediagallery/view.php', array('g' => $gallery->id, 'editing' => 1)));
} else {
    if ($data = $mform->get_data()) {
        if ($bulk) {
            $draftid = file_get_submitted_draft_itemid('content');
            $files = $fs->get_area_files(context_user::instance($USER->id)->id, 'user', 'draft', $draftid, 'id DESC', false);
            $storedfile = reset($files);
            \mod_mediagallery\item::create_from_archive($gallery, $storedfile, $data);
        } else {
            $data->description = $data->description['text'];