Working on new update event endpoint
This commit is contained in:
parent
9eab1525ef
commit
c805fd8eab
@ -15,4 +15,8 @@ class CalendarHandler extends \BaseClass {
|
||||
public function getEventsForStaff($startTime, $endTime, $searchEventsFilter, $heskSettings) {
|
||||
return $this->calendarGateway->getEventsForStaff($startTime, $endTime, $searchEventsFilter, $heskSettings);
|
||||
}
|
||||
|
||||
public function updateEvent($calendarEvent, $userContext, $heskSettings) {
|
||||
$this->calendarGateway->updateEvent($calendarEvent, $userContext, $heskSettings);
|
||||
}
|
||||
}
|
@ -23,4 +23,19 @@ class ReminderUnit {
|
||||
return 'UNKNOWN';
|
||||
}
|
||||
}
|
||||
|
||||
static function getByName($name) {
|
||||
switch ($name) {
|
||||
case 'MINUTE':
|
||||
return self::MINUTE;
|
||||
case 'HOUR':
|
||||
return self::HOUR;
|
||||
case 'DAY':
|
||||
return self::DAY;
|
||||
case 'WEEK':
|
||||
return self::WEEK;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -3,12 +3,16 @@
|
||||
namespace Controllers\Calendar;
|
||||
|
||||
|
||||
use BusinessLogic\Calendar\CalendarEvent;
|
||||
use BusinessLogic\Calendar\CalendarHandler;
|
||||
use BusinessLogic\Calendar\ReminderUnit;
|
||||
use BusinessLogic\Calendar\SearchEventsFilter;
|
||||
use BusinessLogic\Exceptions\ValidationException;
|
||||
use BusinessLogic\Helpers;
|
||||
use BusinessLogic\Security\UserContext;
|
||||
use BusinessLogic\Security\UserPrivilege;
|
||||
use BusinessLogic\ValidationModel;
|
||||
use Controllers\JsonRetriever;
|
||||
|
||||
class CalendarController extends \BaseClass {
|
||||
function get() {
|
||||
@ -38,4 +42,36 @@ class CalendarController extends \BaseClass {
|
||||
|
||||
return output($events);
|
||||
}
|
||||
|
||||
function put($id) {
|
||||
/* @var $userContext UserContext */
|
||||
global $applicationContext, $hesk_settings, $userContext;
|
||||
|
||||
$json = JsonRetriever::getJsonData();
|
||||
|
||||
$event = $this->transformJson($json);
|
||||
|
||||
/* @var $calendarHandler CalendarHandler */
|
||||
$calendarHandler = $applicationContext->get(CalendarHandler::clazz());
|
||||
|
||||
return output($calendarHandler->updateEvent($event, $userContext, $hesk_settings));
|
||||
}
|
||||
|
||||
private function transformJson($json, $creating = false) {
|
||||
$event = new CalendarEvent();
|
||||
|
||||
if ($creating) {
|
||||
$event->id = Helpers::safeArrayGet($json, 'id');
|
||||
}
|
||||
|
||||
$event->startTime = date('Y-m-d H:i:s', Helpers::safeArrayGet($json, 'startTime'));
|
||||
$event->endTime = date('Y-m-d H:i:s', Helpers::safeArrayGet($json, 'endTime'));
|
||||
$event->allDay = Helpers::safeArrayGet($json, 'allDay') === 'true';
|
||||
$event->title = Helpers::safeArrayGet($json, 'title');
|
||||
$event->location = Helpers::safeArrayGet($json, 'location');
|
||||
$event->comments = Helpers::safeArrayGet($json, 'comments');
|
||||
$event->categoryId = Helpers::safeArrayGet($json, 'categoryId');
|
||||
$event->reminderValue = Helpers::safeArrayGet($json, 'reminderValue');
|
||||
$event->reminderUnits = ReminderUnit::getByName(Helpers::safeArrayGet($json, 'reminderUnits'));
|
||||
}
|
||||
}
|
@ -8,6 +8,7 @@ use BusinessLogic\Calendar\CalendarEvent;
|
||||
use BusinessLogic\Calendar\ReminderUnit;
|
||||
use BusinessLogic\Calendar\SearchEventsFilter;
|
||||
use BusinessLogic\Calendar\TicketEvent;
|
||||
use BusinessLogic\Security\UserContext;
|
||||
use Core\Constants\Priority;
|
||||
use DataAccess\CommonDao;
|
||||
|
||||
@ -128,4 +129,32 @@ class CalendarGateway extends CommonDao {
|
||||
|
||||
return $events;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $event CalendarEvent
|
||||
* @param $userContext UserContext
|
||||
* @param $heskSettings array
|
||||
*/
|
||||
public function updateEvent($event, $userContext, $heskSettings) {
|
||||
$this->init();
|
||||
|
||||
$sql = "UPDATE `" . hesk_dbEscape($heskSettings['db_pfix']) . "calendar_event` SET `start` = '" . hesk_dbEscape($event->startTime)
|
||||
. "', `end` = '" . hesk_dbEscape($event->endTime) . "', `all_day` = '" . ($event->allDay ? 1 : 0) . "', `name` = '"
|
||||
. hesk_dbEscape(addslashes($event->title)) . "', `location` = '" . hesk_dbEscape(addslashes($event->location)) . "', `comments` = '"
|
||||
. hesk_dbEscape(addslashes($event->comments)) . "', `category` = " . intval($event->categoryId) . " WHERE `id` = " . intval($event->id);
|
||||
|
||||
if ($event->reminderValue != null) {
|
||||
$delete_sql = "DELETE FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "calendar_event_reminder` WHERE `event_id` = " . intval($event->id)
|
||||
. " AND `user_id` = " . intval($userContext->id);
|
||||
hesk_dbQuery($delete_sql);
|
||||
$insert_sql = "INSERT INTO `" . hesk_dbEscape($heskSettings['db_pfix']) . "calendar_event_reminder` (`user_id`, `event_id`,
|
||||
`amount`, `unit`) VALUES (" . intval($userContext->id) . ", " . intval($event->id) . ", " . intval($event->reminderValue) . ",
|
||||
" . intval($event->reminderUnits) . ")";
|
||||
hesk_dbQuery($insert_sql);
|
||||
}
|
||||
|
||||
hesk_dbQuery($sql);
|
||||
|
||||
$this->close();
|
||||
}
|
||||
}
|
@ -154,30 +154,7 @@ function update_event($event, $hesk_settings) {
|
||||
print_error('Access Denied', 'You cannot edit an event in this category');
|
||||
}
|
||||
|
||||
$event['start'] = date('Y-m-d H:i:s', strtotime($event['start']));
|
||||
$event['end'] = date('Y-m-d H:i:s', strtotime($event['end']));
|
||||
if ($event['create_ticket_date'] != null) {
|
||||
$event['create_ticket_date'] = date('Y-m-d H:i:s', strtotime($event['create_ticket_date']));
|
||||
}
|
||||
$event['all_day'] = $event['all_day'] ? 1 : 0;
|
||||
$event['assign_to'] = $event['assign_to'] != null ? intval($event['assign_to']) : 'NULL';
|
||||
|
||||
$sql = "UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "calendar_event` SET `start` = '" . hesk_dbEscape($event['start'])
|
||||
. "', `end` = '" . hesk_dbEscape($event['end']) . "', `all_day` = '" . hesk_dbEscape($event['all_day']) . "', `name` = '"
|
||||
. hesk_dbEscape(addslashes($event['title'])) . "', `location` = '" . hesk_dbEscape(addslashes($event['location'])) . "', `comments` = '"
|
||||
. hesk_dbEscape(addslashes($event['comments'])) . "', `category` = " . intval($event['category']) . " WHERE `id` = " . intval($event['id']);
|
||||
|
||||
if ($event['reminder_amount'] != null) {
|
||||
$delete_sql = "DELETE FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "calendar_event_reminder` WHERE `event_id` = " . intval($event['id'])
|
||||
. " AND `user_id` = " . intval($event['reminder_user']);
|
||||
hesk_dbQuery($delete_sql);
|
||||
$insert_sql = "INSERT INTO `" . hesk_dbEscape($hesk_settings['db_pfix']) . "calendar_event_reminder` (`user_id`, `event_id`,
|
||||
`amount`, `unit`) VALUES (" . intval($event['reminder_user']) . ", " . intval($event['id']) . ", " . intval($event['reminder_amount']) . ",
|
||||
" . intval($event['reminder_units']) . ")";
|
||||
hesk_dbQuery($insert_sql);
|
||||
}
|
||||
|
||||
hesk_dbQuery($sql);
|
||||
}
|
||||
|
||||
function delete_event($id, $hesk_settings) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user