Ejemplo n.º 1
0
 public static function createSoundDict($sounds)
 {
     $res = array();
     foreach ($sounds as $sound) {
         $res[$sound['id']] = SoundUtil::getSoundRow($sound['id'], $sound['title'], $sound['file_name']);
     }
     return $res;
 }
Ejemplo n.º 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;
     */
 }
Ejemplo n.º 3
0
 function get()
 {
     $model = new SoundModel();
     $results = $model->getSounds();
     $response = array('sounds' => array());
     foreach ($results as $row) {
         $response['sounds'][] = SoundUtil::getSoundRow($row['id'], $row['title'], $row['file_name']);
     }
     echo json_encode($response);
     /* モック用
             $json = <<<JSON
     {
       "sounds":[
         {
           "id":1,
           "title":"拍手",
           "file_name":"bbb"
         },
         {
           "id":2,
           "title":"拍手2",
           "file_name":"ccc"
         },
         {
           "id":3,
           "title":"笑い",
           "file_name":"aaa"
         },
         {
           "id":4,
           "title":"笑い2",
           "file_name":"ddd"
         }
       ]
     }
     JSON;
             echo $json;
     */
 }
Ejemplo n.º 4
0
 function get()
 {
     if ($this->tap != self::ONE_TAP && $this->tap != self::TWO_TAP && $this->tap != self::LONG_TAP) {
         //タップの種類が想定以外のものの場合は400を返す
         $this->app->response->setStatus(400);
         return;
     }
     $beaconM = new BeaconModel();
     $soundM = new SoundModel();
     //beaconの一覧を取得
     $beacons = $beaconM->getBeacons(array($this->id));
     $beacon = $beacons[0];
     $sound_id;
     if ($this->tap === self::ONE_TAP) {
         $sound_id = $beacon['one_sound'];
     } else {
         if ($this->tap === self::TWO_TAP) {
             $sound_id = $beacon['two_sound'];
         } else {
             if ($this->tap === self::LONG_TAP) {
                 $sound_id = $beacon['long_sound'];
             }
         }
     }
     $sounds = $soundM->getSounds(array($sound_id));
     $sound = $sounds[0];
     $sound = SoundUtil::getSoundRow($sound['id'], $sound['title'], $sound['file_name']);
     echo json_encode($sound);
     /*
             $jsonOne = <<<JSON
     {
         "id":3,
         "title":"笑い",
         "file_name":"aaa"
     }
     JSON;
             $jsonTwo = <<<JSON
     {
         "id":4,
         "title":"笑い2",
         "file_name":"ddd"
     }
     JSON;
             $jsonLong = <<<JSON
     {
         "id":1
         "title":"拍手2",
         "file_name":"ccc"
     }
     JSON;
             if ($this->tap === self::ONE_TAP) {
                 echo $jsonOne;
             } else if ($this->tap === self::TWO_TAP) {
                 echo $jsonTwo;
             } else if ($this->tap === self::LONG_TAP) {
                 echo $jsonLong;
             } else {
                 $this->app->response->setStatus(400);
             }
     */
 }
Ejemplo n.º 5
0
 function get()
 {
     $beaconM = new BeaconModel();
     $soundM = new SoundModel();
     //beaconの一覧を取得
     $beacons = $beaconM->getBeacons();
     $sound_ids = array();
     //音データを取得するためにはいれつを作成
     foreach ($beacons as $beacon) {
         $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 = array();
     foreach ($beacons as $beacon) {
         $response['beacons'][] = BeaconUtil::getBeaconRow($beacon['id'], $sounds[$beacon['one_sound']], $sounds[$beacon['two_sound']], $sounds[$beacon['long_sound']]);
     }
     echo json_encode($response);
     /*
             $json = <<<JSON
     {
       "beacons":[
         {
           "id":1,
           "one":{
             "title":"笑い",
             "file_name":"aaa"
           },
           "two":{
             "title":"拍手",
             "file_name":"bbb"
           },
           "long":{
             "title":"拍手2",
             "file_name":"ccc"
           }
         },
         {
           "id":2,
           "one":{
             "title":"笑い",
             "file_name":"aaa"
           },
           "two":{
             "title":"笑い2",
             "file_name":"ddd"
           },
           "long":{
             "title":"拍手2",
             "file_name":"ccc"
           }
         }
       ]
     }
     JSON;
             echo $json;
     */
 }