
########
Calendar
########


****
NAME
****


Kernel::System::Calendar - calendar lib


***********
DESCRIPTION
***********


All calendar functions.


****************
PUBLIC INTERFACE
****************


new()
=====


create an object. Do not use it directly, instead use:


.. code-block:: perl

     use Kernel::System::ObjectManager;
     local $Kernel::OM = Kernel::System::ObjectManager->new();
     my $CalendarObject = $Kernel::OM->Get('Kernel::System::Calendar');



CalendarCreate()
================


creates a new calendar for given user.


.. code-block:: perl

     my %Calendar = $CalendarObject->CalendarCreate(
         CalendarName         => 'Meetings',          # (required) Personal calendar name
         GroupID              => 3,                   # (required) GroupID
         Color                => '#FF7700',           # (required) Color in hexadecimal RGB notation
         UserID               => 4,                   # (required) UserID
 
         TicketAppointments   => [                    # (optional) Ticket appointments, array ref of hashes
             {
                 StartDate    => 'FirstResponse',
                 EndDate      => 'Plus_5',
                 QueueID      => [ 2 ],
                 SearchParams => {
                     Title => 'This is a title',
                     Types => 'This is a type',
                 },
             },
         ],
 
         ValidID => 1,                   # (optional) Default is 1.
     );


returns Calendar hash if successful:


.. code-block:: perl

     %Calendar = (
         CalendarID   => 2,
         GroupID      => 3,
         CalendarName => 'Meetings',
         CreateTime   => '2016-01-01 08:00:00',
         CreateBy     => 4,
         ChangeTime   => '2016-01-01 08:00:00',
         ChangeBy     => 4,
         ValidID      => 1,
     );


Events:


.. code-block:: perl

     CalendarCreate



CalendarGet()
=============


Get calendar by name or id.


.. code-block:: perl

     my %Calendar = $CalendarObject->CalendarGet(
         CalendarName => 'Meetings',          # (required) Calendar name
                                              # or
         CalendarID   => 4,                   # (required) CalendarID
 
         UserID       => 2,                   # (optional) UserID - System will check if user has access to calendar if provided
     );


Returns Calendar data:


.. code-block:: perl

     %Calendar = (
         CalendarID         => 2,
         GroupID            => 3,
         CalendarName       => 'Meetings',
         Color              => '#FF7700',
         TicketAppointments => [
             {
                 StartDate => 'FirstResponse',
                 EndDate   => 'Plus_5',
                 QueueID   => [ 2 ],
                 SearchParams => {
                     Title => 'This is a title',
                     Types => 'This is a type',
                 },
             },
         ],
         CreateTime => '2016-01-01 08:00:00',
         CreateBy   => 1,
         ChangeTime => '2016-01-01 08:00:00',
         ChangeBy   => 1,
         ValidID    => 1,
     );



CalendarList()
==============


Get calendar list.


.. code-block:: perl

     my @Result = $CalendarObject->CalendarList(
         UserID     => 4,            # (optional) For permission check
         Permission => 'rw',         # (optional) Required permission (default ro)
         ValidID    => 1,            # (optional) Default 0.
                                     # 0 - All states
                                     # 1 - All valid
                                     # 2 - All invalid
                                     # 3 - All temporary invalid
     );


Returns:


.. code-block:: perl

     @Result = [
         {
             CalendarID   => 2,
             GroupID      => 3,
             CalendarName => 'Meetings',
             Color        => '#FF7700',
             CreateTime   => '2016-01-01 08:00:00',
             CreateBy     => 3,
             ChangeTime   => '2016-01-01 08:00:00',
             ChangeBy     => 3,
             ValidID      => 1,
         },
         {
             CalendarID   => 3,
             GroupID      => 3,
             CalendarName => 'Customer presentations',
             Color        => '#BB00BB',
             CreateTime   => '2016-01-01 08:00:00',
             CreateBy     => 3,
             ChangeTime   => '2016-01-01 08:00:00',
             ChangeBy     => 3,
             ValidID      => 0,
         },
         # ...
     ];



CalendarUpdate()
================


updates an existing calendar.


