This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /** |
||
4 | * Webcms2 admin module package. |
||
5 | */ |
||
6 | |||
7 | namespace AdminModule; |
||
8 | |||
9 | use Nette; |
||
10 | use Kdyby\BootstrapFormRenderer\BootstrapRenderer; |
||
11 | use Nette\Application\UI; |
||
12 | use Monolog\Logger; |
||
13 | use Monolog\Handler\StreamHandler; |
||
14 | |||
15 | /** |
||
16 | * Base class for all application presenters. |
||
17 | * |
||
18 | * @property-read string $name |
||
19 | * @property-read string $action |
||
20 | * |
||
21 | * @author Tomáš Voslař <tomas.voslar at webcook.cz> |
||
22 | * @package WebCMS2 |
||
23 | */ |
||
24 | class BasePresenter extends \WebCMS2\Common\BasePresenter |
||
25 | { |
||
26 | /** @var Doctrine\ORM\EntityManager */ |
||
27 | protected $em; |
||
28 | |||
29 | /* @var \WebCMS\Translation\Translation */ |
||
30 | public $translation; |
||
31 | |||
32 | /* @var \WebCMS\Translation\Translator */ |
||
33 | public $translator; |
||
34 | |||
35 | /* @var Nette\Http\SessionSection */ |
||
36 | public $state; |
||
37 | |||
38 | /* @var User */ |
||
39 | public $systemUser; |
||
40 | |||
41 | /* @var \WebCMS\Settings */ |
||
42 | public $settings; |
||
43 | |||
44 | /* @var Page */ |
||
45 | public $actualPage; |
||
46 | |||
47 | /* @var \WebCMS\Helpers\PriceFormatter */ |
||
48 | public $priceFormatter; |
||
49 | |||
50 | /* Method is executed before render. */ |
||
51 | 35 | protected function beforeRender() |
|
52 | { |
||
53 | 35 | $this->setLayout("layout"); |
|
54 | |||
55 | 35 | $this->setBasePathModule(); |
|
56 | |||
57 | 35 | if ($this->isAjax()) { |
|
58 | $this->invalidateControl('flashMessages'); |
||
59 | } |
||
60 | |||
61 | // boxes settings, only if page is module |
||
62 | 35 | if ($this->getParam('id')) { |
|
0 ignored issues
–
show
|
|||
63 | 1 | $this->template->boxesSettings = true; |
|
0 ignored issues
–
show
The property
$template is declared private in Nette\Application\UI\Control . Since you implemented __get() , maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() Accessing
boxesSettings on the interface Nette\Templating\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
![]() |
|||
64 | 1 | } else { |
|
65 | 34 | $this->template->boxesSettings = false; |
|
0 ignored issues
–
show
The property
$template is declared private in Nette\Application\UI\Control . Since you implemented __get() , maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() Accessing
boxesSettings on the interface Nette\Templating\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
![]() |
|||
66 | } |
||
67 | |||
68 | // check filled info email |
||
69 | 35 | $infoEmail = $this->settings->get('Info email', \WebCMS\Settings::SECTION_BASIC)->getValue(); |
|
70 | 35 | if (!Nette\Utils\Validators::isEmail($infoEmail)) { |
|
71 | 35 | $this->flashMessage('Please fill in correct info email. Settings -> Basic settings.', 'warning'); |
|
72 | 35 | } |
|
73 | |||
74 | 35 | if (!$this->isAjax()) { |
|
75 | 35 | $this->template->structures = $this->getStructures(); // TODO add function for AJAX and normal request it is not necessary to load everything |
|
0 ignored issues
–
show
The property
$template is declared private in Nette\Application\UI\Control . Since you implemented __get() , maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() Accessing
structures on the interface Nette\Templating\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
![]() |
|||
76 | 35 | } |
|
77 | |||
78 | 35 | $this->template->registerHelperLoader('\WebCMS\Helpers\SystemHelper::loader'); |
|
0 ignored issues
–
show
The property
$template is declared private in Nette\Application\UI\Control . Since you implemented __get() , maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
79 | 35 | $this->template->actualPage = $this->actualPage; |
|
0 ignored issues
–
show
The property
$template is declared private in Nette\Application\UI\Control . Since you implemented __get() , maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() Accessing
actualPage on the interface Nette\Templating\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
![]() |
|||
80 | 35 | $this->template->user = $this->getUser(); |
|
0 ignored issues
–
show
The property
$template is declared private in Nette\Application\UI\Control . Since you implemented __get() , maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() Accessing
user on the interface Nette\Templating\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
![]() |
|||
81 | 35 | $this->template->setTranslator($this->translator); |
|
0 ignored issues
–
show
The property
$template is declared private in Nette\Application\UI\Control . Since you implemented __get() , maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
82 | 35 | $this->template->language = $this->state->language; |
|
0 ignored issues
–
show
The property
$template is declared private in Nette\Application\UI\Control . Since you implemented __get() , maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() Accessing
language on the interface Nette\Templating\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
![]() |
|||
83 | 35 | $this->template->version = \WebCMS\Helpers\SystemHelper::getVersion(); |
|
0 ignored issues
–
show
The property
$template is declared private in Nette\Application\UI\Control . Since you implemented __get() , maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() Accessing
version on the interface Nette\Templating\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
![]() |
|||
84 | 35 | $this->template->activePresenter = $this->getPresenter()->getName(); |
|
0 ignored issues
–
show
The property
$template is declared private in Nette\Application\UI\Control . Since you implemented __get() , maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() Accessing
activePresenter on the interface Nette\Templating\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
![]() |
|||
85 | 35 | $this->template->settings = $this->settings; |
|
0 ignored issues
–
show
The property
$template is declared private in Nette\Application\UI\Control . Since you implemented __get() , maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() Accessing
settings on the interface Nette\Templating\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
![]() |
|||
86 | 35 | $this->template->languages = $this->em->getRepository('WebCMS\Entity\Language')->findAll(); |
|
0 ignored issues
–
show
The property
$template is declared private in Nette\Application\UI\Control . Since you implemented __get() , maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() Accessing
languages on the interface Nette\Templating\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
![]() |
|||
87 | 35 | } |
|
88 | |||
89 | /** |
||
90 | * |
||
91 | */ |
||
92 | 41 | private function processLanguage() |
|
93 | { |
||
94 | 41 | $this->state = $this->getSession('admin'); |
|
0 ignored issues
–
show
It seems like
$this->getSession('admin') can also be of type object<Nette\Http\Session> . However, the property $state is declared as type object<Nette\Http\SessionSection> . Maybe add an additional type check?
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
![]() |
|||
95 | |||
96 | // changing language |
||
97 | 41 | if ($this->getParameter('language_id_change')) { |
|
98 | $this->state->language = $this->em->find('WebCMS\Entity\Language', $this->getParameter('language_id_change')); |
||
99 | $this->forward(':Admin:Homepage:default'); |
||
100 | } |
||
101 | |||
102 | 41 | if (!isset($this->state->language)) { |
|
103 | 1 | $this->state->language = $this->em->getRepository('WebCMS\Entity\Language')->findOneBy(array( |
|
104 | 1 | 'defaultBackend' => 1, |
|
105 | 1 | )); |
|
106 | 1 | } |
|
107 | |||
108 | 41 | $language = $this->em->find('WebCMS\Entity\Language', $this->state->language->getId()); |
|
109 | // check whether is language still in db |
||
110 | 41 | if (!$language) { |
|
111 | unset($this->state->language); |
||
112 | $this->forward('Homepage:default'); |
||
113 | } |
||
114 | |||
115 | // reload entity from db |
||
116 | 41 | $this->state->language = $this->em->find('WebCMS\Entity\Language', $this->state->language->getId()); |
|
117 | |||
118 | 41 | \WebCMS\Helpers\PriceFormatter::setLocale($this->state->language->getLocale()); |
|
119 | |||
120 | // translations |
||
121 | 41 | $default = $this->em->getRepository('WebCMS\Entity\Language')->findOneBy(array( |
|
122 | 41 | 'defaultBackend' => 1, |
|
123 | 41 | )); |
|
124 | |||
125 | 41 | $translation = new \WebCMS\Translation\Translation($this->em, $default, 1); |
|
126 | 41 | $this->translation = $translation->getTranslations(); |
|
127 | 41 | $this->translator = new \WebCMS\Translation\Translator($this->translation); |
|
128 | 41 | } |
|
129 | |||
130 | /* Startup method. */ |
||
131 | 41 | protected function startup() |
|
132 | { |
||
133 | 41 | parent::startup(); |
|
134 | |||
135 | 41 | if (!$this->getUser()->isLoggedIn() && $this->presenter->getName() !== "Admin:Login") { |
|
136 | $this->forward(':Admin:Login:'); |
||
137 | } |
||
138 | |||
139 | 41 | $this->processLanguage(); |
|
140 | |||
141 | // system settings |
||
142 | 41 | $this->settings = new \WebCMS\Settings($this->em, $this->state->language); |
|
143 | 41 | $this->settings->setSettings($this->getSettings()); |
|
144 | |||
145 | // system helper sets variables |
||
146 | 41 | \WebCMS\Helpers\SystemHelper::setVariables(array( |
|
147 | 41 | 'baseUrl' => $this->presenter->getHttpRequest()->url->baseUrl, |
|
148 | 41 | 'infoEmail' => $this->settings->get('Info email', 'basic')->getValue(), |
|
149 | 41 | )); |
|
150 | |||
151 | // price formatting |
||
152 | 41 | $this->priceFormatter = new \WebCMS\Helpers\PriceFormatter($this->state->language->getLocale()); |
|
153 | |||
154 | 41 | $id = $this->getParam('idPage'); |
|
0 ignored issues
–
show
|
|||
155 | 41 | if ($id) { |
|
156 | $this->actualPage = $this->em->find('WebCMS\Entity\Page', $id); |
||
157 | } |
||
158 | |||
159 | 41 | $this->checkPermission(); |
|
160 | |||
161 | 41 | $this->logAction(); |
|
162 | 41 | } |
|
163 | |||
164 | 41 | private function logAction() |
|
165 | { |
||
166 | // Create the logger |
||
167 | 41 | $logger = new Logger('History'); |
|
168 | // Now add some handlers |
||
169 | 41 | $parameters = $this->getContext()->getParameters(); |
|
170 | |||
171 | 41 | $logger->pushHandler(new StreamHandler($parameters['tempDir'].'/../log/webcms.log', Logger::DEBUG)); |
|
172 | |||
173 | $data = array( |
||
174 | 41 | 'user' => $this->getUser()->getIdentity() ? $this->getUser()->getIdentity()->getData()['username'] : 'unknown', |
|
175 | 41 | 'action' => $this->getAction(), |
|
176 | 41 | 'presenter' => $this->getName(), |
|
177 | 41 | 'title' => is_object($this->actualPage) ? $this->actualPage->getTitle() : 'System', |
|
178 | 41 | 'url' => $this->getHttpRequest()->url->absoluteUrl, |
|
179 | 41 | ); |
|
180 | |||
181 | 41 | if ($this->getName() === 'Admin:Homepage' || $this->getName() === 'Admin:Login') { |
|
182 | 5 | $logger->addNotice('Login', $data); |
|
183 | 5 | } else { |
|
184 | 36 | $logger->addInfo('Request catcher', $data); |
|
185 | } |
||
186 | 41 | } |
|
187 | |||
188 | 41 | protected function getLanguageId() |
|
189 | { |
||
190 | 41 | return $this->state->language->getId(); |
|
191 | } |
||
192 | |||
193 | 8 | protected function createSettingsForm($settings) |
|
194 | { |
||
195 | 8 | $form = $this->createForm(); |
|
196 | |||
197 | 8 | if (!$settings) { |
|
198 | 1 | return $form; |
|
199 | } |
||
200 | |||
201 | 7 | foreach ($settings as $s) { |
|
202 | 7 | $form = $this->createFormElement($form, $s); |
|
203 | 7 | } |
|
204 | |||
205 | 7 | $form->addSubmit('submit', 'Save settings'); |
|
206 | 7 | $form->onSuccess[] = callback($this, 'settingsFormSubmitted'); |
|
207 | |||
208 | 7 | return $form; |
|
209 | } |
||
210 | |||
211 | 7 | private function createFormElement($form, $setting) |
|
212 | { |
||
213 | 7 | if (!is_null($setting->getLanguage())) { |
|
214 | 7 | $ident = $this->em->getRepository('WebCMS\Entity\Setting')->findOneBy(array( |
|
215 | 7 | 'key' => $setting->getKey(), |
|
216 | 7 | 'section' => $setting->getSection(), |
|
217 | 7 | 'language' => $this->state->language->getId() |
|
218 | 7 | )); |
|
219 | 7 | } else { |
|
220 | 5 | $ident = $setting; |
|
221 | } |
||
222 | |||
223 | 7 | switch ($setting->getType()) { |
|
224 | 7 | case 'textarea': |
|
225 | 1 | $form->addTextArea($ident->getId(), $setting->getKey())->setDefaultValue($ident->getValue())->setAttribute('class', 'editor'); |
|
226 | 1 | break; |
|
227 | 7 | case 'textarea-plain': |
|
228 | 2 | $form->addTextArea($ident->getId(), $setting->getKey())->setDefaultValue($ident->getValue()); |
|
229 | 2 | break; |
|
230 | 7 | case 'radio': |
|
231 | 1 | $form->addRadioList($ident->getId(), $setting->getKey(), $setting->getOptions())->setDefaultValue($ident->getValue()); |
|
232 | 1 | break; |
|
233 | 7 | case 'select': |
|
234 | 2 | $form->addSelect($ident->getId(), $setting->getKey(), $setting->getOptions())->setDefaultValue($ident->getValue()); |
|
235 | 2 | break; |
|
236 | 7 | case 'checkbox': |
|
237 | 2 | $form->addCheckbox($ident->getId(), $setting->getKey())->setDefaultValue($ident->getValue()); |
|
238 | 2 | break; |
|
239 | 7 | case 'checkbox-toggle': |
|
240 | 2 | $form->addCheckbox($ident->getId(), $setting->getKey())->setDefaultValue($ident->getValue())->setAttribute('data-toggle', 'toggle'); |
|
241 | 2 | break; |
|
242 | 5 | default: |
|
243 | 5 | $form->addText($ident->getId(), $setting->getKey())->setDefaultValue($ident->getValue())->setAttribute('class', 'form-control'); |
|
244 | 5 | break; |
|
245 | 7 | } |
|
246 | |||
247 | 7 | return $form; |
|
248 | } |
||
249 | |||
250 | public function settingsFormSubmitted(\Nette\Application\UI\Form $form) |
||
251 | { |
||
252 | $values = $form->getValues(); |
||
253 | |||
254 | foreach ($values as $id => $v) { |
||
255 | $setting = $this->em->find('WebCMS\Entity\Setting', $id); |
||
256 | $setting->setValue($v); |
||
257 | } |
||
258 | |||
259 | $this->em->flush(); |
||
260 | |||
261 | $this->flashMessage('Settings has been saved.', 'success'); |
||
262 | $this->forward('this'); |
||
263 | } |
||
264 | |||
265 | /* Invalidate ajax content. */ |
||
266 | |||
267 | 26 | protected function reloadContent() |
|
268 | { |
||
269 | 26 | if ($this->isAjax()) { |
|
270 | $this->invalidateControl('content'); |
||
271 | } |
||
272 | 26 | } |
|
273 | |||
274 | /* Invalidate ajax modal content. */ |
||
275 | |||
276 | 6 | protected function reloadModalContent() |
|
277 | { |
||
278 | 6 | if ($this->isAjax()) { |
|
279 | $this->invalidateControl('modalContent'); |
||
280 | } |
||
281 | 6 | } |
|
282 | |||
283 | /** |
||
284 | * Creates default basic grid. |
||
285 | * @param Nette\Application\UI\Presenter $presenter |
||
286 | * @param String $name |
||
287 | * @param String $entity |
||
288 | * @param string[] $where |
||
289 | * @return \Grido\Grid |
||
290 | */ |
||
291 | 7 | public function createGrid(Nette\Application\UI\Presenter $presenter, $name, $entity, $order = null, $where = null) |
|
292 | { |
||
293 | 5 | $grid = new \Grido\Grid($presenter, $name); |
|
294 | |||
295 | 5 | $qb = $this->em->createQueryBuilder(); |
|
296 | |||
297 | 5 | if ($order) { |
|
298 | 1 | foreach ($order as $o) { |
|
299 | 1 | $qb->addOrderBy('l.'.$o['by'], $o['dir']); |
|
300 | 1 | } |
|
301 | 2 | } |
|
302 | |||
303 | 5 | if ($where) { |
|
304 | 3 | foreach ($where as $w) { |
|
305 | 3 | $qb->andWhere('l.'.$w); |
|
306 | 3 | } |
|
307 | 3 | } |
|
308 | |||
309 | 5 | if (strpos($entity, 'WebCMS') === false) { |
|
310 | 5 | $grid->setModel($qb->select('l')->from("WebCMS\Entity\\$entity", 'l')); |
|
311 | 5 | } else { |
|
312 | $grid->setModel($qb->select('l')->from($entity, 'l')); |
||
313 | } |
||
314 | |||
315 | 7 | $grid->setRememberState(true); |
|
316 | 5 | $grid->setDefaultPerPage(10); |
|
317 | 5 | $grid->setTranslator($this->translator); |
|
318 | 5 | $grid->setFilterRenderType(\Grido\Components\Filters\Filter::RENDER_INNER); |
|
319 | |||
320 | 5 | return $grid; |
|
321 | } |
||
322 | |||
323 | /** |
||
324 | * Creates form and rewrite renderer for bootstrap. |
||
325 | * @return UI\Form |
||
326 | */ |
||
327 | 18 | public function createForm() |
|
328 | { |
||
329 | 18 | $form = new Nette\Application\UI\Form(); |
|
330 | |||
331 | 18 | $form->getElementPrototype()->addAttributes(array('class' => 'ajax')); |
|
332 | 18 | $form->setTranslator($this->translator); |
|
333 | 18 | $form->setRenderer(new BootstrapRenderer()); |
|
334 | |||
335 | 18 | return $form; |
|
336 | 1 | } |
|
337 | |||
338 | /** |
||
339 | * Injects entity manager. |
||
340 | * @param \Doctrine\ORM\EntityManager $em |
||
341 | * @return BasePresenter |
||
342 | * @throws \Nette\InvalidStateException |
||
343 | */ |
||
344 | 41 | public function injectEntityManager(\Doctrine\ORM\EntityManager $em) |
|
0 ignored issues
–
show
You have injected the EntityManager via parameter
$em . This is generally not recommended as it might get closed and become unusable. Instead, it is recommended to inject the ManagerRegistry and retrieve the EntityManager via getManager() each time you need it.
The function someFunction(ManagerRegistry $registry) {
$em = $registry->getManager();
$em->getConnection()->beginTransaction();
try {
// Do something.
$em->getConnection()->commit();
} catch (\Exception $ex) {
$em->getConnection()->rollback();
$em->close();
throw $ex;
}
}
If that code throws an exception and the On the other hand, if you instead inject the ![]() |
|||
345 | { |
||
346 | 41 | if ($this->em) { |
|
347 | throw new \Nette\InvalidStateException('Entity manager has been already set.'); |
||
348 | } |
||
349 | |||
350 | 41 | $this->em = $em; |
|
0 ignored issues
–
show
It seems like
$em of type object<Doctrine\ORM\EntityManager> is incompatible with the declared type object<AdminModule\Doctrine\ORM\EntityManager> of property $em .
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property. Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.. ![]() |
|||
351 | |||
352 | 41 | return $this; |
|
353 | } |
||
354 | |||
355 | 41 | private function initAcl() |
|
356 | { |
||
357 | // checking permission of user |
||
358 | 41 | $acl = new Nette\Security\Permission(); |
|
359 | |||
360 | // roles |
||
361 | 41 | $roles = $this->em->getRepository("WebCMS\Entity\Role")->findAll(); |
|
362 | |||
363 | 41 | $acl->addRole('guest'); |
|
364 | 41 | foreach ($roles as $r) { |
|
365 | 41 | $acl->addRole($r->getName()); |
|
366 | 41 | } |
|
367 | |||
368 | // load resources |
||
369 | 41 | $resources = $this->initPagesResources(); |
|
370 | |||
371 | // add all resources to acl |
||
372 | 41 | $acl->addResource('admin:Homepage'); |
|
373 | 41 | $acl->addResource('admin:Login'); |
|
374 | 41 | foreach ($resources as $key => $r) { |
|
375 | 41 | $acl->addResource($key); |
|
376 | 41 | } |
|
377 | |||
378 | 41 | return $acl; |
|
379 | } |
||
380 | |||
381 | 41 | private function initPagesResources() |
|
382 | { |
||
383 | 41 | $resources = \WebCMS\Helpers\SystemHelper::getResources(); |
|
384 | |||
385 | // pages resources |
||
386 | 41 | $pages = $this->em->getRepository('WebCMS\Entity\Page')->findAll(); |
|
387 | |||
388 | 41 | foreach ($pages as $page) { |
|
389 | if ($page->getParent() != NULL) { |
||
390 | $module = $this->createObject($page->getModuleName()); |
||
391 | |||
392 | foreach ($module->getPresenters() as $presenter) { |
||
393 | $key = 'admin:'.$page->getModuleName().''.$presenter['name'].$page->getId(); |
||
394 | $resources[$key] = $page->getTitle(); |
||
395 | } |
||
396 | } |
||
397 | 41 | } |
|
398 | |||
399 | 41 | return $resources; |
|
400 | } |
||
401 | |||
402 | /** |
||
403 | * @param Nette\Security\IIdentity|null $identity |
||
404 | */ |
||
405 | 41 | private function initPermissions($identity) |
|
406 | { |
||
407 | 41 | if (is_object($identity)) { |
|
408 | 41 | $permissions = $identity->data['permissions']; |
|
0 ignored issues
–
show
Accessing
data on the interface Nette\Security\IIdentity suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
![]() |
|||
409 | 41 | } else { |
|
410 | $permissions = array(); |
||
411 | } |
||
412 | |||
413 | 41 | return $permissions; |
|
414 | } |
||
415 | |||
416 | 41 | private function getPageResource() |
|
417 | { |
||
418 | 41 | if (substr_count(lcfirst($this->name), ':') == 2) { |
|
419 | $resource = \WebCMS\Helpers\SystemHelper::strlReplace(':', '', lcfirst($this->name).$this->getParameter('idPage')); |
||
420 | } else { |
||
421 | 41 | $resource = lcfirst($this->name); |
|
422 | } |
||
423 | |||
424 | 41 | return $resource; |
|
425 | } |
||
426 | |||
427 | /** |
||
428 | * @param Nette\Security\Permission $acl |
||
429 | */ |
||
430 | 41 | private function checkRights($acl, $roles) |
|
431 | { |
||
432 | 41 | $resource = $this->getPageResource(); |
|
433 | |||
434 | 41 | $hasRigths = false; |
|
435 | 41 | foreach ($roles as $role) { |
|
436 | 41 | $check = $acl->isAllowed($role, $resource, $this->action); |
|
437 | |||
438 | 41 | if ($check) { |
|
439 | 41 | $hasRigths = true; |
|
440 | 41 | } |
|
441 | 41 | } |
|
442 | |||
443 | 41 | return $hasRigths; |
|
444 | } |
||
445 | |||
446 | /** |
||
447 | * Checks user permission. |
||
448 | * |
||
449 | * @return void |
||
450 | */ |
||
451 | 41 | private function checkPermission() |
|
452 | { |
||
453 | // creates system acl |
||
454 | 41 | $acl = $this->initAcl(); |
|
455 | |||
456 | 41 | $identity = $this->getUser()->getIdentity(); |
|
457 | 41 | $permissions = $this->initPermissions($identity); |
|
458 | 41 | foreach ($permissions as $key => $p) { |
|
459 | if ($p && $acl->hasResource($key)) { |
||
460 | $acl->allow($identity->roles[0], $key, Nette\Security\Permission::ALL); |
||
0 ignored issues
–
show
Accessing
roles on the interface Nette\Security\IIdentity suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
![]() |
|||
461 | } |
||
462 | 41 | } |
|
463 | |||
464 | // homepage and login page can access everyone |
||
465 | 41 | $acl->allow(Nette\Security\Permission::ALL, 'admin:Homepage', Nette\Security\Permission::ALL); |
|
466 | 41 | $acl->allow(Nette\Security\Permission::ALL, 'admin:Login', Nette\Security\Permission::ALL); |
|
467 | |||
468 | // superadmin has access to everywhere |
||
469 | 41 | $acl->allow('superadmin', Nette\Security\Permission::ALL, Nette\Security\Permission::ALL); |
|
470 | |||
471 | 41 | $roles = $this->getUser()->getRoles(); |
|
472 | |||
473 | 41 | if (!$this->checkRights($acl, $roles)) { |
|
474 | $this->presenter->flashMessage($this->translation['You do not have a permission to do this operation!'], 'danger'); |
||
475 | $this->redirect(":Admin:Homepage:"); |
||
476 | } |
||
477 | 41 | } |
|
478 | |||
479 | 35 | private function getStructures() |
|
480 | { |
||
481 | 35 | $qb = $this->em->createQueryBuilder(); |
|
482 | |||
483 | 35 | $qb->addOrderBy('l.root', 'ASC'); |
|
484 | 35 | $qb->andWhere('l.parent IS NULL'); |
|
485 | 35 | $qb->andWhere('l.language = '.$this->state->language->getId()); |
|
486 | |||
487 | 35 | return $qb->select('l')->from("WebCMS\Entity\Page", 'l')->getQuery()->getResult(); |
|
488 | } |
||
489 | |||
490 | /* SEO SETTINGS */ |
||
491 | |||
492 | public function renderSeo($idPage) |
||
493 | { |
||
494 | $this->reloadContent(); |
||
495 | |||
496 | $this->template->actualPage = $this->actualPage; |
||
0 ignored issues
–
show
The property
$template is declared private in Nette\Application\UI\Control . Since you implemented __get() , maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() Accessing
actualPage on the interface Nette\Templating\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
![]() |
|||
497 | $this->template->idPage = $idPage; |
||
0 ignored issues
–
show
The property
$template is declared private in Nette\Application\UI\Control . Since you implemented __get() , maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() Accessing
idPage on the interface Nette\Templating\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
![]() |
|||
498 | } |
||
499 | |||
500 | View Code Duplication | public function createComponentSeoForm() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
501 | { |
||
502 | $form = $this->createForm(); |
||
503 | |||
504 | $form->addText('slug', 'Seo url')->setAttribute('class', 'form-control'); |
||
0 ignored issues
–
show
'form-control' is of type string , but the function expects a boolean .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
505 | $form->addText('metaTitle', 'Seo title')->setAttribute('class', 'form-control'); |
||
0 ignored issues
–
show
'form-control' is of type string , but the function expects a boolean .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
506 | $form->addText('metaKeywords', 'Seo keywords')->setAttribute('class', 'form-control'); |
||
0 ignored issues
–
show
'form-control' is of type string , but the function expects a boolean .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
507 | $form->addText('metaDescription', 'Seo description')->setAttribute('class', 'form-control'); |
||
0 ignored issues
–
show
'form-control' is of type string , but the function expects a boolean .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
508 | $form->addSubmit('send', 'Save')->setAttribute('class', 'btn btn-success'); |
||
0 ignored issues
–
show
'btn btn-success' is of type string , but the function expects a boolean .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
509 | $form->onSuccess[] = callback($this, 'seoFormSubmitted'); |
||
510 | |||
511 | $form->setDefaults($this->actualPage->toArray()); |
||
512 | |||
513 | return $form; |
||
514 | } |
||
515 | |||
516 | public function seoFormSubmitted($form) |
||
517 | { |
||
518 | $values = $form->getValues(); |
||
519 | |||
520 | if (empty($values->slug)) { |
||
521 | $this->actualPage->setSlug(null); |
||
522 | } else { |
||
523 | $this->actualPage->setSlug($values->slug); |
||
524 | } |
||
525 | $this->actualPage->setMetaTitle($values->metaTitle); |
||
526 | $this->actualPage->setMetaKeywords($values->metaKeywords); |
||
527 | $this->actualPage->setMetaDescription($values->metaDescription); |
||
528 | |||
529 | $path = $this->em->getRepository('WebCMS\Entity\Page')->getPath($this->actualPage); |
||
530 | $final = array(); |
||
531 | foreach ($path as $p) { |
||
532 | if ($p->getParent() != NULL) { |
||
533 | $final[] = $p->getSlug(); |
||
534 | } |
||
535 | } |
||
536 | |||
537 | $this->actualPage->setPath(implode('/', $final)); |
||
538 | |||
539 | $this->em->flush(); |
||
540 | |||
541 | $this->flashMessage('Seo settings has been saved.', 'success'); |
||
542 | $this->forward('this'); |
||
543 | } |
||
544 | |||
545 | /* BOXES SETTINGS */ |
||
546 | |||
547 | 1 | public function renderBoxes($idPage) |
|
548 | { |
||
549 | $this->reloadContent(); |
||
550 | |||
551 | $parameters = $this->getContext()->container->getParameters(); |
||
552 | $boxes = $parameters['boxes']; |
||
553 | |||
554 | /* |
||
555 | foreach ($boxes as &$box) { |
||
556 | //$box['component'] = $id . '-' . $box['presenter'] . '-' . $box['function']; |
||
557 | }*/ |
||
558 | if (!is_array($boxes)) { |
||
559 | $boxes = array(); |
||
560 | } |
||
561 | |||
562 | $this->template->actualPage = $this->actualPage; |
||
0 ignored issues
–
show
The property
$template is declared private in Nette\Application\UI\Control . Since you implemented __get() , maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() Accessing
actualPage on the interface Nette\Templating\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
![]() |
|||
563 | $this->template->boxes = $boxes; |
||
0 ignored issues
–
show
The property
$template is declared private in Nette\Application\UI\Control . Since you implemented __get() , maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() Accessing
boxes on the interface Nette\Templating\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
![]() |
|||
564 | $this->template->idPage = $idPage; |
||
0 ignored issues
–
show
The property
$template is declared private in Nette\Application\UI\Control . Since you implemented __get() , maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() Accessing
idPage on the interface Nette\Templating\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
![]() |
|||
565 | 1 | } |
|
566 | |||
567 | public function createComponentBoxesForm() |
||
568 | { |
||
569 | $form = $this->createForm(); |
||
570 | |||
571 | $parameters = $this->getContext()->container->getParameters(); |
||
572 | $boxes = $parameters['boxes']; |
||
573 | |||
574 | $pages = $this->em->getRepository('WebCMS\Entity\Page')->findBy(array( |
||
575 | 'language' => $this->state->language, |
||
576 | )); |
||
577 | |||
578 | $boxesAssoc = array(); |
||
579 | View Code Duplication | foreach ($pages as $page) { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
580 | if ($page->getParent() != NULL) { |
||
581 | $module = $this->createObject($page->getModuleName()); |
||
582 | |||
583 | foreach ($module->getBoxes() as $box) { |
||
584 | $boxesAssoc[$page->getId().'-'.$box['module'].'-'.$box['presenter'].'-'.$box['function']] = $page->getTitle().' - '.$this->translation[$box['name']]; |
||
585 | } |
||
586 | } |
||
587 | } |
||
588 | |||
589 | $boxesAssoc = array( |
||
590 | 0 => $this->translation['Box is not linked.'], |
||
591 | ) + $boxesAssoc; |
||
592 | |||
593 | if (!empty($boxes)) { |
||
594 | foreach ($boxes as $name => $active) { |
||
595 | $form->addSelect($name, $name, $boxesAssoc) |
||
596 | ->setTranslator(null) |
||
597 | ->setAttribute('class', 'form-control'); |
||
0 ignored issues
–
show
'form-control' is of type string , but the function expects a boolean .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
598 | } |
||
599 | } |
||
600 | |||
601 | // set defaults |
||
602 | $boxes = $this->em->getRepository('WebCMS\Entity\Box')->findBy(array( |
||
603 | 'pageTo' => $this->actualPage, |
||
604 | )); |
||
605 | |||
606 | $defaults = array(); |
||
607 | if (!empty($boxes)) { |
||
608 | foreach ($boxes as $box) { |
||
609 | if (is_object($box->getPageFrom())) { |
||
610 | $defaults[$box->getBox()] = $box->getPageFrom()->getId().'-'.$box->getModuleName().'-'.$box->getPresenter().'-'.$box->getFunction(); |
||
611 | } |
||
612 | } |
||
613 | } |
||
614 | |||
615 | $form->setDefaults($defaults); |
||
616 | $form->addSubmit('submit', 'Save'); |
||
617 | $form->onSuccess[] = callback($this, 'boxesFormSubmitted'); |
||
618 | |||
619 | return $form; |
||
620 | } |
||
621 | |||
622 | public function boxesFormSubmitted(UI\Form $form) |
||
623 | { |
||
624 | $values = $form->getValues(); |
||
625 | |||
626 | // delete old asscociations |
||
627 | $q = $this->em->createQuery('delete from WebCMS\Entity\Box m where m.pageTo = '.$this->actualPage->getId()); |
||
628 | $numDeleted = $q->execute(); |
||
0 ignored issues
–
show
$numDeleted is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
629 | |||
630 | // persist new associations |
||
631 | foreach ($values as $key => $value) { |
||
632 | if ($value) { |
||
633 | $params = explode('-', $value); |
||
634 | |||
635 | $pageFrom = $this->em->find('WebCMS\Entity\Page', $params[0]); |
||
636 | |||
637 | $box = new \WebCMS\Entity\Box(); |
||
638 | $box->setPageFrom($pageFrom); |
||
639 | $box->setPageTo($this->actualPage); |
||
640 | $box->setModuleName($params[1]); |
||
641 | $box->setPresenter($params[2]); |
||
642 | $box->setFunction($params[3]); |
||
643 | $box->setBox($key); |
||
644 | |||
645 | $this->em->persist($box); |
||
646 | } |
||
647 | } |
||
648 | |||
649 | $this->em->flush(); |
||
650 | |||
651 | $this->flashMessage('Boxes settings has been saved.', 'success'); |
||
652 | $this->forward('this'); |
||
653 | } |
||
654 | |||
655 | public function handleAddToFavourite($link, $title) |
||
656 | { |
||
657 | $user = $this->em->getRepository('WebCMS\Entity\User')->find($this->getUser()->getId()); |
||
658 | |||
659 | $fav = new \WebCMS\Entity\Favourites(); |
||
660 | $fav->setLink($link); |
||
661 | $fav->setUser($user); |
||
662 | $fav->setTitle($title); |
||
663 | |||
664 | $this->em->persist($fav); |
||
665 | |||
666 | $this->em->flush(); |
||
667 | |||
668 | $this->flashMessage('Link has been added to favourites.', 'success'); |
||
669 | } |
||
670 | |||
671 | public function handleGetTranslations() |
||
672 | { |
||
673 | $payload = array(); |
||
674 | foreach ($_GET['keys'] as $key => $value) { |
||
675 | $payload[$key] = $this->translator->translate($key); |
||
676 | } |
||
677 | |||
678 | $this->sendResponse(new \Nette\Application\Responses\JsonResponse($payload)); |
||
679 | } |
||
680 | |||
681 | 1 | public function handleRemoveFromFavourite($idFav) |
|
682 | { |
||
683 | $fav = $this->em->getRepository('WebCMS\Entity\Favourites')->find($idFav); |
||
684 | |||
685 | $this->em->remove($fav); |
||
686 | $this->em->flush(); |
||
687 | |||
688 | $this->flashMessage('Link has been removed from favourites.', 'success'); |
||
689 | 1 | } |
|
690 | |||
691 | 39 | public function flashMessage($text, $type = 'info') |
|
692 | { |
||
693 | 39 | parent::flashMessage($this->translation[$text], $type); |
|
694 | 39 | } |
|
695 | |||
696 | /** |
||
697 | * Formats layout template file names. |
||
698 | * @return array |
||
699 | */ |
||
700 | 30 | public function formatLayoutTemplateFiles() |
|
701 | { |
||
702 | 30 | $name = $this->getName(); |
|
703 | 30 | $presenter = substr($name, strrpos(':'.$name, ':')); |
|
0 ignored issues
–
show
$presenter is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
704 | 30 | $layout = $this->layout ? $this->layout : 'layout'; |
|
0 ignored issues
–
show
The property
$layout is declared private in Nette\Application\UI\Presenter . Since you implemented __get() , maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() |
|||
705 | 30 | $dir = dirname($this->getReflection()->getFileName()); |
|
706 | 30 | $dir = is_dir("$dir/templates") ? $dir : dirname($dir); |
|
707 | |||
708 | $list = array( |
||
709 | 30 | APP_DIR."/../libs/webcms2/webcms2/AdminModule/templates/@$layout.latte", |
|
710 | 30 | ); |
|
711 | |||
712 | View Code Duplication | do { |
|
0 ignored issues
–
show
This code seems to be duplicated across your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
713 | 30 | $list[] = "$dir/templates/@$layout.latte"; |
|
714 | 30 | $list[] = "$dir/templates/@$layout.phtml"; |
|
715 | 30 | $dir = dirname($dir); |
|
716 | 30 | } while ($dir && ($name = substr($name, 0, strrpos($name, ':')))); |
|
717 | |||
718 | 30 | return $list; |
|
719 | } |
||
720 | |||
721 | /** |
||
722 | * Transfer collection into array. |
||
723 | * |
||
724 | * @param [type] $collection [description] |
||
0 ignored issues
–
show
The doc-type
[type] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types. ![]() |
|||
725 | * @param string $title [description] |
||
726 | * |
||
727 | * @return array [description] |
||
728 | */ |
||
729 | public function collectionToArray($collection, $title = 'title') |
||
730 | { |
||
731 | $array = array(); |
||
732 | foreach ($collection as $item) { |
||
733 | $getter = 'get'.ucfirst($title); |
||
734 | $array[$item->getId()] = $item->$getter(); |
||
735 | } |
||
736 | |||
737 | return $array; |
||
738 | } |
||
739 | |||
740 | 35 | public function setBasePathModule() |
|
741 | { |
||
742 | 35 | $this->template->basePathModule = __DIR__.'/../../'; |
|
0 ignored issues
–
show
The property
$template is declared private in Nette\Application\UI\Control . Since you implemented __get() , maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. ![]() Accessing
basePathModule on the interface Nette\Templating\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?
If you access a property on an interface, you most likely code against a concrete implementation of the interface. Available Fixes
![]() |
|||
743 | 35 | } |
|
744 | } |
||
745 |
This method has been deprecated.