Exemple #1
0
 /**
  * Instance construct
  *
  * @param integer $id
  * @param array $widgetInfo
  * @param array $options
  */
 public function __construct($id = null, $widgetInfo = [], $options = [])
 {
     $this->validation = $this->checkOptions($options);
     if ($this->validation) {
         $this->newOptions = $options;
         $id = (int) $id;
         if ($id > 0) {
             /**
              * @var CoreWidgetValues $widget
              */
             $widget = CoreWidgetValues::findFirst(['conditions' => 'widget_value_id = ?0', 'bind' => [$id]]);
             if (!$widget) {
                 $this->options = new \stdClass();
                 $this->options->_layout = 'default';
             } else {
                 $this->options = json_decode($widget->options);
                 $this->_id = $id;
             }
         }
         $this->_widget_name = explode('_', get_class($this))[0];
         $this->widget_class_name = strtolower(get_class($this));
         /**
          * @var CoreWidgets $widgetInfoDb
          */
         $widgetInfoDb = CoreWidgets::findFirst(['conditions' => 'lower(base_name) = ?0', 'bind' => [str_replace('_widget', '', $this->widget_class_name)]]);
         $widgetInfo['_layout'] = 'default';
         if (isset($widgetInfo['title'])) {
             $this->_title = __($widgetInfo['title']);
         } else {
             $this->_title = __($widgetInfoDb->title);
         }
         if (isset($widgetInfo['description'])) {
             $this->_description = __($widgetInfo['description']);
         } else {
             $this->_description = __($widgetInfoDb->description);
         }
         $this->_layout = $this->_getLayout($this->_widget_name);
     }
 }
 /**
  * Delete old widget
  *
  * @param array $allWidget
  */
 protected final function deleteOldWidget($allWidget = [])
 {
     if (count($allWidget)) {
         $oldWidget = CoreWidgets::find()->toArray();
         $oldWidget = array_column($oldWidget, 'base_name');
         $widgetMustDelete = array_diff($oldWidget, $allWidget);
         if (count($widgetMustDelete)) {
             foreach ($widgetMustDelete as $w) {
                 $tmp = CoreWidgets::findFirst(['conditions' => 'base_name = ?0', 'bind' => [$w]]);
                 if ($tmp) {
                     $tmp->delete();
                 }
             }
         }
     }
 }