.. code-block:: perl

     my $Success = $CalendarObject->CalendarUpdate(
         CalendarID         => 1,                   # (required) CalendarID
         GroupID            => 2,                   # (required) Calendar group
         CalendarName       => 'Meetings',          # (required) Personal calendar name
         Color              => '#FF9900',           # (required) Color in hexadecimal RGB notation
         UserID             => 4,                   # (required) UserID (who made update)
         ValidID            => 1,                   # (required) ValidID
         TicketAppointments => [                    # (optional) Ticket appointments, array ref of hashes
             {
                 StartDate => 'FirstResponse',
                 EndDate   => 'Plus_5',
                 QueueID   => [ 2 ],
                 SearchParams => {
                     Title => 'This is a title',
                     Types => 'This is a type',
                 },
             },
         ],
     );


Returns 1 if successful.

Events:
    CalendarUpdate


CalendarImport()
================


import a calendar


.. code-block:: perl

     my $Success = $CalendarObject->CalendarImport(
         Data => {
             CalendarData => {
                 CalendarID   => 2,
                 GroupID      => 3,
                 CalendarName => 'Meetings',
                 Color        => '#FF7700',
                 ValidID      => 1,
             },
             AppointmentData => {
                 {
                     AppointmentID => 2,
                     ParentID      => 1,
                     CalendarID    => 1,
                     UniqueID      => '20160101T160000-71E386@localhost',
                     # ...
                 },
                 # ...
             },
         },
         OverwriteExistingEntities => 0,     # (optional) Overwrite existing calendar and appointments, default: 0
                                             # Calendar with same name will be overwritten
                                             # Appointments with same UniqueID in existing calendar will be overwritten
         UserID => 1,
     );


returns 1 if successful


CalendarExport()
================


export a calendar


.. code-block:: perl

     my %Data = $CalendarObject->CalendarExport(
         CalendarID => 2,
         UserID     => 1,
     }


returns calendar hash with data:


.. code-block:: perl

     %Data = (
         CalendarData => {
             CalendarID   => 2,
             GroupID      => 3,
             CalendarName => 'Meetings',
             Color        => '#FF7700',
             ValidID      => 1,
         },
         AppointmentData => (
             {
                 AppointmentID => 2,
                 ParentID      => 1,
                 CalendarID    => 1,
                 UniqueID      => '20160101T160000-71E386@localhost',
                 # ...
             },
             # ...
         ),
     );



CalendarPermissionGet()
=======================


Get permission level for given CalendarID and UserID.


.. code-block:: perl

     my $Permission = $CalendarObject->CalendarPermissionGet(
         CalendarID  => 1,                   # (required) CalendarID
         UserID      => 4,                   # (required) UserID
     );


Returns:


.. code-block:: perl

     $Permission = 'rw';    # 'ro', 'rw',



TicketAppointmentProcessTicket()
================================


Handle the automatic ticket appointments for the ticket.


.. code-block:: perl

     $CalendarObject->TicketAppointmentProcessTicket(
         TicketID => 1,
     );


This method does not have return value.


TicketAppointmentProcessCalendar()
==================================


Handle the automatic ticket appointments for the calendar.


.. code-block:: perl

     my %Result = $CalendarObject->TicketAppointmentProcessCalendar(
         CalendarID => 1,
     );


Returns log of processed tickets and rules:


.. code-block:: perl

     %Result = (
         Process => [
             {
                 TicketID => 1,
                 RuleID   => '9bb20ea035e7a9930652a9d82d00c725',
                 Success  => 1,
             },
             {
                 TicketID => 2,
                 RuleID   => '9bb20ea035e7a9930652a9d82d00c725',
                 Success  => 1,
             },
         ],
         Cleanup => [
             {
                 RuleID  => 'b272a035ed82d65a927a99300e00c9b5',
                 Success => 1,
             },
         ],
     );



TicketAppointmentProcessRule()
==============================


Process the ticket appointment rule and create, update or delete appointment if necessary.


.. code-block:: perl

     my $Success = $CalendarObject->TicketAppointmentProcessRule(
         CalendarID => 1,
         Config => {
             DynamicField_TestDate => {
                 Module => 'Kernel::System::Calendar::Ticket::DynamicField',
             },
             # ...
         },
         Rule => {
             StartDate => 'DynamicField_TestDate',
             EndDate   => 'Plus_5',
             QueueID   => [ 2 ],
             RuleID    => '9bb20ea035e7a9930652a9d82d00c725',
             SearchParams => {
                 Title => 'Welcome*',
             },
         },
         TicketID => 1,
     );


Returns 1 if successful.


TicketAppointmentUpdateTicket()
===============================


Updates the ticket with data from ticket appointment.


.. code-block:: perl

     $CalendarObject->TicketAppointmentUpdateTicket(
         AppointmentID => 1,
         TicketID      => 1,
     );


