Current File : /home/karenpetzb/application/modules/default/controllers/BlogController.php |
<?php
class BlogController extends Modules_Default_Controllers_MainController
{
public function init()
{
$this->view->baseUrl = $this->getBaseUrl();
$this->checkMaintenance();
}
public function actualitesAction()
{
try {
$blogCategory = new BlogCategory();
$blogSubject = new BlogSubject();
$id = 1;
$this->view->type_name = "actualites";
if ($this->getRequest()->getParam('id')) {
$id = (int)$this->getRequest()->getParam('id');
}
$currentCategory = $blogCategory->fetchRow('ID = '.$id);
$this->view->currentCategory = $currentCategory;
$this->view->title = $currentCategory['title'];
$this->view->listSubjects = $blogSubject->AllSubjectsBy($id);
$this->view->listCategories = $blogCategory->getAllActivesCategories(1);
}
catch (Zend_Exception $e) {
$this->view->messageError = $e->getMessage();
$this->log($e->getMessage(),'err');
}
}
public function sujetAction()
{
try {
$blogCategory = new BlogCategory();
$blogSubject = new BlogSubject();
$blogComment = new BlogComment();
$id = 0;
if ($this->getRequest()->getParam('id')) {
$id = (int)$this->getRequest()->getParam('id');
$added = (int)$this->getRequest()->getParam('a');
if ($added == 1) {
$this->view->messageSuccess = "Le commentaire a �t� ajout�";
} else if ($added == 2) {
$this->view->messageError = "Le commentaire n'a pas �t� ajout�";
}
$currentSubject = $blogSubject->fetchRow('ID = '.$id);
$currentCategory = $blogCategory->fetchRow('ID = '.$currentSubject['id_category']);
$this->view->listSubjects = $blogSubject->AllSubjectsBy($currentSubject['id_category']);
$this->view->listComments = $blogComment->AllCommentsBy($id);
$this->view->listCategories = $blogCategory->getAllActivesCategories(1);
$this->view->currentCategory = $currentCategory;
$this->view->currentSubject = $currentSubject;
$this->view->title = $currentSubject['title'];
}
}
catch (Zend_Exception $e) {
$this->view->messageError = $e->getMessage();
$this->log($e->getMessage(),'err');
}
}
public function addpostAction()
{
try {
if ($this->_request->isPost()) {
$filter = new Zend_Filter();
$filter ->addFilter(new Zend_Filter_StripTags())
->addFilter(new Zend_Filter_StringTrim());
$validator = new Zend_Validate();
$validator -> addValidator(new Zend_Validate_NotEmpty());
$params = array();
$params = $this->getRequest()->getPost();
$id = (int)$params['subject_id'];
$pseudo = $filter->filter($params['pseudo']);
$message = $filter->filter($params['commentaire']);
if ($validator->isValid($pseudo) && $validator->isValid($message) && $id > 0) {
$data = array (
'id_subject' => $id,
'is_publish' => 1,
'pseudo' => $pseudo,
'message' => $message,
'date_updated' => date('Y-m-d H:i:s')
);
$blogComment = new BlogComment();
$blogComment->insert($data);
$this->_redirect('/blog/sujet/id/'.$id.'/a/1');
} else {
$this->_redirect('/blog/sujet/id/'.$id.'/a/2');
}
}
} catch (Zend_Exception $e) {
$this->log($e->getMessage(),'err');
}
$this->_redirect('/');
}
}
?>