Completed
Push — master ( b8f763...47a15d )
by Craig
14:22 queued 07:28
created

AbstractRouteEntity::setHost()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Routes.
4
 *
5
 * @copyright Zikula contributors (Zikula)
6
 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
7
 * @author Zikula contributors <[email protected]>.
8
 * @link http://www.zikula.org
9
 * @link http://zikula.org
10
 * @version Generated by ModuleStudio 0.7.0 (http://modulestudio.de).
11
 */
12
13
namespace Zikula\RoutesModule\Entity\Historical\v110\Base;
14
15
use Doctrine\ORM\Mapping as ORM;
16
use Gedmo\Mapping\Annotation as Gedmo;
17
use DoctrineExtensions\StandardFields\Mapping\Annotation as ZK;
18
use Symfony\Component\Validator\Constraints as Assert;
19
use Symfony\Component\Validator\Context\ExecutionContextInterface;
20
21
use DataUtil;
22
use FormUtil;
23
use RuntimeException;
24
use ServiceUtil;
25
use UserUtil;
26
use Zikula_Workflow_Util;
27
use Zikula\Core\Doctrine\EntityAccess;
28
29
/**
30
 * Entity class that defines the entity structure and behaviours.
31
 *
32
 * This is the base entity class for route entities.
33
 * The following annotation marks it as a mapped superclass so subclasses
34
 * inherit orm properties.
35
 *
36
 * @ORM\MappedSuperclass
37
 *
38
 * @abstract
39
 */
40
abstract class AbstractRouteEntity extends EntityAccess
41
{
42
    /**
43
     * @var string The tablename this object maps to
44
     */
45
    protected $_objectType = 'route';
46
47
    /**
48
     * @Assert\Type(type="bool")
49
     * @var boolean Option to bypass validation if needed
50
     */
51
    protected $_bypassValidation = false;
52
53
    /**
54
     * @var array The current workflow data of this object
55
     */
56
    protected $__WORKFLOW__ = [];
57
58
    /**
59
     * @ORM\Id
60
     * @ORM\GeneratedValue(strategy="AUTO")
61
     * @ORM\Column(type="integer", unique=true)
62
     * @Assert\Type(type="integer")
63
     * @Assert\NotNull()
64
     * @Assert\LessThan(value=1000000000, message="Length of field value must not be higher than 9.")) {
65
     * @var integer $id
66
     */
67
    protected $id = 0;
68
69
    /**
70
     * the current workflow state
71
     * @ORM\Column(length=20)
72
     * @Assert\NotBlank()
73
     * @Assert\Choice(callback="getWorkflowStateAllowedValues", multiple=false)
74
     * @var string $workflowState
75
     */
76
    protected $workflowState = 'initial';
77
78
    /**
79
     * @ORM\Column(length=255)
80
     * @Assert\NotBlank()
81
     * @Assert\Choice(callback="getRouteTypeAllowedValues", multiple=false)
82
     * @var string $routeType
83
     */
84
    protected $routeType = 'additional';
85
86
    /**
87
     * @ORM\Column(length=255, nullable=true)
88
     * @Assert\Length(min="0", max="255")
89
     * @var string $replacedRouteName
90
     */
91
    protected $replacedRouteName = '';
92
93
    /**
94
     * @ORM\Column(length=255)
95
     * @Assert\NotBlank()
96
     * @Assert\Length(min="0", max="255")
97
     * @var string $bundle
98
     */
99
    protected $bundle = '';
100
101
    /**
102
     * @ORM\Column(length=255)
103
     * @Assert\NotBlank()
104
     * @Assert\Length(min="0", max="255")
105
     * @var string $controller
106
     */
107
    protected $controller = '';
108
109
    /**
110
     * @ORM\Column(name="route_action", length=255)
111
     * @Assert\NotBlank()
112
     * @Assert\Length(min="0", max="255")
113
     * @var string $action
114
     */
115
    protected $action = '';
116
117
    /**
118
     * @ORM\Column(name="route_path", length=255)
119
     * @Assert\NotBlank()
120
     * @Assert\Length(min="0", max="255")
121
     * @var string $path
122
     */
123
    protected $path = '';
124
125
    /**
126
     * @ORM\Column(length=255, nullable=true)
127
     * @Assert\Length(min="0", max="255")
128
     * @var string $host
129
     */
130
    protected $host = '';
131
132
    /**
133
     * @ORM\Column(length=255)
134
     * @Assert\NotBlank()
135
     * @var string $schemes
136
     */
137
    protected $schemes = 'http';
138
139
    /**
140
     * @ORM\Column(length=255)
141
     * @Assert\NotBlank()
142
     * @var string $methods
143
     */
144
    protected $methods = 'GET';
145
146
    /**
147
     * @ORM\Column(type="boolean")
148
     * @Assert\IsTrue(message="This option is mandatory.")
149
     * @Assert\Type(type="bool")
150
     * @var boolean $prependBundlePrefix
151
     */
152
    protected $prependBundlePrefix = true;
153
154
    /**
155
     * @ORM\Column(type="boolean")
156
     * @Assert\IsTrue(message="This option is mandatory.")
157
     * @Assert\Type(type="bool")
158
     * @var boolean $translatable
159
     */
160
    protected $translatable = true;
161
162
    /**
163
     * @ORM\Column(length=255, nullable=true)
164
     * @Assert\Length(min="0", max="255")
165
     * @var string $translationPrefix
166
     */
167
    protected $translationPrefix = '';
168
169
    /**
170
     * @ORM\Column(name="route_defaults", type="array")
171
     * @Assert\NotBlank()
172
     * @Assert\Type(type="array")
173
     * @var array $defaults
174
     */
175
    protected $defaults = [];
176
177
    /**
178
     * @ORM\Column(type="array")
179
     * @Assert\NotNull()
180
     * @Assert\Type(type="array")
181
     * @var array $requirements
182
     */
183
    protected $requirements = [];
184
185
    /**
186
     * @ORM\Column(name="route_condition", length=255, nullable=true)
187
     * @Assert\Length(min="0", max="255")
188
     * @var string $condition
189
     */
190
    protected $condition = '';
191
192
    /**
193
     * @ORM\Column(length=255, nullable=true)
194
     * @Assert\Length(min="0", max="255")
195
     * @var string $description
196
     */
197
    protected $description = '';
198
199
    /**
200
     * @Gedmo\SortablePosition
201
     * @ORM\Column(type="integer")
202
     * @Assert\Type(type="integer")
203
     * @Assert\NotNull()
204
     * @Assert\LessThan(value=2147483647, message="Length of field value must not be higher than 11.")) {
205
     * @var integer $sort
206
     */
207
    protected $sort = 0;
208
209
    /**
210
     * @Gedmo\SortableGroup
211
     * @ORM\Column(name="sort_group", length=255)
212
     * @Assert\NotNull()
213
     * @Assert\Length(min="0", max="255")
214
     * @var string $group
215
     */
216
    protected $group = '';
217
218
219
    /**
220
     * @ORM\Column(type="integer")
221
     * @ZK\StandardFields(type="userid", on="create")
222
     * @Assert\Type(type="integer")
223
     * @var integer $createdUserId
224
     */
225
    protected $createdUserId;
226
227
    /**
228
     * @ORM\Column(type="integer")
229
     * @ZK\StandardFields(type="userid", on="update")
230
     * @Assert\Type(type="integer")
231
     * @var integer $updatedUserId
232
     */
233
    protected $updatedUserId;
234
235
    /**
236
     * @ORM\Column(type="datetime")
237
     * @Gedmo\Timestampable(on="create")
238
     * @Assert\DateTime()
239
     * @var \DateTime $createdDate
240
     */
241
    protected $createdDate;
242
243
    /**
244
     * @ORM\Column(type="datetime")
245
     * @Gedmo\Timestampable(on="update")
246
     * @Assert\DateTime()
247
     * @var \DateTime $updatedDate
248
     */
249
    protected $updatedDate;
250
251
252
    /**
253
     * Constructor.
254
     * Will not be called by Doctrine and can therefore be used
255
     * for own implementation purposes. It is also possible to add
256
     * arbitrary arguments as with every other class method.
257
     *
258
     * @param TODO
259
     */
260
    public function __construct()
261
    {
262
        $this->workflowState = 'initial';
263
        $this->initWorkflow();
264
    }
265
266
    /**
267
     * Gets the _object type.
268
     *
269
     * @return string
270
     */
271
    public function get_objectType()
272
    {
273
        return $this->_objectType;
274
    }
275
276
    /**
277
     * Sets the _object type.
278
     *
279
     * @param string $_objectType
280
     *
281
     * @return void
282
     */
283
    public function set_objectType($_objectType)
284
    {
285
        $this->_objectType = $_objectType;
286
    }
287
288
    /**
289
     * Gets the _bypass validation.
290
     *
291
     * @return boolean
292
     */
293
    public function get_bypassValidation()
294
    {
295
        return $this->_bypassValidation;
296
    }
297
298
    /**
299
     * Sets the _bypass validation.
300
     *
301
     * @param boolean $_bypassValidation
302
     *
303
     * @return void
304
     */
305
    public function set_bypassValidation($_bypassValidation)
306
    {
307
        $this->_bypassValidation = $_bypassValidation;
308
    }
309
310
    /**
311
     * Gets the __ w o r k f l o w__.
312
     *
313
     * @return array
314
     */
315
    public function get__WORKFLOW__()
316
    {
317
        return $this->__WORKFLOW__;
318
    }
319
320
    /**
321
     * Sets the __ w o r k f l o w__.
322
     *
323
     * @param array $__WORKFLOW__
324
     *
325
     * @return void
326
     */
327
    public function set__WORKFLOW__(array $__WORKFLOW__ = [])
328
    {
329
        $this->__WORKFLOW__ = $__WORKFLOW__;
330
    }
331
332
333
    /**
334
     * Gets the id.
335
     *
336
     * @return integer
337
     */
338
    public function getId()
339
    {
340
        return $this->id;
341
    }
342
343
    /**
344
     * Sets the id.
345
     *
346
     * @param integer $id
347
     *
348
     * @return void
349
     */
350
    public function setId($id)
351
    {
352
        $this->id = $id;
353
    }
354
355
    /**
356
     * Gets the workflow state.
357
     *
358
     * @return string
359
     */
360
    public function getWorkflowState()
361
    {
362
        return $this->workflowState;
363
    }
364
365
    /**
366
     * Sets the workflow state.
367
     *
368
     * @param string $workflowState
369
     *
370
     * @return void
371
     */
372
    public function setWorkflowState($workflowState)
373
    {
374
        $this->workflowState = $workflowState;
375
    }
376
377
    /**
378
     * Gets the route type.
379
     *
380
     * @return string
381
     */
382
    public function getRouteType()
383
    {
384
        return $this->routeType;
385
    }
386
387
    /**
388
     * Sets the route type.
389
     *
390
     * @param string $routeType
391
     *
392
     * @return void
393
     */
394
    public function setRouteType($routeType)
395
    {
396
        $this->routeType = $routeType;
397
    }
398
399
    /**
400
     * Gets the replaced route name.
401
     *
402
     * @return string
403
     */
404
    public function getReplacedRouteName()
405
    {
406
        return $this->replacedRouteName;
407
    }
408
409
    /**
410
     * Sets the replaced route name.
411
     *
412
     * @param string $replacedRouteName
413
     *
414
     * @return void
415
     */
416
    public function setReplacedRouteName($replacedRouteName)
417
    {
418
        $this->replacedRouteName = $replacedRouteName;
419
    }
420
421
    /**
422
     * Gets the bundle.
423
     *
424
     * @return string
425
     */
426
    public function getBundle()
427
    {
428
        return $this->bundle;
429
    }
430
431
    /**
432
     * Sets the bundle.
433
     *
434
     * @param string $bundle
435
     *
436
     * @return void
437
     */
438
    public function setBundle($bundle)
439
    {
440
        $this->bundle = $bundle;
441
    }
442
443
    /**
444
     * Gets the controller.
445
     *
446
     * @return string
447
     */
448
    public function getController()
449
    {
450
        return $this->controller;
451
    }
452
453
    /**
454
     * Sets the controller.
455
     *
456
     * @param string $controller
457
     *
458
     * @return void
459
     */
460
    public function setController($controller)
461
    {
462
        $this->controller = $controller;
463
    }
464
465
    /**
466
     * Gets the action.
467
     *
468
     * @return string
469
     */
470
    public function getAction()
471
    {
472
        return $this->action;
473
    }
474
475
    /**
476
     * Sets the action.
477
     *
478
     * @param string $action
479
     *
480
     * @return void
481
     */
482
    public function setAction($action)
483
    {
484
        $this->action = $action;
485
    }
486
487
    /**
488
     * Gets the path.
489
     *
490
     * @return string
491
     */
492
    public function getPath()
493
    {
494
        return $this->path;
495
    }
496
497
    /**
498
     * Sets the path.
499
     *
500
     * @param string $path
501
     *
502
     * @return void
503
     */
504
    public function setPath($path)
505
    {
506
        $this->path = $path;
507
    }
508
509
    /**
510
     * Gets the host.
511
     *
512
     * @return string
513
     */
514
    public function getHost()
515
    {
516
        return $this->host;
517
    }
518
519
    /**
520
     * Sets the host.
521
     *
522
     * @param string $host
523
     *
524
     * @return void
525
     */
526
    public function setHost($host)
527
    {
528
        $this->host = $host;
529
    }
530
531
    /**
532
     * Gets the schemes.
533
     *
534
     * @return string
535
     */
536
    public function getSchemes()
537
    {
538
        return $this->schemes;
539
    }
540
541
    /**
542
     * Sets the schemes.
543
     *
544
     * @param string $schemes
545
     *
546
     * @return void
547
     */
548
    public function setSchemes($schemes)
549
    {
550
        $this->schemes = $schemes;
551
    }
552
553
    /**
554
     * Gets the methods.
555
     *
556
     * @return string
557
     */
558
    public function getMethods()
559
    {
560
        return $this->methods;
561
    }
562
563
    /**
564
     * Sets the methods.
565
     *
566
     * @param string $methods
567
     *
568
     * @return void
569
     */
570
    public function setMethods($methods)
571
    {
572
        $this->methods = $methods;
573
    }
574
575
    /**
576
     * Gets the prepend bundle prefix.
577
     *
578
     * @return boolean
579
     */
580
    public function getPrependBundlePrefix()
581
    {
582
        return $this->prependBundlePrefix;
583
    }
584
585
    /**
586
     * Sets the prepend bundle prefix.
587
     *
588
     * @param boolean $prependBundlePrefix
589
     *
590
     * @return void
591
     */
592
    public function setPrependBundlePrefix($prependBundlePrefix)
593
    {
594
        if ($prependBundlePrefix !== $this->prependBundlePrefix) {
595
            $this->prependBundlePrefix = (bool)$prependBundlePrefix;
596
        }
597
    }
598
599
    /**
600
     * Gets the translatable.
601
     *
602
     * @return boolean
603
     */
604
    public function getTranslatable()
605
    {
606
        return $this->translatable;
607
    }
608
609
    /**
610
     * Sets the translatable.
611
     *
612
     * @param boolean $translatable
613
     *
614
     * @return void
615
     */
616
    public function setTranslatable($translatable)
617
    {
618
        if ($translatable !== $this->translatable) {
619
            $this->translatable = (bool)$translatable;
620
        }
621
    }
622
623
    /**
624
     * Gets the translation prefix.
625
     *
626
     * @return string
627
     */
628
    public function getTranslationPrefix()
629
    {
630
        return $this->translationPrefix;
631
    }
632
633
    /**
634
     * Sets the translation prefix.
635
     *
636
     * @param string $translationPrefix
637
     *
638
     * @return void
639
     */
640
    public function setTranslationPrefix($translationPrefix)
641
    {
642
        $this->translationPrefix = $translationPrefix;
643
    }
644
645
    /**
646
     * Gets the defaults.
647
     *
648
     * @return array
649
     */
650
    public function getDefaults()
651
    {
652
        return $this->defaults;
653
    }
654
655
    /**
656
     * Sets the defaults.
657
     *
658
     * @param array $defaults
659
     *
660
     * @return void
661
     */
662
    public function setDefaults($defaults)
663
    {
664
        $this->defaults = $defaults;
665
    }
666
667
    /**
668
     * Gets the requirements.
669
     *
670
     * @return array
671
     */
672
    public function getRequirements()
673
    {
674
        return $this->requirements;
675
    }
676
677
    /**
678
     * Sets the requirements.
679
     *
680
     * @param array $requirements
681
     *
682
     * @return void
683
     */
684
    public function setRequirements($requirements)
685
    {
686
        $this->requirements = $requirements;
687
    }
688
689
    /**
690
     * Gets the condition.
691
     *
692
     * @return string
693
     */
694
    public function getCondition()
695
    {
696
        return $this->condition;
697
    }
698
699
    /**
700
     * Sets the condition.
701
     *
702
     * @param string $condition
703
     *
704
     * @return void
705
     */
706
    public function setCondition($condition)
707
    {
708
        $this->condition = $condition;
709
    }
710
711
    /**
712
     * Gets the description.
713
     *
714
     * @return string
715
     */
716
    public function getDescription()
717
    {
718
        return $this->description;
719
    }
720
721
    /**
722
     * Sets the description.
723
     *
724
     * @param string $description
725
     *
726
     * @return void
727
     */
728
    public function setDescription($description)
729
    {
730
        $this->description = $description;
731
    }
732
733
    /**
734
     * Gets the sort.
735
     *
736
     * @return integer
737
     */
738
    public function getSort()
739
    {
740
        return $this->sort;
741
    }
742
743
    /**
744
     * Sets the sort.
745
     *
746
     * @param integer $sort
747
     *
748
     * @return void
749
     */
750
    public function setSort($sort)
751
    {
752
        $this->sort = $sort;
753
    }
754
755
    /**
756
     * Gets the group.
757
     *
758
     * @return string
759
     */
760
    public function getGroup()
761
    {
762
        return $this->group;
763
    }
764
765
    /**
766
     * Sets the group.
767
     *
768
     * @param string $group
769
     *
770
     * @return void
771
     */
772
    public function setGroup($group)
773
    {
774
        $this->group = $group;
775
    }
776
777
    /**
778
     * Gets the created user id.
779
     *
780
     * @return integer
781
     */
782
    public function getCreatedUserId()
783
    {
784
        return $this->createdUserId;
785
    }
786
787
    /**
788
     * Sets the created user id.
789
     *
790
     * @param integer $createdUserId
791
     *
792
     * @return void
793
     */
794
    public function setCreatedUserId($createdUserId)
795
    {
796
        $this->createdUserId = $createdUserId;
797
    }
798
799
    /**
800
     * Gets the updated user id.
801
     *
802
     * @return integer
803
     */
804
    public function getUpdatedUserId()
805
    {
806
        return $this->updatedUserId;
807
    }
808
809
    /**
810
     * Sets the updated user id.
811
     *
812
     * @param integer $updatedUserId
813
     *
814
     * @return void
815
     */
816
    public function setUpdatedUserId($updatedUserId)
817
    {
818
        $this->updatedUserId = $updatedUserId;
819
    }
820
821
    /**
822
     * Gets the created date.
823
     *
824
     * @return \DateTime
825
     */
826
    public function getCreatedDate()
827
    {
828
        return $this->createdDate;
829
    }
830
831
    /**
832
     * Sets the created date.
833
     *
834
     * @param \DateTime $createdDate
835
     *
836
     * @return void
837
     */
838
    public function setCreatedDate($createdDate)
839
    {
840
        $this->createdDate = $createdDate;
841
    }
842
843
    /**
844
     * Gets the updated date.
845
     *
846
     * @return \DateTime
847
     */
848
    public function getUpdatedDate()
849
    {
850
        return $this->updatedDate;
851
    }
852
853
    /**
854
     * Sets the updated date.
855
     *
856
     * @param \DateTime $updatedDate
857
     *
858
     * @return void
859
     */
860
    public function setUpdatedDate($updatedDate)
861
    {
862
        $this->updatedDate = $updatedDate;
863
    }
864
865
866
867
868
    /**
869
     * Returns the formatted title conforming to the display pattern
870
     * specified for this entity.
871
     *
872
     * @return string The display title
873
     */
874 View Code Duplication
    public function getTitleFromDisplayPattern()
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...
875
    {
876
        $serviceManager = ServiceUtil::getManager();
877
        $listHelper = $serviceManager->get('zikula_routes_module.listentries_helper');
0 ignored issues
show
Unused Code introduced by
$listHelper 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 $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
878
879
        $formattedTitle = ''
880
                . $this->getPath()
881
                . ' ('
882
                . $this->getSort()
883
                . ')';
884
885
        return $formattedTitle;
886
    }
887
888
889
    /**
890
     * Returns a list of possible choices for the workflowState list field.
891
     * This method is used for validation.
892
     *
893
     * @return array List of allowed choices
894
     */
895 View Code Duplication
    public static function getWorkflowStateAllowedValues()
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...
896
    {
897
        $serviceManager = ServiceUtil::getManager();
898
        $helper = $serviceManager->get('zikula_routes_module.listentries_helper');
899
        $listEntries = $helper->getWorkflowStateEntriesForRoute();
900
901
        $allowedValues = [];
902
        foreach ($listEntries as $entry) {
903
            $allowedValues[] = $entry['value'];
904
        }
905
906
        return $allowedValues;
907
    }
908
909
    /**
910
     * Returns a list of possible choices for the routeType list field.
911
     * This method is used for validation.
912
     *
913
     * @return array List of allowed choices
914
     */
915 View Code Duplication
    public static function getRouteTypeAllowedValues()
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...
916
    {
917
        $serviceManager = ServiceUtil::getManager();
918
        $helper = $serviceManager->get('zikula_routes_module.listentries_helper');
919
        $listEntries = $helper->getRouteTypeEntriesForRoute();
920
921
        $allowedValues = [];
922
        foreach ($listEntries as $entry) {
923
            $allowedValues[] = $entry['value'];
924
        }
925
926
        return $allowedValues;
927
    }
928
929
    /**
930
     * @Assert\Callback()
931
     */
932 View Code Duplication
    public function isSchemesValueAllowed(ExecutionContextInterface $context)
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...
933
    {
934
        $serviceManager = ServiceUtil::getManager();
935
        $helper = $serviceManager->get('zikula_routes_module.listentries_helper');
936
        $listEntries = $helper->getSchemesEntriesForRoute();
937
        $dom = ZLanguage::getModuleDomain('ZikulaRoutesModule');
938
939
        $allowedValues = [];
940
        foreach ($listEntries as $entry) {
941
            $allowedValues[] = $entry['value'];
942
        }
943
944
        $selected = explode('###', $this->schemes);
945
        foreach ($selected as $value) {
946
            if ($value == '') {
947
                continue;
948
            }
949
            if (!in_array($value, $allowedValues, true)) {
950
                $context->buildViolation(__('Invalid value provided', $dom))
951
                    ->atPath('schemes')
952
                    ->addViolation();
953
            }
954
        }
955
    }
956
957
    /**
958
     * @Assert\Callback()
959
     */
960 View Code Duplication
    public function isMethodsValueAllowed(ExecutionContextInterface $context)
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...
961
    {
962
        $serviceManager = ServiceUtil::getManager();
963
        $helper = $serviceManager->get('zikula_routes_module.listentries_helper');
964
        $listEntries = $helper->getMethodsEntriesForRoute();
965
        $dom = ZLanguage::getModuleDomain('ZikulaRoutesModule');
966
967
        $allowedValues = [];
968
        foreach ($listEntries as $entry) {
969
            $allowedValues[] = $entry['value'];
970
        }
971
972
        $selected = explode('###', $this->methods);
973
        foreach ($selected as $value) {
974
            if ($value == '') {
975
                continue;
976
            }
977
            if (!in_array($value, $allowedValues, true)) {
978
                $context->buildViolation(__('Invalid value provided', $dom))
979
                    ->atPath('methods')
980
                    ->addViolation();
981
            }
982
        }
983
    }
984
985
    /**
986
     * Sets/retrieves the workflow details.
987
     *
988
     * @param boolean $forceLoading load the workflow record
989
     *
990
     * @throws RuntimeException Thrown if retrieving the workflow object fails
991
     */
992
    public function initWorkflow($forceLoading = false)
993
    {
994
        $currentFunc = FormUtil::getPassedValue('func', 'index', 'GETPOST', FILTER_SANITIZE_STRING);
995
        $isReuse = FormUtil::getPassedValue('astemplate', '', 'GETPOST', FILTER_SANITIZE_STRING);
996
997
        // apply workflow with most important information
998
        $idColumn = 'id';
999
1000
        $serviceManager = ServiceUtil::getManager();
1001
        $workflowHelper = $serviceManager->get('zikula_routes_module.workflow_helper');
1002
1003
        $schemaName = $workflowHelper->getWorkflowName($this['_objectType']);
1004
        $this['__WORKFLOW__'] = [
1005
            'module' => 'ZikulaRoutesModule',
1006
            'state' => $this['workflowState'],
1007
            'obj_table' => $this['_objectType'],
1008
            'obj_idcolumn' => $idColumn,
1009
            'obj_id' => $this[$idColumn],
1010
            'schemaname' => $schemaName
1011
        ];
1012
1013
        // load the real workflow only when required (e. g. when func is edit or delete)
1014
        if ((!in_array($currentFunc, ['index', 'view', 'display']) && empty($isReuse)) || $forceLoading) {
1015
            $result = Zikula_Workflow_Util::getWorkflowForObject($this, $this['_objectType'], $idColumn, 'ZikulaRoutesModule');
1016
            if (!$result) {
1017
                $flashBag = $serviceManager->get('session')->getFlashBag();
1018
                $flashBag->add('error', $serviceManager->get('translator.default')->__('Error! Could not load the associated workflow.'));
1019
            }
1020
        }
1021
1022 View Code Duplication
        if (!is_object($this['__WORKFLOW__']) && !isset($this['__WORKFLOW__']['schemaname'])) {
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...
1023
            $workflow = $this['__WORKFLOW__'];
1024
            $workflow['schemaname'] = $schemaName;
1025
            $this['__WORKFLOW__'] = $workflow;
1026
        }
1027
    }
1028
1029
    /**
1030
     * Resets workflow data back to initial state.
1031
     * To be used after cloning an entity object.
1032
     */
1033
    public function resetWorkflow()
1034
    {
1035
        $this->setWorkflowState('initial');
1036
1037
        $serviceManager = ServiceUtil::getManager();
1038
        $workflowHelper = $serviceManager->get('zikula_routes_module.workflow_helper');
1039
1040
        $schemaName = $workflowHelper->getWorkflowName($this['_objectType']);
1041
        $this['__WORKFLOW__'] = [
1042
            'module' => 'ZikulaRoutesModule',
1043
            'state' => $this['workflowState'],
1044
            'obj_table' => $this['_objectType'],
1045
            'obj_idcolumn' => 'id',
1046
            'obj_id' => 0,
1047
            'schemaname' => $schemaName
1048
        ];
1049
    }
1050
1051
    /**
1052
     * Start validation and raise exception if invalid data is found.
1053
     *
1054
     * @return boolean Whether everything is valid or not
1055
     */
1056
    public function validate()
1057
    {
1058
        if ($this->_bypassValidation === true) {
1059
            return true;
1060
        }
1061
1062
        $serviceManager = ServiceUtil::getManager();
1063
1064
        $validator = $serviceManager->get('validator');
1065
        $errors = $validator->validate($this);
1066
1067 View Code Duplication
        if (count($errors) > 0) {
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...
1068
            $flashBag = $serviceManager->get('session')->getFlashBag();
1069
            foreach ($errors as $error) {
1070
                $flashBag->add('error', $error->getMessage());
1071
            }
1072
1073
            return false;
1074
        }
1075
1076
        return true;
1077
    }
1078
1079
    /**
1080
     * Return entity data in JSON format.
1081
     *
1082
     * @return string JSON-encoded data
1083
     */
1084
    public function toJson()
1085
    {
1086
        return json_encode($this->toArray());
1087
    }
1088
1089
    /**
1090
     * Creates url arguments array for easy creation of display urls.
1091
     *
1092
     * @return array The resulting arguments list
1093
     */
1094 View Code Duplication
    public function createUrlArgs()
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...
1095
    {
1096
        $args = [];
1097
1098
        $args['id'] = $this['id'];
1099
1100
        if (property_exists($this, 'slug')) {
1101
            $args['slug'] = $this['slug'];
1102
        }
1103
1104
        return $args;
1105
    }
1106
1107
    /**
1108
     * Create concatenated identifier string (for composite keys).
1109
     *
1110
     * @return String concatenated identifiers
1111
     */
1112
    public function createCompositeIdentifier()
1113
    {
1114
        $itemId = $this['id'];
1115
1116
        return $itemId;
1117
    }
1118
1119
    /**
1120
     * Determines whether this entity supports hook subscribers or not.
1121
     *
1122
     * @return boolean
1123
     */
1124
    public function supportsHookSubscribers()
1125
    {
1126
        return false;
1127
    }
1128
1129
    /**
1130
     * Returns an array of all related objects that need to be persisted after clone.
1131
     *
1132
     * @param array $objects The objects are added to this array. Default: []
1133
     *
1134
     * @return array of entity objects
1135
     */
1136
    public function getRelatedObjectsToPersist(&$objects = [])
0 ignored issues
show
Unused Code introduced by
The parameter $objects 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...
1137
    {
1138
        return [];
1139
    }
1140
1141
    /**
1142
     * ToString interceptor implementation.
1143
     * This method is useful for debugging purposes.
1144
     *
1145
     * @return string The output string for this entity
1146
     */
1147
    public function __toString()
1148
    {
1149
        return $this->getId();
1150
    }
1151
1152
    /**
1153
     * Clone interceptor implementation.
1154
     * This method is for example called by the reuse functionality.
1155
     * Performs a quite simple shallow copy.
1156
     *
1157
     * See also:
1158
     * (1) http://docs.doctrine-project.org/en/latest/cookbook/implementing-wakeup-or-clone.html
1159
     * (2) http://www.php.net/manual/en/language.oop5.cloning.php
1160
     * (3) http://stackoverflow.com/questions/185934/how-do-i-create-a-copy-of-an-object-in-php
1161
     */
1162 View Code Duplication
    public function __clone()
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...
1163
    {
1164
        // If the entity has an identity, proceed as normal.
1165
        if ($this->id) {
1166
            // unset identifiers
1167
            $this->setId(0);
1168
1169
            // reset Workflow
1170
            $this->resetWorkflow();
1171
1172
            $this->setCreatedDate(null);
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<DateTime>.

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);
Loading history...
1173
            $this->setCreatedUserId(null);
1174
            $this->setUpdatedDate(null);
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<DateTime>.

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);
Loading history...
1175
            $this->setUpdatedUserId(null);
1176
1177
        }
1178
        // otherwise do nothing, do NOT throw an exception!
1179
    }
1180
}
1181