Current File : /home/karenpetzb/application/modules/backoffice/controllers/AnnoncecmsController.php |
<?php
class Backoffice_AnnoncecmsController extends Modules_Backoffice_Controllers_MainController
{
public function init()
{
$this->view->title = "Administration";
$this->view->currentMenu = "AnnonceCms";
$this->isConnectedWithRole('isCategory');
}
public function indexAction()
{
$this->_forward('/list');
}
public function editAction()
{
$this->view->titlePage = "Modifier un article";
//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 AnnonceCms();
if ($this->getRequest()->getParam('id')) {
$id = (int)$this->getRequest()->getParam('id');
if ($id>0) {
$this->view->populateFormAnnonceCms = $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'],
'CONTENT_SHORT' => $filter->filter($params['content_short']),
'CONTENT_LONG' => $params['content_long'],
'POSITION' => (int) $filter->filter($params['position']),
'isSHOW' => $params['isshow'],
'ID_CATS' => ''
);
if (isset($params['categories'])) {
foreach($params['categories'] as $value)
{
$dataAnnonce['ID_CATS'] .= ":".$value.":";
}
}
if ($validator->isValid($dataAnnonce['NOM']) &&
$validator->isValid($dataAnnonce['CONTENT'])&&
!empty($dataAnnonce['ID_CATS'])
) {
try {
$id = (int)$params['id'];
if ( $id > 0) {
$annonce->update($dataAnnonce,'ID = '.$id);
$this->view->messageSuccess = "L'article a �t� modifi�";
$this->view->populateFormAnnonceCms = $annonce->fetchRow('ID = '.$id);
$this->log("L'article a �t� modifi� ".$id,'info');
}
} catch (Zend_Exception $e) {
$this->log($e->getMessage(),'err');
$this->view->populateFormAnnonceCms = $dataAnnonce;
}
} else {
foreach ($validator->getErrors() as $errorCode) {
$this->view->messageError .= $this->getErrorValidator($errorCode);
}
$this->view->populateFormAnnonceCms = $dataAnnonce;
}
}
}
public function addAction()
{
$this->view->titlePage = "Ajouter un article";
$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 (
'NOM' => $filter->filter($params['nom']),
'CONTENT' => $params['content'],
'CONTENT_SHORT' => $filter->filter($params['content_short']),
'CONTENT_LONG' => $params['content_long'],
'POSITION' => (int) $filter->filter($params['position']),
'isSHOW' => $params['isshow'],
'ID_CATS' => ''
);
if (isset($params['categories'])) {
foreach($params['categories'] as $value)
{
$dataAnnonce['ID_CATS'] .= ":".$value.":";
}
}
if (
$validator->isValid($dataAnnonce['NOM']) &&
$validator->isValid($dataAnnonce['CONTENT']) &&
!empty($dataAnnonce['ID_CATS'])
) {
try {
$annonce = new AnnonceCms();
$annonce->insert($dataAnnonce);
$this->view->messageSuccess = "L'article a �t� ajout�";
$this->log("L'article a �t� ajout�",'info');
$lastid = $annonce->getAdapter()->lastInsertId();
$this->_request->setParam('id', $lastid);
$this->_forward('/edit');
} catch (Zend_Exception $e) {
$this->log($e->getMessage(),'err');
$this->view->populateFormAnnonceCms = $dataAnnonce;
}
} else {
foreach ($validator->getErrors() as $errorCode) {
$this->view->messageError .= $this->getErrorValidator($errorCode);
}
$this->view->populateFormAnnonceCms = $dataAnnonce;
}
}
}
public function listAction()
{
$this->view->titlePage = "Gestion des articles";
//Appel model pour listing
$annonces = new AnnonceCms();
$result = $annonces->getAllAnnonces();
$category = new Category();
$this->view->listallcategories = $category->getAllCategoriesByID(0);
$this->view->listAnnoncecms = $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 AnnonceCms();
$annonce->delete('ID = '.$id);
$this->view->messageSuccess = "L'article a �t� supprim�";
$this->log("L'article a �t� supprim�",'info');
} catch (Zend_Exception $e) {
$this->log($e->getMessage(),'err');
$this->view->messageError = $e->getMessage();
}
}
}
$this->_forward('/list');
}
}
?>