2020-04-22 22:48:56 +03:00
|
|
|
|
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
2017-11-01 16:24:25 +03:00
|
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------------
|
2024-01-01 01:14:38 +03:00
|
|
|
|
* MaketRandevu - MAKET Randevu Portalı
|
2017-11-01 16:24:25 +03:00
|
|
|
|
*
|
|
|
|
|
* @package EasyAppointments
|
|
|
|
|
* @author A.Tselegidis <alextselegidis@gmail.com>
|
2021-12-18 19:43:45 +03:00
|
|
|
|
* @copyright Copyright (c) Alex Tselegidis
|
|
|
|
|
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
|
|
|
|
|
* @link https://easyappointments.org
|
2017-11-01 16:24:25 +03:00
|
|
|
|
* @since v1.3.0
|
|
|
|
|
* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
2020-04-22 22:48:56 +03:00
|
|
|
|
use Jsvrcek\ICS\CalendarExport;
|
|
|
|
|
use Jsvrcek\ICS\CalendarStream;
|
|
|
|
|
use Jsvrcek\ICS\Exception\CalendarEventException;
|
2020-09-23 14:53:15 +03:00
|
|
|
|
use Jsvrcek\ICS\Model\CalendarAlarm;
|
2017-11-01 16:24:25 +03:00
|
|
|
|
use Jsvrcek\ICS\Model\CalendarEvent;
|
2020-09-23 14:53:15 +03:00
|
|
|
|
use Jsvrcek\ICS\Model\Description\Location;
|
2017-11-01 16:24:25 +03:00
|
|
|
|
use Jsvrcek\ICS\Model\Relationship\Attendee;
|
|
|
|
|
use Jsvrcek\ICS\Model\Relationship\Organizer;
|
|
|
|
|
use Jsvrcek\ICS\Utility\Formatter;
|
|
|
|
|
|
|
|
|
|
/**
|
2021-11-06 18:21:27 +03:00
|
|
|
|
* Ics file library.
|
2017-11-01 16:24:25 +03:00
|
|
|
|
*
|
2021-10-28 15:00:18 +03:00
|
|
|
|
* Handle ICS related functionality.
|
2017-11-01 16:24:25 +03:00
|
|
|
|
*
|
2021-10-28 15:00:18 +03:00
|
|
|
|
* An ICS file is a calendar file saved in a universal calendar format used by many email and calendar programs,
|
|
|
|
|
* including Microsoft Outlook, Google Calendar, and Apple Calendar.
|
2023-11-29 12:24:09 +03:00
|
|
|
|
*
|
2021-10-28 15:00:18 +03:00
|
|
|
|
* @package Libraries
|
2017-11-01 16:24:25 +03:00
|
|
|
|
*/
|
2023-11-29 12:24:09 +03:00
|
|
|
|
class Ics_file
|
|
|
|
|
{
|
2022-02-23 11:07:21 +03:00
|
|
|
|
/**
|
2023-03-13 11:06:18 +03:00
|
|
|
|
* @var EA_Controller|CI_Controller
|
2022-02-23 11:07:21 +03:00
|
|
|
|
*/
|
2023-03-13 11:06:18 +03:00
|
|
|
|
protected EA_Controller|CI_Controller $CI;
|
2022-02-23 11:07:21 +03:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Availability constructor.
|
|
|
|
|
*/
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
2023-11-29 12:24:09 +03:00
|
|
|
|
$this->CI = &get_instance();
|
2022-02-23 11:07:21 +03:00
|
|
|
|
|
|
|
|
|
$this->CI->load->library('ics_provider');
|
|
|
|
|
$this->CI->load->library('ics_calendar');
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-01 16:24:25 +03:00
|
|
|
|
/**
|
|
|
|
|
* Get the ICS file contents for the provided arguments.
|
|
|
|
|
*
|
2021-10-28 15:00:18 +03:00
|
|
|
|
* @param array $appointment Appointment data.
|
|
|
|
|
* @param array $service Service data.
|
|
|
|
|
* @param array $provider Provider data.
|
|
|
|
|
* @param array $customer Customer data.
|
2017-11-01 16:24:25 +03:00
|
|
|
|
*
|
|
|
|
|
* @return string Returns the contents of the ICS file.
|
2020-04-22 22:48:56 +03:00
|
|
|
|
*
|
|
|
|
|
* @throws CalendarEventException
|
|
|
|
|
* @throws Exception
|
2017-11-01 16:24:25 +03:00
|
|
|
|
*/
|
2021-10-28 15:00:18 +03:00
|
|
|
|
public function get_stream(array $appointment, array $service, array $provider, array $customer): string
|
2017-11-01 16:24:25 +03:00
|
|
|
|
{
|
2021-10-28 15:00:18 +03:00
|
|
|
|
$appointment_timezone = new DateTimeZone($provider['timezone']);
|
2020-09-23 14:53:15 +03:00
|
|
|
|
|
|
|
|
|
$appointment_start = new DateTime($appointment['start_datetime'], $appointment_timezone);
|
2021-10-28 15:00:18 +03:00
|
|
|
|
|
2020-09-23 14:53:15 +03:00
|
|
|
|
$appointment_end = new DateTime($appointment['end_datetime'], $appointment_timezone);
|
2017-11-01 16:24:25 +03:00
|
|
|
|
|
2021-10-28 15:00:18 +03:00
|
|
|
|
// Set up the event.
|
2017-11-01 16:24:25 +03:00
|
|
|
|
$event = new CalendarEvent();
|
|
|
|
|
|
|
|
|
|
$event
|
|
|
|
|
->setStart($appointment_start)
|
|
|
|
|
->setEnd($appointment_end)
|
2020-09-23 14:53:15 +03:00
|
|
|
|
->setStatus('CONFIRMED')
|
2017-11-01 16:24:25 +03:00
|
|
|
|
->setSummary($service['name'])
|
|
|
|
|
->setUid($appointment['id']);
|
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
if (!empty($service['location'])) {
|
2020-09-23 14:53:15 +03:00
|
|
|
|
$location = new Location();
|
2023-11-29 12:24:09 +03:00
|
|
|
|
$location->setName((string) $service['location']);
|
2020-09-23 14:53:15 +03:00
|
|
|
|
$event->addLocation($location);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$description = [
|
|
|
|
|
'',
|
|
|
|
|
lang('provider'),
|
|
|
|
|
'',
|
|
|
|
|
lang('name') . ': ' . $provider['first_name'] . ' ' . $provider['last_name'],
|
2021-10-28 15:00:18 +03:00
|
|
|
|
lang('email') . ': ' . $provider['email'],
|
2020-09-23 14:53:15 +03:00
|
|
|
|
lang('phone_number') . ': ' . $provider['phone_number'],
|
|
|
|
|
lang('address') . ': ' . $provider['address'],
|
|
|
|
|
lang('city') . ': ' . $provider['city'],
|
|
|
|
|
lang('zip_code') . ': ' . $provider['zip_code'],
|
|
|
|
|
'',
|
|
|
|
|
lang('customer'),
|
|
|
|
|
'',
|
|
|
|
|
lang('name') . ': ' . $customer['first_name'] . ' ' . $customer['last_name'],
|
2021-10-28 15:00:18 +03:00
|
|
|
|
lang('email') . ': ' . $customer['email'],
|
|
|
|
|
lang('phone_number') . ': ' . ($customer['phone_number'] ?? '-'),
|
2020-09-23 14:53:15 +03:00
|
|
|
|
lang('address') . ': ' . $customer['address'],
|
|
|
|
|
lang('city') . ': ' . $customer['city'],
|
|
|
|
|
lang('zip_code') . ': ' . $customer['zip_code'],
|
|
|
|
|
'',
|
|
|
|
|
lang('notes'),
|
|
|
|
|
'',
|
2023-12-22 13:35:41 +03:00
|
|
|
|
$appointment['notes'],
|
2020-09-23 14:53:15 +03:00
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$event->setDescription(implode("\\n", $description));
|
|
|
|
|
|
2017-11-01 16:24:25 +03:00
|
|
|
|
$attendee = new Attendee(new Formatter());
|
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
if (isset($customer['email']) && !empty($customer['email'])) {
|
2017-11-01 16:24:25 +03:00
|
|
|
|
$attendee->setValue($customer['email']);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-23 14:53:15 +03:00
|
|
|
|
// Add the event attendees.
|
2017-11-01 16:24:25 +03:00
|
|
|
|
$attendee->setName($customer['first_name'] . ' ' . $customer['last_name']);
|
2023-11-29 12:24:09 +03:00
|
|
|
|
$attendee
|
|
|
|
|
->setCalendarUserType('INDIVIDUAL')
|
2020-09-23 14:53:15 +03:00
|
|
|
|
->setRole('REQ-PARTICIPANT')
|
|
|
|
|
->setParticipationStatus('NEEDS-ACTION')
|
|
|
|
|
->setRsvp('TRUE');
|
|
|
|
|
$event->addAttendee($attendee);
|
|
|
|
|
|
|
|
|
|
$alarm = new CalendarAlarm();
|
|
|
|
|
$alarm_datetime = clone $appointment_start;
|
|
|
|
|
$alarm->setTrigger($alarm_datetime->modify('-15 minutes'));
|
|
|
|
|
$alarm->setSummary('Alarm notification');
|
|
|
|
|
$alarm->setDescription('This is an event reminder');
|
|
|
|
|
$alarm->setAction('EMAIL');
|
|
|
|
|
$alarm->addAttendee($attendee);
|
|
|
|
|
$event->addAlarm($alarm);
|
|
|
|
|
|
|
|
|
|
$alarm = new CalendarAlarm();
|
|
|
|
|
$alarm_datetime = clone $appointment_start;
|
|
|
|
|
$alarm->setTrigger($alarm_datetime->modify('-60 minutes'));
|
|
|
|
|
$alarm->setSummary('Alarm notification');
|
|
|
|
|
$alarm->setDescription('This is an event reminder');
|
|
|
|
|
$alarm->setAction('EMAIL');
|
|
|
|
|
$alarm->addAttendee($attendee);
|
|
|
|
|
$event->addAlarm($alarm);
|
|
|
|
|
|
|
|
|
|
$attendee = new Attendee(new Formatter());
|
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
if (isset($provider['email']) && !empty($provider['email'])) {
|
2020-09-23 14:53:15 +03:00
|
|
|
|
$attendee->setValue($provider['email']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$attendee->setName($provider['first_name'] . ' ' . $provider['last_name']);
|
2023-11-29 12:24:09 +03:00
|
|
|
|
$attendee
|
|
|
|
|
->setCalendarUserType('INDIVIDUAL')
|
2020-09-23 14:53:15 +03:00
|
|
|
|
->setRole('REQ-PARTICIPANT')
|
|
|
|
|
->setParticipationStatus('ACCEPTED')
|
|
|
|
|
->setRsvp('FALSE');
|
2017-11-01 16:24:25 +03:00
|
|
|
|
$event->addAttendee($attendee);
|
|
|
|
|
|
|
|
|
|
// Set the organizer.
|
|
|
|
|
$organizer = new Organizer(new Formatter());
|
|
|
|
|
|
2023-11-29 12:24:09 +03:00
|
|
|
|
$organizer->setValue($provider['email'])->setName($provider['first_name'] . ' ' . $provider['last_name']);
|
2017-11-01 16:24:25 +03:00
|
|
|
|
|
|
|
|
|
$event->setOrganizer($organizer);
|
|
|
|
|
|
|
|
|
|
// Setup calendar.
|
2022-02-23 11:07:21 +03:00
|
|
|
|
$calendar = new Ics_calendar();
|
2017-11-01 16:24:25 +03:00
|
|
|
|
|
|
|
|
|
$calendar
|
|
|
|
|
->setProdId('-//EasyAppointments//Open Source Web Scheduler//EN')
|
2020-11-16 12:47:10 +03:00
|
|
|
|
->setTimezone(new DateTimeZone($provider['timezone']))
|
2017-11-01 16:24:25 +03:00
|
|
|
|
->addEvent($event);
|
|
|
|
|
|
|
|
|
|
// Setup exporter.
|
2023-11-29 12:24:09 +03:00
|
|
|
|
$calendarExport = new CalendarExport(new CalendarStream(), new Formatter());
|
2017-11-01 16:24:25 +03:00
|
|
|
|
$calendarExport->addCalendar($calendar);
|
|
|
|
|
|
|
|
|
|
return $calendarExport->getStream();
|
|
|
|
|
}
|
|
|
|
|
}
|