Esempio n. 1
0
File: area.php Progetto: anqh/forum
 /**
  * Action: edit
  */
 public function action_edit()
 {
     $this->history = false;
     // Load area
     $area_id = (int) $this->request->param('id');
     if ($area_id) {
         $area = Model_Forum_Area::factory($area_id);
         if (!$area->loaded()) {
             throw new Model_Exception($area, $area_id);
         }
         Permission::required($area, Model_Forum_Area::PERMISSION_UPDATE, self::$user);
     } else {
         $area = new Model_Forum_Area();
         $area->author_id = self::$user->id;
         $area->created = time();
     }
     // Load group
     if ($area->loaded()) {
         $group = $area->group();
     } else {
         if ($group_id = (int) $this->request->param('group_id')) {
             $group = Model_Forum_Group::factory($group_id);
             $area->forum_group_id = $group->id;
             if (!$group->loaded()) {
                 throw new Model_Exception($group, $group_id);
             }
             Permission::required($group, Model_Forum_Group::PERMISSION_CREATE_AREA, self::$user);
         }
     }
     // Handle post
     $errors = array();
     if ($_POST) {
         $area->set_fields(Arr::extract($_POST, Model_Forum_Area::$editable_fields));
         try {
             $area->save();
             $this->request->redirect(Route::model($area));
         } catch (Validation_Exception $e) {
             $errors = $e->array->errors('validate');
         }
     }
     // Build page
     $this->view = new View_Page(__('Forum area') . ($area->name ? ': ' . HTML::chars($area->name) : ''));
     $this->view->tab = 'areas';
     // Set actions
     if ($area->loaded() && Permission::has($area, Model_Forum_Area::PERMISSION_DELETE, self::$user)) {
         $this->view->actions[] = array('link' => Route::model($area, 'delete'), 'text' => '<i class="icon-trash icon-white"></i> ' . __('Delete area'), 'class' => 'btn btn-danger area-delete');
     }
     $this->view->add(View_Page::COLUMN_MAIN, $this->section_edit($area, $errors));
 }