SettingsPresenter::actionUpdateMeta()   C
last analyzed

Complexity

Conditions 7
Paths 5

Size

Total Lines 29
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 0
Metric Value
dl 0
loc 29
ccs 0
cts 23
cp 0
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 19
nc 5
nop 3
crap 56
1
<?php
2
3
namespace AdminModule;
4
5
use Nette\Utils\Finder;
6
7
/**
8
 * Settings presenter.
9
 * @author Tomáš Voslař <tomas.voslar at webcook.cz>
10
 * @package WebCMS2
11
 */
12
class SettingsPresenter extends \AdminModule\BasePresenter
13
{
14
    /* @var Thumbnail */
15
    private $thumbnail;
16
17 10
    protected function beforeRender()
18
    {
19 10
        parent::beforeRender();
20 10
    }
21
22 10
    protected function startup()
23
    {
24 10
        parent::startup();
25 10
    }
26
27
    /* BASIC */
28
29 1 View Code Duplication
    public function createComponentBasicSettingsForm()
0 ignored issues
show
Duplication introduced by
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.

Loading history...
30
    {
31 1
        $settings = array();
32 1
        $settings[] = $this->settings->get('Root domain', \WebCMS\Settings::SECTION_BASIC, 'checkbox');
33 1
        $settings[] = $this->settings->get('Navbar dropdown', \WebCMS\Settings::SECTION_BASIC, 'checkbox');
34 1
        $settings[] = $this->settings->get('Info email', \WebCMS\Settings::SECTION_BASIC, 'text');
35 1
        $settings[] = $this->settings->get('Navbar class', \WebCMS\Settings::SECTION_BASIC, 'text');
36 1
        $settings[] = $this->settings->get('Navbar id', \WebCMS\Settings::SECTION_BASIC, 'text');
37 1
        $settings[] = $this->settings->get('Sidebar class', \WebCMS\Settings::SECTION_BASIC, 'text');
38
39 1
        return $this->createSettingsForm($settings);
40
    }
41
42 1
    public function renderDefault()
43
    {
44 1
        $this->reloadContent();
45 1
    }
46
47
    /* PICTURES */
48
49 10
    public function createComponentPicturesSettingsForm()
50
    {
51 1
        $settings = array();
52
53
        // global settings for all languages
54 1
        $this->settings->setLanguage(null);
55
56 1
        $settings[] = $this->settings->get('Watermark picture path', \WebCMS\Settings::SECTION_IMAGE, 'text');
57
58 1
        $settings[] = $this->settings->get('Apply watermark', \WebCMS\Settings::SECTION_IMAGE, 'radio', array(
59 1
            0 => 'Do not apply watermark',
60 1
            1 => 'Use picture as watermark',
61 1
            2 => 'Use text as watermark',
62 1
        ));
63
64 1
        $settings[] = $this->settings->get('Watermark text', \WebCMS\Settings::SECTION_IMAGE, 'text');
65 10
        $settings[] = $this->settings->get('Watermark text size', \WebCMS\Settings::SECTION_IMAGE, 'text');
66 1
        $settings[] = $this->settings->get('Watermark text font', \WebCMS\Settings::SECTION_IMAGE, 'select', array(
67 1
            'Courier New.ttf' => 'Courier new',
68 1
            'Comic Sans MS.ttf' => 'Comic sans',
69 1
            'Arial.ttf' => 'Arial',
70 1
            'Times New Roman.ttf' => 'Times new roman',
71 1
        ));
72
73 1
        $settings[] = $this->settings->get('Watermark text color', \WebCMS\Settings::SECTION_IMAGE, 'text');
74
75 10
        $settings[] = $this->settings->get('Watermark position', \WebCMS\Settings::SECTION_IMAGE, 'radio', array(
76 1
            0 => 'Top left',
77 1
            1 => 'Top right',
78 10
            2 => 'Center',
79 10
            3 => 'Bottom left',
80 10
            4 => 'Bottom right',
81 10
        ));
82
83
        // set back language for further settings in app
84 10
        $this->settings->setLanguage($this->state->language);
85
86 10
        return $this->createSettingsForm($settings);
87
    }
88
89 1
    public function renderPictures($panel)
90
    {
91 1
        $this->reloadContent();
92
93 1
        $this->template->watermarkPath = $this->settings->get('Watermark picture path', \WebCMS\Settings::SECTION_IMAGE)->getValue();
0 ignored issues
show
Documentation introduced by
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 _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?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.

Loading history...
Bug introduced by
Accessing watermarkPath 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

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
94 1
        $this->template->panel = $panel;
0 ignored issues
show
Documentation introduced by
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 _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?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.

Loading history...
Bug introduced by
Accessing panel 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

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
95 1
    }
96
97 1
    public function actionAddThumbnail($id)
98
    {
99 1
        if ($id) {
100
            $this->thumbnail = $this->em->find("WebCMS\Entity\Thumbnail", $id);
101
        } else {
102 1
            $this->thumbnail = new \WebCMS\Entity\Thumbnail();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \WebCMS\Entity\Thumbnail() of type object<WebCMS\Entity\Thumbnail> is incompatible with the declared type object<AdminModule\Thumbnail> of property $thumbnail.

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..

Loading history...
103
        }
104 1
    }
105
106
    public function actionDeleteThumbnail($id)
107
    {
108
        $this->thumbnail = $this->em->find("WebCMS\Entity\Thumbnail", $id);
109
        $this->em->remove($this->thumbnail);
110
        $this->em->flush();
111
112
        $this->flashMessage('Thumbnail has been removed.', 'success');
113
114
        $this->forward('Settings:pictures', array('panel' => 'thumbnails'));
115
    }
116
117 1
    public function renderAddThumbnail($id)
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
118
    {
119 1
        $this->reloadModalContent();
120
121 1
        $this->template->thumbnail = $this->thumbnail;
0 ignored issues
show
Documentation introduced by
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 _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?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.

Loading history...
Bug introduced by
Accessing thumbnail 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

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
122 1
    }
123
124 10
    public function createComponentThumbnailForm()
125
    {
126 1
        $form = $this->createForm();
127
128 1
        $form->addText('key', 'Key');
129 1
        $form->addSelect('resize', 'Resize type', array(
130 1
            \Nette\Image::EXACT => 'Exact',
131 1
            \Nette\Image::FILL => 'Fill',
132 1
            \Nette\Image::FIT => 'Fit',
133 1
            \Nette\Image::SHRINK_ONLY => 'Shrink',
134 1
            \Nette\Image::STRETCH => 'Stretch',
135 1
        ));
136
137 1
        $form->addText('x', 'Width')
138 1
            ->setRequired('You must fill in widh')
139 1
            ->addConditionOn($form['resize'], \Nette\Forms\Form::EQUAL, \Nette\Image::EXACT)
140 1
            ->addRule(\Nette\Forms\Form::PATTERN, 'Width must be greater than 0', '^[1-9][0-9]*$');
141
142 10
        $form->addText('y', 'Height')
143 1
            ->setRequired('You must fill in height')
144 1
            ->addConditionOn($form['resize'], \Nette\Forms\Form::EQUAL, \Nette\Image::EXACT)
145 1
            ->addRule(\Nette\Forms\Form::PATTERN, 'Height must be greater than 0', '^[1-9][0-9]*$');
146
147 10
        $form->addCheckbox('crop', 'Crop?');
148 1
        $form->addCheckbox('watermark', 'Watermark?');
149
150 1
        if (\WebCMS\Helpers\SystemHelper::isSuperAdmin($this->user)) {
151 1
            $form->addCheckbox('system', 'System?');
152 1
        } else {
153
            $form->addHidden('system', 'System?');
154
        }
155
156 1
        $form->addSubmit('submit', 'Save');
157
158 1
        $form->onSuccess[] = callback($this, 'thumbnailFormSubmitted');
159 1
        $form->setDefaults($this->thumbnail->toArray());
160
161 1
        return $form;
162
    }
163
164
    public function thumbnailFormSubmitted(\Nette\Forms\Form $form)
165
    {
166
        $values = $form->getValues();
167
168
        if (!$this->thumbnail->getId()) {
169
            $thumb = new \WebCMS\Entity\Thumbnail();
170
        } else {
171
            $thumb = $this->thumbnail;
172
        }
173
174
        if (!\WebCMS\Helpers\SystemHelper::isSuperAdmin($this->user) && $thumb->getSystem()) {
175
            $this->flashMessage('You do not have a permission to do this operation.', 'danger');
176
            $this->redirect('Settings:pictures', array('panel' => 'thumbnails'));
177
        }
178
179
        $thumb->setKey($values->key);
180
        $thumb->setX($values->x);
181
        $thumb->setY($values->y);
182
        $thumb->setResize($values->resize);
183
        $thumb->setCrop($values->crop);
184
        $thumb->setWatermark($values->watermark);
185
        $thumb->setSystem($values->system);
186
187
        $this->em->persist($thumb);
188
        $this->em->flush();
189
190
        $this->flashMessage('Thumbnail setting was added.', 'success');
191
192
        if (!$this->isAjax()) {
193
            $this->redirect('Settings:pictures', array('panel' => 'thumbnails'));
194
        }
195
    }
196
197
    protected function createComponentThumbnailGrid($name)
198
    {
199
        $grid = $this->createGrid($this, $name, "Thumbnail");
200
201
        $grid->addColumnText('key', 'Key');
202
        $grid->addColumnText('x', 'Width');
203
        $grid->addColumnText('y', 'Height');
204
205
        $grid->addColumnText('watermark', 'Watermark')->setReplacement(array(
206
            1 => 'Yes',
207
            NULL => 'No',
208
        ));
209
210
        $grid->addColumnText('system', 'System')->setReplacement(array(
211
            1 => 'Yes',
212
            NULL => 'No',
213
        ));
214
215
        $grid->addActionHref("addThumbnail", 'Edit')->getElementPrototype()->addAttributes(array('class' => array('btn', 'btn-primary', 'ajax'), 'data-toggle' => 'modal', 'data-target' => '#myModal', 'data-remote' => 'false'));
216
        $grid->addActionHref("deleteThumbnail", 'Delete')->getElementPrototype()->addAttributes(array('class' => array('btn', 'btn-danger'), 'data-confirm' => 'Are you sure you want to delete this item?'));
217
218
        return $grid;
219
    }
220
221
    /* EMAILS */
222
223 1 View Code Duplication
    public function createComponentEmailsSettingsForm()
0 ignored issues
show
Duplication introduced by
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.

Loading history...
224
    {
225 1
        $settings = array();
226 1
        $settings[] = $this->settings->get('User new password subject', \WebCMS\Settings::SECTION_EMAIL, 'text');
227 1
        $settings[] = $this->settings->get('User new password', \WebCMS\Settings::SECTION_EMAIL, 'textarea');
228
229 1
        return $this->createSettingsForm($settings);
230
    }
231
232 1
    public function renderEmails()
233
    {
234 1
        $this->reloadContent();
235 1
    }
236
237
    /* BOXES SETTINGS - BATCH */
238
239 1
    public function renderBoxesSettings()
240
    {
241 1
        $this->reloadContent();
242
243
        // fetch all boxes
244 1
        $parameters = $this->getContext()->container->getParameters();
245
246
        // fetch all pages
247 1
        $pages = $this->em->getRepository('WebCMS\Entity\Page')->findBy(array(
248 1
            'language' => $this->state->language,
249 1
        ));
250
251 1
        $boxesAssoc = array();
252 1 View Code Duplication
        foreach ($pages as $page) {
0 ignored issues
show
Duplication introduced by
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.

Loading history...
253
            if ($page->getParent() != NULL) {
254
                $module = $this->createObject($page->getModuleName());
255
256
                foreach ($module->getBoxes() as $box) {
257
                    $boxesAssoc[$page->getId().'-'.$box['module'].'-'.$box['presenter'].'-'.$box['function']] = $page->getTitle().' - '.$this->translation[$box['name']];
258
                }
259
            }
260 1
        }
261
262
        $boxesAssoc = array(
263 1
            0 => $this->translation['Box is not linked.'],
264 1
            ) + $boxesAssoc;
265
266 1
        $boxesAssocError = array();
267 1
        foreach ($parameters['boxes'] as $name => $status) {
268
            
269
            $criteria = new \Doctrine\Common\Collections\Criteria();
270
            $criteria->where($criteria->expr()->eq('box', $name));
271
            $criteria->andWhere($criteria->expr()->isNull('pageTo'));
272
273
            $enabled = $this->em->getRepository('WebCMS\Entity\Box')->matching($criteria);
274
275
            if ($enabled->isEmpty()) {
276
                $boxesAssocError[$name] = false;
277
            } else {
278
                $boxesAssocError[$name] = true;
279
            }
280 1
        }
281
282 1
        $this->template->boxes = $parameters['boxes'];
0 ignored issues
show
Documentation introduced by
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 _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?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.

Loading history...
Bug introduced by
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

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
283 1
        $this->template->pages = $pages;
0 ignored issues
show
Documentation introduced by
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 _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?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.

Loading history...
Bug introduced by
Accessing pages 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

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
284 1
        $this->template->boxesAssoc = $boxesAssoc;
0 ignored issues
show
Documentation introduced by
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 _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?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.

Loading history...
Bug introduced by
Accessing boxesAssoc 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

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
285 1
        $this->template->boxesAssocError = $boxesAssocError;
0 ignored issues
show
Documentation introduced by
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 _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?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.

Loading history...
Bug introduced by
Accessing boxesAssocError 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

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
286 1
    }
287
288
    public function handleUpdateBox($name, $value)
289
    {
290
        $this->reloadContent();
291
292
        $parsed = explode('-', $name);
293
294
        $pageTo = $this->em->getRepository('WebCMS\Entity\Page')->find($parsed[0]);
295
        $box = $parsed[1];
296
297
        $exists = $this->em->getRepository('WebCMS\Entity\Box')->findOneBy(array(
298
            'pageTo' => $pageTo,
299
            'box' => $box,
300
        ));
301
302
        if (is_object($exists)) {
303
            $boxAssign = $exists;
304
        } else {
305
            $boxAssign = new \WebCMS\Entity\Box();
306
        }
307
308
        $parsed = explode('-', $value);
309
310 View Code Duplication
        if (count($parsed) > 3) {
0 ignored issues
show
Duplication introduced by
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.

Loading history...
311
            $pageFrom = $this->em->getRepository('WebCMS\Entity\Page')->find($parsed[0]);
312
            $moduleName = $parsed[1];
313
            $presenter = $parsed[2];
314
            $function = $parsed[3];
315
316
            $boxAssign->setBox($box);
317
            $boxAssign->setFunction($function);
318
            $boxAssign->setModuleName($moduleName);
319
            $boxAssign->setPresenter($presenter);
320
            $boxAssign->setPageFrom($pageFrom);
321
            $boxAssign->setPageTo($pageTo);
322
323
            if (!$boxAssign->getId()) {
324
                $this->em->persist($boxAssign);
325
            }
326
327
            $this->em->persist($boxAssign);
328
        } else {
329
            if (is_object($exists)) {
330
                $this->em->remove($exists);
331
            }
332
        }
333
334
        $this->em->flush();
335
336
        $this->flashMessage('Box settings changed.', 'success');
337
    }
338
339 1
    public function handleUpdateErrorBox($name, $value)
340
    {
341 1
        $this->reloadContent();
342
343
        $parsed = explode('-', $name);
344
345
        $box = $parsed[1];
346
347
        $criteria = new \Doctrine\Common\Collections\Criteria();
348
        $criteria->where($criteria->expr()->isNull('pageTo'));
349
        $criteria->andWhere($criteria->expr()->eq('box', $box));
350
351
        $exists = $this->em->getRepository('WebCMS\Entity\Box')->matching($criteria);        
352
353
        if (!$exists->isEmpty()) {
354
            $boxInfo = $exists->toArray();
355
            $boxAssign = $boxInfo[0];
356
        } else {
357
            $boxInfo = NULL;
358
            $boxAssign = new \WebCMS\Entity\Box();
359
        }
360
361
        $parsed = explode('-', $value);
362
363 View Code Duplication
        if (count($parsed) > 3) {
0 ignored issues
show
Duplication introduced by
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.

Loading history...
364
            $pageFrom = $this->em->getRepository('WebCMS\Entity\Page')->find($parsed[0]);
365
            $moduleName = $parsed[1];
366
            $presenter = $parsed[2];
367
            $function = $parsed[3];
368
369
            $boxAssign->setBox($box);
370
            $boxAssign->setFunction($function);
371
            $boxAssign->setModuleName($moduleName);
372
            $boxAssign->setPresenter($presenter);
373
            $boxAssign->setPageFrom($pageFrom);
374
375
            if (!$boxAssign->getId()) {
376
                $this->em->persist($boxAssign);
377
            }
378
379
            $this->em->persist($boxAssign);
380
        } else {
381
            if (!$exists->isEmpty()) {
382
                $this->em->remove($boxInfo[0]);
383
            }
384
        }
385
386
        $this->em->flush();
387
        
388
        $this->flashMessage('Box settings changed.', 'success');
389
    }
390
391
    /* SEO SETTINGS - BATCH */
392
393 1
    public function renderSeoSettings()
394
    {
395 1
        $this->reloadContent();
396
397
        // fetch all pages
398 1
        $pages = $this->em->getRepository('WebCMS\Entity\Page')->findBy(array(
399 1
            'language' => $this->state->language,
400 1
        ));
401
402 1
        $this->template->pages = $pages;
0 ignored issues
show
Documentation introduced by
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 _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?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.

Loading history...
Bug introduced by
Accessing pages 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

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
403 1
    }
404
405 1
    public function createComponentSeoBasicForm()
406
    {
407 1
        $settings = array();
408
409 1
        $settings[] = $this->settings->get('Seo keywords', \WebCMS\Settings::SECTION_BASIC, 'text');
410 1
        $settings[] = $this->settings->get('Seo title', \WebCMS\Settings::SECTION_BASIC, 'text');
411 1
        $settings[] = $this->settings->get('Seo description', \WebCMS\Settings::SECTION_BASIC, 'text');
412 1
        $settings[] = $this->settings->get('Seo title before', \WebCMS\Settings::SECTION_BASIC, 'checkbox');
413
414 1
        return $this->createSettingsForm($settings);
415
    }
416
417
    public function actionUpdateMeta($idPage, $type, $value)
418
    {
419
        $page = $this->em->getRepository('WebCMS\Entity\Page')->find($idPage);
420
421
        if ($type === 'title') {
422
            $page->setMetaTitle($value);
423
        } elseif ($type === 'keywords') {
424
            $page->setMetaKeywords($value);
425
        } elseif ($type === 'description') {
426
            $page->setMetaDescription($value);
427
        } elseif ($type === 'slug') {
428
            $page->setSlug($value);
429
430
            $path = $this->em->getRepository('WebCMS\Entity\Page')->getPath($page);
431
            $final = array();
432
            foreach ($path as $p) {
433
                if ($p->getParent() != NULL) {
434
                    $final[] = $p->getSlug();
435
                }
436
            }
437
438
            $page->setPath(implode('/', $final));
439
        }
440
441
        $this->em->flush();
442
443
        $this->flashMessage('Seo has been updated.', 'success');
444
        $this->invalidateControl('flashMessages');
445
    }
446
447
    /* SCRIPTS SETTINGS */
448
449 1 View Code Duplication
    public function renderScriptsSettings()
0 ignored issues
show
Duplication introduced by
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.

Loading history...
450
    {
451 1
        $this->reloadContent();
452
453 1
        $globalScriptsVars = array('pageScriptsHead', 'pageScriptsBodyStart', 'pageScriptsBodyEnd');
454 1
        $hooks = array();
455
456 1
        foreach (Finder::findFiles('@*.latte')->in(APP_DIR . '/templates') as $key => $file) {
457
            $filename = $file->getFileName();
458
459
            foreach ($globalScriptsVars as $key => $var) {
460
                if (\WebCMS\Helpers\SystemHelper::checkFileContainsStr(APP_DIR . '/templates/' . $filename, $var)) {
461
                    $hooks[$filename][$var] = true;
462
                } else {
463
                    $hooks[$filename][$var] = false;
464
                }
465
            }
466 1
        }
467
468 1
        $this->template->scriptsHooks = $hooks;
0 ignored issues
show
Documentation introduced by
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 _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?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.

Loading history...
Bug introduced by
Accessing scriptsHooks 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

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
469 1
    }
470
471 1 View Code Duplication
    public function createComponentScriptsGlobalForm()
0 ignored issues
show
Duplication introduced by
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.

Loading history...
472
    {
473 1
        $settings = array();
474
475 1
        $settings[] = $this->settings->get('Scripts head', \WebCMS\Settings::SECTION_BASIC, 'textarea-plain');
476 1
        $settings[] = $this->settings->get('Enable scripts head', \WebCMS\Settings::SECTION_BASIC, 'checkbox-toggle');
477 1
        $settings[] = $this->settings->get('Scripts body start', \WebCMS\Settings::SECTION_BASIC, 'textarea-plain');
478 1
        $settings[] = $this->settings->get('Enable scripts body start', \WebCMS\Settings::SECTION_BASIC, 'checkbox-toggle');
479 1
        $settings[] = $this->settings->get('Scripts body end', \WebCMS\Settings::SECTION_BASIC, 'textarea-plain');
480 1
        $settings[] = $this->settings->get('Enable scripts body end', \WebCMS\Settings::SECTION_BASIC, 'checkbox-toggle');
481
482 1
        return $this->createSettingsForm($settings);
483
    }
484
485
    /* STYLES SETTINGS */
486
487 1 View Code Duplication
    public function renderStylesSettings()
0 ignored issues
show
Duplication introduced by
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.

Loading history...
488
    {
489 1
        $this->reloadContent();
490
491 1
        $globalStylesVars = array('pageStylesHead');
492 1
        $hooks = array();
493
494 1
        foreach (Finder::findFiles('@*.latte')->in(APP_DIR . '/templates') as $key => $file) {
495
            $filename = $file->getFileName();
496
497
            foreach ($globalStylesVars as $key => $var) {
498
                if (\WebCMS\Helpers\SystemHelper::checkFileContainsStr(APP_DIR . '/templates/' . $filename, $var)) {
499
                    $hooks[$filename][$var] = true;
500
                } else {
501
                    $hooks[$filename][$var] = false;
502
                }
503
            }
504 1
        }
505
506 1
        $this->template->stylesHooks = $hooks;
0 ignored issues
show
Documentation introduced by
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 _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?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.

Loading history...
Bug introduced by
Accessing stylesHooks 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

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
507 1
    }
508
509 1 View Code Duplication
    public function createComponentStylesGlobalForm()
0 ignored issues
show
Duplication introduced by
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.

Loading history...
510
    {
511 1
        $settings = array();
512
513 1
        $settings[] = $this->settings->get('Styles head', \WebCMS\Settings::SECTION_BASIC, 'textarea-plain');
514 1
        $settings[] = $this->settings->get('Enable styles head', \WebCMS\Settings::SECTION_BASIC, 'checkbox-toggle');
515
516 1
        return $this->createSettingsForm($settings);
517
    }
518
519
    /* PROJECT SPECIFIC SETTINGS */
520
521 1
    public function createComponentProjectSettingsForm()
522
    {
523 1
        $parameters = $this->getContext()->container->getParameters();
524 1
        $settings = array();
525
526 1
        if (array_key_exists('settings', $parameters)) {
527
            $projectSettings = $parameters['settings'];
528
529
            foreach ($projectSettings as $key => $value) {
530
                $settings[] = $this->settings->get($key, \WebCMS\Settings::SECTION_BASIC, 'checkbox');
531
            }
532
        } else {
533 1
            $this->flashMessage('There are no settings in config file.', 'info');
534
        }
535
536 1
        return $this->createSettingsForm($settings);
537
    }
538
539 1
    public function renderProject()
540
    {
541 1
        $this->reloadContent();
542 1
    }
543
544
    /* API third party */
545
546 1
    public function renderApi()
547
    {
548 1
        $this->reloadContent();
549 1
    }
550
551 1
    public function createComponentApiSettingsForm()
552
    {
553 1
        $settings = array();
554
555 1
        $settings[] = $this->settings->get('Translate service', \WebCMS\Settings::SECTION_BASIC, 'select', \Webcook\Translator\ServiceFactory::getServices());
556
557 1
        $settings[] = $this->settings->get('Yandex API key', \WebCMS\Settings::SECTION_BASIC, 'text');
558
559 1
        $settings[] = $this->settings->get('Google API key', \WebCMS\Settings::SECTION_BASIC, 'text');
560
561 1
        $settings[] = $this->settings->get('Bing client id', \WebCMS\Settings::SECTION_BASIC, 'text');
562 1
        $settings[] = $this->settings->get('Bing client secret', \WebCMS\Settings::SECTION_BASIC, 'text');
563
564 1
        return $this->createSettingsForm($settings);
565
    }
566
}
567