From 814523ba6e21999ca8f2978dde9907228696fe95 Mon Sep 17 00:00:00 2001 From: Mike Koch Date: Sun, 17 Dec 2017 22:05:32 -0500 Subject: [PATCH] getEventsForStaff endpoint appears to be working --- api/BusinessLogic/Calendar/ReminderUnit.php | 26 +++++++++++++++++ .../Calendar/CalendarController.php | 26 ++++++++++++++--- api/Core/Constants/Priority.php | 15 ++++++++++ api/DataAccess/Calendar/CalendarGateway.php | 28 +++++++++++-------- api/index.php | 2 ++ 5 files changed, 82 insertions(+), 15 deletions(-) create mode 100644 api/BusinessLogic/Calendar/ReminderUnit.php diff --git a/api/BusinessLogic/Calendar/ReminderUnit.php b/api/BusinessLogic/Calendar/ReminderUnit.php new file mode 100644 index 00000000..866ad8e9 --- /dev/null +++ b/api/BusinessLogic/Calendar/ReminderUnit.php @@ -0,0 +1,26 @@ +errorKeys = array('START_AND_END_TIMES_REQUIRED'); + throw new ValidationException($validationModel); + } + + $startTime = $_GET['start']; + $endTime = $_GET['end']; /* @var $calendarHandler CalendarHandler */ $calendarHandler = $applicationContext->get(CalendarHandler::clazz()); - $events = $calendarHandler->getEventsForStaff($startTime, $endTime, new SearchEventsFilter(), $hesk_settings); + $searchEventsFilter = new SearchEventsFilter(); + $searchEventsFilter->reminderUserId = $userContext->id; + $searchEventsFilter->includeTicketsAssignedToOthers = in_array(UserPrivilege::CAN_VIEW_ASSIGNED_TO_OTHER, $userContext->permissions); + $searchEventsFilter->includeUnassignedTickets = in_array(UserPrivilege::CAN_VIEW_UNASSIGNED, $userContext->permissions); + $searchEventsFilter->includeTickets = true; + $searchEventsFilter->categories = $userContext->admin ? null : $userContext->categories; + + $events = $calendarHandler->getEventsForStaff($startTime, $endTime, $searchEventsFilter, $hesk_settings); return output($events); } diff --git a/api/Core/Constants/Priority.php b/api/Core/Constants/Priority.php index 39b86313..de361ab3 100644 --- a/api/Core/Constants/Priority.php +++ b/api/Core/Constants/Priority.php @@ -8,4 +8,19 @@ class Priority extends \BaseClass { const HIGH = 1; const MEDIUM = 2; const LOW = 3; + + static function getByValue($value) { + switch ($value) { + case self::CRITICAL: + return 'CRITICAL'; + case self::HIGH: + return 'HIGH'; + case self::MEDIUM: + return 'MEDIUM'; + case self::LOW: + return 'LOW'; + default: + return 'UNKNOWN'; + } + } } \ No newline at end of file diff --git a/api/DataAccess/Calendar/CalendarGateway.php b/api/DataAccess/Calendar/CalendarGateway.php index b3ae4b92..dc724a73 100644 --- a/api/DataAccess/Calendar/CalendarGateway.php +++ b/api/DataAccess/Calendar/CalendarGateway.php @@ -4,10 +4,12 @@ namespace DataAccess\Calendar; use BusinessLogic\Calendar\CalendarEvent; +use BusinessLogic\Calendar\ReminderUnit; use BusinessLogic\Calendar\SearchEventsFilter; use BusinessLogic\Calendar\TicketEvent; use BusinessLogic\Security\UserContext; use BusinessLogic\Security\UserPrivilege; +use Core\Constants\Priority; use DataAccess\CommonDao; class CalendarGateway extends CommonDao { @@ -20,13 +22,15 @@ class CalendarGateway extends CommonDao { public function getEventsForStaff($startTime, $endTime, $searchEventsFilter, $heskSettings) { $this->init(); + $events = array(); + $startTimeSql = "CONVERT_TZ(FROM_UNIXTIME(" . hesk_dbEscape($startTime) . " / 1000), @@session.time_zone, '+00:00')"; $endTimeSql = "CONVERT_TZ(FROM_UNIXTIME(" . hesk_dbEscape($endTime) . " / 1000), @@session.time_zone, '+00:00')"; // EVENTS $sql = "SELECT `events`.*, `categories`.`name` AS `category_name`, `categories`.`background_color` AS `background_color`, `categories`.`foreground_color` AS `foreground_color`, `categories`.`display_border_outline` AS `display_border`, - `reminders`.`amount` AS `reminder_value`, `reminder`.`unit` AS `reminder_unit` + `reminders`.`amount` AS `reminder_value`, `reminders`.`unit` AS `reminder_unit` FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "calendar_event` AS `events` INNER JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "categories` AS `categories` ON `events`.`category` = `categories`.`id` @@ -52,13 +56,13 @@ class CalendarGateway extends CommonDao { $event->title = $row['name']; $event->location = $row['location']; $event->comments = $row['comments']; - $event->categoryId = $row['category']; + $event->categoryId = intval($row['category']); $event->categoryName = $row['category_name']; $event->backgroundColor = $row['background_color']; $event->foregroundColor = $row['foreground_color']; - $event->displayBorder = $row['display_border']; - $event->reminderValue = $row['reminder_value']; - $event->reminderUnits = $row['reminder_unit']; + $event->displayBorder = $row['display_border'] === '1'; + $event->reminderValue = $row['reminder_value'] === null ? null : floatval($row['reminder_value']); + $event->reminderUnits = $row['reminder_unit'] === null ? null : ReminderUnit::getByValue($row['reminder_unit']); $events[] = $event; } @@ -80,8 +84,8 @@ class CalendarGateway extends CommonDao { AND `categories`.`usage` <> 2 LEFT JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "users` AS `owner` ON `tickets`.`owner` = `owner`.`id` - WHERE `due_date` >= {$startTimeSql}) - AND `due_date` <= {$endTimeSql}) + WHERE `due_date` >= {$startTimeSql} + AND `due_date` <= {$endTimeSql} AND `status` IN (SELECT `id` FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "statuses` WHERE `IsClosed` = 0) AND (`owner` = " . $searchEventsFilter->reminderUserId; @@ -107,20 +111,22 @@ class CalendarGateway extends CommonDao { $event->subject = $row['subject']; $event->title = $row['subject']; $event->startTime = $row['due_date']; - $event->url = $heskSettings['hesk_url'] . '/' . $heskSettings['admin_dir'] . '/admin_ticket.php?track=' . $event['trackingId']; - $event->categoryId = $row['category']; + $event->url = $heskSettings['hesk_url'] . '/' . $heskSettings['admin_dir'] . '/admin_ticket.php?track=' . $event->trackingId; + $event->categoryId = intval($row['category']); $event->categoryName = $row['category_name']; $event->backgroundColor = $row['background_color']; $event->foregroundColor = $row['foreground_color']; - $event->displayBorder = $row['display_border']; + $event->displayBorder = $row['display_border'] === '0'; $event->owner = $row['owner_name']; - $event->priority = $row['priority']; + $event->priority = Priority::getByValue($row['priority']); $events[] = $event; } } $this->close(); + + return $events; } /** diff --git a/api/index.php b/api/index.php index 4766701c..9e617185 100644 --- a/api/index.php +++ b/api/index.php @@ -202,6 +202,8 @@ Link::all(array( '/v1/statuses' => action(\Controllers\Statuses\StatusController::clazz(), RequestMethod::all()), // Settings '/v1/settings' => action(\Controllers\Settings\SettingsController::clazz(), RequestMethod::all()), + // Calendar + '/v1/calendar/events/staff' => action(\Controllers\Calendar\CalendarController::clazz(), array(RequestMethod::GET), SecurityHandler::INTERNAL_OR_AUTH_TOKEN), /* Internal use only routes */ // Resend email response