コード例 #1
0
 public function execute()
 {
     $view = $this->app->views->get('bspanel/edit');
     if (count($_POST) > 0) {
         foreach ($this->fields as $field) {
             $name = $field['name'];
             $type = $field['type'];
             $value = Arr::get($_POST, $name);
             if ($type == 'boolean') {
                 $value == (bool) $value;
             }
             $model = $this->app->models->factory($this->model, array($this->key_field => $name));
             if (!$model->loaded()) {
                 $model = $this->app->models->factory($this->model);
                 $model->{$this->key_field} = $name;
             }
             $model->{$this->value_field} = $value;
             $model->save();
             $view->success = true;
         }
     }
     $builder = new FormBuilder($this->app);
     foreach ($this->fields as $field) {
         $name = $field['name'];
         $model = $this->app->models->factory($this->model, array($this->key_field => $name));
         if ($model->loaded()) {
             $builder->set_value($name, $model->{$this->value_field});
         }
         $builder->add_field($field);
     }
     $view->title = $this->title;
     $view->fields = $builder->render();
     $this->response->body($view);
     parent::execute();
 }
コード例 #2
0
ファイル: ModelsList.php プロジェクト: doorframework/bspanel
 public function execute()
 {
     if ($this->grid) {
         if (isset($_GET['data'])) {
             $this->grid_data();
         } else {
             $this->show_grid();
         }
     } else {
         $this->show_list();
     }
     parent::execute();
 }
コード例 #3
0
ファイル: Login.php プロジェクト: doorframework/bspanel
 public function execute()
 {
     if (count($_POST) > 0) {
         $this->app->auth->login(Arr::get($_POST, 'username'), Arr::get($_POST, 'password'));
     }
     if ($this->app->auth->logged_in('admin_panel')) {
         $this->redirect("admin");
         return;
     }
     $this->add_style("bspanel/panel/login");
     $view = $this->app->views->get('bspanel/login');
     $view->is_error = count($_POST) > 0;
     $view->username = Arr::get($_POST, 'username');
     $this->response->body($view);
     parent::execute();
 }
コード例 #4
0
ファイル: GridData.php プロジェクト: doorframework/bspanel
 public function execute()
 {
     $model = $this->app->models->factory($this->model);
     $filter_value = null;
     $return_uri = $this->return_uri;
     if ($this->filter_param !== null) {
         $filter_value = Arr::get($_GET, $this->filter_param);
         if ($filter_value === null) {
             throw new Exception("filter param {$this->filter_param} not specified");
         }
         $model->where($this->filter_param, '=', new MongoId($filter_value));
         $return_uri = str_replace("<id>", $filter_value, $return_uri);
     }
     if (isset($_POST['update_sort'])) {
         $this->update_sort($model->find_all()->as_array(), explode(",", $_POST['ids']));
         $this->response->body("true");
         $this->show_layout = false;
         return;
     }
     $view = $this->app->views->get("bspanel/list");
     $view->model = $model;
     $cursor = $model->find_all();
     if ($this->sortable) {
         $cursor->sort(array($this->sort_column => 1));
     } elseif ($this->sort !== null) {
         $cursor->sort($this->sort);
     }
     $view->items = $cursor->as_array();
     $view->create_button = $this->create;
     $view->uri = $this->request->uri();
     $view->return_uri = $return_uri;
     $view->buttons = $this->buttons;
     $view->columns = $this->columns;
     $view->sortable = $this->sortable;
     $view->filter_param = $this->filter_param;
     $view->filter_value = $filter_value;
     $l = $this->app->lang;
     if ($this->filter_model === null) {
         $view->title = $l->get_ucf($model->get_model_name() . ".list");
     } else {
         $filter_model = $this->app->models->factory($this->filter_model, $filter_value);
         $view->title = $filter_model->name() . ": " . $l->get_ucf($model->get_model_name() . ".list");
     }
     $this->title = $view->title;
     $this->response->body($view->render());
     parent::execute();
 }
コード例 #5
0
ファイル: Edit.php プロジェクト: doorframework/bspanel
 public function execute()
 {
     $return_uri = $this->return_uri;
     $id = $this->param('id');
     if (!$this->app->is_id($id)) {
         $id = null;
     }
     $model = $this->app->models->factory($this->model, $id);
     if ($id !== null && false == $model->loaded()) {
         $this->redirect($this->return_uri);
         return;
     }
     $filter_value = null;
     if ($this->filter_param !== null) {
         $filter_param = $this->filter_param;
         if ($id === null) {
             $filter_value = Arr::get($_GET, $this->filter_param);
             if ($filter_value === null) {
                 throw new Exception("filter value not set");
             }
             $model->{$filter_param} = $filter_value;
         } else {
             $filter_value = $model->{$filter_param};
         }
         $return_uri = str_replace("<id>", $filter_value, $return_uri);
     }
     $view = $this->app->views->get("bspanel/edit");
     $view->model = $model;
     $view->return_uri = $return_uri;
     $view->filter_param = $this->filter_param;
     $view->filter_value = $filter_value;
     $l = $this->app->lang;
     if ($this->filter_model === null) {
         $view->title = $l->get_ucf($model->get_model_name()) . ": " . $l->get("editing");
     } else {
         $filter_model = $this->app->models->factory($this->filter_model, $filter_value);
         $view->title = $filter_model->name() . " : " . $model->name() . " : " . $l->get("editing");
     }
     $this->title = $view->title;
     $builder = new FormBuilder($this->app);
     $builder->set_model($model);
     $builder->add_fields($this->edit_fields);
     $builder->data('view_images_uri', $this->view_images_uri);
     $builder->data('upload_image_uri', $this->upload_image_uri);
     $builder->data('upload_images_uri', $this->upload_images_uri);
     if (count($_POST) > 0) {
         $field_types = $builder->get_fields_types();
         foreach ($field_types as $name => $type) {
             if ($type instanceof IField) {
                 $type->fill_model($model, $_POST);
             } elseif (!array_key_exists($name, $_POST)) {
                 if ($type == 'boolean') {
                     $model->{$name} = false;
                 } elseif ($type == 'tags') {
                     $model->{$name} = array();
                 }
             }
         }
         $fields_keys = array_keys($model->fields());
         $relations_keys = array_keys($model->relations());
         $model->values($_POST, $fields_keys);
         if (!$model->check()) {
             $view->errors = true;
         } elseif (!$model->loaded()) {
             $model->save();
             $model->values($_POST, $relations_keys);
             $model->save();
             $this->redirect($return_uri);
         } else {
             $model->save();
             $model->values($_POST, $relations_keys);
             $model->save();
             $view->success = true;
         }
     }
     $view->fields = $builder->render();
     $this->response->body($view->render());
     $this->add_script('ckeditor/ckeditor');
     parent::execute();
 }