Пример #1
0
 /**
  * Save widget
  *
  * @param $sidebar
  * @param integer $ordering
  * @param integer $id
  * @param mixed $newInstance
  * @param string $themeName
  * @return bool
  */
 public final function save($sidebar, $ordering = null, $id = null, $newInstance = null, $themeName = null)
 {
     $ordering = intval($ordering);
     if ($this->validation) {
         if (!$themeName) {
             /**
              * @var CoreTemplates $CoreTemplates
              */
             $CoreTemplates = CoreTemplates::findFirst("location = 'frontend' AND published = 1");
             $themeName = $CoreTemplates->base_name;
         }
         /**
          * @var CoreWidgetValues $CoreWidgetValues
          */
         if ((int) $id) {
             $CoreWidgetValues = CoreWidgetValues::findFirst($id);
         } else {
             $CoreWidgetValues = new CoreWidgetValues();
         }
         $CoreWidgetValues->reOder('sidebar_base_name = ?0', [0 => $sidebar]);
         $queryUp = "UPDATE core_widget_values SET ordering = ordering + 1 WHERE ordering >= {$ordering} AND theme_name = '{$themeName}' AND sidebar_base_name = '{$sidebar}'";
         $queryDown = "UPDATE core_widget_values SET ordering = ordering - 1 WHERE ordering < {$ordering} AND theme_name = '{$themeName}' AND sidebar_base_name = '{$sidebar}'";
         $this->db->execute($queryDown);
         $this->db->execute($queryUp);
         $CoreWidgetValues->sidebar_base_name = $sidebar;
         $CoreWidgetValues->theme_name = $themeName;
         $CoreWidgetValues->class_name = $this->_widget_name . '_Widget';
         $CoreWidgetValues->options = $this->_processOptions($id, $newInstance);
         $CoreWidgetValues->published = 1;
         $CoreWidgetValues->ordering = $ordering;
         $CoreWidgetValues->title = $this->_title;
         if ($CoreWidgetValues->save()) {
             //Do something
         } else {
             //Do something
         }
         $this->_id = $CoreWidgetValues->widget_value_id;
         $CoreWidgetValues->reOder('sidebar_base_name = ?0', [0 => $sidebar]);
         return true;
     }
     return false;
 }