Current File : /home/karenpetzb/application/modules/backoffice/controllers/AnnoncefrontController.php
<?php
class Backoffice_AnnoncefrontController extends Modules_Backoffice_Controllers_MainController
{

	public function init()
	{
		$this->view->title = "Administration";
		$this->view->currentMenu = "AnnonceFront";
		$this->isConnectedWithRole('isPromo');
	}
	public function indexAction()
	{
		$this->_forward('/list');
	}

	public function editAction()
	{
			
		$this->view->titlePage = "Modifier une annonce";
		$this->view->messageSuccess = "";
		$this->view->messageError = "";
			
		//filtres pour changer les chaines
		$filter = new Zend_Filter();
		$filter	->addFilter(new Zend_Filter_StripTags())
		->addFilter(new Zend_Filter_StringTrim());

		//valideurs pour les chaines
		$validator = new Zend_Validate();
		$validator -> addValidator(new Zend_Validate_NotEmpty());

		$annonce = new AnnonceFrontHeader();
		if ($this->getRequest()->getParam('id')) {
			$id = (int)$this->getRequest()->getParam('id');
			if ($id>0) {
				$this->view->populateFormAnnonceFront = $annonce->fetchRow('ID = '.$id);
			}
		}
		if ($this->getRequest()->isPost()) {

			//get the form params
			$params = $this->_request->getPost();

			//Refractor the params
			$dataAnnonce = array (
			 		'ID' => (int)$params['id'],
			 		'NOM' => $filter->filter($params['nom']),
			 		'CONTENT' => $params['content'],
			 		'isSHOW' => $params['isshow']
					);

					if ($validator->isValid($dataAnnonce['NOM']) &&
					$validator->isValid($dataAnnonce['CONTENT'])
					) {
						try {
							$id = (int)$params['id'];
							if ( $id > 0) {
									
								$annonce->update($dataAnnonce,'ID = '.$id);
								$this->view->messageSuccess = "L'information a �t� modifi�e";
								$this->view->populateFormAnnonceFront = $annonce->fetchRow('ID = '.$id);
								$this->log("L'information a �t� modifi�e ".$id,'info');
							}
						} catch (Zend_Exception $e) {
							$this->log($e->getMessage(),'err');
							$this->view->populateFormAnnonceFront = $dataAnnonce;
						}
					} else {
						foreach ($validator->getErrors() as $errorCode) {
							$this->view->messageError =  $this->getErrorValidator($errorCode);
						}
						$this->view->populateFormAnnonceFront = $dataAnnonce;
					}

		}
		$this->_forward('/list');
	}


	public function addAction()
	{
			
		$this->view->titlePage = "Ajouter une annonce";
		$this->view->messageSuccess = "";
		$this->view->messageError = "";

		if ($this->_request->isPost()) {

			//filtres pour changer les chaines
			$filter = new Zend_Filter();
			$filter	->addFilter(new Zend_Filter_StripTags())
			->addFilter(new Zend_Filter_StringTrim());

			//valideurs pour les chaines
			$validator = new Zend_Validate();
			$validator -> addValidator(new Zend_Validate_NotEmpty());


			//get the form params
			$params = $this->_request->getPost();

			//Refractor the params
			$dataAnnonce = array (
			 		'NOM' => $filter->filter($params['nom']),
			 		'CONTENT' => $params['content'],
			 		'isSHOW' => $params['isshow']
					);
					if (
					$validator->isValid($dataAnnonce['NOM']) &&
					$validator->isValid($dataAnnonce['CONTENT'])
					) {
						try {
							$annonce = new AnnonceFrontHeader();
							$annonce->insert($dataAnnonce);
							$this->view->messageSuccess = "L'information a �t� ajout�e";
							$this->log("L'information a �t� ajout�e",'info');
						} catch (Zend_Exception $e) {
							$this->log($e->getMessage(),'err');
							$this->view->populateFormAnnonceFront = $dataAnnonce;
						}

					} else {
						foreach ($validator->getErrors() as $errorCode) {
							$this->view->messageError .=  $this->getErrorValidator($errorCode);
						}
						$this->view->populateFormAnnonceFront = $dataAnnonce;
					}

		}
		$this->_forward('/list');
	}

	public function listAction()
	{
		$this->view->titlePage = "Gestion des informations sur la page d'accueil"; 
		
		//Appel model pour listing
		$annonces = new AnnonceFrontHeader();
		$result = $annonces->getAllAnnonces();
			
		$this->view->listannoncefront = $result;
	}



	public function delAction() {

		$this->view->messageSuccess = "";
		$this->view->messageError = "";

		if($this->_request->getParam('id')) {
			$id = (int)$this->_request->getParam('id');
			if ($id > 0) {
				try {
					$annonce = new AnnonceFrontHeader();

					$annonce->delete('ID = '.$id);
					$this->view->messageSuccess = "L'information a �t� supprim�e";

					$this->log("L'information a �t� supprim�e",'info');
				} catch (Zend_Exception $e) {
					$this->log($e->getMessage(),'err');
					$this->view->messageError = $e->getMessage();
				}
			}
		}
		$this->_forward('/list');
	}

}
?>