Current File : /home/karenpetzb/application/modules/backoffice/controllers/AnnonceController.php |
<?php
class Backoffice_AnnonceController extends Modules_Backoffice_Controllers_MainController
{
public function init()
{
$this->view->title = "Administration";
$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())
-> addValidator(new Zend_Validate_StringLength(3));
$annonce = new AnnonceContent();
if ($this->getRequest()->getParam('id')) {
$id = (int)$this->getRequest()->getParam('id');
if ($id>0) {
$this->view->populateFormAnnonce = $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'],
'TITRE' => $filter->filter($params['titre']),
'CONTENT' => $params['content'],
'isSHOW' => $params['isshow']
);
if ($validator->isValid($dataAnnonce['TITRE']) &&
$validator->isValid($dataAnnonce['CONTENT'])
) {
try {
$id = (int)$params['id'];
if ( $id > 0) {
$annonce->update($dataAnnonce,'ID = '.$id);
$this->view->messageSuccess = "L'annonce a �t� modifi�e";
$this->view->populateFormAnnonce = $annonce->fetchRow('ID = '.$id);
}
} catch (Zend_Exception $e) {
$this->view->populateFormAnnonce = $dataAnnonce;
$this->log($e->getMessage(),'err');
}
} else {
foreach ($validator->getErrors() as $errorCode) {
$this->view->messageError .= $this->getErrorValidator($errorCode);
}
$this->view->populateFormAnnonce = $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())
-> addValidator(new Zend_Validate_StringLength(3));
//get the form params
$params = $this->_request->getPost();
//Refractor the params
$dataAnnonce = array (
'TITRE' => $filter->filter($params['titre']),
'CONTENT' => $params['content'],
'isSHOW' => $params['isshow']
);
if (
$validator->isValid($dataAnnonce['TITRE']) &&
$validator->isValid($dataAnnonce['CONTENT'])
) {
try {
$annonce = new AnnonceContent();
$annonce->insert($dataAnnonce);
$this->view->messageSuccess = "L'annonce a �t� ajout�e";
} catch (Zend_Exception $e) {
$this->view->populateFormAnnonce = $dataAnnonce;
$this->log($e->getMessage(),'err');
}
} else {
foreach ($validator->getErrors() as $errorCode) {
$this->view->messageError .= $this->getErrorValidator($errorCode);
}
$this->view->populateFormAnnonce = $dataAnnonce;
}
}
$this->_forward('/list');
}
public function listAction()
{
$this->view->titlePage = "Listing des Annonces";
$adminNamespace = $this->getSession();
//Appel model pour listing
$annonces = new AnnonceContent();
$result = $annonces->select()->order('isSHOW ASC')->order('TITRE ASC')->query()->fetchAll();
$this->view->listannonce = $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 AnnonceContent();
$annonce->delete('ID = '.$id);
$this->view->messageSuccess = "L'annonce a �t� supprim�e";
} catch (Zend_Exception $e) {
$this->view->messageError = $e->getMessage();
$this->log($e->getMessage(),'err');
}
}
}
$this->_forward('/list');
}
}
?>