public function getAttendees($eventId) { $attendee = new Attendee(); $attendee->setId(1); $attendee->setEmail('*****@*****.**'); $attendee->setName('Daniel Gomes'); $attendee->setTwitterHandler(''); return array($attendee); }
/** * @param string $json The response content must be a valid json string * @return array A list of \Phplx\Raffle\Model\Attendee * @throws \Exception */ private function parseAttendees($json) { try { $data = json_decode($json); $attendees = array(); foreach ($data->attendees as $person) { $attendee = new Attendee(); $attendee->setId($person->attendee->order_id); $attendee->setName($person->attendee->first_name . ' ' . $person->attendee->last_name); $attendee->setEmail($person->attendee->email); $attendee->setTwitterHandler($this->getTwitterUsername($person->attendee)); $attendees[] = $attendee; } return $attendees; } catch (\Exception $error) { if ($jsonError = json_last_error()) { throw new \Exception((string) $jsonError); } throw new \Exception('Unable to parse Attendees'); } }
/** * Parses the json data into an Event object * * @param $data * * @return Event */ private function parseEventFromJson($data) { $dataObj = json_decode($data); $event = new Event($dataObj->event->id); if (isset($dataObj->event->attendees)) { // cleans the array $attendees = array_filter($dataObj->event->attendees); foreach ($attendees as $item) { $attendee = new Attendee(); $attendee->setId($item->id); $attendee->setName($item->name); $attendee->setEmail($item->email); if (isset($item->twitterHandler) && !empty($item->twitterHandler)) { $attendee->setTwitterHandler($item->twitterHandler); } $event->addAttendee($attendee); } } if (isset($dataObj->event->prizes)) { // cleans the array $prizes = array_filter($dataObj->event->prizes); foreach ($prizes as $item) { $prize = new Prize(); $prize->setSponsorName($item->sponsor); $prize->setPrizeTitle($item->prize); if (isset($item->winner)) { $attendee = new Attendee(); $attendee->setId($item->winner->id); $prize->setWinner($attendee); } if (isset($item->tweet_message)) { $prize->setTweetMessage($item->tweet_message); } $event->addPrize($prize); } } return $event; }