| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace DorsetDigital\Elements\PhotoSwipe\Models; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Bummzack\SortableFile\Forms\SortableUploadField; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use DNADesign\Elemental\Models\BaseElement; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use DorsetDigital\Elements\PhotoSwipe\Controllers\GalleryController; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use SilverStripe\Assets\Image; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use SilverStripe\i18n\i18n; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use SilverStripe\Security\Security; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use SilverStripe\View\SSViewer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | class Gallery extends BaseElement | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     private static $singular_name = 'Photoswipe Gallery'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     private static $plural_name = 'Photoswipe Galleries'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     private static $description = 'Responsive image gallery'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     private static $table_name = 'DorsetDigital_Elements_PhotoSwipe'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     private static $controller_class = GalleryController::class; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     private static $inline_editable = false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     private static $casting = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         'getSummary' => 'HTMLText' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     private static $many_many = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         'GalleryImages' => Image::class | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     private static $many_many_extraFields = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         'GalleryImages' => [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |             'SortOrder' => 'Int' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         ] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     private static $owns = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         'GalleryImages' | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     public function getCMSFields() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $fields = parent::getCMSFields(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         $fields->removeByName('GalleryImages'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         $fields->addFieldToTab('Root.Main', SortableUploadField::create( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             'GalleryImages', $this->owner->fieldLabel('Images') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |         )->setFolderName('galleryimages')->setAllowedFileCategories('image/supported')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |         return $fields; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     public function getSortedImages() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         return $this->GalleryImages()->sort('SortOrder'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     public function getType() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         return 'Photoswipe Gallery'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     protected function provideBlockSchema() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         $blockSchema = parent::provideBlockSchema(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $blockSchema[ 'content' ] = $this->getSummary(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         return $blockSchema; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |     public function getSummary() | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |         return i18n::with_locale(Security::getCurrentUser()->Locale, function() { | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |             $template = SSViewer::get_templates_by_class(static::class, '_Summary'); | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |             $summary = $this->renderWith($template); | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |             return $summary->RAW(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         }); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 75 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 76 |  |  | } |