Example #1
0
 public function post_change_list()
 {
     if ($station_id = Input::post('station_id')) {
         $result = Model_Traininfo::get_change_station_list($station_id);
         $this->response($result, 200);
         return true;
     }
     $this->response($this->_error('情報がありません'), 200);
 }
Example #2
0
 public function action_delete($id = null)
 {
     is_null($id) and Response::redirect('traininfo');
     if ($traininfo = Model_Traininfo::find($id)) {
         $traininfo->delete();
         Session::set_flash('success', 'Deleted traininfo #' . $id);
     } else {
         Session::set_flash('error', 'Could not delete traininfo #' . $id);
     }
     Response::redirect('traininfo');
 }
Example #3
0
 public function action_entry()
 {
     // 登録時
     if (Input::method() == 'POST') {
         // バリデーション
         $val = Model_Twitteruser::validate('create');
         $input = array('uid' => Session::get('uid'), 'token' => Session::get('token'), 'secret' => Session::get('secret'));
         if ($val->run($input)) {
             // バリデーション成功時
             $user = Model_User::forge(array('name' => Session::get('nickname'), 'password' => substr(str_shuffle('1234567890abcdefghijklmnopqrstuvwxyz'), 0, 10), 'sex' => Input::post('sex'), 'birth_station_id' => Input::post('birth_station_id')));
             $twitter_user = Model_TwitterUser::forge($input);
             if ($user and $twitter_user) {
                 // ユーザー生成成功
                 try {
                     \DB::start_transaction();
                     if ($user->save() === false) {
                         // User保存失敗
                         throw new \Exception('user save failed.');
                     }
                     $twitter_user->user_id = $user->id;
                     if ($twitter_user->save() === false) {
                         // TwitterUser保存失敗
                         throw new \Exception('twitter_user save failed.');
                     }
                     //その他Userに付随する情報を作成
                     //user_state
                     $state = Model_Userstate::forge(array('id' => $user->id, 'ride_state' => '0', 'now_station_id' => $user->birth_station_id));
                     if ($state->save() === false) {
                         // user_state保存失敗
                         throw new \Exception('user_state save failed.');
                     }
                     //user_fortune
                     //ポイントは動的にできるように。。。
                     $fortune = Model_Userfortune::forge(array('id' => $user->id, 'points' => 10000, 'domination1' => ' ', 'domination2' => ' ', 'domination3' => ' '));
                     if ($fortune->save() == false) {
                         // user_state保存失敗
                         throw new \Exception('user_fortune save failed.');
                     }
                     // 保存成功
                     \DB::commit_transaction();
                     //サインアップ成功なのでいらないSessionは消す
                     Session::delete('uid');
                     Session::delete('token');
                     Session::delete('secret');
                     Session::delete('nickname');
                     Model_User::login_twitter($user->id);
                     Response::redirect('portal');
                 } catch (\Exception $e) {
                     \DB::rollback_transaction();
                     Response::redirect('portal');
                 }
             } else {
                 // ユーザー生成失敗
                 Response::redirect('portal');
             }
         } else {
             // バリデーション失敗時
             Response::redirect('portal');
         }
         // 登録できたら ポータルに戻る.
     }
     // Viewに受け渡す用
     $exp = ['name' => Session::get('nickname'), 'stations' => Model_Traininfo::get_birth_train_summary()];
     $this->template->title = '新規アカウント登録';
     $this->template->content = View_Twig::forge('portal/entry', $exp);
 }
Example #4
0
 public function action_getoff($id = null)
 {
     is_null($id) and Response::redirect('userstate/getoffdriver');
     if (!($userstate = Model_Userstate::find($id))) {
         Session::set_flash('error', '指定ユーザーの乗車状態を見つかりません #' . $id);
         Response::redirect('userstate/getoffdriver');
     }
     if ($userstate->ride_state == 0) {
         Session::set_flash('error', '既に未乗車状態になるため、降りる操作ができません!');
         Response::redirect('userstate/getoffdriver');
     }
     if (!($userfortune = Model_Userfortune::find($id))) {
         Session::set_flash('error', '指定ユーザーの乗車状態を見つかりません #' . $id);
         Response::redirect('userstate/getoffdriver');
     }
     // 実際利用ポイントを計算する
     //$usepoints = Model_Traininfo::get_user_points($userstate);
     $usepoints = $userstate->ticket_price;
     $traininfo = Model_Traininfo::find($userstate->train_id);
     if ($traininfo->from_station_id != $userstate->to_station_id) {
         $usepoints = 100 * abs($traininfo->from_station_index - $userstate->from_station_index);
     }
     // 未乗車状態に更新する
     $userstate->ride_state = '0';
     // 現時いる駅を更新する
     $userstate->now_station_id = $traininfo->from_station_id;
     // 乗る電車をクリアする
     $userstate->train_id = '';
     // 出発駅をクリアする
     $userstate->from_station_id = '';
     // 出発駅番号をクリアする
     $userstate->from_station_index = null;
     // 目的駅をクリアする
     $userstate->to_station_id = '';
     // 目的駅番号をクリアする
     $userstate->to_station_index = null;
     // チケットタイプをクリアする
     $userstate->ticket_type = '';
     // チケット価格をクリアする
     $userstate->ticket_price = '';
     $userfortune->points = $userfortune->points - $usepoints;
     try {
         if (!$userstate->save()) {
             throw new Exception('user state error.');
         }
         if (!$userfortune->save()) {
             throw new Exception('is not update points.');
         }
     } catch (Exception $e) {
         $message = $e->getMessage();
         Session::set_flash('error', "{$message}, {$id}");
     } finally {
         Response::redirect('userstate/getoffdriver');
         return;
     }
     $this->template->title = "GetoffDriver for development!";
     $this->template->content = View::forge('userstate/getoff');
 }