forked from IlchCMS/Ilch-2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Index.php
93 lines (75 loc) · 4.07 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
/**
* @copyright Ilch 2.0
* @package ilch
*/
namespace Modules\Downloads\Controllers;
use Modules\Downloads\Mappers\Downloads as DownloadsMapper;
use Modules\Downloads\Mappers\File as FileMapper;
use Modules\Comment\Mappers\Comment as CommentMapper;
use Modules\Comment\Models\Comment as CommentModel;
use Modules\Downloads\Models\File as FileModel;
class Index extends \Ilch\Controller\Frontend
{
public function indexAction()
{
$this->getLayout()->getHmenu()
->add($this->getTranslator()->trans('menuDownloadsOverview'), array('action' => 'index'));
$downloadsMapper = new DownloadsMapper();
$fileMapper = new FileMapper();
$downloadsItems = $downloadsMapper->getDownloadsItemsByParent(1, 0);
$this->getLayout()->set('metaTitle', $this->getTranslator()->trans('downloads'));
$this->getLayout()->set('metaDescription', $this->getTranslator()->trans('downloads'));
$this->getView()->set('downloadsItems', $downloadsItems);
$this->getView()->set('downloadsMapper', $downloadsMapper);
$this->getView()->set('fileMapper', $fileMapper);
}
public function showAction()
{
$fileMapper = new FileMapper();
$pagination = new \Ilch\Pagination();
$downloadsMapper = new DownloadsMapper();
$id = $this->getRequest()->getParam('id');
$downloads = $downloadsMapper->getDownloadsById($id);
$this->getLayout()->set('metaTitle', $this->getTranslator()->trans('downloads').' - '.$downloads->getTitle());
$this->getLayout()->set('metaDescription', $this->getTranslator()->trans('downloads').' - '.$downloads->getDesc());
$this->getLayout()->getHmenu()
->add($this->getTranslator()->trans('menuDownloadsOverview'), array('action' => 'index'))
->add($downloads->getTitle(), array('action' => 'show', 'id' => $id));
$pagination->setPage($this->getRequest()->getParam('page'));
$this->getView()->set('file', $fileMapper->getFileByDownloadsId($id, $pagination));
$this->getView()->set('pagination', $pagination);
}
public function showFileAction()
{
$commentMapper = new CommentMapper;
$fileMapper = new FileMapper();
$downloadsMapper = new DownloadsMapper();
$id = $this->getRequest()->getParam('id');
$downloadsId = $this->getRequest()->getParam('downloads');
if ($this->getRequest()->getPost('downloads_comment_text')) {
$commentModel = new CommentModel();
$commentModel->setKey('downloads/index/showfile/downloads/'.$downloadsId.'/id/'.$id);
$commentModel->setText($this->getRequest()->getPost('downloads_comment_text'));
$date = new \Ilch\Date();
$commentModel->setDateCreated($date);
$commentModel->setUserId($this->getUser()->getId());
$commentMapper->save($commentModel);
}
$downloads = $downloadsMapper->getDownloadsById($downloadsId);
$comments = $commentMapper->getCommentsByKey('downloads/index/showfile/downloads/'.$downloadsId.'/id/'.$id);
$file = $fileMapper->getFileById($id);
$model = new FileModel();
$model->setFileId($file->getFileId());
$model->setVisits($file->getVisits() + 1);
$fileMapper->saveVisits($model);
$this->getLayout()->set('metaTitle', $this->getTranslator()->trans('downloads').' - '.$this->getTranslator()->trans('file').' - '.$file->getFileTitle());
$this->getLayout()->set('metaDescription', $this->getTranslator()->trans('downloads').' - '.$file->getFileDesc());
$this->getLayout()->getHmenu()
->add($this->getTranslator()->trans('menuDownloadsOverview'), array('action' => 'index'))
->add($downloads->getTitle(), array('action' => 'show', 'id' => $downloadsId))
->add($file->getFileTitle(), array('action' => 'showfile', 'downloads' => $downloadsId, 'id' => $id));
$this->getView()->set('file', $fileMapper->getFileById($id));
$this->getView()->set('comments', $comments);
}
}