Exemplo n.º 1
0
 protected function _add()
 {
     $data = $this->request->post();
     $widget = Widget_Manager::factory($data['type']);
     try {
         $widget->name = $data['name'];
         $widget->description = Arr::get($data, 'description');
         $id = Widget_Manager::create($widget);
         Observer::notify('widget_after_add', $id);
     } catch (ORM_Validation_Exception $e) {
         Flash::set('post_data', $data);
         Messages::errors($e->errors('validation'));
         $this->go_back();
     }
     // save and quit or save and continue editing?
     if ($this->request->post('commit') !== NULL) {
         $this->go();
     } else {
         $this->go(array('controller' => 'widgets', 'action' => 'edit', 'id' => $id));
     }
 }
Exemplo n.º 2
0
 /**
  * Усмтановка виджета из массива
  * 
  * array(
  *		'type' => [Widget type],
  *		'data' => array (
  *			[KEY] => [VALUE]
  *			.....
  *		),
  *		'blocks' => array (
  *			[PAGE_ID] => [BLOCK NAME]
  *		)
  *	)
  * 
  * @param array $widget_array
  * @return integer $id
  */
 public static function install(array $widget_array)
 {
     if (empty($widget_array['type']) or empty($widget_array['data']) or empty($widget_array['data']['name'])) {
         return;
     }
     $widget = Widget_Manager::factory($widget_array['type']);
     try {
         $widget->name = $widget_array['data']['name'];
         $widget->description = Arr::get($widget_array, 'description');
         $widget->set_values($widget_array['data']);
         $widget->set_cache_settings($widget_array['data']);
         $id = Widget_Manager::create($widget);
     } catch (Exception $e) {
         return FALSE;
     }
     $blocks = array();
     foreach (Arr::get($widget_array, 'blocks', array()) as $page_id => $block_name) {
         $blocks[$page_id] = array('name' => $block_name, 'position' => 500);
     }
     Widget_Manager::set_location($id, $blocks);
     return $id;
 }