/** * The admin listing version for galleries. * * Will simply display a list of gallery albums on the system. * * @return mixed */ public function admin() { $view = $this->getView(); if (!$this->setAccess('p:gallery_manage')) { return View::ERROR_ACCESSDENIED; } $albums = GalleryAlbumModel::Find(null, null, 'title'); $view->mastertemplate = 'admin'; $view->title = 'Gallery Albums Administration'; $view->assignVariable('albums', $albums); $view->addControl('Gallery Albums', '/gallery', 'directory'); $view->addControl('Add Album', '/gallery/create', 'add'); $view->addControl('Edit Gallery Listing Page', '/gallery/updatelisting', 'edit'); }
<?php // Load the necessary files to do this require_once ROOT_PDIR . 'components/gallery/models/GalleryAlbumModel.php'; $albums = GalleryAlbumModel::Find(null, null, null); foreach ($albums as $album) { /** @var $album GalleryAlbumModel */ // Set this album's cached title from the page. $album->set('title', $album->getLink('Page')->get('title')); $album->save(); }
/** * Page for creating and updating a gallery widget */ public function update() { $view = $this->getView(); $request = $this->getPageRequest(); if (!\Core\user()->checkAccess('p:/gallery/manage_all')) { return View::ERROR_ACCESSDENIED; } if ($request->getParameter(0)) { $model = new WidgetModel('/gallery/view/' . $request->getParameter(0)); } else { $model = new WidgetModel(); } // The settings and their default values $defaults = array('album' => '', 'count' => 5, 'order' => 'weight', 'dimensions' => '100x75', 'uselightbox' => false); $settings = array(); foreach ($defaults as $key => $def) { $settings[$key] = $model->getSetting($key) ? $model->getSetting($key) : $def; } $isnew = !$model->exists(); $form = new Form(); $form->set('callsmethod', 'GalleryFormHandler::SaveWidgetHandler'); $form->addElement('system', array('name' => 'id', 'value' => $request->getParameter(0))); $form->addElement('text', array('name' => 'title', 'required' => true, 'title' => 'Widget Title', 'value' => $model->get('title'), 'description' => 'Just the identifying title used on admin pages.')); // The options herein are pic the gallery to display from, // pick how many images to show, // and order to retrieve them. $albums = GalleryAlbumModel::Find(null, null, 'title'); $albumopts = array('' => 'All Galleries'); foreach ($albums as $album) { $albumopts[$album->get('id')] = $album->get('title'); } $form->addElement('select', array('name' => 'album', 'value' => $settings['album'], 'title' => 'Gallery Album', 'options' => $albumopts)); $form->addElement('select', array('name' => 'count', 'title' => 'Number of thumbnails', 'value' => $settings['count'], 'options' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20))); $form->addElement('select', array('name' => 'order', 'title' => 'Order By', 'value' => $settings['order'], 'options' => array('weight' => 'Standard Order', 'created desc' => 'Date (Newest First)', 'random' => 'Random'))); $form->addElement('text', array('name' => 'dimensions', 'title' => 'Thumbnail Dimensions', 'value' => $settings['dimensions'], 'description' => 'Enter the desired thumbnail dimensions, in the format of (for example), 100x75, width then height separated by an "x" and no spaces.')); if (Core::IsComponentAvailable('jquery-lightbox')) { $form->addElement('checkbox', array('name' => 'uselightbox', 'checked' => $settings['uselightbox'], 'value' => 1, 'title' => 'Use Lightbox', 'description' => 'Check to open images in a lightbox window for quick previewing.')); } else { $form->addElement('hidden', array('name' => 'uselightbox', 'value' => 0)); } $form->addElement('submit', array('value' => ($isnew ? 'Create' : 'Update') . ' Widget')); $view->templatename = 'pages/gallerywidget/update.tpl'; $view->mastertemplate = 'admin'; $view->title = ($isnew ? 'Create' : 'Update') . ' Gallery Widget'; $view->assign('form', $form); $view->addControl('Gallery Widgets', '/gallerywidget/admin', 'directory'); }