forked from IlchCMS/Ilch-2.0
/
Index.php
50 lines (40 loc) · 1.74 KB
/
Index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/**
* @copyright Ilch 2.0
* @package ilch
*/
namespace Modules\Comment\Controllers;
use Modules\Comment\Mappers\Comment as CommentMapper;
use Modules\Comment\Models\Comment as CommentModel;
class Index extends \Ilch\Controller\Frontend
{
public function init()
{
$locale = '';
if ((bool)$this->getConfig()->get('multilingual_acp')) {
if ($this->getTranslator()->getLocale() != $this->getConfig()->get('content_language')) {
$locale = $this->getTranslator()->getLocale();
}
}
$this->locale = $locale;
}
public function indexAction()
{
$this->getLayout()->getHmenu()->add($this->getTranslator()->trans('menuComments'), array('action' => 'index'));
$commentMapper = new CommentMapper();
$this->getView()->set('comments', $commentMapper->getComments());
if ($this->getRequest()->getPost('comment_comment_text')) {
$commentModel = new CommentModel();
$commentModel->setKey('article/index/show/id/'.$this->getRequest()->getParam('id_a').'/id_c/'.$this->getRequest()->getParam('id'));
$commentModel->setFKId($this->getRequest()->getParam('id'));
$commentModel->setText($this->getRequest()->getPost('comment_comment_text'));
$date = new \Ilch\Date();
$commentModel->setDateCreated($date);
$commentModel->setUserId($this->getUser()->getId());
$commentMapper->save($commentModel);
}
$comments = $commentMapper->getComments('comment/index/index/id/'.$this->getRequest()->getParam('id'));
$this->getView()->set('comment_reply', $this->getConfig()->get('comment_reply'));
$this->getView()->set('comments', $comments);
}
}