/** * Defines forms elements */ public function definition() { global $CFG; $mform = $this->_form; $mg = $this->_customdata['mediagallery']; $gallery = $this->_customdata['gallery']; $groupmode = $this->_customdata['groupmode']; $groups = $this->_customdata['groups']; $context = $this->_customdata['context']; $tags = $this->_customdata['tags']; $lockfields = false; if ($gallery && $gallery->mode == 'thebox' && !$gallery->is_thebox_creator_or_agent()) { $lockfields = true; } // General settings. $mform->addElement('header', 'general', get_string('general', 'form')); $mform->addElement('text', 'name', get_string('galleryname', 'mediagallery'), array('size' => '64')); if (!empty($CFG->formatstringstriptags)) { $mform->setType('name', PARAM_TEXT); } else { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $mform->addHelpButton('name', 'mediagalleryname', 'mediagallery'); if ($groupmode != NOGROUPS || $groupmode === 'aag') { if (count($groups) > 1) { $opts = array(); $counts = $mg->get_group_gallery_counts(); foreach ($groups as $group) { $manage = has_capability('mod/mediagallery:manage', $context); if (!isset($counts[$group->id]) || $counts[$group->id]->count < $mg->maxgalleries || $mg->maxgalleries == 0 || $manage) { $opts[$group->id] = $group->name; } } $mform->addElement('select', 'groupid', get_string('group'), $opts); $mform->addHelpButton('groupid', 'group', 'mediagallery'); } else { $groupkeys = array_keys($groups); $groupid = !empty($groupkeys) ? $groupkeys[0] : 0; $mform->addElement('hidden', 'groupid', $groupid); $mform->setType('groupid', PARAM_INT); } } // Mode. Normal or YT. $opts = array('standard' => get_string('modestandard', 'mod_mediagallery'), 'youtube' => get_string('modeyoutube', 'mod_mediagallery')); if (get_config('mediagallery', 'disablestandardgallery') || $mg->mode != 'standard') { unset($opts['standard']); } $mform->addElement('select', 'mode', get_string('mode', 'mod_mediagallery'), $opts); $mform->addHelpButton('mode', 'mode', 'mediagallery'); if ($mg->colltype != 'instructor') { $mform->addElement('checkbox', 'contributable', get_string('contributable', 'mod_mediagallery')); $mform->addHelpButton('contributable', 'contributable', 'mediagallery'); } mediagallery_add_tag_field($mform, $tags, false, !$lockfields); if ($lockfields) { $mform->hardFreeze('name'); $mform->hardFreeze('tags'); } // Gallery settings. $mform->addElement('header', 'display', get_string('settingsgallerydisplay', 'mediagallery')); $options = array(\mod_mediagallery\base::TYPE_ALL => get_string('typeall', 'mediagallery'), \mod_mediagallery\base::TYPE_IMAGE => get_string('typeimage', 'mediagallery'), \mod_mediagallery\base::TYPE_VIDEO => get_string('typevideo', 'mediagallery'), \mod_mediagallery\base::TYPE_AUDIO => get_string('typeaudio', 'mediagallery')); $mform->addElement('select', 'galleryfocus', get_string('galleryfocus', 'mediagallery'), $options); $mform->addHelpButton('galleryfocus', 'galleryfocus', 'mediagallery'); $mform->setDefault('galleryfocus', $mg->galleryfocus); $mform->disabledIf('galleryfocus', 'mode', 'eq', 'youtube'); if ($mg->enforcedefaults) { $mform->hardFreeze('galleryfocus'); } $options = array(); if ($mg->grid) { $options[gallery::VIEW_GRID] = get_string('gridview', 'mediagallery'); } if ($mg->carousel) { $options[gallery::VIEW_CAROUSEL] = get_string('carousel', 'mediagallery'); } $mform->addElement('select', 'galleryview', get_string('galleryviewoptions', 'mediagallery'), $options); if ($mg->enforcedefaults && !($mg->grid && $mg->carousel)) { $default = $mg->grid ? gallery::VIEW_GRID : gallery::VIEW_CAROUSEL; $mform->setDefault('galleryview', $default); $mform->hardFreeze('galleryview'); } if (!$mg->enforcedefaults) { if (isset($options[gallery::VIEW_GRID])) { $coloptions = array(0 => get_string('automatic', 'mediagallery'), 1 => 1, 2 => 2, 3 => 3, 4 => 4); $mform->addElement('select', 'gridcolumns', get_string('gridviewcolumns', 'mediagallery'), $coloptions); $mform->disabledIf('gridcolumns', 'galleryview', 'ne', gallery::VIEW_GRID); $mform->setDefault('gridcolumns', $mg->gridcolumns); $rowoptions = array(0 => get_string('automatic', 'mediagallery'), 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10); $mform->addElement('select', 'gridrows', get_string('gridviewrows', 'mediagallery'), $rowoptions); $mform->disabledIf('gridrows', 'galleryview', 'ne', gallery::VIEW_GRID); $mform->setDefault('gridrows', $mg->gridrows); } } else { if ($mg->grid) { $mform->addElement('static', 'gridcolumns', get_string('gridviewcolumns', 'mediagallery'), $mg->gridcolumns); $mform->addElement('static', 'gridrows', get_string('gridviewrows', 'mediagallery'), $mg->gridrows); } } $mform->addHelpButton('galleryview', 'galleryviewoptions', 'mediagallery'); if ($mg->grid) { $mform->addHelpButton('gridcolumns', 'gridviewcolumns', 'mediagallery'); $mform->addHelpButton('gridrows', 'gridviewrows', 'mediagallery'); } // Visibility settings. $mform->addElement('header', 'display', get_string('settingsvisibility', 'mediagallery')); $mform->addElement('date_time_selector', 'visibleinstructor', get_string('visibleinstructor', 'mediagallery'), array('optional' => true)); $mform->addHelpButton('visibleinstructor', 'visibleinstructor', 'mediagallery'); $mform->addElement('date_time_selector', 'visibleother', get_string('visibleother', 'mediagallery'), array('optional' => true)); $mform->addHelpButton('visibleother', 'visibleother', 'mediagallery'); $mform->setDefault('visibleother', time()); $mform->addElement('hidden', 'm', $mg->id); $mform->setType('m', PARAM_INT); $mform->addElement('hidden', 'id'); $mform->setType('id', PARAM_INT); $mform->addElement('hidden', 'source', 'moodle'); $mform->setType('source', PARAM_ALPHA); $mform->hardFreeze('source'); $this->add_action_buttons(); }
/** * 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(); }
/** * Defines forms elements */ public function definition() { global $CFG; $mform = $this->_form; $config = get_config('mediagallery'); // General settings. $mform->addElement('header', 'general', get_string('general', 'form')); $mform->addElement('text', 'name', get_string('mediagalleryname', 'mediagallery'), array('size' => '64')); if (!empty($CFG->formatstringstriptags)) { $mform->setType('name', PARAM_TEXT); } else { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); $mform->addHelpButton('name', 'mediagalleryname', 'mediagallery'); $this->standard_intro_elements(); $opts = array('standard' => get_string('modestandard', 'mod_mediagallery')); if (!empty($config->disablestandardgallery) && (empty($this->_instance) || $this->current->mode == 'thebox')) { unset($opts['standard']); } if (count($opts) == 1) { $key = key($opts); $mform->addElement('hidden', 'mode', $key); $mform->setType('mode', PARAM_ALPHA); $mform->hardFreeze('mode'); } else { $mform->addElement('select', 'mode', get_string('collmode', 'mod_mediagallery'), $opts); $mform->addHelpButton('mode', 'collmode', 'mediagallery'); $mform->disabledIf('mode', 'instance', 'neq', ''); } $options = array('instructor' => get_string('colltypeinstructor', 'mediagallery'), 'contributed' => get_string('colltypecontributed', 'mediagallery'), 'assignment' => get_string('colltypeassignment', 'mediagallery'), 'peerreviewed' => get_string('colltypepeerreviewed', 'mediagallery')); $mform->addElement('select', 'colltype', get_string('colltype', 'mediagallery'), $options); $mform->addHelpButton('colltype', 'colltype', 'mediagallery'); mediagallery_add_tag_field($mform, array(), true); $options = get_max_upload_sizes($CFG->maxbytes, $this->course->maxbytes, 0, $config->maxbytes); $mform->addElement('select', 'maxbytes', get_string('maxbytes', 'mediagallery'), $options); $mform->setDefault('maxbytes', $config->maxbytes); $numbers = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 100); $options = array_merge(array(0 => get_string('unlimited')), $numbers); $mform->addElement('select', 'maxitems', get_string('maxitems', 'mediagallery'), $options); $mform->setType('maxitems', PARAM_INT); $mform->setDefault('maxitems', 0); $mform->addHelpButton('maxitems', 'maxitems', 'mediagallery'); $mform->disabledIf('maxitems', 'colltype', 'eq', 'instructor'); $options = array(0 => get_string('unlimited'), '-1' => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10, 20 => 20, 30 => 30, 40 => 40, 50 => 50, 100 => 100); $mform->addElement('select', 'maxgalleries', get_string('maxgalleries', 'mediagallery'), $options); $mform->setType('maxgalleries', PARAM_INT); $mform->setDefault('maxgalleries', 1); $mform->addHelpButton('maxgalleries', 'maxgalleries', 'mediagallery'); $mform->disabledIf('maxgalleries', 'colltype', 'eq', 'instructor'); if ($CFG->usecomments) { $mform->addElement('selectyesno', 'allowcomments', get_string('allowcomments', 'mediagallery')); $mform->setDefault('allowcomments', 1); $mform->addHelpButton('allowcomments', 'allowcomments', 'mediagallery'); } $mform->addElement('selectyesno', 'allowlikes', get_string('allowlikes', 'mediagallery')); $mform->setDefault('allowlikes', 1); $mform->addHelpButton('allowlikes', 'allowlikes', 'mediagallery'); // Display settings. $mform->addElement('header', 'display', get_string('settingsdisplay', 'mediagallery')); $options = array(0 => get_string('showall', 'mediagallery'), 10 => 10, 25 => 25, 50 => 50, 100 => 100, 200 => 200); $mform->addElement('select', 'thumbnailsperpage', get_string('thumbnailsperpage', 'mediagallery'), $options); $options = array(2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6); $mform->addElement('select', 'thumbnailsperrow', get_string('thumbnailsperrow', 'mediagallery'), $options); $mform->addElement('selectyesno', 'displayfullcaption', get_string('displayfullcaption', 'mediagallery')); $options = array(\mod_mediagallery\base::POS_BOTTOM => get_string('bottom', 'mediagallery'), \mod_mediagallery\base::POS_TOP => get_string('top', 'mediagallery')); $mform->addElement('select', 'captionposition', get_string('captionposition', 'mediagallery'), $options); // Gallery settings. $mform->addElement('header', 'display', get_string('settingsgallery', 'mediagallery')); $typeoptgroup = array(); $typeoptgroup[] = $mform->createElement('radio', 'focus', '', get_string('typeall', 'mediagallery'), \mod_mediagallery\base::TYPE_ALL); $typeoptgroup[] = $mform->createElement('radio', 'focus', '', get_string('typeimage', 'mediagallery'), \mod_mediagallery\base::TYPE_IMAGE); $typeoptgroup[] = $mform->createElement('radio', 'focus', '', get_string('typevideo', 'mediagallery'), \mod_mediagallery\base::TYPE_VIDEO); $typeoptgroup[] = $mform->createElement('radio', 'focus', '', get_string('typeaudio', 'mediagallery'), \mod_mediagallery\base::TYPE_AUDIO); $mform->addGroup($typeoptgroup, 'gallerytypeoptions', get_string('galleryfocus', 'mediagallery')); $mform->addHelpButton('gallerytypeoptions', 'galleryfocus', 'mediagallery'); $mform->addRule('gallerytypeoptions', null, 'required', null, 'client'); $viewoptgroup = array(); $viewoptgroup[] = $mform->createElement('checkbox', 'carousel', '', get_string('carousel', 'mediagallery')); $viewoptgroup[] = $mform->createElement('checkbox', 'grid', '', get_string('gridview', 'mediagallery')); $mform->addGroup($viewoptgroup, 'galleryviewoptions', get_string('galleryviewoptions', 'mediagallery')); $mform->addHelpButton('galleryviewoptions', 'galleryviewoptions', 'mediagallery'); $mform->addRule('galleryviewoptions', null, 'required', null, 'client'); $options = array(0 => get_string('automatic', 'mediagallery'), 1 => 1, 2 => 2, 3 => 3, 4 => 4); $mform->addElement('select', 'gridcolumns', get_string('gridviewcolumns', 'mediagallery'), $options); $mform->addHelpButton('gridcolumns', 'gridviewcolumns', 'mediagallery'); $mform->disabledIf('gridcolumns', 'galleryviewoptions[grid]', 'notchecked'); $mform->setDefault('gridcolumns', 0); $options = array(0 => get_string('automatic', 'mediagallery'), 1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10); $mform->addElement('select', 'gridrows', get_string('gridviewrows', 'mediagallery'), $options); $mform->addHelpButton('gridrows', 'gridviewrows', 'mediagallery'); $mform->disabledIf('gridrows', 'galleryviewoptions[grid]', 'notchecked'); $mform->setDefault('gridrows', 0); $mform->addElement('checkbox', 'enforcedefaults', get_string('enforcedefaults', 'mediagallery')); $mform->addHelpButton('enforcedefaults', 'enforcedefaults', 'mediagallery'); // Availability settings. $mform->addElement('header', 'display', get_string('settingsavailability', 'mediagallery')); $mform->addElement('date_time_selector', 'readonlyfrom', get_string('readonlyfrom', 'mediagallery'), array('optional' => true)); $mform->addElement('date_time_selector', 'readonlyto', get_string('readonlyto', 'mediagallery'), array('optional' => true)); if ($CFG->enableavailability) { $mform->addElement('static', 'restrictavailableinfo', '', get_string('restrictavailableinfo', 'mediagallery')); } $mform->addElement('hidden', 'source', 'moodle'); $mform->setType('source', PARAM_ALPHA); $mform->hardFreeze('source'); $this->standard_coursemodule_elements(); $this->add_action_buttons(); }