static function handleCollaborationEvent($event, $item, &$parameters) { $participantList = eZCollaborationItemParticipantLink::fetchParticipantList(array('item_id' => $item->attribute('id'), 'participant_type' => eZCollaborationItemParticipantLink::TYPE_USER, 'as_object' => false)); $userIDList = array(); $participantMap = array(); foreach ($participantList as $participant) { $userIDList[] = $participant['participant_id']; $participantMap[$participant['participant_id']] = $participant; } // $collaborationIdentifier = $event->attribute( 'collaboration_identifier' ); $collaborationIdentifier = $event->attribute('data_text1'); $ruleList = eZCollaborationNotificationRule::fetchItemTypeList($collaborationIdentifier, $userIDList, false); $userIDList = array(); foreach ($ruleList as $rule) { $userIDList[] = $rule['user_id']; } $userList = array(); if (count($userIDList) > 0) { $db = eZDB::instance(); $userIDListText = $db->generateSQLINStatement($userIDList, 'contentobject_id', false, false, 'int'); $userList = $db->arrayQuery("SELECT contentobject_id, email FROM ezuser WHERE {$userIDListText}"); } else { return eZNotificationEventHandler::EVENT_SKIPPED; } $itemHandler = $item->attribute('handler'); $collectionHandling = $itemHandler->notificationCollectionHandling(); $db = eZDB::instance(); $db->begin(); if ($collectionHandling == self::NOTIFICATION_COLLECTION_ONE_FOR_ALL) { $tpl = eZTemplate::factory(); $tpl->resetVariables(); $tpl->setVariable('collaboration_item', $item); $result = $tpl->fetch('design:notification/handler/ezcollaboration/view/plain.tpl'); $subject = $tpl->variable('subject'); if ($tpl->hasVariable('message_id')) { $parameters['message_id'] = $tpl->variable('message_id'); } if ($tpl->hasVariable('references')) { $parameters['references'] = $tpl->variable('references'); } if ($tpl->hasVariable('reply_to')) { $parameters['reply_to'] = $tpl->variable('reply_to'); } if ($tpl->hasVariable('from')) { $parameters['from'] = $tpl->variable('from'); } if ($tpl->hasVariable('content_type')) { $parameters['content_type'] = $tpl->variable('content_type'); } $collection = eZNotificationCollection::create($event->attribute('id'), eZCollaborationNotificationHandler::NOTIFICATION_HANDLER_ID, eZCollaborationNotificationHandler::TRANSPORT); $collection->setAttribute('data_subject', $subject); $collection->setAttribute('data_text', $result); $collection->store(); foreach ($userList as $subscriber) { $collection->addItem($subscriber['email']); } } else { if ($collectionHandling == self::NOTIFICATION_COLLECTION_PER_PARTICIPATION_ROLE) { $userCollection = array(); foreach ($userList as $subscriber) { $contentObjectID = $subscriber['contentobject_id']; $participant = $participantMap[$contentObjectID]; $participantRole = $participant['participant_role']; $userItem = array('participant' => $participant, 'email' => $subscriber['email']); if (!isset($userCollection[$participantRole])) { $userCollection[$participantRole] = array(); } $userCollection[$participantRole][] = $userItem; } $tpl = eZTemplate::factory(); $tpl->resetVariables(); foreach ($userCollection as $participantRole => $collectionItems) { $templateName = $itemHandler->notificationParticipantTemplate($participantRole); if (!$templateName) { $templateName = eZCollaborationItemHandler::notificationParticipantTemplate($participantRole); } $itemInfo = $itemHandler->attribute('info'); $typeIdentifier = $itemInfo['type-identifier']; $tpl->setVariable('collaboration_item', $item); $tpl->setVariable('collaboration_participant_role', $participantRole); $result = $tpl->fetch('design:notification/handler/ezcollaboration/view/' . $typeIdentifier . '/' . $templateName); $subject = $tpl->variable('subject'); if ($tpl->hasVariable('message_id')) { $parameters['message_id'] = $tpl->variable('message_id'); } if ($tpl->hasVariable('references')) { $parameters['references'] = $tpl->variable('references'); } if ($tpl->hasVariable('reply_to')) { $parameters['reply_to'] = $tpl->variable('reply_to'); } if ($tpl->hasVariable('from')) { $parameters['from'] = $tpl->variable('from'); } if ($tpl->hasVariable('content_type')) { $parameters['content_type'] = $tpl->variable('content_type'); } $collection = eZNotificationCollection::create($event->attribute('id'), eZCollaborationNotificationHandler::NOTIFICATION_HANDLER_ID, eZCollaborationNotificationHandler::TRANSPORT); $collection->setAttribute('data_subject', $subject); $collection->setAttribute('data_text', $result); $collection->store(); foreach ($collectionItems as $collectionItem) { $collection->addItem($collectionItem['email']); } } } else { if ($collectionHandling == self::NOTIFICATION_COLLECTION_PER_USER) { } else { eZDebug::writeError("Unknown collaboration notification collection handling type '{$collectionHandling}', skipping notification", __METHOD__); } } } $db->commit(); return eZNotificationEventHandler::EVENT_HANDLED; }
function handlePublishEvent($event, &$parameters) { $versionObject = $event->attribute('content'); if (!$versionObject) { return eZNotificationEventHandler::EVENT_SKIPPED; } $contentObject = $versionObject->attribute('contentobject'); if (!$contentObject) { return eZNotificationEventHandler::EVENT_SKIPPED; } $contentNode = $contentObject->attribute('main_node'); if (!$contentNode) { return eZNotificationEventHandler::EVENT_SKIPPED; } // Notification should only be sent out when the object is published (is visible) if ($contentNode->attribute('is_invisible') == 1) { return eZNotificationEventHandler::EVENT_SKIPPED; } $contentClass = $contentObject->attribute('content_class'); if (!$contentClass) { return eZNotificationEventHandler::EVENT_SKIPPED; } if ($versionObject->attribute('version') != $contentObject->attribute('current_version')) { return eZNotificationEventHandler::EVENT_SKIPPED; } $tpl = eZTemplate::factory(); $tpl->resetVariables(); $parentNode = $contentNode->attribute('parent'); if (!$parentNode instanceof eZContentObjectTreeNode) { eZDebug::writeError('DB corruption: Node id ' . $contentNode->attribute('node_id') . ' is missing parent node.', __METHOD__); return eZNotificationEventHandler::EVENT_SKIPPED; } $parentContentObject = $parentNode->attribute('object'); if (!$parentContentObject instanceof eZContentObject) { eZDebug::writeError('DB corruption: Node id ' . $parentNode->attribute('node_id') . ' is missing object.', __METHOD__); return eZNotificationEventHandler::EVENT_SKIPPED; } $parentContentClass = $parentContentObject->attribute('content_class'); if (!$parentContentClass instanceof eZContentClass) { eZDebug::writeError('DB corruption: Object id ' . $parentContentObject->attribute('id') . ' is missing class object.', __METHOD__); return eZNotificationEventHandler::EVENT_SKIPPED; } $res = eZTemplateDesignResource::instance(); $res->setKeys(array(array('object', $contentObject->attribute('id')), array('node', $contentNode->attribute('node_id')), array('class', $contentObject->attribute('contentclass_id')), array('class_identifier', $contentClass->attribute('identifier')), array('parent_node', $contentNode->attribute('parent_node_id')), array('parent_class', $parentContentObject->attribute('contentclass_id')), array('parent_class_identifier', $parentContentClass != null ? $parentContentClass->attribute('identifier') : 0), array('depth', $contentNode->attribute('depth')), array('url_alias', $contentNode->attribute('url_alias')))); $tpl->setVariable('object', $contentObject); $notificationINI = eZINI::instance('notification.ini'); $emailSender = $notificationINI->variable('MailSettings', 'EmailSender'); $ini = eZINI::instance(); if (!$emailSender) { $emailSender = $ini->variable('MailSettings', 'EmailSender'); } if (!$emailSender) { $emailSender = $ini->variable("MailSettings", "AdminEmail"); } $tpl->setVariable('sender', $emailSender); $result = $tpl->fetch('design:notification/handler/ezsubtree/view/plain.tpl'); $subject = $tpl->variable('subject'); if ($tpl->hasVariable('message_id')) { $parameters['message_id'] = $tpl->variable('message_id'); } if ($tpl->hasVariable('references')) { $parameters['references'] = $tpl->variable('references'); } if ($tpl->hasVariable('reply_to')) { $parameters['reply_to'] = $tpl->variable('reply_to'); } if ($tpl->hasVariable('from')) { $parameters['from'] = $tpl->variable('from'); } if ($tpl->hasVariable('content_type')) { $parameters['content_type'] = $tpl->variable('content_type'); } $collection = eZNotificationCollection::create($event->attribute('id'), self::NOTIFICATION_HANDLER_ID, self::TRANSPORT); $collection->setAttribute('data_subject', $subject); $collection->setAttribute('data_text', $result); $collection->store(); $assignedNodes = $contentObject->parentNodes(true); $nodeIDList = array(); foreach ($assignedNodes as $node) { if ($node) { $pathString = $node->attribute('path_string'); $pathString = ltrim(rtrim($pathString, '/'), '/'); $nodeIDListPart = explode('/', $pathString); $nodeIDList = array_merge($nodeIDList, $nodeIDListPart); } } $nodeIDList[] = $contentNode->attribute('node_id'); $nodeIDList = array_unique($nodeIDList); $userList = eZSubtreeNotificationRule::fetchUserList($nodeIDList, $contentObject); $locale = eZLocale::instance(); $weekDayNames = $locale->attribute('weekday_name_list'); $weekDaysByName = array_flip($weekDayNames); foreach ($userList as $subscriber) { $item = $collection->addItem($subscriber['address']); if ($subscriber['use_digest'] == 0) { $settings = eZGeneralDigestUserSettings::fetchByUserId($subscriber['user_id']); if ($settings !== null && $settings->attribute('receive_digest') == 1) { $time = $settings->attribute('time'); $timeArray = explode(':', $time); $hour = $timeArray[0]; if ($settings->attribute('digest_type') == eZGeneralDigestUserSettings::TYPE_DAILY) { eZNotificationSchedule::setDateForItem($item, array('frequency' => 'day', 'hour' => $hour)); } else { if ($settings->attribute('digest_type') == eZGeneralDigestUserSettings::TYPE_WEEKLY) { $weekday = $weekDaysByName[$settings->attribute('day')]; eZNotificationSchedule::setDateForItem($item, array('frequency' => 'week', 'day' => $weekday, 'hour' => $hour)); } else { if ($settings->attribute('digest_type') == eZGeneralDigestUserSettings::TYPE_MONTHLY) { eZNotificationSchedule::setDateForItem($item, array('frequency' => 'month', 'day' => $settings->attribute('day'), 'hour' => $hour)); } } } $item->store(); } } } return eZNotificationEventHandler::EVENT_HANDLED; }
/** * @param eZNotificationEvent $event * @param array $parameters * * @return int */ function handlePublishEvent($event, &$parameters) { /** @var eZContentObjectVersion $versionObject */ $versionObject = $event->attribute('content'); if (!$versionObject) { return eZNotificationEventHandler::EVENT_SKIPPED; } /** @var eZContentObject $contentObject */ $contentObject = $versionObject->attribute('contentobject'); if (!$contentObject) { return eZNotificationEventHandler::EVENT_SKIPPED; } /** @var eZContentObjectTreeNode $contentNode */ $contentNode = $contentObject->attribute('main_node'); if (!$contentNode) { return eZNotificationEventHandler::EVENT_SKIPPED; } // Notification should only be sent out when the object is published (is visible) if ($contentNode->attribute('is_invisible') == 1) { return eZNotificationEventHandler::EVENT_SKIPPED; } /** @var eZContentClass $contentClass */ $contentClass = $contentObject->attribute('content_class'); if (!$contentClass) { return eZNotificationEventHandler::EVENT_SKIPPED; } if ($versionObject->attribute('version') != $contentObject->attribute('current_version')) { return eZNotificationEventHandler::EVENT_SKIPPED; } try { $post = ITNewsletterPost::instanceFromEzContentObject($contentObject); if (!$post instanceof ITNewsletterPost) { throw new Exception("Post not found"); } if (!$post->isValid()) { throw new Exception("Post not valid"); } /* if ( !$post->attribute( 'is_sent' ) ) { throw new Exception( "Post not already sent" ); } * */ } catch (Exception $e) { return eZNotificationEventHandler::EVENT_SKIPPED; } $tpl = eZTemplate::factory(); $tpl->resetVariables(); /** @var eZContentObjectTreeNode $parentNode */ $parentNode = $contentNode->attribute('parent'); if (!$parentNode instanceof eZContentObjectTreeNode) { eZDebug::writeError('DB corruption: Node id ' . $contentNode->attribute('node_id') . ' is missing parent node.', __METHOD__); return eZNotificationEventHandler::EVENT_SKIPPED; } /** @var eZContentObject $parentContentObject */ $parentContentObject = $parentNode->attribute('object'); if (!$parentContentObject instanceof eZContentObject) { eZDebug::writeError('DB corruption: Node id ' . $parentNode->attribute('node_id') . ' is missing object.', __METHOD__); return eZNotificationEventHandler::EVENT_SKIPPED; } /** @var eZContentClass $parentContentClass */ $parentContentClass = $parentContentObject->attribute('content_class'); if (!$parentContentClass instanceof eZContentClass) { eZDebug::writeError('DB corruption: Object id ' . $parentContentObject->attribute('id') . ' is missing class object.', __METHOD__); return eZNotificationEventHandler::EVENT_SKIPPED; } $res = eZTemplateDesignResource::instance(); $res->setKeys(array(array('object', $contentObject->attribute('id')), array('node', $contentNode->attribute('node_id')), array('class', $contentObject->attribute('contentclass_id')), array('class_identifier', $contentClass->attribute('identifier')), array('parent_node', $contentNode->attribute('parent_node_id')), array('parent_class', $parentContentObject->attribute('contentclass_id')), array('parent_class_identifier', $parentContentClass != null ? $parentContentClass->attribute('identifier') : 0), array('depth', $contentNode->attribute('depth')), array('url_alias', $contentNode->attribute('url_alias')))); $tpl->setVariable('object', $contentObject); $notificationINI = eZINI::instance('notification.ini'); $emailSender = $notificationINI->variable('MailSettings', 'EmailSender'); $ini = eZINI::instance(); if (!$emailSender) { $emailSender = $ini->variable('MailSettings', 'EmailSender'); } if (!$emailSender) { $emailSender = $ini->variable("MailSettings", "AdminEmail"); } $tpl->setVariable('sender', $emailSender); $result = $tpl->fetch('design:notification/handler/templatepat/view/plain.tpl'); $subject = $tpl->variable('subject'); if ($tpl->hasVariable('message_id')) { $parameters['message_id'] = $tpl->variable('message_id'); } if ($tpl->hasVariable('references')) { $parameters['references'] = $tpl->variable('references'); } if ($tpl->hasVariable('reply_to')) { $parameters['reply_to'] = $tpl->variable('reply_to'); } if ($tpl->hasVariable('from')) { $parameters['from'] = $tpl->variable('from'); } if ($tpl->hasVariable('content_type')) { $parameters['content_type'] = $tpl->variable('content_type'); } $collection = eZNotificationCollection::create($event->attribute('id'), self::NOTIFICATION_HANDLER_ID, self::TRANSPORT); $collection->setAttribute('data_subject', $subject); $collection->setAttribute('data_text', $result); $collection->store(); $tags = $post->notificationTags(); $userList = ITNewsletterNotificationRule::fetchUserList($tags); $locale = eZLocale::instance(); $weekDayNames = $locale->attribute('weekday_name_list'); $weekDaysByName = array_flip($weekDayNames); foreach ($userList as $user) { $item = $collection->addItem($user->attribute('email')); // digest forzato eZNotificationSchedule::setDateForItem($item, array('frequency' => 'day', 'hour' => '12')); $item->store(); ///** @var eZGeneralDigestUserSettings $settings */ //$settings = eZGeneralDigestUserSettings::fetchForUser( $user->attribute( 'email' ) ); //if ( $settings !== null && $settings->attribute( 'receive_digest' ) == 1 ) //{ // $time = $settings->attribute( 'time' ); // $timeArray = explode( ':', $time ); // $hour = $timeArray[0]; // // if ( $settings->attribute( 'digest_type' ) == eZGeneralDigestUserSettings::TYPE_DAILY ) // { // eZNotificationSchedule::setDateForItem( $item, array( 'frequency' => 'day', // 'hour' => $hour ) ); // } // else if ( $settings->attribute( 'digest_type' ) == eZGeneralDigestUserSettings::TYPE_WEEKLY ) // { // $weekday = $weekDaysByName[ $settings->attribute( 'day' ) ]; // eZNotificationSchedule::setDateForItem( $item, array( 'frequency' => 'week', // 'day' => $weekday, // 'hour' => $hour ) ); // } // else if ( $settings->attribute( 'digest_type' ) == eZGeneralDigestUserSettings::TYPE_MONTHLY ) // { // eZNotificationSchedule::setDateForItem( $item, // array( 'frequency' => 'month', // 'day' => $settings->attribute( 'day' ), // 'hour' => $hour ) ); // } // $item->store(); //} } return eZNotificationEventHandler::EVENT_HANDLED; }