NcplaylistController.php 4.37 KB
<?php
/**
 * @package  anc_playlist 
 * @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_Playlist_Adminhtml_NcplaylistController extends Mage_Adminhtml_Controller_Action {

//	private static $customerid;

	public function listAction() {
		$siteBlock = $this->getLayout()->createBlock('anc_playlist/adminhtml_ncplaylist');
		$this->loadLayout()
				->_addContent($siteBlock)
				->renderLayout();
	}

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

	public function indexAction() {
		$this->_initAction();
		$this->renderLayout();
				$this->_redirect(
				'*/*/list',
				array(
					
				)
			);
	}

	public function editAction() {
		$id = $this->getRequest()->getParam('id');

		$model = Mage::getModel('anc_playlist/ncplaylist')->load($id);
		if ($model->getId() || $id == 0) {
			Mage::register('anc_playlist', $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_playlist/adminhtml_ncplaylist_edit'))
					->_addLeft($this->getLayout()
							->createBlock('anc_playlist/adminhtml_ncplaylist_edit_tabs')
			);
			$this->renderLayout();
		} else {
			Mage::getSingleton('adminhtml/session')
					->addError('Test does not exist');
			$this->_redirect('*/*/');
		}
	}

	public function newAction() {
		$this->_forward('edit');
	}

	public function saveAction() {
		if ($this->getRequest()->getPost()) {
			try {
				
				$postData = $this->getRequest()->getPost();

				$testModel = Mage::getModel('anc_playlist/ncplaylist');
				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);
				if ($this->getRequest()->getParam('back')) {
					$this->_redirect(
							'*/*/edit', array(
						'id' => $testModel->getId(),
							)
					);
					return;
				}
				$this->_redirect('*/*/list');
				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_playlist/ncplaylist');
				$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('playlist/form');
	}

}