1 <?php
2
3 namespace Objednavky;
4
5 use Nette;
6 use Nette\Application\UI;
7 use Nette\Utils\Html;
8 use Nette\Database\Table\Selection;
9 use Kdyby\BootstrapFormRenderer\BootstrapRenderer;
10 use PLus\Orders\Repositories;
11
12
13
14 15 16
17 abstract class BasePresenter extends Nette\Application\UI\Presenter
18 {
19
20
21 public $roleRepository;
22
23
24 public $parameters;
25
26
27 public $mySession;
28
29
30 public $orderRepository;
31
32
33 public $unitRepository;
34
35
36 public $unituserRepository;
37
38
39 public $areaRepository;
40
41
42 public $itemorderRepository;
43
44
45 public $newsRepository;
46
47
48 protected function startup() {
49 parent::startup();
50 $this->mySession = $this->session->getSection("mySession");
51
52 $this->checkLogin();
53 }
54
55
56 protected function beforeRender() {
57 parent::beforeRender();
58 $this->mySession->backlink = $this->storeRequest();
59 $this->template->presenterName = $this->getName();
60 $this->template->version = $this->parameters->getVersion();
61
62 $user_id = $this->user->getId();
63
64
65 if ($this->getUser()->isInRole('department') || $this->getUser()->isInRole('chief') || $this->getUser()->isInRole('sa')) {
66 $unit = $this->unitRepository->getUnits($user_id);
67 $ids = $this->unituserRepository->getIds($unit);
68 $this->template->countreturnedorder = $this->orderRepository->getGridCountReturnedByUnit($user_id, $ids);
69 }
70
71 if ($this->getUser()->isInRole('trader') || $this->getUser()->isInRole('sa')) {
72
73 $this->template->counttraderin = $this->orderRepository->getCountTraderIn();
74
75 $this->template->counttradervalidate = $this->orderRepository->getCountTraderValidate();
76
77 $order_ids = $this->itemorderRepository->findOrderWithoutImplementer();
78 $this->template->counttradertorealize = $this->orderRepository->getCountTraderToRealize($order_ids);
79 }
80
81 if ($this->getUser()->isInRole('expert') || $this->getUser()->isInRole('sa')) {
82
83 $areas = $this->areaRepository->findAreaById($user_id);
84 $this->template->countexpertvalidate = $this->orderRepository->getCountExpertValidate($areas);
85
86 $order__ids = $this->itemorderRepository->findOrderByImplementerId($user_id);
87 $this->template->countexperttorealize = $this->orderRepository->getCountExpertToRealize($order__ids);
88 }
89
90 if ($this->getUser()->isInRole('manager') || $this->getUser()->isInRole('sa')) {
91
92 $this->template->countmanagervalidate = $this->orderRepository->getCountManagerValidate();
93 }
94
95
96 $this->template->newsoflimit = $this->newsRepository->getLimitValidNews($this->parameters->getNewsLimit());
97 $this->template->validnews = $this->newsRepository->getCountValidNews()->cntvalid;
98 $this->template->visitvalidnews = $this->newsRepository->getCountVisitValidNews($this->newsRepository->getValidNews(), $this->getUser()->id)->cntvisit;
99 }
100
101
102 protected function checkLogin() {
103
104 if (!$this->getUser()->isLoggedIn()) {
105 $this->redirect('Sign:in', array('backlink' => $this->storeRequest()));
106 }
107
108 if (!$this->roleRepository->isAllowed($this->getUser(), $this->getName(), $this->getAction(), $this->getParameter('do'))) {
109 $this->flashMessage('Nemáte oprávnění na provedení akce', 'error');
110 $this->redirect('Homepage:default');
111 }
112 }
113
114
115 116 117 118 119 120
121 public function createTemplate($class = NULL) {
122 $tpl = parent::createTemplate($class);
123 $tpl->registerHelper('checkImage', callback($this, 'checkImage'));
124 return $tpl;
125 }
126 127 128 129 130 131
132 public function checkImage($name) {
133 $path = 'img/avatar/';
134 $info = @getimagesize($path . $name);
135 if ($info) {
136 return $path . $name;
137 }
138 return $path .'NA.jpg ';
139 }
140 }
141