/** * Executes the widget. */ public function run() { $this->_dir = isset($_GET['dir']) ? $_GET['dir'] : null; if (!$this->_dir) { $this->_albums = parent::getAlbums(); $pages = new CPagination(count($this->_albums)); $pages->pageSize = $this->albumsPerPage; $this->_albums = parent::splitImages($this->_albums, $pages->pageSize); } else { $this->_images = parent::getImages($this->_dir); $pages = new CPagination(count($this->_images)); $pages->pageSize = $this->imagesPerPage; $this->_images = parent::splitImages($this->_images, $pages->pageSize); } $this->render('gallery', array('id' => $this->id, 'name' => $this->name, 'showNav' => $this->showNav, 'pages' => $pages, 'displayNumImages' => $this->displayNumImages, 'imagesPerRow' => $this->imagesPerRow, 'albumsPerRow' => $this->albumsPerRow, 'details' => parent::getDetails($this->_dir), 'albums' => $this->_albums, 'images' => $this->_images)); }
/** * Processes any actions and renders the correct view. */ protected function renderManager() { if (isset($_GET['action'])) { switch ($_GET['action']) { case 'cache': /* * Cache manager */ $model = new EGalleryCache(); if (isset($_POST['EGalleryCache'])) { $model->attributes = $_POST['EGalleryCache']; if ($model->validate()) { if ($model->allCaches) { /* * All caches need to be cleared. */ $cachesToClear = null; } else { /* * Caches to clear have been specified, organise * which ones need clearing. */ $cachesToClear = array(); if ($model->albums) { $cachesToClear[] = 'getAlbums'; $cachesToClear[] = 'getTitle'; $cachesToClear[] = 'getImagesSingle'; $cachesToClear[] = 'getImageCount'; } if ($model->images) { $cachesToClear[] = 'getImages'; $cachesToClear[] = 'getImagesSingle'; $cachesToClear[] = 'getImageCount'; } if ($model->details) { $cachesToClear[] = 'getTitle'; $cachesToClear[] = 'getDetails'; $cachesToClear[] = 'getDescription'; $cachesToClear[] = 'getDescriptionSingle'; } } if ($this->clearCaches($cachesToClear)) { Yii::app()->user->setFlash('EGallerySuccess', 'The specified caches have been cleared.'); /* * Reset the $model since it has been finished with, * otherwise we end up with the previously selected * options still selected. */ $model = new EGalleryCache(); } else { // TODO Make better error reporting (tracking) for cache clearing Yii::app()->user->setFlash('EGalleryError', 'Something failed when trying to clear the cache. A better error message will be provided in the future.'); } } } $this->render('galleryManagerCache', array('model' => $model)); break; case 'images': /* * Gallery manager */ if (!$this->_dir) { /* * Main album list */ $this->_albums = parent::getAlbums(); $pages = new CPagination(count($this->_albums)); $pages->pageSize = $this->albumsPerPage; $this->_albums = parent::splitImages($this->_albums, $pages->pageSize); } else { /* * Album selected, image list */ $this->_images = parent::getImages($this->_dir); $pages = new CPagination(count($this->_images)); $pages->pageSize = $this->imagesPerPage; $this->_images = parent::splitImages($this->_images, $pages->pageSize); } $model = new EGalleryImages(); $this->render('galleryManagerImages', array('model' => $model, 'pages' => $pages, 'displayNumImages' => $this->displayNumImages, 'imagesPerRow' => $this->imagesPerRow, 'albumsPerRow' => $this->albumsPerRow, 'details' => parent::getDetails($this->_dir), 'albums' => $this->_albums, 'images' => $this->_images)); break; default: /* * Undefined action */ break 2; } } }