PCR-360 Wiki

Skype Service to Skype Service Pool

PHP
/**
 * Creates a Bulk Update Event to move Active Services in the "Skype for Business" Catalog
 * to the "Skype-DID" Pool
 *
 * Event:           Custom PHP Event
 * Frequency:       Daily
 * Time:
 * Listener Class:  Core_Model_Event
 * Listener Method: eventCustom
 * Issue#:          CUSTOM-22
 */

$user = <<<SQL
SELECT RECID, CONTACTS_RECID
FROM USERS
WHERE USERID = 'tjf15'
SQL;

if (($user = $this->query($user))) {
    $pool = <<<SQL
SELECT RECID
FROM POOLS
WHERE POOL_NAME = 'Skype-DID'
SQL;

    if (($pool = $this->query($pool))) {
        $pool = (int) $pool[0]['RECID'];

        $services = <<<SQL
SELECT SERVICES.RECID
FROM SERVICES
LEFT JOIN SERV_CATALOG
    ON SERVICES.SERV_CATALOG_RECID = SERV_CATALOG.RECID
LEFT JOIN SERVICES_POOLS
    ON SERVICES.RECID = SERVICES_POOLS.SERVICES_RECID
LEFT JOIN LISTS
    ON SERVICES.SERVICE_STATUS_LISTS_RECID = LISTS.RECID
LEFT JOIN LIST_TYPES
    ON LISTS.LIST_TYPES_RECID = LIST_TYPES.RECID
WHERE LISTS.CODE = 'ACTIVE'
AND LIST_TYPES.TYPE = 'SERVICE_STATUS'
AND SERV_CATALOG.SERVICE_NAME = 'Skype for Business'
AND (SERVICES_POOLS.POOLS_RECID IS NULL OR SERVICES_POOLS.POOLS_RECID <> {$pool})
SQL;

        if (($services = $this->query($services))) {
            PCR_Event::attachDb(
                'services-bulk-update',
                [
                    'Application_Model_Service_Service' => 'eventBulkUpdate'
                ]
            );

            $eventParams = [
                'service_type_enabled'    => 0,
                'location_enabled'        => 0,
                'status_enabled'          => 0,
                'service_host_enabled'    => 0,
                'sla_enabled'             => 0,
                'contact_owner_enabled'   => 0,
                'dept_hier_owner_enabled' => 0,
                'gla_enabled'             => 0,
                'pools_enabled'           => 1,
                'billable_enabled'        => 0,
                'directory_enabled'       => 0,
                'essential_enabled'       => 0,
                'report_911_enabled'      => 0,
                'isLocationRequired'      => 0,
                'isServiceHostRequired'   => 0,
                'contact'                 => (int) $user[0]['CONTACTS_RECID'],
                'users_recid'             => (int) $user[0]['RECID'],
                'pools'                   => [$pool],
                'comment' => 'Number Activated on Skype for Business Platform'
            ];

            foreach ($services as $service) {
                $eventParams['selectedServiceRecids'][] = (int) $service['RECID'];
            }

            PCR_Event::trigger('services-bulk-update', $eventParams);
        }
    }
}