This method does not have return value.


TicketAppointmentTicketID()
===========================


get ticket id of a ticket appointment.


.. code-block:: perl

     my $TicketID = $CalendarObject->TicketAppointmentTicketID(
         AppointmentID => 1,
     );


returns appointment ID if successful.


TicketAppointmentRuleIDsGet()
=============================


get used ticket appointment rules for specific calendar.


.. code-block:: perl

     my @RuleIDs = $CalendarObject->TicketAppointmentRuleIDsGet(
         CalendarID => 1,
         TicketID   => 1,    # (optional) Return rules used only for specific ticket
     );


returns array of rule IDs if found.


TicketAppointmentRuleGet()
==========================


get ticket appointment rule.


.. code-block:: perl

     my $Rule = $CalendarObject->TicketAppointmentRuleGet(
         CalendarID => 1,
         RuleID     => '9bb20ea035e7a9930652a9d82d00c725',
     );


returns rule hash:


TicketAppointmentTypesGet()
===========================


get defined ticket appointment types from config.


.. code-block:: perl

     my %TicketAppointmentTypes = $CalendarObject->TicketAppointmentTypesGet();


returns hash of appointment types:


.. code-block:: perl

     %TicketAppointmentTypes = ();



TicketAppointmentDelete()
=========================


delete ticket appointment(s).


.. code-block:: perl

     my $Success = $CalendarObject->TicketAppointmentDelete(
         CalendarID    => 1,                                     # (required) CalendarID
         RuleID        => '9bb20ea035e7a9930652a9d82d00c725',    # (required) RuleID
                                                                 # or
         TicketID      => 1,                                     # (required) Ticket ID
         AppointmentID => 1,                                     # (optional) Appointment ID is known
     );


returns 1 if successful.


GetAccessToken()
================


get access token for the calendar.


.. code-block:: perl

     my $Token = $CalendarObject->GetAccessToken(
         CalendarID => 1,              # (required) CalendarID
         UserLogin  => 'agent-1',      # (required) User login
     );


Returns:


.. code-block:: perl

     $Token = 'rw';



GetTextColor()
==============


Returns best text color for supplied background, based on luminosity difference algorithm.


.. code-block:: perl

     my $BestTextColor = $CalendarObject->GetTextColor(
         Background => '#FFF',    # (required) must be in valid hexadecimal RGB notation
     );


Returns:


.. code-block:: perl

     $BestTextColor = '#000';



_TicketAppointmentGet()
=======================


get ticket appointment id if exists.


.. code-block:: perl

     my $AppointmentID = $CalendarObject->_TicketAppointmentGet(
         CalendarID => 1,
         TicketID   => 1,
         RuleID     => '9bb20ea035e7a9930652a9d82d00c725',
     );


returns appointment ID if successful.


_TicketAppointmentList()
========================


Get list of ticket appointments based on a rule.


.. code-block:: perl

     my %Appointments = $CalendarObject->_TicketAppointmentList(
         CalendarID => 1,
         RuleID     => '9bb20ea035e7a9930652a9d82d00c725',
         Key        => 'TicketID',                           # (optional) Return result will be based on this key.
                                                                          Default: TicketID, Possible: TicketID|AppointmentID
     );


Returns list of ticket appointments, where key will be either TicketID (default) or AppointmentID:


.. code-block:: perl

     %Appointments = (
         1 => 1,
         2 => 2,
         # ...
     );



_TicketAppointmentCreate()
==========================


create ticket appointment.


.. code-block:: perl

     my $Success = $CalendarObject->_TicketAppointmentCreate(
         CalendarID => 1,
         TicketID   => 1,
         RuleID     => '9bb20ea035e7a9930652a9d82d00c725',
         Title      => '[Ticket#20160823810000010] Some Ticket Title',
         StartTime  => '2016-08-23 00:00:00',
         EndTime    => '2016-08-24 00:00:00',
     );


returns 1 if successful.


_TicketAppointmentUpdate()
==========================


update ticket appointment.


.. code-block:: perl

     my $Success = $CalendarObject->_TicketAppointmentUpdate(
         AppointmentID => 1,
         TicketID      => 1,
         RuleID        => '9bb20ea035e7a9930652a9d82d00c725',
         Title         => '[Ticket#20160823810000010] Some Ticket Title',
         StartTime     => '2016-08-23 00:00:00',
         EndTime       => '2016-08-24 00:00:00',
     );


returns 1 if successful.




