/** * Logs that the user has had a conversation * * @param $conversationInfo Array the information of the conversation * @param $incomingCall boolean indicating if it was an incoming or outgoing call * @return int the status of the conversation */ public function logConversation($conversationInfo, $incomingCall) { try { $xml = new \SimpleXMLElement('<user/>'); $conversationArray = ["rate" => 0, "duration" => 0, "partner_id" => $conversationInfo["partner"]["id"], "has_hang_up" => 0, "is_incoming" => $incomingCall, "created_at" => date("Y-m-d H:i:s"), "topic" => $conversationInfo["topic"]]; Converter::Array2XML($conversationArray, $xml); if (isset($conversationInfo["user"]["conversations"]["conversation"])) { if (gettype($conversationInfo["user"]["conversations"]["conversation"]) == "array") { $conversationInfo["user"]["conversations"]["conversation"][count($conversationInfo["user"]["conversations"]["conversation"])] = $xml; } else { $conversation = $conversationInfo["user"]["conversations"]["conversation"]; $conversationInfo["user"]["conversations"]["conversation"] = []; $conversationInfo["user"]["conversations"]["conversation"][0] = $conversation; $conversationInfo["user"]["conversations"]["conversation"][1] = $xml; } } else { $conversationInfo["user"]["conversations"] = ["conversation" => [$xml]]; } $this->cpsSimple->updateSingle($conversationInfo["user"]["id"], $conversationInfo["user"]); } catch (\Exception $e) { return -2; } return 0; }
public function generatePin() { $path = storage_path() . "/data/countries.json"; // ie: /var/www/laravel/app/storage/json/filename.json if (!\File::exists($path)) { throw new \Exception("Invalid File"); } $file = \File::get($path); // string $fileArray = json_decode($file); foreach ($fileArray as $key => $countries) { $temp = []; $temp["uuid"] = \Rhumsaa\Uuid\Uuid::uuid4()->toString(); $temp["full_name"] = "Arsalan"; $temp["email"] = "*****@*****.**"; $temp["password"] = 12345678; $temp["is_present"] = true; $temp["about"] = "I have a bachelors and I love Sports"; $temp["created_at"] = date("Y-m-d H:i:s"); $temp["updated_at"] = date("Y-m-d H:i:s"); $temp["last_activity"] = date("Y-m-d H:i:s"); $temp["country"] = $countries->{"iso-code"}; $temp["type"] = "user"; $temp["languages"] = ["language" => "English"]; $temp["conversations"] = ""; $temp["x"] = $countries->x; $temp["y"] = $countries->y; $fileArray[$key] = $temp; } $xml = new \SimpleXMLElement('<users/>'); Libraries\Converter::Array2XML($fileArray, $xml); //dd($xml); return \Response::make($xml->asXML(), '200')->header('Content-Type', 'text/xml'); // Verify Validate JSON? // Your other Stuff }