Example #1
0
 /**
  * action_save
  * @return save widget (make active)
  */
 public function action_save()
 {
     // save only changed values
     if ($this->request->post()) {
         //deleting the fragment cache...a bit ugly but works.
         View::delete_fragment('sidebar_front');
         View::delete_fragment('footer_front');
         //get place holder name
         $placeholder = core::post('placeholder');
         //get widget class
         $widget = core::post('widget_class');
         //widget name
         $widget_name = core::post('widget_name');
         //$data = array();
         //extract all the data and prepare array
         foreach ($this->request->post() as $name => $value) {
             if ($name != 'placeholder' and $name != 'widget_class' and $name != 'widget_name') {
                 $data[$name] = $value;
             }
         }
         $old_placeholder = NULL;
         $widget = new $widget();
         //the widget exists, we load it since we need the previous placeholder
         if ($widget_name != NULL) {
             $widget->load($widget_name);
             $old_placeholder = $widget->placeholder;
         }
         $widget->placeholder = $placeholder;
         $widget->data = $data;
         try {
             $widget->save($old_placeholder);
             //clean cache config
             $c = new ConfigDB();
             $c->reload_config();
             if ($widget_name != NULL) {
                 Alert::set(Alert::SUCCESS, sprintf(__('Widget %s saved in %s'), $widget_name, $placeholder));
             } else {
                 Alert::set(Alert::SUCCESS, sprintf(__('Widget created in %s'), $placeholder));
             }
         } catch (Exception $e) {
             //throw 500
             throw HTTP_Exception::factory(500, $e->getMessage());
         }
         $this->redirect(Route::url('oc-panel', array('controller' => 'widget', 'action' => 'index')));
     }
 }
Example #2
0
 /**
  * everytime we save the config we relad the cache
  * @return boolean 
  */
 public function reload_config()
 {
     $c = new ConfigDB();
     return $c->reload_config();
 }