Skip to content

Commit

Permalink
Add gallery modul and update media modul
Browse files Browse the repository at this point in the history
First version of gallery module
  • Loading branch information
c0r1an committed May 11, 2014
1 parent 83cf171 commit 09a787a
Show file tree
Hide file tree
Showing 34 changed files with 4,259 additions and 67 deletions.
2,458 changes: 2,458 additions & 0 deletions application/libraries/Ilch/Thumbnail.php

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions application/modules/admin/layouts/index.php
Expand Up @@ -421,6 +421,7 @@ class="btn btn-default"
var iframeUrlFile = "<?=$this->getUrl('admin/media/iframe/index/type/file/');?>";
var iframeUrlMedia = "<?=$this->getUrl('admin/media/iframe/index/type/media/');?>";
var iframeSingleUrlImage = "<?=$this->getUrl('admin/media/iframe/index/type/single/');?>";
var iframeSingleUrlGallery = "<?=$this->getUrl('admin/media/iframe/multi/type/multi/');?>";
var ilchMediaPlugin = "<?=$this->getStaticUrl('../application/modules/media/static/js/ilchmedia/');?>";
</script>
</body>
Expand Down
68 changes: 68 additions & 0 deletions application/modules/gallery/config/config.php
@@ -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;';
}
}

Binary file added application/modules/gallery/config/gallery.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
47 changes: 47 additions & 0 deletions application/modules/gallery/controllers/admin/Base.php
@@ -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'))
)
)
);
}
}
78 changes: 78 additions & 0 deletions application/modules/gallery/controllers/admin/gallery.php
@@ -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')));
}
}
}
98 changes: 98 additions & 0 deletions application/modules/gallery/controllers/admin/index.php
@@ -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);
}
}
46 changes: 46 additions & 0 deletions application/modules/gallery/controllers/index.php
@@ -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);
}
}

0 comments on commit 09a787a

Please sign in to comment.