/** * Returns field value as formatted date. * * @param string $format Output format of the date. If null the format set in client configuration is used. * @return string */ public function getDate($format = null) { if ($format === null) { $format = kyConfig::get()->getDateFormat(); } return date($format, $this->timestamp); }
/** * Returns statistics for all tickets in database. Result is cached. * Format or result: * <pre> * array( * 'departments' => array( //statistics per department (if there are no tickets in department then there will be no record with its id here) * <department id> => array( //tickets assigned to department with this id * 'last_activity' => <date and time of last activity on tickets in this department>, * 'total_items' => <total amount of tickets in this department>, * 'total_unresolved_items' => <total amount of unresolved tickets in this department>, * 'ticket_statuses' => array( //statistics per ticket status in the department * <ticket status id> => array( * 'last_activity' => <date and time of last activity on tickets with this status in this department>, * 'total_items' => <total amount of tickets with this status in this department> * ), * ... * ), * 'ticket_types' => array( //statistics per ticket type in the department * <ticket type id> => array( * 'last_activity' => <date and time of last activity on tickets of this type in this department>, * 'total_items' => <total amount of tickets of this type in this department>, * 'total_unresolved_items' => <total amount of unresolved tickets of this type in this department>, * ), * ..., * 'unknown' => array( //in Kayako 4.01.204 all ticket types will be unknown because of a bug (http://dev.kayako.com/browse/SWIFT-1465) * ... * ) * ) * 'ticket_owners' => array( //statistics per ticket owner in the department * <owner staff id> => array( * 'last_activity' => <date and time of last activity on tickets assigned to this staff in this department>, * 'total_items' => <total amount of tickets assigned to this staff in this department>, * 'total_unresolved_items' => <total amount of unresolved tickets assigned to this staff in this department>, * ), * ..., * 'unassigned' => array( //tickets not assigned to any staff * ... * ) * ) * ), * ..., * 'unknown' => array( //tickets in Trash * ... * ) * ), * 'ticket_statuses' => array( //statistics per ticket status in all departments * <ticket status id> => array( * 'last_activity' => <date and time of last activity on tickets with this status in all departments>, * 'total_items' => <total amount of tickets with this status in all departments> * ), * ... * ), * 'ticket_owners' => array( //statistics per ticket owner in all departments * <owner staff id> => array( * 'last_activity' => <date and time of last activity on tickets assigned to this staff in all department>, * 'total_items' => <total amount of tickets assigned to this staff in all department>, * 'total_unresolved_items' => <total amount of unresolved tickets assigned to this staff in all department>, * ), * ..., * 'unassigned' => array( //tickets not assigned to any staff no matter what department * ... * ) * ) * ) * </pre> * * @param bool $reload True to reload statistics data from server. * @return array */ public static function getStatistics($reload = false) { if (self::$statistics !== null && !$reload) { return self::$statistics; } self::$statistics = array('departments' => array(), 'ticket_statuses' => array(), 'ticket_owners' => array()); $raw_stats = self::getRESTClient()->get('/Tickets/TicketCount', array()); foreach ($raw_stats['departments'][0]['department'] as $department_raw_stats) { $department_id = intval($department_raw_stats['_attributes']['id']); $department_stats = array(); $department_stats['last_activity'] = intval($department_raw_stats['lastactivity']) > 0 ? date(kyConfig::get()->getDatetimeFormat(), $department_raw_stats['lastactivity']) : null; $department_stats['total_items'] = $department_raw_stats['totalitems']; $department_stats['total_unresolved_items'] = $department_raw_stats['totalunresolveditems']; foreach ($department_raw_stats['ticketstatus'] as $ticket_status_raw_stats) { $ticket_status_id = intval($ticket_status_raw_stats['_attributes']['id']); $ticket_status_stats = array(); $ticket_status_stats['last_activity'] = intval($ticket_status_raw_stats['_attributes']['lastactivity']) > 0 ? date(kyConfig::get()->getDatetimeFormat(), $ticket_status_raw_stats['_attributes']['lastactivity']) : null; $ticket_status_stats['total_items'] = $ticket_status_raw_stats['_attributes']['totalitems']; $department_stats['ticket_statuses'][$ticket_status_id] = $ticket_status_stats; } //this is broken in Kayako 4.01.240, tickettype id is always 0 (unknown) - http://dev.kayako.com/browse/SWIFT-1465 foreach ($department_raw_stats['tickettype'] as $ticket_type_raw_stats) { $ticket_type_id = intval($ticket_type_raw_stats['_attributes']['id']); $ticket_type_stats = array(); $ticket_type_stats['last_activity'] = intval($ticket_type_raw_stats['_attributes']['lastactivity']) > 0 ? date(kyConfig::get()->getDatetimeFormat(), $ticket_type_raw_stats['_attributes']['lastactivity']) : null; $ticket_type_stats['total_items'] = $ticket_type_raw_stats['_attributes']['totalitems']; $ticket_type_stats['total_unresolved_items'] = $ticket_type_raw_stats['_attributes']['totalunresolveditems']; $department_stats['ticket_types'][$ticket_type_id > 0 ? $ticket_type_id : 'unknown'] = $ticket_type_stats; } foreach ($department_raw_stats['ownerstaff'] as $owner_staff_raw_stats) { $staff_id = intval($owner_staff_raw_stats['_attributes']['id']); $owner_staff_stats = array(); $owner_staff_stats['last_activity'] = intval($owner_staff_raw_stats['_attributes']['lastactivity']) > 0 ? date(kyConfig::get()->getDatetimeFormat(), $owner_staff_raw_stats['_attributes']['lastactivity']) : null; $owner_staff_stats['total_items'] = $owner_staff_raw_stats['_attributes']['totalitems']; $owner_staff_stats['total_unresolved_items'] = $owner_staff_raw_stats['_attributes']['totalunresolveditems']; $department_stats['ticket_owners'][$staff_id > 0 ? $staff_id : 'unassigned'] = $owner_staff_stats; } //unknown department is for example for tickets in Trash self::$statistics['departments'][$department_id > 0 ? $department_id : 'unknown'] = $department_stats; } foreach ($raw_stats['statuses'][0]['ticketstatus'] as $ticket_status_raw_stats) { $ticket_status_id = intval($ticket_status_raw_stats['_attributes']['id']); $ticket_status_stats = array(); $ticket_status_stats['last_activity'] = intval($ticket_status_raw_stats['_attributes']['lastactivity']) > 0 ? date(kyConfig::get()->getDatetimeFormat(), $ticket_status_raw_stats['_attributes']['lastactivity']) : null; $ticket_status_stats['total_items'] = $ticket_status_raw_stats['_attributes']['totalitems']; self::$statistics['ticket_statuses'][$ticket_status_id] = $ticket_status_stats; } foreach ($raw_stats['owners'][0]['ownerstaff'] as $owner_staff_raw_stats) { $staff_id = intval($owner_staff_raw_stats['_attributes']['id']); $owner_staff_stats = array(); $owner_staff_stats['last_activity'] = intval($owner_staff_raw_stats['_attributes']['lastactivity']) > 0 ? date(kyConfig::get()->getDatetimeFormat(), $owner_staff_raw_stats['_attributes']['lastactivity']) : null; $owner_staff_stats['total_items'] = $owner_staff_raw_stats['_attributes']['totalitems']; $owner_staff_stats['total_unresolved_items'] = $owner_staff_raw_stats['_attributes']['totalunresolveditems']; self::$statistics['ticket_owners'][$staff_id > 0 ? $staff_id : 'unassigned'] = $owner_staff_stats; } return self::$statistics; }
/** * Returns expiration date of Service Level Agreement plan assignment or null when expiration is disabled. * * @see http://www.php.net/manual/en/function.date.php * * @param string $format Output format of the date. If null the format set in client configuration is used. * @return string * @filterBy * @orderBy */ public function getSLAPlanExpiry($format = null) { if ($format === null) { $format = kyConfig::get()->getDatetimeFormat(); } return date($format, $this->sla_plan_expiry); }
/** * @copyright 2001-2015 Kayako * @license https://www.freebsd.org/copyright/freebsd-license.html * @link https://github.com/kayako/whmcs-integration */ require_once __DIR__ . '/config.php'; require_once 'API/kyConfig.php'; require_once 'API/kyRESTClientInterface.php'; require_once 'API/kyRESTClient.php'; require_once 'API/kyHelpers.php'; //Include common functions require_once 'functions.php'; //Include constants file require_once 'constants.php'; kyConfig::set(new kyConfig(API_URL, API_KEY, SECRET_KEY)); $_restClient = kyConfig::get()->getRESTClient(); $_newsController = '/News/NewsItem'; $_commentController = '/News/Comment'; if (isset($_GET['itemid'])) { if ($_GET['action'] == 'savecomment') { $_itemIDKey = 'newsitemid'; $_itemID = $_GET['itemid']; $_rootCommentElement = 'newsitemcomment'; include 'savecomment.php'; } include 'announcementitem.php'; } else { include 'announcementlist.php'; } $smarty->assign('_baseURL', WHMCS_URL); $smarty->assign('_templateURL', getcwd() . '/templates/kayako');
/** * Returns expiration date of the user or null when expiration is disabled. * * @see http://www.php.net/manual/en/function.date.php * * @param string $format Output format of the date. If null the format set in client configuration is used. * @return string * @filterBy * @orderBy */ public function getExpiry($format = null) { if ($this->expiry == null) { return null; } if ($format === null) { $format = kyConfig::get()->getDatetimeFormat(); } return date($format, $this->expiry); }
/** * Returns date and time when the comment was created. * * @see http://www.php.net/manual/en/function.date.php * * @param string $format Output format of the date. If null the format set in client configuration is used. * @return string * @filterBy * @orderBy */ public function getDateline($format = null) { if ($this->dateline == null) { return null; } if ($format === null) { $format = kyConfig::get()->getDatetimeFormat(); } return date($format, $this->dateline); }
/** * Returns REST client. * * @return kyRESTClientInterface */ protected static function getRESTClient() { return kyConfig::get()->getRESTClient(); }
/** * Returns date and time when to bill the worker. * * @see http://www.php.net/manual/en/function.date.php * * @param string $format Output format of the date. If null the format set in client configuration is used. * @return string * @filterBy * @orderBy */ public function getBillDate($format = null) { if ($format === null) { $format = kyConfig::get()->getDatetimeFormat(); } return date($format, $this->bill_date); }
/** * Returns date and time this note was created. * * @see http://www.php.net/manual/en/function.date.php * * @param string $format Output format of the date. If null the format set in client configuration is used. * @return string * @filterBy * @orderBy */ public function getCreationDate($format = null) { if ($format === null) { $format = kyConfig::get()->getDatetimeFormat(); } return date($format, $this->creation_date); }
/** * Returns field default value. * * @return string * @filterBy * @orderBy */ public function getDefaultValue() { switch ($this->type) { case self::TYPE_TEXT: case self::TYPE_TEXTAREA: case self::TYPE_PASSWORD: return $this->default_value; break; case self::TYPE_DATE: return date(kyConfig::get()->getDateFormat(), $this->default_value); break; default: return null; break; } }
<?php require_once "../kyIncludes.php"; print "<pre>"; /** * Initialization. */ kyConfig::set(new kyConfig("<API URL>", "<API key>", "<Secret key>")); kyConfig::get()->setDebugEnabled(true); /** * Optional. Setting defaults for new tickets. * WARNING: * Names may be different in your instalation. */ $default_status_id = kyTicketStatus::getAll()->filterByTitle("Open")->first()->getId(); $default_priority_id = kyTicketPriority::getAll()->filterByTitle("Normal")->first()->getId(); $default_type_id = kyTicketType::getAll()->filterByTitle("Issue")->first()->getId(); kyTicket::setDefaults($default_status_id, $default_priority_id, $default_type_id); $general_department = kyDepartment::getAll()->filterByTitle("General")->filterByModule(kyDepartment::MODULE_TICKETS)->first(); /** * Cleanup - delete what's left from previous run of this example. */ $example_department = kyDepartment::getAll()->filterByTitle("Printers (example)"); if (count($example_department) > 0) { $tickets_to_delete = kyTicket::getAll($example_department)->filterBySubject("Printer not working (example)"); $tickets_to_delete->deleteAll(); if (count($tickets_to_delete) > 0) { printf("Tickets DELETED:\n%s", $tickets_to_delete); } } $users_to_delete = kyUser::getAll()->filterByEmail("*****@*****.**");