public function getBeneficiaryEvents($criteria = array()) { if (empty($criteria) || !array_key_exists('beneficiaryId', $criteria)) { throw new \Exception('Unknown beneficiary\'s event list with these given criteria'); } $data = null; try { $params = array(); if (isset($criteria['startDate'])) { if ($criteria['startDate'] instanceof \DateTime) { $criteria['startDate'] = $criteria['startDate']->getTimestamp(); } $params['start_date'] = $criteria['startDate']; } else { $params['start_date'] = time() - 60 * 60 * 24; } if (isset($criteria['endDate'])) { if ($criteria['endDate'] instanceof \DateTime) { $criteria['endDate'] = $criteria['endDate']->getTimestamp(); } $params['end_date'] = $criteria['endDate']; } if (isset($criteria['participants'])) { $params['participants'] = $criteria['participants']; } $request = $this->client->get('beneficiaries/' . $criteria['beneficiaryId'] . '/agenda', array(), array('query' => $params)); $response = $request->send()->json(); if (null == $response || !isset($response['status'])) { throw new \Exception($response['message'], StatusConstants::UNKNWON_ERROR); } if (StatusConstants::OK != $response['status']) { throw new \Exception($response['message'], StatusConstants::toCode($response['status'])); } // - Got it! if (isset($response['agenda'])) { $result = $response['agenda']; $beneficiary = null; if (isset($result['beneficiary']) && is_array($result['beneficiary'])) { $beneficiaryData = $result['beneficiary']; $beneficiary = new BeneficiaryUser(@$beneficiaryData['id'], @$beneficiaryData['title'], @$beneficiaryData['first_name'], @$beneficiaryData['last_name']); } $participants = array(); if (isset($result['participants']) && is_array($result['participants'])) { foreach ($result['participants'] as $participantData) { if (!isset($participantData['id'])) { continue; } $participants[$participantData['id']] = new OrganizationUser($participantData['id'], @$participantData['title'], @$participantData['first_name'], @$participantData['last_name'], '', '', '', '', '', @$participantData['org_type'], @$participantData['role'], @$participantData['sub_role']); } } if (isset($result['events']) && is_array($result['events'])) { $data = array(); foreach ($result['events'] as $eventData) { $event = new Event(@$eventData['object'], @$eventData['description'], @$eventData['place']); $event->setId(@$eventData['id']); $event->setDateStart(@$eventData['start_date']); $event->setDateEnd(@$eventData['end_date']); $event->addParticipant($beneficiary); if (isset($eventData['participants']) && is_array($eventData['participants'])) { foreach ($eventData['participants'] as $participant) { if (!isset($participant['id']) || !isset($participants[$participant['id']])) { continue; } $event->addParticipant($participants[$participant['id']]); } } $data[] = $event; } } } } catch (\Exception $e) { throw new \Exception('Erreur lors de la recherche d\'événements.', StatusConstants::toCode($e->getCode()), $e); } return $data; }