| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Dynamic\DynamicBlocks\Model; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Dynamic\DynamicBlocks\Block\AccordionBlock; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use SilverStripe\AssetAdmin\Forms\UploadField; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use SilverStripe\ORM\DataObject; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | class AccordionPanel extends DataObject | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     private static $singular_name = 'Accordion Panel'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     private static $plural_name = 'Accordion Panels'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     private static $description = 'A panel for a Accordion widget'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     private static $db = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         'Title' => 'Varchar(255)', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         'Content' => 'HTMLText', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         'Sort' => 'Int', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     private static $has_one = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         'Accordion' => AccordionBlock::class, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         'Image' => Image::class, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         //'BlockLink' => 'Link', // todo readd once Linkable is SS4 compatible | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     private static $default_sort = 'Sort'; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      * @return \SilverStripe\Forms\FieldList | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     public function getCMSFields() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 1 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $fields = parent::getCMSFields(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 | 1 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         $fields->removeByName(array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 | 1 |  |             'Sort', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 | 1 |  |             'AccordionID', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 | 1 |  |         )); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 | 1 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         $fields->addFieldToTab( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 | 1 |  |             'Root.Main', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 | 1 |  |             UploadField::create('Image') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 | 1 |  |             //    ->setFolderName('Uploads/Elements/Accordions') | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 | 1 |  |             , | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |             'Content' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 | 1 |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 1 |  |         /* // todo readd once Linkable is SS4 compatible | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 | 1 |  |         $fields->addFieldToTab( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 1 |  |             'Root.Main', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |             LinkField::create('BlockLinkID', 'Link'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 | 1 |  |             'Image' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 | 1 |  |         */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         return $fields; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 | 1 |  |      * @return \SilverStripe\ORM\ValidationResult | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 82 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 83 | 1 |  |     public function validate() | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 85 | 1 |  |         $result = parent::validate(); | 
            
                                                                        
                            
            
                                    
            
            
                | 86 | 1 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 87 | 1 |  |         if (!$this->Title) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 88 |  |  |             $result->error('Title is required'); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 89 | 1 |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 91 |  |  |         return $result; | 
            
                                                                        
                            
            
                                    
            
            
                | 92 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |      * @param null $member | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |      * @param array $context | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 | 1 |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 | 1 |  |     public function canCreate($member = null, $context = []) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |         return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |      * @param null $member | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |      * @param array $context | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 | 1 |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 | 1 |  |     public function canView($member = null, $context = []) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |      * @param null $member | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |      * @param array $context | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 | 1 |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 | 1 |  |     public function canEdit($member = null, $context = []) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |         return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |      * @param null $member | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |      * @param array $context | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 | 1 |  |      * @return bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 | 1 |  |     public function canDelete($member = null, $context = []) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |         return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 | 1 |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 133 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 134 |  |  |  | 
            
                        
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.