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';
         }
     }
 }
 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;
 }