/** * @param int $eventType * @param string $eventObjectClassName core class name * @param int $partnerId * @return array<EventNotificationTemplate> */ public static function getNotificationTemplates($eventType, $eventObjectClassName, $partnerId) { if (is_null(self::$allNotificationTemplates)) { self::$allNotificationTemplates = EventNotificationTemplatePeer::retrieveByPartnerId($partnerId); KalturaLog::debug("Found [" . count(self::$allNotificationTemplates) . "] templates"); } $notificationTemplates = array(); foreach (self::$allNotificationTemplates as $notificationTemplate) { /* @var $notificationTemplate EventNotificationTemplate */ if (!$notificationTemplate->getAutomaticDispatchEnabled()) { continue; } if ($notificationTemplate->getEventType() != $eventType) { continue; } $templateObjectClassName = KalturaPluginManager::getObjectClass('EventNotificationEventObjectType', $notificationTemplate->getObjectType()); if (strcmp($eventObjectClassName, $templateObjectClassName) && !is_subclass_of($eventObjectClassName, $templateObjectClassName)) { continue; } $notificationTemplates[] = $notificationTemplate; } return $notificationTemplates; }
/** * Dispatch event notification object by id * * @action dispatch * @param int $id * @param KalturaEventNotificationDispatchJobData $jobData * @throws KalturaEventNotificationErrors::EVENT_NOTIFICATION_TEMPLATE_NOT_FOUND * @throws KalturaEventNotificationErrors::EVENT_NOTIFICATION_DISPATCH_DISABLED * @throws KalturaEventNotificationErrors::EVENT_NOTIFICATION_DISPATCH_FAILED * @return int */ public function dispatchAction($id, KalturaEventNotificationDispatchJobData $data) { // get the object $dbEventNotificationTemplate = EventNotificationTemplatePeer::retrieveByPK($id); if (!$dbEventNotificationTemplate) { throw new KalturaAPIException(KalturaEventNotificationErrors::EVENT_NOTIFICATION_TEMPLATE_NOT_FOUND, $id); } if (!$dbEventNotificationTemplate->getManualDispatchEnabled()) { throw new KalturaAPIException(KalturaEventNotificationErrors::EVENT_NOTIFICATION_DISPATCH_DISABLED, $id); } $jobData = $data->toObject($dbEventNotificationTemplate->getJobData()); $job = kEventNotificationFlowManager::addEventNotificationDispatchJob($dbEventNotificationTemplate->getType(), $jobData); if (!$job) { throw new KalturaAPIException(KalturaEventNotificationErrors::EVENT_NOTIFICATION_DISPATCH_FAILED, $id); } return $job->getId(); }
/** * @param int $eventType * @param int $eventObjectType * @param int $partnerId * @return array<EventNotificationTemplate> */ public static function getNotificationTemplates($eventType, $eventObjectType, $partnerId) { if (is_null(self::$allNotificationTemplates)) { self::$allNotificationTemplates = EventNotificationTemplatePeer::retrieveByPartnerId($partnerId); KalturaLog::debug("Found [" . count(self::$allNotificationTemplates) . "] templates"); } $notificationTemplates = array(); foreach (self::$allNotificationTemplates as $notificationTemplate) { /* @var $notificationTemplate EventNotificationTemplate */ if ($notificationTemplate->getEventType() == $eventType && $notificationTemplate->getObjectType() == $eventObjectType && $notificationTemplate->getAutomaticDispatchEnabled()) { $notificationTemplates[] = $notificationTemplate; } } return $notificationTemplates; }
/** * list business-process cases * * @action list * @param KalturaEventNotificationEventObjectType $objectType * @param string $objectId * @return KalturaBusinessProcessCaseArray * * @throws KalturaBusinessProcessNotificationErrors::BUSINESS_PROCESS_CASE_NOT_FOUND * @throws KalturaBusinessProcessNotificationErrors::BUSINESS_PROCESS_SERVER_NOT_FOUND */ public function listAction($objectType, $objectId) { $dbObject = kEventNotificationFlowManager::getObject($objectType, $objectId); if (!$dbObject) { throw new KalturaAPIException(KalturaErrors::OBJECT_NOT_FOUND); } $templatesIds = BusinessProcessNotificationTemplate::getCaseTemplatesIds($dbObject); if (!count($templatesIds)) { throw new KalturaAPIException(KalturaBusinessProcessNotificationErrors::BUSINESS_PROCESS_CASE_NOT_FOUND); } $array = new KalturaBusinessProcessCaseArray(); foreach ($templatesIds as $templateId) { $dbTemplate = EventNotificationTemplatePeer::retrieveByPK($templateId); if (!$dbTemplate || !$dbTemplate instanceof BusinessProcessStartNotificationTemplate) { KalturaLog::info("Template [{$templateId}] not found"); continue; } $caseIds = $dbTemplate->getCaseIds($dbObject, false); if (!count($caseIds)) { KalturaLog::info("No cases found"); continue; } $dbBusinessProcessServer = BusinessProcessServerPeer::retrieveByPK($dbTemplate->getServerId()); if (!$dbBusinessProcessServer) { KalturaLog::info("Business-Process server [" . $dbTemplate->getServerId() . "] not found"); continue; } $businessProcessServer = KalturaBusinessProcessServer::getInstanceByType($dbBusinessProcessServer->getType()); $businessProcessServer->fromObject($dbBusinessProcessServer); $provider = kBusinessProcessProvider::get($businessProcessServer); if (!$provider) { KalturaLog::info("Provider [" . $businessProcessServer->type . "] not found"); continue; } foreach ($caseIds as $caseId) { try { $case = $provider->getCase($caseId); $businessProcessCase = new KalturaBusinessProcessCase(); $businessProcessCase->businessProcessStartNotificationTemplateId = $templateId; $businessProcessCase->fromObject($case); $array[] = $businessProcessCase; } catch (ActivitiClientException $e) { KalturaLog::err("Case [{$caseId}] not found: " . $e->getMessage()); } } } return $array; }