getEventsForStaff endpoint appears to be working
This commit is contained in:
parent
13161696ae
commit
814523ba6e
26
api/BusinessLogic/Calendar/ReminderUnit.php
Normal file
26
api/BusinessLogic/Calendar/ReminderUnit.php
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BusinessLogic\Calendar;
|
||||||
|
|
||||||
|
|
||||||
|
class ReminderUnit {
|
||||||
|
const MINUTE = 0;
|
||||||
|
const HOUR = 1;
|
||||||
|
const DAY = 2;
|
||||||
|
const WEEK = 3;
|
||||||
|
|
||||||
|
static function getByValue($value) {
|
||||||
|
switch ($value) {
|
||||||
|
case 0:
|
||||||
|
return 'MINUTE';
|
||||||
|
case 1:
|
||||||
|
return 'HOUR';
|
||||||
|
case 2:
|
||||||
|
return 'DAY';
|
||||||
|
case 3:
|
||||||
|
return 'WEEK';
|
||||||
|
default:
|
||||||
|
return 'UNKNOWN';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -5,18 +5,36 @@ namespace Controllers\Calendar;
|
|||||||
|
|
||||||
use BusinessLogic\Calendar\CalendarHandler;
|
use BusinessLogic\Calendar\CalendarHandler;
|
||||||
use BusinessLogic\Calendar\SearchEventsFilter;
|
use BusinessLogic\Calendar\SearchEventsFilter;
|
||||||
|
use BusinessLogic\Exceptions\ValidationException;
|
||||||
|
use BusinessLogic\Security\UserContext;
|
||||||
|
use BusinessLogic\Security\UserPrivilege;
|
||||||
|
use BusinessLogic\ValidationModel;
|
||||||
|
|
||||||
class CalendarController extends \BaseClass {
|
class CalendarController extends \BaseClass {
|
||||||
function get() {
|
function get() {
|
||||||
global $applicationContext, $hesk_settings;
|
/* @var $userContext UserContext */
|
||||||
|
global $applicationContext, $hesk_settings, $userContext;
|
||||||
|
|
||||||
$startTime = isset($_GET['start']) ? $_GET['start'] : round(microtime(true) * 1000);
|
if (!isset($_GET['start']) || !isset($_GET['end'])) {
|
||||||
$endTime = isset($_GET['end']) ? $_GET['end'] : round(microtime(true) * 1000);
|
$validationModel = new ValidationModel();
|
||||||
|
$validationModel->errorKeys = array('START_AND_END_TIMES_REQUIRED');
|
||||||
|
throw new ValidationException($validationModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
$startTime = $_GET['start'];
|
||||||
|
$endTime = $_GET['end'];
|
||||||
|
|
||||||
/* @var $calendarHandler CalendarHandler */
|
/* @var $calendarHandler CalendarHandler */
|
||||||
$calendarHandler = $applicationContext->get(CalendarHandler::clazz());
|
$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);
|
return output($events);
|
||||||
}
|
}
|
||||||
|
@ -8,4 +8,19 @@ class Priority extends \BaseClass {
|
|||||||
const HIGH = 1;
|
const HIGH = 1;
|
||||||
const MEDIUM = 2;
|
const MEDIUM = 2;
|
||||||
const LOW = 3;
|
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';
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -4,10 +4,12 @@ namespace DataAccess\Calendar;
|
|||||||
|
|
||||||
|
|
||||||
use BusinessLogic\Calendar\CalendarEvent;
|
use BusinessLogic\Calendar\CalendarEvent;
|
||||||
|
use BusinessLogic\Calendar\ReminderUnit;
|
||||||
use BusinessLogic\Calendar\SearchEventsFilter;
|
use BusinessLogic\Calendar\SearchEventsFilter;
|
||||||
use BusinessLogic\Calendar\TicketEvent;
|
use BusinessLogic\Calendar\TicketEvent;
|
||||||
use BusinessLogic\Security\UserContext;
|
use BusinessLogic\Security\UserContext;
|
||||||
use BusinessLogic\Security\UserPrivilege;
|
use BusinessLogic\Security\UserPrivilege;
|
||||||
|
use Core\Constants\Priority;
|
||||||
use DataAccess\CommonDao;
|
use DataAccess\CommonDao;
|
||||||
|
|
||||||
class CalendarGateway extends CommonDao {
|
class CalendarGateway extends CommonDao {
|
||||||
@ -20,13 +22,15 @@ class CalendarGateway extends CommonDao {
|
|||||||
public function getEventsForStaff($startTime, $endTime, $searchEventsFilter, $heskSettings) {
|
public function getEventsForStaff($startTime, $endTime, $searchEventsFilter, $heskSettings) {
|
||||||
$this->init();
|
$this->init();
|
||||||
|
|
||||||
|
$events = array();
|
||||||
|
|
||||||
$startTimeSql = "CONVERT_TZ(FROM_UNIXTIME(" . hesk_dbEscape($startTime) . " / 1000), @@session.time_zone, '+00:00')";
|
$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')";
|
$endTimeSql = "CONVERT_TZ(FROM_UNIXTIME(" . hesk_dbEscape($endTime) . " / 1000), @@session.time_zone, '+00:00')";
|
||||||
|
|
||||||
// EVENTS
|
// EVENTS
|
||||||
$sql = "SELECT `events`.*, `categories`.`name` AS `category_name`, `categories`.`background_color` AS `background_color`,
|
$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`,
|
`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`
|
FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "calendar_event` AS `events`
|
||||||
INNER JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "categories` AS `categories`
|
INNER JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "categories` AS `categories`
|
||||||
ON `events`.`category` = `categories`.`id`
|
ON `events`.`category` = `categories`.`id`
|
||||||
@ -52,13 +56,13 @@ class CalendarGateway extends CommonDao {
|
|||||||
$event->title = $row['name'];
|
$event->title = $row['name'];
|
||||||
$event->location = $row['location'];
|
$event->location = $row['location'];
|
||||||
$event->comments = $row['comments'];
|
$event->comments = $row['comments'];
|
||||||
$event->categoryId = $row['category'];
|
$event->categoryId = intval($row['category']);
|
||||||
$event->categoryName = $row['category_name'];
|
$event->categoryName = $row['category_name'];
|
||||||
$event->backgroundColor = $row['background_color'];
|
$event->backgroundColor = $row['background_color'];
|
||||||
$event->foregroundColor = $row['foreground_color'];
|
$event->foregroundColor = $row['foreground_color'];
|
||||||
$event->displayBorder = $row['display_border'];
|
$event->displayBorder = $row['display_border'] === '1';
|
||||||
$event->reminderValue = $row['reminder_value'];
|
$event->reminderValue = $row['reminder_value'] === null ? null : floatval($row['reminder_value']);
|
||||||
$event->reminderUnits = $row['reminder_unit'];
|
$event->reminderUnits = $row['reminder_unit'] === null ? null : ReminderUnit::getByValue($row['reminder_unit']);
|
||||||
|
|
||||||
$events[] = $event;
|
$events[] = $event;
|
||||||
}
|
}
|
||||||
@ -80,8 +84,8 @@ class CalendarGateway extends CommonDao {
|
|||||||
AND `categories`.`usage` <> 2
|
AND `categories`.`usage` <> 2
|
||||||
LEFT JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "users` AS `owner`
|
LEFT JOIN `" . hesk_dbEscape($heskSettings['db_pfix']) . "users` AS `owner`
|
||||||
ON `tickets`.`owner` = `owner`.`id`
|
ON `tickets`.`owner` = `owner`.`id`
|
||||||
WHERE `due_date` >= {$startTimeSql})
|
WHERE `due_date` >= {$startTimeSql}
|
||||||
AND `due_date` <= {$endTimeSql})
|
AND `due_date` <= {$endTimeSql}
|
||||||
AND `status` IN (SELECT `id` FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "statuses` WHERE `IsClosed` = 0)
|
AND `status` IN (SELECT `id` FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "statuses` WHERE `IsClosed` = 0)
|
||||||
AND (`owner` = " . $searchEventsFilter->reminderUserId;
|
AND (`owner` = " . $searchEventsFilter->reminderUserId;
|
||||||
|
|
||||||
@ -107,20 +111,22 @@ class CalendarGateway extends CommonDao {
|
|||||||
$event->subject = $row['subject'];
|
$event->subject = $row['subject'];
|
||||||
$event->title = $row['subject'];
|
$event->title = $row['subject'];
|
||||||
$event->startTime = $row['due_date'];
|
$event->startTime = $row['due_date'];
|
||||||
$event->url = $heskSettings['hesk_url'] . '/' . $heskSettings['admin_dir'] . '/admin_ticket.php?track=' . $event['trackingId'];
|
$event->url = $heskSettings['hesk_url'] . '/' . $heskSettings['admin_dir'] . '/admin_ticket.php?track=' . $event->trackingId;
|
||||||
$event->categoryId = $row['category'];
|
$event->categoryId = intval($row['category']);
|
||||||
$event->categoryName = $row['category_name'];
|
$event->categoryName = $row['category_name'];
|
||||||
$event->backgroundColor = $row['background_color'];
|
$event->backgroundColor = $row['background_color'];
|
||||||
$event->foregroundColor = $row['foreground_color'];
|
$event->foregroundColor = $row['foreground_color'];
|
||||||
$event->displayBorder = $row['display_border'];
|
$event->displayBorder = $row['display_border'] === '0';
|
||||||
$event->owner = $row['owner_name'];
|
$event->owner = $row['owner_name'];
|
||||||
$event->priority = $row['priority'];
|
$event->priority = Priority::getByValue($row['priority']);
|
||||||
|
|
||||||
$events[] = $event;
|
$events[] = $event;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->close();
|
$this->close();
|
||||||
|
|
||||||
|
return $events;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -202,6 +202,8 @@ Link::all(array(
|
|||||||
'/v1/statuses' => action(\Controllers\Statuses\StatusController::clazz(), RequestMethod::all()),
|
'/v1/statuses' => action(\Controllers\Statuses\StatusController::clazz(), RequestMethod::all()),
|
||||||
// Settings
|
// Settings
|
||||||
'/v1/settings' => action(\Controllers\Settings\SettingsController::clazz(), RequestMethod::all()),
|
'/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 */
|
/* Internal use only routes */
|
||||||
// Resend email response
|
// Resend email response
|
||||||
|
Loading…
x
Reference in New Issue
Block a user