/** * Converts the response in JSON format to the value object i.e Recommender * * @param json * - response in JSON format * * @return Recommender object filled with json data * */ public function buildResponse($json) { $recommenderObj = new Recommender(); $recommendedItemList = array(); $recommenderObj->setRecommendedItemList($recommendedItemList); $recommenderObj->setStrResponse($json); $jsonObj = new JSONObject($json); $jsonObjApp42 = $jsonObj->__get("app42"); $jsonObjResponse = $jsonObjApp42->__get("response"); $recommenderObj->setResponseSuccess($jsonObjResponse->__get("success")); $jsonObjRecommender = $jsonObjResponse->__get("recommender"); $this->buildObjectFromJSONTree($recommenderObj, $jsonObjRecommender); if (!$jsonObjRecommender->has("recommended")) { return $recommenderObj; } if ($jsonObjRecommender->__get("recommended") instanceof JSONObject) { // Only One attribute is there $jsonObjRecommended = $jsonObjRecommender->__get("recommended"); $recomItem = new RecommendedItem($recommenderObj); $this->buildObjectFromJSONTree($recomItem, $jsonObjRecommended); } else { // There is an Array of attribute $jsonObjRecommenderArray = $jsonObjRecommender->getJSONArray("recommended"); for ($i = 0; $i < count($jsonObjRecommenderArray); $i++) { // Get Individual Attribute Node and set it into Object //$jsonObjRecommended = new JSONObject($jsonObjRecommenderArray[$i]); $jsonObjRecommended = $jsonObjRecommenderArray[$i]; $recomItem = new RecommendedItem($recommenderObj); $jsonObjRecommended = new JSONObject($jsonObjRecommended); $this->buildObjectFromJSONTree($recomItem, $jsonObjRecommended); } } return $recommenderObj; }
/** * Converts the response in JSON format to the value object i.e Log * * @param json * - response in JSON format * * @return Log object filled with json data * */ function buildResponse($json) { $logObj = new Logging(); $msgList = array(); $logObj->setMessageList($msgList); $logObj->setStrResponse($json); $jsonObj = new JSONObject($json); $jsonObjApp42 = $jsonObj->__get("app42"); $jsonObjResponse = $jsonObjApp42->__get("response"); $logObj->setResponseSuccess($jsonObjResponse->__get("success")); $jsonObjLog = $jsonObjResponse->__get("logs"); if (!$jsonObjLog->has("log")) { return $logObj; } if ($jsonObjLog->__get("log") instanceof JSONObject) { // Only One attribute is there $jsonObjLogMessage = $jsonObjLog->__get("log"); $messageItem = new Message($logObj); $this->buildObjectFromJSONTree($messageItem, $jsonObjLogMessage); } else { // There is an Array of attribute $jsonObjMessageArray = $jsonObjLog->getJSONArray("log"); for ($i = 0; $i < count($jsonObjMessageArray); $i++) { // Get Individual Attribute Node and set it into Object $jsonObjLogMessage = $jsonObjMessageArray[$i]; $messageItem = new Message($logObj); $jsonObjLogMessage = new JSONObject($jsonObjLogMessage); $this->buildObjectFromJSONTree($messageItem, $jsonObjLogMessage); } } return $logObj; }
/** * 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); }
/** * @param json * @return * @throws Exception */ public function getTotalRecords($json) { $totalRecords = -1; $jsonObj = new JSONObject($json); $jsonObjApp42 = $jsonObj->__get("app42"); $jsonObjResponse = $jsonObjApp42->__get("response"); // if(($jsonObjResponse != null) && ($jsonObjResponse->__get("totalRecords"))){ if ($jsonObjResponse != null) { $totalRecords = $jsonObjResponse->__get("totalRecords"); } return $totalRecords; }
/** * Converts the response in JSON format to the list of value objects i.e Geo * * @param json * - response in JSON format * * @return List of Geo Points object filled with json data * */ public function buildArrayResponse($json) { $geoObjList = array(); $jsonObj = new JSONObject($json); $jsonObjApp42 = $jsonObj->__get("app42"); $jsonObjResponse = $jsonObjApp42->__get("response"); $jsonObjGeoStorage = $jsonObjResponse->__get("geo"); if ($jsonObjGeoStorage->__get("storage") instanceof JSONObject) { //Single Item $jsonObjGeoStorage = $jsonObjGeoStorage->__get("storage"); $geoObj = new Geo(); $pointList = array(); $geoObj->setPointList($pointList); $geoObj->setStrResponse($json); $geoObj->setResponseSuccess($jsonObjResponse->__get("success")); $this->buildObjectFromJSONTree($geoObj, $jsonObjGeoStorage); array_push($geoObjList, $geoObj); if ($jsonObjGeoStorage->has("points")) { $this->buildInternalObj($geoObj, $jsonObjGeoStorage); } } else { //Multiple Item $jsonStorageArray = $jsonObjGeoStorage->getJSONArray("storage"); for ($i = 0; $i < count($jsonStorageArray); $i++) { $jsonObjStorage = $jsonStorageArray[$i]; $geoObj = new Geo(); $pointList = array(); $geoObj->setPointList($pointList); $geoObj->setStrResponse($json); $geoObj->setResponseSuccess($jsonObjResponse->__get("success")); $jsonObjStorage = new JSONObject($jsonObjStorage); $this->buildObjectFromJSONTree($geoObj, $jsonObjStorage); array_push($geoObjList, $geoObj); if ($jsonObjStorage->has("points")) { $this->buildInternalObj($geoObj, $jsonObjStorage); } } } return $geoObjList; }
/** * Converts the response in JSON format to the value object i.e Session * * @param json * - response in JSON format * * @return Session object filled with json data * */ public function buildResponse($json) { $sessionObj = new Session(); $attributeList = array(); $sessionObj->setAttributeList($attributeList); $sessionObj->setStrResponse($json); $jsonObj = new JSONObject($json); $jsonObjApp42 = $jsonObj->__get("app42"); $jsonObjResponse = $jsonObjApp42->__get("response"); $sessionObj->setResponseSuccess($jsonObjResponse->__get("success")); $jsonObjSession = $jsonObjResponse->__get("session"); $this->buildObjectFromJSONTree($sessionObj, $jsonObjSession); if (!$jsonObjSession->has("attributes")) { return $sessionObj; } $jsonObjAttributes = $jsonObjSession->__get("attributes"); if (!$jsonObjAttributes->has("attribute")) { return $sessionObj; } if ($jsonObjAttributes->__get("attribute") instanceof JSONObject) { // Only One attribute is there $jsonObjAttribute = $jsonObjAttributes->__get("attribute"); $attribute = new Attribute($sessionObj); $this->buildObjectFromJSONTree($attribute, $jsonObjAttribute); } else { // There is an Array of attribute $jsonObjAttributeArray = $jsonObjAttributes->getJSONArray("attribute"); for ($i = 0; $i < count($jsonObjAttributeArray); $i++) { //Get Individual Attribute Node and set it into Object $jsonObjAttribute = $jsonObjAttributeArray[$i]; $attribute = new Attribute($sessionObj); $jsonObjAttribute = new JSONObject($jsonObjAttribute); $this->buildObjectFromJSONTree($attribute, $jsonObjAttribute); } } return $sessionObj; }
/** * Converts the response in JSON format to the value object i.e Email * * @params json * - response in JSON format * * @return Email object filled with json data * */ function buildResponse($json) { $emailObj = new Email(); $configList = array(); $emailObj->setConfigList($configList); $emailObj->setStrResponse($json); $jsonObj = new JSONObject($json); $jsonObjApp42 = $jsonObj->__get("app42"); $jsonObjResponse = $jsonObjApp42->__get("response"); $emailObj->setResponseSuccess($jsonObjResponse->__get("success")); $jsonObjEmail = $jsonObjResponse->__get("email"); $this->buildObjectFromJSONTree($emailObj, $jsonObjEmail); if (!$jsonObjEmail->has("configurations")) { return $emailObj; } $jsonEmailConfig = $jsonObjEmail->__get("configurations"); if (!$jsonEmailConfig->has("config")) { return $emailObj; } if ($jsonEmailConfig->__get("config") instanceof JSONObject) { // Only One attribute is there $jsonObjConfig = $jsonEmailConfig->__get("config"); $configItem = new Configuration($emailObj); $this->buildObjectFromJSONTree($configItem, $jsonObjConfig); } else { // There is an Array of attribute $jsonObjConfigArray = $jsonEmailConfig->getJSONArray("config"); for ($i = 0; $i < count($jsonObjConfigArray); $i++) { // Get Individual Attribute Node and set it into Object $jsonObjConfigs = $jsonObjConfigArray[$i]; $configItem = new Configuration($emailObj); $jsonObjConfig = new JSONObject($jsonObjConfigs); $this->buildObjectFromJSONTree($configItem, $jsonObjConfig); } } return $emailObj; }
function buildArrayResponse($json) { $pushListObject = array(); $channelList = array(); $jsonObj = new JSONObject($json); $jsonObjApp42 = $jsonObj->__get("app42"); $jsonObjResponse = $jsonObjApp42->__get("response"); $jsonObjPush = $jsonObjResponse->__get("push"); if ($jsonObjPush instanceof JSONObject) { $pushObj = new PushNotification(); $pushObj->setChannelList($channelList); $this->buildObjectFromJSONTree($pushObj, $jsonObjPush); if ($jsonObjPush->has("channels")) { $jsonPushChannels = $jsonObjPush->__get("channels"); if ($jsonPushChannels->__get("channel") instanceof JSONObject) { // Only One attribute is there $jsonObjchannel = $jsonPushChannels->__get("channel"); $channelList1 = new Channel($pushObj); $this->buildObjectFromJSONTree($channelList1, $jsonObjchannel); } else { // There is an Array of attribute $jsonObjChanelArray = $jsonPushChannels->getJSONArray("channel"); for ($i = 0; $i < count($jsonObjChanelArray); $i++) { // Get Individual Attribute Node and set it into Object $jsonObjChannelLi = $jsonObjChanelArray[$i]; $channelListObj = new Channel($pushObj); $jsonObjChann = new JSONObject($jsonObjChannelLi); $this->buildObjectFromJSONTree($channelListObj, $jsonObjChann); } } } $pushObj->setStrResponse($json); $pushObj->setResponseSuccess($this->isRespponseSuccess($json)); array_push($pushListObject, $pushObj); } else { $pushJSONArray = $jsonObjResponse->getJSONArray("push"); for ($i = 0; $i < count($pushJSONArray); $i++) { $pushObject = new PushNotification(); $pushObject->setChannelList($channelList); $pushJSONObj = $pushJSONArray[$i]; $pushJSONObject = new JSONObject($pushJSONObj); $this->buildObjectFromJSONTree($pushObject, $pushJSONObject); if ($pushJSONObject->has("channels")) { $jsonPushChannelss = $pushJSONObject->__get("channels"); if ($jsonPushChannelss->has("channel")) { if ($jsonPushChannelss->__get("channel") instanceof JSONObject) { // Only One attribute is there $jsonObjchannelA = $jsonPushChannelss->__get("channel"); $channelListObject = new Channel($pushObject); $this->buildObjectFromJSONTree($channelListObject, $jsonObjchannelA); } else { // There is an Array of attribute $jsonObjChanelArray = $jsonPushChannelss->getJSONArray("channel"); for ($i = 0; $i < count($jsonObjChanelArray); $i++) { // Get Individual Attribute Node and set it into Object $jsonObjChannelList = $jsonObjChanelArray[$i]; $channelList2 = new Channel($pushObject); $jsonObjChannel = new JSONObject($jsonObjChannelList); $this->buildObjectFromJSONTree($channelList2, $jsonObjChannel); // $pushObj->setChannelList($channelList); } } } } $pushObject->setStrResponse($json); $pushObject->setResponseSuccess($this->isRespponseSuccess($json)); array_push($pushListObject, $pushObject); } } return $pushListObject; }
function buildJsonFacebookProfileLink($me, $friendJSONObj) { $jsonObjMe = new JSONObject($friendJSONObj); if ($jsonObjMe->has("id") && $jsonObjMe->__get("id") != null) { $me->setId($jsonObjMe->__get("id")); $me->setName($jsonObjMe->__get("name")); $me->setPicture($jsonObjMe->__get("picture")); $me->setFirstName($jsonObjMe->__get("firstName")); $me->setLastName($jsonObjMe->__get("lastName")); $me->setGender($jsonObjMe->__get("gender")); $me->setLink($jsonObjMe->__get("link")); $me->setLocale($jsonObjMe->__get("locale")); $me->setUserName($jsonObjMe->__get("username")); } }
function buildJsonFacebookProfile($me, $friendJSONObj) { $jsonObjMe = new JSONObject($friendJSONObj); if ($jsonObjMe->has("id") && $jsonObjMe->__get("id") != null) { $me->setId($jsonObjMe->__get("id")); $me->setName($jsonObjMe->__get("name")); $me->setPicture($jsonObjMe->__get("picture")); } }