|
@@ -2,19 +2,28 @@
|
|
|
|
|
|
|
|
namespace Opentalent\OtTemplating\Domain\Repository;
|
|
namespace Opentalent\OtTemplating\Domain\Repository;
|
|
|
|
|
|
|
|
|
|
+use Exception;
|
|
|
use Opentalent\OtTemplating\Domain\Model\Event;
|
|
use Opentalent\OtTemplating\Domain\Model\Event;
|
|
|
|
|
+use Opentalent\OtTemplating\Exception\ApiRequestException;
|
|
|
|
|
|
|
|
class EventRepository extends BaseApiRepository
|
|
class EventRepository extends BaseApiRepository
|
|
|
{
|
|
{
|
|
|
CONST URI = BaseApiRepository::BASE_URI . 'public/events';
|
|
CONST URI = BaseApiRepository::BASE_URI . 'public/events';
|
|
|
const HYDRA_TYPE = 'PortailEvent';
|
|
const HYDRA_TYPE = 'PortailEvent';
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Returns an Event object from an Api record
|
|
|
|
|
+ * @param array $record A record as returned by $this->getApiRecords
|
|
|
|
|
+ * @return Event|null
|
|
|
|
|
+ * @throws Exception
|
|
|
|
|
+ */
|
|
|
private function eventFromJson($record) {
|
|
private function eventFromJson($record) {
|
|
|
if ($record->{'@type'} != $this::HYDRA_TYPE) {
|
|
if ($record->{'@type'} != $this::HYDRA_TYPE) {
|
|
|
return null;
|
|
return null;
|
|
|
}
|
|
}
|
|
|
$event = new Event();
|
|
$event = new Event();
|
|
|
- $event->setId(end(explode('/', $record->{'@id'})));
|
|
|
|
|
|
|
+ $a = explode('/', $record->{'@id'});
|
|
|
|
|
+ $event->setId(end($a));
|
|
|
$event->setOrganizationId($record->{'organizationId'});
|
|
$event->setOrganizationId($record->{'organizationId'});
|
|
|
$event->setSubdomain($record->{'subDomain'});
|
|
$event->setSubdomain($record->{'subDomain'});
|
|
|
$event->setName($record->{'name'});
|
|
$event->setName($record->{'name'});
|
|
@@ -49,6 +58,13 @@ class EventRepository extends BaseApiRepository
|
|
|
return $event;
|
|
return $event;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Returns an array of Event objects from an array of Api records
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param array $records An array of records as returned by $this->getApiRecords
|
|
|
|
|
+ * @return array
|
|
|
|
|
+ * @throws Exception
|
|
|
|
|
+ */
|
|
|
private function eventsFromJson($records) {
|
|
private function eventsFromJson($records) {
|
|
|
$events = [];
|
|
$events = [];
|
|
|
foreach ($records as $record) {
|
|
foreach ($records as $record) {
|
|
@@ -62,11 +78,12 @@ class EventRepository extends BaseApiRepository
|
|
|
*
|
|
*
|
|
|
* @param int $id The id of the event
|
|
* @param int $id The id of the event
|
|
|
* @return Event Event
|
|
* @return Event Event
|
|
|
- * @throws \Exception
|
|
|
|
|
|
|
+ * @throws ApiRequestException
|
|
|
|
|
+ * @throws Exception
|
|
|
*/
|
|
*/
|
|
|
public function findById($id) {
|
|
public function findById($id) {
|
|
|
$params = [];
|
|
$params = [];
|
|
|
- $record = $this->getApiFirstRecord($this::URI . '/' . $id);
|
|
|
|
|
|
|
+ $record = $this->getApiFirstRecord($this::URI . '/' . $id, $params);
|
|
|
return $this->eventFromJson($record);
|
|
return $this->eventFromJson($record);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -77,8 +94,9 @@ class EventRepository extends BaseApiRepository
|
|
|
* @param \Datetime $fromDate Only return events with ending date posterior or equal to this date (leave null for disable the filter)
|
|
* @param \Datetime $fromDate Only return events with ending date posterior or equal to this date (leave null for disable the filter)
|
|
|
* @param \Datetime $toDate Only return events with starting date anterior or equal to this date (leave null for disable the filter)
|
|
* @param \Datetime $toDate Only return events with starting date anterior or equal to this date (leave null for disable the filter)
|
|
|
* @param int $limit Limit the number of results returned (-1 to disable the limitation)
|
|
* @param int $limit Limit the number of results returned (-1 to disable the limitation)
|
|
|
- * @return array Events
|
|
|
|
|
- * @throws \Exception
|
|
|
|
|
|
|
+ * @return array Events
|
|
|
|
|
+ * @throws ApiRequestException
|
|
|
|
|
+ * @throws Exception
|
|
|
*/
|
|
*/
|
|
|
public function findByOrganizationId(int $organizationId, $fromDate = null, $toDate = null, $limit = -1) {
|
|
public function findByOrganizationId(int $organizationId, $fromDate = null, $toDate = null, $limit = -1) {
|
|
|
$params = [];
|
|
$params = [];
|
|
@@ -108,7 +126,8 @@ class EventRepository extends BaseApiRepository
|
|
|
* @param \Datetime $toDate Only return events with starting date anterior or equal to this date (leave null for disable the filter)
|
|
* @param \Datetime $toDate Only return events with starting date anterior or equal to this date (leave null for disable the filter)
|
|
|
* @param int $limit Limit the number of results returned (-1 to disable the limitation)
|
|
* @param int $limit Limit the number of results returned (-1 to disable the limitation)
|
|
|
* @return array Events
|
|
* @return array Events
|
|
|
- * @throws \Exception
|
|
|
|
|
|
|
+ * @throws ApiRequestException
|
|
|
|
|
+ * @throws Exception
|
|
|
*/
|
|
*/
|
|
|
public function findParentsByOrganizationId(int $organizationId, $fromDate = null, $toDate = null, $limit = -1) {
|
|
public function findParentsByOrganizationId(int $organizationId, $fromDate = null, $toDate = null, $limit = -1) {
|
|
|
$params = [];
|
|
$params = [];
|
|
@@ -136,11 +155,12 @@ class EventRepository extends BaseApiRepository
|
|
|
* Get the events of the organization's parents
|
|
* Get the events of the organization's parents
|
|
|
*
|
|
*
|
|
|
* @param int $organizationId The id of the organization
|
|
* @param int $organizationId The id of the organization
|
|
|
- * @param \Datetime $fromDate Only return events with ending date posterior or equal to this date (leave null for disable the filter)
|
|
|
|
|
- * @param \Datetime $toDate Only return events with starting date anterior or equal to this date (leave null for disable the filter)
|
|
|
|
|
|
|
+ * @param \Datetime|null $fromDate Only return events with ending date posterior or equal to this date (leave null for disable the filter)
|
|
|
|
|
+ * @param \Datetime|null $toDate Only return events with starting date anterior or equal to this date (leave null for disable the filter)
|
|
|
* @param int $limit Limit the number of results returned (-1 to disable the limitation)
|
|
* @param int $limit Limit the number of results returned (-1 to disable the limitation)
|
|
|
* @return array Events
|
|
* @return array Events
|
|
|
- * @throws \Exception
|
|
|
|
|
|
|
+ * @throws ApiRequestException
|
|
|
|
|
+ * @throws Exception
|
|
|
*/
|
|
*/
|
|
|
public function findChildrenByOrganizationId(int $organizationId, $fromDate = null, $toDate = null, $limit = -1) {
|
|
public function findChildrenByOrganizationId(int $organizationId, $fromDate = null, $toDate = null, $limit = -1) {
|
|
|
$params = [];
|
|
$params = [];
|
|
@@ -170,7 +190,8 @@ class EventRepository extends BaseApiRepository
|
|
|
* @param int $organizationId The id of the organization
|
|
* @param int $organizationId The id of the organization
|
|
|
* @param array $searchParams Search arguments
|
|
* @param array $searchParams Search arguments
|
|
|
* @return array Events
|
|
* @return array Events
|
|
|
- * @throws \Exception
|
|
|
|
|
|
|
+ * @throws ApiRequestException
|
|
|
|
|
+ * @throws Exception
|
|
|
*/
|
|
*/
|
|
|
public function searchBy(int $organizationId, $searchParams = []) {
|
|
public function searchBy(int $organizationId, $searchParams = []) {
|
|
|
$params = [];
|
|
$params = [];
|