AlbumController.php 4.76 KB
<?php
/**
 * @package  anc_album
 * @category magento
 * @mailto	code [at] netz.coop
 * @author	netz.coop eG* 
 * @copyright (c) 2014, netz.coop eG
 * 
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */ 

class Anc_Album_Adminhtml_AlbumController extends Mage_Adminhtml_Controller_Action {

//	private static $customerid;

	public function listAction() {
//		D::ulli('list', 1);
		$admin_id = Mage::getSingleton('admin/session')->getUser()->getId();
//		D::li('$admin_id: '.$admin_id,1,1);		
//		Mage::helper('anc_image/ncimage')->printAdminId();
		$albumBlock = $this->getLayout()->createBlock('anc_album/adminhtml_albums');
		$this->loadLayout()
				->_addContent($albumBlock)
				->renderLayout();
	}

	protected function _initAction() {
		$this->loadLayout()->_setActiveMenu('anc_album/ANC')
				->_addBreadcrumb('test Manager', 'test Manager');
		return $this;
	}

	public function indexAction() {
//		D::ulli('index', 1);
		$this->_initAction();
		$this->renderLayout();
		/**
		 * go to listAction
		 */
		$this->_redirect(
				'*/*/list', array(
//					'id' => $oModel->getId(),
//					'store' => $sStoreId
				)
		);
	}

	public function editAction() {
//		D::ulli('edit', 1);
		$id = $this->getRequest()->getParam('id');
//		if (!$id){
//			$id=2;
//		}
		$model = Mage::getModel('anc_album/ncalbum')->load($id);
		if ($model->getId() || $id == 0) {
			Mage::register('anc_album', $model);
			$this->loadLayout();
			$this->_setActiveMenu('test/set_time');
			$this->_addBreadcrumb('test Manager', 'test Manager');
			$this->_addBreadcrumb('Test Description', 'Test Description');
			$this->getLayout()->getBlock('head')
					->setCanLoadExtJs(true);
			$this->_addContent($this->getLayout()
							->createBlock('anc_album/adminhtml_albums_edit'))
					->_addLeft($this->getLayout()
							->createBlock('anc_album/adminhtml_albums_edit_tabs')
			);
			$this->renderLayout();
		} else {
			Mage::getSingleton('adminhtml/session')
					->addError('Test does not exist');
			$this->_redirect('*/*/');
		}
	}

	public function newAction() {
		D::ulli('new', 1);
		$this->_forward('edit');
	}

	public function saveAction() {
//		D::ulli('Save', 1);



		if ($this->getRequest()->getPost()) {
			try {

				$postData = $this->getRequest()->getPost();
				D::s($postData, '$postDataAlbum', 5, 1);
				$testModel = Mage::getModel('anc_album/ncalbum');
				if ($this->getRequest()->getParam('id') <= 0)
					$testModel->setCreatedTime(
							Mage::getSingleton('core/date')
									->gmtDate()
					);
				$testModel
						->addData($postData)
						->setUpdateTime(
								Mage::getSingleton('core/date')
								->gmtDate())
						->setId($this->getRequest()->getParam('id'))
						->save();
				Mage::getSingleton('adminhtml/session')
						->addSuccess('successfully saved');
				Mage::getSingleton('adminhtml/session')
						->settestData(false);
				$this->_redirect('*/*/list');
				/**
				 * Für save and continue
				 */
				if ($this->getRequest()->getParam('back')) {
					$this->_redirect(
							'*/*/edit', array(
						'id' => $testModel->getId(),
							)
					);
					return;
				}


				return;
			} catch (Exception $e) {
				Mage::getSingleton('adminhtml/session')
						->addError($e->getMessage());
				Mage::getSingleton('adminhtml/session')
						->settestData($this->getRequest()
								->getPost()
				);
				$this->_redirect('*/*/edit', array('id' => $this->getRequest()
							->getParam('id')));
				return;
			}
		}
		$this->_redirect('*/*/');
	}

	public function deleteAction() {
		if ($this->getRequest()->getParam('id') > 0) {
			try {
				$testModel = Mage::getModel('anc_album/ncalbum');
				$testModel->setId($this->getRequest()
								->getParam('id'))
						->delete();
				Mage::getSingleton('adminhtml/session')
						->addSuccess('successfully deleted');
				$this->_redirect('*/*/');
				$this->_redirect('*/*/list');
			} catch (Exception $e) {
				Mage::getSingleton('adminhtml/session')
						->addError($e->getMessage());
				$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
			}
		}
		$this->_redirect('*/*/list');
//		$this->_redirect('*/*/');
	}

	protected function _isAllowed() {
		return Mage::getSingleton('admin/session')->isAllowed('album/form');
	}

}