| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace backend\widgets\box; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use yii\base\Widget; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use yii\helpers\Html; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use common\assets\IonIconsAsset; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * Class SmallBox | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @package backend\widgets\box | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 13 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  | class SmallBox extends Widget | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |     const BG_GREEN = 'bg-green'; | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |     const BG_AQUA = 'bg-aqua'; | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |     const BG_YELLOW = 'bg-yellow'; | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |     const BG_RED = 'bg-red'; | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |     const BG_GRAY = 'bg-gray'; | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |     const BG_BLACK = 'bg-black'; | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |     const BG_MAROON = 'bg-maroon'; | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |     const BG_PURPLE = 'bg-purple'; | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |     const BG_TEAL = 'bg-teal'; | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |     const BG_NAVY = 'bg-navy'; | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |     const BG_PRIMARY = 'bg-primary'; | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |     const BG_SUCCESS = 'bg-success'; | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |     const BG_WARNING = 'bg-warning'; | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |     const BG_INFO = 'bg-info'; | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |     const BG_DANGER = 'bg-danger'; | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |      * @var bool | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |     public $status = true; | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |      * @var string | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |     public $header; | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |      * @var string icon name | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |      * @see: http://ionicons.com | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |     public $icon; | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |      * @var string | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |     public $content; | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |      * @var array|string|null | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |      * ['label' => '', 'url' => ['#']]; | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |     public $link; | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |      * @var string | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |     public $style; | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |      * Run | 
            
                                                                        
                            
            
                                    
            
            
                | 62 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 63 |  |  |      * @return string | 
            
                                                                        
                            
            
                                    
            
            
                | 64 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 65 |  |  |     public function run() | 
            
                                                                        
                            
            
                                    
            
            
                | 66 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 67 |  |  |         if ($this->status === true) { | 
            
                                                                        
                            
            
                                    
            
            
                | 68 |  |  |             $this->registerAssets(); | 
            
                                                                        
                            
            
                                    
            
            
                | 69 |  |  |             return $this->renderContent(); | 
            
                                                                        
                            
            
                                    
            
            
                | 70 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 71 |  |  |         return ''; | 
            
                                                                        
                            
            
                                    
            
            
                | 72 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 73 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 74 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 75 |  |  |      * Render Content | 
            
                                                                        
                            
            
                                    
            
            
                | 76 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 77 |  |  |      * @return string | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |     public function renderContent() | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |         $str = ''; | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |         $str .= Html::beginTag('div', ['id' => $this->id, 'class' => 'small-box ' . $this->style]) . PHP_EOL; | 
            
                                                                        
                            
            
                                    
            
            
                | 83 |  |  |         $str .= Html::beginTag('div', ['class' => 'inner']) . PHP_EOL; | 
            
                                                                        
                            
            
                                    
            
            
                | 84 |  |  |         $str .= Html::tag('h3', $this->header) . PHP_EOL; | 
            
                                                                        
                            
            
                                    
            
            
                | 85 |  |  |         $str .= Html::tag('p', $this->content) . PHP_EOL; | 
            
                                                                        
                            
            
                                    
            
            
                | 86 |  |  |         $str .= Html::endTag('div') . PHP_EOL; | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  |         $str .= Html::beginTag('div', ['icon']) . PHP_EOL; | 
            
                                                                        
                            
            
                                    
            
            
                | 88 |  |  |         $str .= Html::tag('i', '', ['class' => 'icon ' . $this->icon]) . PHP_EOL; | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  |         $str .= Html::endTag('div') . PHP_EOL; | 
            
                                                                        
                            
            
                                    
            
            
                | 90 |  |  |         if (is_array($this->link)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 91 |  |  |             if (!empty($this->link['label']) && !empty($this->link['url'])) { | 
            
                                                                        
                            
            
                                    
            
            
                | 92 |  |  |                 $str .= Html::a($this->link['label'], $this->link['url'], [ | 
            
                                                                        
                            
            
                                    
            
            
                | 93 |  |  |                         'class' => 'small-box-footer' | 
            
                                                                        
                            
            
                                    
            
            
                | 94 |  |  |                     ]) . PHP_EOL; | 
            
                                                                        
                            
            
                                    
            
            
                | 95 |  |  |             } | 
            
                                                                        
                            
            
                                    
            
            
                | 96 |  |  |         } elseif (!is_null($this->link)) { | 
            
                                                                        
                            
            
                                    
            
            
                | 97 |  |  |             $str .= Html::tag('div', $this->link, ['class' => 'small-box-footer']); | 
            
                                                                        
                            
            
                                    
            
            
                | 98 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 99 |  |  |         $str .= Html::endTag('div') . PHP_EOL; | 
            
                                                                        
                            
            
                                    
            
            
                | 100 |  |  |         return $str; | 
            
                                                                        
                            
            
                                    
            
            
                | 101 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 103 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 104 |  |  |      * Register Assets | 
            
                                                                        
                            
            
                                    
            
            
                | 105 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |     public function registerAssets() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |         $view = $this->getView(); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 109 |  |  |         IonIconsAsset::register($view); | 
            
                                                                        
                                                                
            
                                    
            
            
                | 110 |  |  |     } | 
            
                                                                        
                                                                
            
                                    
            
            
                | 111 |  |  | } | 
            
                                                                        
                                                                
            
                                    
            
            
                | 112 |  |  |  |