Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add gallery modul and update media modul
First version of gallery module
- Loading branch information
Showing
34 changed files
with
4,259 additions
and
67 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
/** | ||
* Holds Gallery\Config\Config. | ||
* | ||
* @copyright Ilch 2.0 | ||
* @package ilch | ||
*/ | ||
|
||
namespace Gallery\Config; | ||
defined('ACCESS') or die('no direct access'); | ||
|
||
class Config extends \Ilch\Config\Install | ||
{ | ||
public $config = array | ||
( | ||
'key' => 'gallery', | ||
'system_module' => true, | ||
'icon_small' => 'gallery.png', | ||
'languages' => array | ||
( | ||
'de_DE' => array | ||
( | ||
'name' => 'Galerie', | ||
'description' => 'Hier kann die Galerie verwaltet werden.', | ||
), | ||
'en_EN' => array | ||
( | ||
'name' => 'Gallery', | ||
'description' => 'Here you can manage the gallery', | ||
), | ||
) | ||
); | ||
|
||
public function install() | ||
{ | ||
$this->db()->queryMulti($this->getInstallSql()); | ||
} | ||
|
||
public function uninstall() | ||
{ | ||
$this->db()->queryMulti('DROP TABLE `[prefix]_gallery_imgs`'); | ||
$this->db()->queryMulti('DROP TABLE `[prefix]_gallery_items`'); | ||
} | ||
|
||
public function getInstallSql() | ||
{ | ||
return 'CREATE TABLE IF NOT EXISTS `[prefix]_gallery_imgs` | ||
( | ||
`id` int(11) NOT NULL AUTO_INCREMENT, | ||
`image_id` varchar(150) COLLATE utf8_unicode_ci NOT NULL , | ||
`cat` mediumint(9) COLLATE utf8_unicode_ci NOT NULL DEFAULT 0, | ||
PRIMARY KEY (`id`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ; | ||
CREATE TABLE IF NOT EXISTS `[prefix]_gallery_items` | ||
( | ||
`id` int(11) NOT NULL AUTO_INCREMENT, | ||
`gallery_id` int(11) NOT NULL, | ||
`sort` int(11) NOT NULL, | ||
`parent_id` int(11) NOT NULL, | ||
`type` int(11) NOT NULL, | ||
`title` varchar(255) COLLATE utf8_unicode_ci NOT NULL, | ||
`description` varchar(255) COLLATE utf8_unicode_ci NOT NULL, | ||
PRIMARY KEY (`id`) | ||
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;'; | ||
} | ||
} | ||
|
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
/** | ||
* Holds the class Index. | ||
* | ||
* @copyright Ilch 2.0 | ||
* @package ilch | ||
*/ | ||
|
||
namespace Gallery\Controllers\Admin; | ||
|
||
defined('ACCESS') or die('no direct access'); | ||
|
||
/** | ||
* Handles the init for the gallery module. | ||
* | ||
* @copyright Ilch 2.0 | ||
* @package ilch | ||
*/ | ||
class Base extends \Ilch\Controller\Admin | ||
{ | ||
/** | ||
* Initializes the menu. | ||
*/ | ||
public function init() | ||
{ | ||
$active = array(); | ||
|
||
foreach(array('index', 'gallery') as $controllerName) { | ||
$active[$controllerName] = (boolean)($this->getRequest()->getControllerName() == $controllerName); | ||
} | ||
|
||
$this->getLayout()->addMenu | ||
( | ||
'menuGallery', | ||
array | ||
( | ||
array | ||
( | ||
'name' => 'menuGallery', | ||
'active' => $active['index'] or $active['gallery'], | ||
'icon' => 'fa fa-th', | ||
'url' => $this->getLayout()->getUrl(array('controller' => 'index', 'action' => 'index')) | ||
) | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
/** | ||
* @copyright Ilch 2.0 | ||
* @package ilch | ||
*/ | ||
|
||
namespace Gallery\Controllers\Admin; | ||
|
||
use Gallery\Mappers\Image as ImageMapper; | ||
use Gallery\Mappers\Gallery as GalleryMapper; | ||
use Gallery\Controllers\Admin\Base as BaseController; | ||
|
||
defined('ACCESS') or die('no direct access'); | ||
|
||
class Gallery extends BaseController | ||
{ | ||
public function init() | ||
{ | ||
parent::init(); | ||
$this->getLayout()->addMenuAction | ||
( | ||
array | ||
( | ||
'name' => 'menuActionGalleryInsertImage', | ||
'icon' => 'fa fa-plus-circle', | ||
'url' => 'javascript:media();' | ||
) | ||
); | ||
} | ||
|
||
public function indexAction() | ||
{ | ||
|
||
} | ||
|
||
public function treatGalleryAction() | ||
{ | ||
$imagemapper = new ImageMapper(); | ||
$pagination = new \Ilch\Pagination(); | ||
$gallerymapper = new GalleryMapper(); | ||
$id = $this->getRequest()->getParam('id'); | ||
$galleryTitle = $gallerymapper->getGalleryById($id); | ||
|
||
if ($this->getRequest()->getPost('action') == 'delete') { | ||
foreach($this->getRequest()->getPost('check_gallery') as $imageId) { | ||
$imagemapper->deleteById($imageId); | ||
} | ||
$this->addMessage('deleteSuccess'); | ||
$this->redirect(array('action' => 'treatgallery','id' => $id)); | ||
} | ||
|
||
if ($this->getRequest()->getPost()) { | ||
foreach($this->getRequest()->getPost('check_image') as $imageId ) { | ||
$catId = $this->getRequest()->getParam('id'); | ||
$model = new \Gallery\Models\Image(); | ||
$model->setImageId($imageId); | ||
$model->setCat($catId); | ||
$imagemapper->save($model); | ||
} | ||
} | ||
$pagination->setPage($this->getRequest()->getParam('page')); | ||
$this->getView()->set('image', $imagemapper->getImageByGalleryId($id, $pagination)); | ||
$this->getView()->set('pagination', $pagination); | ||
$this->getView()->set('galleryTitle', $galleryTitle->getTitle()); | ||
} | ||
|
||
public function delAction() | ||
{ | ||
if ($this->getRequest()) { | ||
$imageMapper = new ImageMapper(); | ||
$id = $this->getRequest()->getParam('id'); | ||
$imageMapper->deleteById($id); | ||
|
||
$this->addMessage('deleteSuccess'); | ||
$this->redirect(array('action' => 'treatgallery','id' => $this->getRequest()->getParam('gallery'))); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?php | ||
/** | ||
* @copyright Ilch 2.0 | ||
* @package ilch | ||
*/ | ||
|
||
namespace Gallery\Controllers\Admin; | ||
|
||
use Gallery\Mappers\Gallery as GalleryMapper; | ||
use Gallery\Controllers\Admin\Base as BaseController; | ||
|
||
defined('ACCESS') or die('no direct access'); | ||
|
||
class Index extends BaseController | ||
{ | ||
public function indexAction() | ||
{ | ||
$gallerymapper = new GalleryMapper(); | ||
|
||
/* | ||
* Saves the item tree to database. | ||
*/ | ||
if ($this->getRequest()->isPost()) { | ||
if ($this->getRequest()->getPost('save')) { | ||
$sortItems = json_decode($this->getRequest()->getPost('hiddenMenu')); | ||
$items = $this->getRequest()->getPost('items'); | ||
$oldItems = $gallerymapper->getGalleryItems(1); | ||
|
||
/* | ||
* Deletes old entries from database. | ||
*/ | ||
if (!empty($oldItems)) { | ||
foreach ($oldItems as $oldItem) { | ||
if (!isset($items[$oldItem->getId()])) { | ||
$gallerymapper->deleteItem($oldItem); | ||
} | ||
} | ||
} | ||
|
||
if ($items) { | ||
$sortArray = array(); | ||
|
||
foreach ($sortItems as $sortItem) { | ||
if ($sortItem->item_id !== null) { | ||
$sortArray[$sortItem->item_id] = (int)$sortItem->parent_id; | ||
} | ||
} | ||
|
||
foreach ($items as $item) { | ||
$galleryItem = new \Gallery\Models\GalleryItem; | ||
|
||
if (strpos($item['id'], 'tmp_') !== false) { | ||
$tmpId = str_replace('tmp_', '', $item['id']); | ||
} else { | ||
$galleryItem->setId($item['id']); | ||
} | ||
|
||
$galleryItem->setGalleryId(1); | ||
$galleryItem->setType($item['type']); | ||
$galleryItem->setTitle($item['title']); | ||
$galleryItem->setDesc($item['desc']); | ||
$newId = $gallerymapper->saveItem($galleryItem); | ||
|
||
if (isset($tmpId)) { | ||
foreach ($sortArray as $id => $parentId) { | ||
if ($id == $tmpId) { | ||
unset($sortArray[$id]); | ||
$sortArray[$newId] = $parentId; | ||
} | ||
|
||
if ($parentId == $tmpId) { | ||
$sortArray[$id] = $newId; | ||
} | ||
} | ||
} | ||
} | ||
|
||
$sort = 0; | ||
|
||
foreach ($sortArray as $id => $parent) { | ||
$galleryItem = new \Gallery\Models\GalleryItem(); | ||
$galleryItem->setId($id); | ||
$galleryItem->setSort($sort); | ||
$galleryItem->setParentId($parent); | ||
$gallerymapper->saveItem($galleryItem); | ||
$sort += 10; | ||
} | ||
} | ||
} | ||
|
||
$this->addMessage('saveSuccess'); | ||
} | ||
|
||
$galleryItems = $gallerymapper->getGalleryItemsByParent(1, 0); | ||
$this->getView()->set('galleryItems', $galleryItems); | ||
$this->getView()->set('gallerymapper', $gallerymapper); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
* @copyright Ilch 2.0 | ||
* @package ilch | ||
*/ | ||
|
||
namespace Gallery\Controllers; | ||
|
||
use Gallery\Mappers\Gallery as GalleryMapper; | ||
use Gallery\Mappers\Image as ImageMapper; | ||
|
||
defined('ACCESS') or die('no direct access'); | ||
|
||
class Index extends \Ilch\Controller\Frontend | ||
{ | ||
public function indexAction() | ||
{ | ||
$this->getLayout()->getHmenu() | ||
->add($this->getTranslator()->trans('menuGalleryOverview'), array('action' => 'index')); | ||
$galleryMapper = new GalleryMapper(); | ||
$galleryItems = $galleryMapper->getGalleryItemsByParent(1, 0); | ||
$this->getView()->set('galleryItems', $galleryItems); | ||
|
||
$this->getView()->set('galleryMapper', $galleryMapper); | ||
} | ||
|
||
public function showAction() | ||
{ | ||
$imagemapper = new ImageMapper(); | ||
$pagination = new \Ilch\Pagination(); | ||
$galleryMapper = new GalleryMapper(); | ||
$id = $this->getRequest()->getParam('id'); | ||
$gallery = $galleryMapper->getGalleryById($id); | ||
|
||
|
||
|
||
$this->getLayout()->getHmenu() | ||
->add($this->getTranslator()->trans('menuGalleryOverview'), array('action' => 'index')) | ||
->add($gallery->getTitle(), array('action' => 'show', 'id' => $id)); | ||
|
||
$pagination->setPage($this->getRequest()->getParam('page')); | ||
|
||
$this->getView()->set('image', $imagemapper->getImageByGalleryId($id, $pagination)); | ||
$this->getView()->set('pagination', $pagination); | ||
} | ||
} |
Oops, something went wrong.