function storeSettings($http, $module)
 {
     $user = eZUser::currentUser();
     $address = $user->attribute('email');
     $settings = eZGeneralDigestUserSettings::fetchForUser($address);
     if ($http->hasPostVariable('ReceiveDigest_' . self::NOTIFICATION_HANDLER_ID) && $http->hasPostVariable('ReceiveDigest_' . self::NOTIFICATION_HANDLER_ID) == '1') {
         $settings->setAttribute('receive_digest', 1);
         $digestType = $http->postVariable('DigestType_' . self::NOTIFICATION_HANDLER_ID);
         $settings->setAttribute('digest_type', $digestType);
         if ($digestType == 1) {
             $settings->setAttribute('day', $http->postVariable('Weekday_' . self::NOTIFICATION_HANDLER_ID));
         } else {
             if ($digestType == 2) {
                 $settings->setAttribute('day', $http->postVariable('Monthday_' . self::NOTIFICATION_HANDLER_ID));
             }
         }
         $settings->setAttribute('time', $http->postVariable('Time_' . self::NOTIFICATION_HANDLER_ID));
         $settings->store();
     } else {
         $settings->setAttribute('receive_digest', 0);
         $settings->store();
     }
 }
Beispiel #2
0
 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::fetchForUser($subscriber['address']);
             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;
 }