public function __construct(\mod_mediagallery\gallery $gallery, $editing = false, $options = array()) { $this->gallery = $gallery; $this->options = $options; $this->editing = $editing; $this->galleryview = $gallery->get_display_settings()->galleryview; foreach (array('page', 'comments', 'mediasize', 'syncstamp', 'nosample', 'focus') as $opt) { if (isset($options[$opt])) { $this->{$opt} = $options[$opt]; } } if ($this->mediasize == self::MEDIASIZE_SM) { $this->mediasizeclass = ' small'; } else { if ($this->mediasize == self::MEDIASIZE_LG) { $this->mediasizeclass = ' large'; } } }
public function create_gallery($record = null) { global $CFG, $USER; $record = (object) (array) $record; $defaults = array('groupid' => 0, 'galleryfocus' => \mod_mediagallery\base::TYPE_IMAGE, 'galleryview' => \mod_mediagallery\gallery::VIEW_GRID, 'userid' => $USER->id, 'mode' => 'standard', 'tags' => ''); if (!isset($record->instanceid)) { throw new coding_exception('instanceid must be present in $record'); } if (!isset($record->name)) { throw new coding_exception('name must be present in $record'); } foreach ($defaults as $key => $value) { if (!isset($record->{$key})) { $record->{$key} = $value; } } return \mod_mediagallery\gallery::create($record); }
$data->instanceid = $data->m; unset($data->m); $data->userid = $USER->id; if ($mediagallery->enforcedefaults) { $data->galleryfocus = $mediagallery->galleryfocus; $data->gridcolumns = $mediagallery->gridcolumns; $data->gridrows = $mediagallery->gridrows; if ($mediagallery->grid && !$mediagallery->carousel) { $data->galleryview = \mod_mediagallery\gallery::VIEW_GRID; } else { if (!$mediagallery->grid && $mediagallery->carousel) { $data->galleryview = \mod_mediagallery\gallery::VIEW_CAROUSEL; } } } $gallery = \mod_mediagallery\gallery::create($data); } redirect(new moodle_url('/mod/mediagallery/view.php', array('g' => $gallery->id, 'editing' => 1))); } else { if ($gallery) { if (!$gallery->user_can_edit()) { print_error('nopermissions', 'error', $pageurl, 'edit gallery'); } $data = $gallery->get_record(); $data->tags = $gallery->get_tags(); foreach ($gallery->get_display_settings() as $key => $value) { $data->{$key} = $value; } $mform->set_data($data); } }
protected function view_grid(gallery $gallery, array $options) { $o = ''; $column = 1; $row = 1; $rowopen = false; $view = $gallery->get_display_settings(); $perpage = $view->gridcolumns * $view->gridrows; $offset = $perpage * $options['page']; $cappos = $gallery->get_collection()->captionposition; $items = $gallery->get_items_by_type(); foreach ($items as $item) { if (!$item->display) { continue; } if ($offset) { $offset--; continue; } if ($column > $view->gridcolumns && $view->gridcolumns != 0) { // Row complete. $o .= html_writer::end_tag('div'); $rowopen = false; $column = 1; $row++; } if ($column == 1) { $o .= html_writer::start_tag('div', array('class' => 'grid_row clearfix')); $rowopen = true; } if ($row > $view->gridrows && $view->gridrows != 0) { // Grid is now full. break; } $url = new moodle_url('/mod/mediagallery/item.php', array('i' => $item->id, 'action' => 'info')); $infoicon = html_writer::tag('div', $this->output->action_icon($url, new pix_icon('i/info', get_string('information', 'mediagallery')), null, array('class' => 'action-icon info')), array('class' => 'info')); $caption = html_writer::tag('div', $infoicon . $item->caption, array('class' => 'caption')); $img = html_writer::empty_tag('img', array('src' => $item->get_image_url_by_type('thumbnail'))); $linkattribs = $this->linkattribs($gallery, $item); $link = html_writer::link($item->get_image_url_by_type('lowres'), $img, $linkattribs); $itemframe = ''; if ($cappos == mcbase::POS_TOP) { $itemframe .= $caption; } $itemframe .= html_writer::tag('div', $link, array('class' => 'item-thumb')); if ($gallery->get_display_settings()->galleryfocus == mcbase::TYPE_AUDIO) { $itemframe .= $this->embed_html($item); } if ($cappos == mcbase::POS_BOTTOM) { $itemframe .= $caption; } $itemframe = html_writer::tag('div', $itemframe, array('class' => 'item-wrapper')); $o .= html_writer::tag('div', $itemframe, array('class' => 'item grid_item', 'data-id' => $item->id, 'data-title' => $item->caption, 'id' => 'gallery_item_' . $item->id)); $this->page->requires->yui_module('moodle-mod_mediagallery-base', 'M.mod_mediagallery.base.add_item_info_modal', array($item->get_metainfo()), null, true); $column++; } if ($rowopen) { $o .= html_writer::end_tag('div'); } $count = count($items); if ($count > $perpage && $perpage != 0) { $url = new moodle_url('/mod/mediagallery/view.php', array('g' => $gallery->id, 'page' => $options['page'])); $o .= $this->output->paging_bar($count, $options['page'], $perpage, $url); } return $o; }