Exemple #1
0
 public function addNoteFromJSON($glob)
 {
     //WHY DOESNT THIS HAPPEN VIA THE FRAMEWORK?!
     $data = file_get_contents("php://input");
     $glob = json_decode($data);
     $gameId = $glob->gameId;
     $noteId = $glob->noteId;
     $playerId = $glob->playerId;
     $title = $glob->title;
     $description = $glob->description;
     $publicToMap = $glob->publicToMap;
     $publicToBook = $glob->publicToBook;
     $location = $glob->location;
     $media = $glob->media;
     $tags = $glob->tags;
     $publicToMap = 1;
     $publicToBook = 1;
     if (!is_numeric($gameId)) {
         return new returnData(1, NULL, "JSON package has no numeric member \"gameId\"");
     }
     if (!is_numeric($playerId)) {
         return new returnData(1, NULL, "JSON package has no numeric member \"playerId\"");
     }
     if (!$noteId) {
         $noteId = Notebook::createNote($gameId, $playerId)->data;
     }
     Notebook::updateNote($noteId, $title, $publicToMap, $publicToBook, $location->latitude, $location->longitude);
     //THIS IS THE CLEANEST WAY TO HANDLE LEGACY DESCRIPTION STORAGE
     Module::query("DELETE FROM note_content WHERE game_id = '{$gameId}' AND note_id = '{$noteId}' AND type = 'TEXT'");
     Module::query("INSERT INTO note_content (note_id, game_id, media_id, type, text) VALUES ('" . $noteId . "', '" . $gameId . "', 0, 'TEXT', '" . $description . "')");
     for ($i = 0; is_array($media) && $i < count($media); $i++) {
         $mediaId = Media::createMediaFromJSON($media[$i])->data->media_id;
         Notebook::addContentToNote($noteId, $mediaId, "MEDIA");
     }
     $oldTags = Notebook::getNoteTags($noteId, $gameId);
     for ($i = 0; is_array($oldTags) && $i < count($oldTags); $i++) {
         $tagDeleted = true;
         for ($j = 0; is_array($tags) && $j < count($tags); $j++) {
             if ($oldTags[$i]->tag == $tags[$j]) {
                 $tagDeleted = false;
             }
         }
         if ($tagDeleted) {
             Notebook::deleteTagFromNote($noteId, $oldTags[$i]->tag_id);
         }
     }
     for ($i = 0; is_array($tags) && $i < count($tags); $i++) {
         Notebook::addTagToNote($noteId, $tags[$i]);
     }
     return new returnData(0, Notebook::getNote($noteId)->data);
 }