/** * Builds the Json Document for the storage w.r.t their docId * * @param document * - document for storage * @param jsonObjDoc * - jsonDoc object for storage * */ function buildJsonDocument($document, $jsonObjDoc) { $jsonObjDoc = new JSONObject($jsonObjDoc); if ($jsonObjDoc->has("loc") && $jsonObjDoc->__get("loc") != null) { $geoArray = $jsonObjDoc->getJSONArray("loc"); for ($i = 0; $i < count($geoArray); $i++) { if (count($geoArray) == 2) { $geoTag = new GeoTag(); $geoTag->setLat($geoArray[0]); $geoTag->setLng($geoArray[1]); $document->setLocation($geoTag); $jsonObjDoc->remove("loc"); } } } if ($jsonObjDoc->has("_id") && $jsonObjDoc->__get("_id") != null) { $idObj = $jsonObjDoc->__get("_id"); $oIdObj = $idObj->__get("\$oid"); $document->setDocId($oIdObj); $jsonObjDoc->remove("_id"); } if ($jsonObjDoc->has("_\$updatedAt") && $jsonObjDoc->__get("_\$updatedAt") != null) { $updatedObj = $jsonObjDoc->__get("_\$updatedAt"); $document->setUpdatedAt($updatedObj); $jsonObjDoc->remove("_\$updatedAt"); } if ($jsonObjDoc->has("_\$createdAt") && $jsonObjDoc->__get("_\$createdAt") != null) { $createdAtObj = $jsonObjDoc->__get("_\$createdAt"); $document->setCreatedAt($createdAtObj); $jsonObjDoc->remove("_\$createdAt"); } if ($jsonObjDoc->has("_\$event") && $jsonObjDoc->__get("_\$event") != null) { $eventObj = $jsonObjDoc->__get("_\$event"); $document->setEvent($eventObj); $jsonObjDoc->remove("_\$event"); } if ($jsonObjDoc->has("_\$owner") && $jsonObjDoc->__get("_\$owner") != null) { $idObj = $jsonObjDoc->__get("_\$owner"); $ownerObj = $idObj->__get("owner"); $document->setOwner($ownerObj); $jsonObjDoc->remove("_\$owner"); } $document->setJsonDoc($jsonObjDoc); }