| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace dynamikaweb\googlechart; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use yii\helpers\ArrayHelper; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | class GoogleChart extends \yii\base\Widget | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |     public $title = ''; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |     public $containerId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |     public $visualization; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     public $dataProvider; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     public $pluginOptions = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     public $clientOptions = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     public $htmlOptions = []; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 22 |  |  |      | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |     public function run() | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |         $visualization = ArrayHelper::getValue($this->pluginOptions, 'visualization', $this->visualization); | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |         $clientOptions = ArrayHelper::getValue($this->pluginOptions, 'options', $this->clientOptions); | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |         $htmlOptions = ArrayHelper::getValue($this->pluginOptions, 'htmlOptions', $this->htmlOptions); | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |         $containerId = ArrayHelper::getValue($this->pluginOptions, 'containerId', $this->containerId); | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |         $this->pluginOptions = ArrayHelper::merge($this->pluginOptions, | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |             [ | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |                 'options' => ['title' => $this->title] | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |             ], | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |             [ | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |                 'data' => $this->data, | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |             ], | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |             [ | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |                 'containerId' => $containerId, | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |                 'visualization' => $visualization, | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |                 'htmlOptions' => $htmlOptions,   | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |                 'options' => $clientOptions, | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |             ] | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |         ); | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |         echo HtmlChart::widget($this->pluginOptions); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     protected function getData() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         $data = array(['label_0', $this->title]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         foreach($this->dataProvider->models as $model){ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |             $data [] = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |                 strip_tags(array_shift($model)), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |                 array_shift($model) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |             ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         return $data; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 61 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 62 |  |  | } |