Пример #1
0
 function post()
 {
     $id = $this->app->request->post('id');
     $delete = $this->app->request->post('delete');
     if (empty($id)) {
         //必須なパラメータがなければ400を返して抜ける
         $this->app->response->setStatus(400);
         return;
     }
     try {
         $model = new BeaconModel();
         if (empty($delete) || $delete === 1) {
             $model->insertBeacon($id, 3, 6, 9);
         } else {
             $model->deleteBeacon($id);
         }
         echo '{"status": 0}';
     } catch (PDOException $e) {
         if ($e->errorInfo[1] === 1062) {
             $this->app->response->setStatus(403);
         } else {
             $this->app->response->setStatus(400);
         }
         echo json_encode($e);
     }
 }
Пример #2
0
 function get()
 {
     $beaconM = new BeaconModel();
     $soundM = new SoundModel();
     //beaconの一覧を取得
     $beacons = $beaconM->getBeacons(array($this->id));
     $sound_ids = array();
     $beacon = $beacons[0];
     //音データを取得するためにはいれつを作成
     $sound_ids[] = $beacon['one_sound'];
     $sound_ids[] = $beacon['two_sound'];
     $sound_ids[] = $beacon['long_sound'];
     $sound_ids = array_values(array_unique($sound_ids));
     //sound_idsを元に音データを取得
     $sounds = SoundUtil::createSoundDict($soundM->getSounds($sound_ids));
     $response = BeaconUtil::getBeaconRow($beacon['id'], $sounds[$beacon['one_sound']], $sounds[$beacon['two_sound']], $sounds[$beacon['long_sound']]);
     echo json_encode($response);
     /*
             $json = <<<JSON
     {
         "id":2,
         "one":{
             "id":3,
             "title":"笑い",
             "file_name":"aaa"
         },
         "two":{
             "id":4,
             "title":"笑い2",
             "file_name":"ddd"
         },
         "long":{
             "id":1
             "title":"拍手2",
             "file_name":"ccc"
         }
     }
     JSON;
             echo $json;
     */
 }
Пример #3
0
 function post()
 {
     $sound_id = $this->app->request->post('sound_id');
     if ($this->tap != self::ONE_TAP && $this->tap != self::TWO_TAP && $this->tap != self::LONG_TAP) {
         //タップの種類が想定以外のものの場合は400を返す
         $this->app->response->setStatus(400);
         return;
     }
     if (empty($sound_id)) {
         $this->app->response->setStatus(400);
     }
     $model = new BeaconModel();
     $model->updateBeacon($this->id, $this->tap . "_sound", $sound_id);
     echo '{"status": 0}';
 }