| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Dynamic\ProductCatalog\Docs; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use SilverStripe\AssetAdmin\Forms\UploadField; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use SilverStripe\Assets\File; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use SilverStripe\Assets\Image; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use SilverStripe\Forms\TextField; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use SilverStripe\ORM\DataObject; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | class ProductDoc extends DataObject | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     private static $db = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |         'Name' => 'Varchar(255)', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |         'Title' => 'Varchar(255)', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |         'Content' => 'HTMLText', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |         'FileLink' => 'Varchar(255)', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     private static $has_one = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         'Image' => Image::class, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         'Download' => File::class, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     private static $summary_fields = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         'Name' => 'Name', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         'Title' => 'Title', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     private static $searchable_fields = array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         'Name', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         'Title', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 | 6 |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      * @var string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 | 6 |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     private static $default_sort = 'Title'; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 | 6 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 | 6 |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 | 6 |  |      * @return \SilverStripe\Forms\FieldList | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 | 6 |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 | 6 |  |     public function getCMSFields() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 | 6 |  |         $fields = parent::getCMSFields(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 | 6 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 | 6 |  |         $file = UploadField::create('Download') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 | 6 |  |             //->setFolderName('Uploads/FileDownloads') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 | 6 |  |             //->setConfig('allowedMaxFileNumber', 1) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 | 6 |  |             //->setAllowedFileCategories('doc') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |             //->setAllowedMaxFileNumber(1) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 | 6 |  |         ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 | 6 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 | 6 |  |         $fields->addFieldsToTab('Root.Download', array( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 | 6 |  |             $file, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |             TextField::create('FileLink') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 | 6 |  |                 ->setDescription('URL of external file. will display on page if no Download is specified above.') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |                 ->setAttribute('placeholder', 'http://'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 | 6 |  |         )); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         $fields->insertBefore( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |             UploadField::create('Image') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |                 //->setFolderName('Uploads/ProductDocs/Images') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |                 ->setDescription('Preview image of file') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 | 45 |  |             , | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |             'Content' | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 | 45 |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 | 45 |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         return $fields; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 | 45 |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      * if SetClass dropdown is set, create a new instance of the new class. | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 86 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 87 |  |  |     public function onAfterWrite() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                        
            
                                    
            
            
                | 88 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 89 |  |  |         parent::onAfterWrite(); | 
            
                                                        
            
                                    
            
            
                | 90 |  |  |         if (isset($_REQUEST['SetClass'])) { | 
            
                                                        
            
                                    
            
            
                | 91 |  |  |             $object = $this->newClassInstance($_REQUEST['SetClass']); | 
            
                                                        
            
                                    
            
            
                | 92 |  |  |             $object->write(); | 
            
                                                        
            
                                    
            
            
                | 93 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 94 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 95 |  |  | } | 
            
                        
This check marks private properties in classes that are never used. Those properties can be removed.