| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * This file is part of the Grido (http://grido.bugyik.cz) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * Copyright (c) 2011 Petr Bugyík (http://petr.bugyik.cz) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * For the full copyright and license information, please view | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * the file LICENSE.md that was distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | namespace Grido; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Grido\Grid; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use Nette\Object; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * Customization. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * @package     Grido | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * @author      Petr Bugyík | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * @property string|array $buttonClass | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  * @property string|array $iconClass | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 25 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 26 | 1 |  | class Customization extends Object | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |     const TEMPLATE_DEFAULT = 'default'; | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |     const TEMPLATE_BOOTSTRAP = 'bootstrap'; | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |     /** @var Grid */ | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |     protected $grid; | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |     /** @var string|array */ | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |     protected $buttonClass; | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |     /** @var string|array */ | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |     protected $iconClass; | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |     /** @var array */ | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |     protected $templateFiles = []; | 
            
                                                                        
                            
            
                                    
            
            
                | 43 | 1 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 44 | 1 |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |      * @param Grid $grid | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     public function __construct(Grid $grid) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |         $this->grid = $grid; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 50 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 53 | 1 |  |      * @param string|array $class | 
            
                                                                        
                            
            
                                    
            
            
                | 54 | 1 |  |      * @return \Grido\Customization | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     public function setButtonClass($class) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         $this->buttonClass = $class; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         return $this; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 60 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 62 | 1 |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 63 | 1 |  |      * @param string|array $class | 
            
                                                                        
                            
            
                                    
            
            
                | 64 | 1 |  |      * @return \Grido\Customization | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     public function setIconClass($class) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         $this->iconClass = $class; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         return $this; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 70 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 73 | 1 |  |      * @return string | 
            
                                                                        
                            
            
                                    
            
            
                | 74 | 1 |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 | 1 |  |     public function getButtonClass() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 | 1 |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 | 1 |  |         return is_array($this->buttonClass) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 | 1 |  |             ? implode(' ', $this->buttonClass) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 | 1 |  |             : $this->buttonClass; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 80 | 1 |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 81 | 1 |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |      * @param string $icon | 
            
                                                                        
                            
            
                                    
            
            
                | 84 | 1 |  |      * @return string | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     public function getIconClass($icon = NULL) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         if ($icon === NULL) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |             $class = $this->iconClass; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |             $this->iconClass = (array) $this->iconClass; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 | 1 |  |             $classes = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 | 1 |  |             foreach ($this->iconClass as $fontClass) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 | 1 |  |                 $classes[] = "{$fontClass} {$fontClass}-{$icon}"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 | 1 |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 | 1 |  |             $class = implode(' ', $classes); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 | 1 |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 | 1 |  |         return $class; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 100 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 102 | 1 |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 103 |  |  |      * @return array | 
            
                                                                        
                            
            
                                    
            
            
                | 104 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     public function getTemplateFiles() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         if (empty($this->templateFiles)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |             foreach (new \DirectoryIterator(__DIR__ . '/templates') as $file) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |                 if ($file->isFile()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |                     $this->templateFiles[$file->getBasename('.latte')] = realpath($file->getPathname()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |         return $this->templateFiles; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 116 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 117 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 118 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 119 |  |  |      * Default theme. | 
            
                                                                        
                            
            
                                    
            
            
                | 120 |  |  |      * @return \Grido\Customization | 
            
                                                                        
                            
            
                                    
            
            
                | 121 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |     public function useTemplateDefault() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |         $this->grid->setTemplateFile($this->getTemplateFiles()[self::TEMPLATE_DEFAULT]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |         return $this; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 126 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 127 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 128 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 129 |  |  |      * Twitter Bootstrap theme. | 
            
                                                                        
                            
            
                                    
            
            
                | 130 |  |  |      * @return \Grido\Customization | 
            
                                                                        
                            
            
                                    
            
            
                | 131 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |     public function useTemplateBootstrap() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |         $this->grid->setTemplateFile($this->getTemplateFiles()[self::TEMPLATE_BOOTSTRAP]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |         return $this; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 136 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 137 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 138 |  |  |  |