예제 #1
0
 public function get($p = False)
 {
     $cls = $this->_cls;
     $fcls = $this->_fcls;
     $objects = new \Core\Li();
     return $fcls::mapper()->get_list(\Core\Storage::container()->get_storage($cls)->fetch($p));
 }
예제 #2
0
 public function index()
 {
     $t = $this->_template;
     $t->articles = \Plugins\Articles\Article::mapper()->attach_storage(\Core\Storage::container()->get_storage('Article'))->get_latest_articles(False, 'Agent', 'alias');
     $t->content = $t->render('news.php');
     $t->title = 'News';
     echo $t->render('main.php');
 }
예제 #3
0
 protected function _edit_agent()
 {
     $t = $this->_template;
     $t->add('_jsapps', 'agent_form');
     $storage = \Core\Storage::container()->get_storage('Agent');
     $mapper = \Trouble\Agent::mapper()->attach_storage($storage);
     $t->errors = array();
     if ($this->_args['alias']) {
         $t->title = "Edit Agent";
         $agent = \Trouble\Agent::container()->get_by_alias($this->_args['alias']);
         $this->_auth->check_admin('agent', $agent->id);
     } else {
         try {
             $t->title = "Edit Yourself";
             $agent = \Trouble\Agent::container()->get_by_id($this->_auth->user_id());
         } catch (\Core\AuthNotLoggedInError $e) {
             $t->title = "Agent Application";
             $t->new = True;
             $agent = \Trouble\Agent::create();
         }
     }
     $t->agent = $agent;
     return $t->render('forms/agent.php');
 }
예제 #4
0
 public function get_by_id($id, $agent = False)
 {
     $params = static::params($agent);
     $params['filters'][] = new \Core\Filter('id', $id);
     $games = \Core\Storage::container()->get_storage('Game')->fetch($params);
     if (count($games) == 0) {
         throw new GameNotFoundError();
     }
     return Game::mapper()->create_object($games[0]);
 }
예제 #5
0
 public function save()
 {
     \Core\Storage::container()->get_storage($this->_cls)->save($this);
     return $this;
 }
예제 #6
0
 protected function _edit()
 {
     $t = $this->_template;
     $t->add('_jsapps', 'game_form');
     $storage = \Core\Storage::container()->get_storage('Game');
     $mapper = \Trouble\Game::mapper()->attach_storage($storage);
     try {
         if ($this->_args['game_id']) {
             $t->title = "Edit Game";
             $game = $this->_game;
             $this->_auth->check_admin('game', $game->id);
             $game->form_start_date = $game->start_date->format('Y-m-d');
             $game->form_end_date = $game->end_date->format('Y-m-d');
             $t->administration = $this->_administration($game);
             $t->vouchers = $this->_vouchers($game);
         } else {
             $t->title = "Game Creation";
             $t->new = True;
             $game = \Trouble\Game::create($_POST, True);
         }
         $t->game = $game;
         return $t->render('forms/game.php');
     } catch (\Core\AuthDeniedError $e) {
         throw new \Core\HTTPError(401, "Editing Game");
     } catch (\Core\AuthNotLoggedInError $e) {
         throw new \Core\HTTPError(401, "Editing Game");
     }
 }
예제 #7
0
파일: auth.php 프로젝트: radiosilence/core
 public function is_root($user_id, $user_field = 'user')
 {
     $roots = \Core\Storage::container()->get_storage('Admin')->fetch(array('filters' => array(new \Core\Filter($user_field, $user_id), new \Core\Filter('type', 'ROOT'))));
     if (count($roots) > 0) {
         return True;
     }
     return False;
 }
예제 #8
0
 public function save_game()
 {
     import('core.validation');
     import('trouble.game');
     $validator = \Core\Validator::validator('\\Trouble\\Game');
     $editing = $_POST['id'] > 0 ? True : False;
     try {
         if ($editing) {
             $this->_auth->check_admin('game', $_POST['id']);
             $game = \Trouble\Game::container()->get_by_id($_POST['id']);
             $validator->set_id($game->id);
             $game->overwrite($_POST, True);
         } else {
             $game = \Trouble\Game::mapper()->create_object($_POST);
             $game->creator = $this->_auth->user_id();
         }
         try {
             \Core\Auth::hash($game, 'password');
         } catch (\Core\AuthEmptyPasswordError $e) {
             $game->remove('password');
         }
         $validator->validate($_POST);
         \Core\Storage::container()->get_storage('Game')->save($game);
         if (!$editing) {
             $this->_auth->add_admin('game', $game->id, $game->creator);
         }
         if ($editing) {
             echo $this->_return_message("Success", "Saved.");
         } else {
             echo $this->_return_message("Success", "Created game.");
         }
     } catch (\Core\ValidationError $e) {
         echo $this->_return_message("Fail", "Validation error(s):", $e->get_errors());
     } catch (\Core\AuthNotLoggedInError $e) {
         $this->_not_logged_in();
     } catch (\Core\AuthDeniedError $e) {
         $this->_access_denied();
     } catch (\Exception $e) {
         $this->_unhandled_exception($e);
     }
 }
예제 #9
0
    protected function _edit_article($tok, $author, $id=False) {
        $t = \Plugins\Articles\Plugin::get_template('admin/edit.php');
        $t->admin_url = "/admin";
        $t->tok = $tok;
        try {
            if($id) {
                $t->title = "Edit Article";
                $article = \Plugins\Articles\Article::container()
                    ->get_by_id($id);
            } else {
                $t->title = "Create Article";
                $t->new = True;
                $article = \Plugins\Articles\Article::create($_POST, True);
            }

            if($_POST['_do'] == '1' && $this->_confirmed_request) {
                $article->overwrite($_POST);
                $article->form_values();
                $validator = \Core\Validator::validator('\Plugins\Articles\Article');
                $validator->validate($_POST, \Plugins\Articles\Article::validation());
                
                if($t->new) {
                    $article->author = $author;
                }

                \Core\Storage::container()
                    ->get_storage('Article')
                    ->save($article);
            }

            $t->article = $article;
                
        } catch(\Core\ValidationError $e) {
            return $this->_return_message("Fail",
                "Validation error(s):",
                $e->get_errors(), $t);
        }

        return $t->render();
    }
예제 #10
0
 public function find_by_game(\Trouble\Game $game, $limit = 20)
 {
     $items = \Core\Storage::container()->get_storage('Kill')->fetch(array("joins" => KillContainer::_standard_joins(), "filter" => new \Core\Filter("game", $game['id'])));
     $kills = Kill::mapper()->get_list($items);
     return $kills;
 }