コード例 #1
0
 /**
  * @param array $result
  *
  * @return ITNewsletterPost
  */
 public static function instanceFromEzfindResultArray(array $result)
 {
     $data = array();
     $data['object_id'] = $result['id'];
     foreach (ITNewsletterPost::fields() as $field) {
         $data[$field['object_property']] = isset($result['fields'][$field['solr_identifier']]) ? $result['fields'][$field['solr_identifier']] : null;
     }
     return new ITNewsletterPost($data);
 }
コード例 #2
0
 public function fetch($limit = 10, $offset = 0)
 {
     $fieldsToReturn = array();
     foreach (ITNewsletterPost::fields() as $field) {
         $fieldsToReturn[] = $field['solr_identifier'];
     }
     $solrFetchParams = array('SearchOffset' => $offset, 'SearchLimit' => $limit, 'Facet' => $this->facets, 'SortBy' => array('published' => 'desc'), 'Filter' => $this->filters, 'SearchContentClassID' => array(ITNewsletterPost::CLASS_IDENTIFIER), 'SearchSectionID' => null, 'SearchSubTreeArray' => array(eZINI::instance('content.ini')->variable('NodeSettings', 'RootNode')), 'AsObjects' => false, 'SpellCheck' => null, 'IgnoreVisibility' => null, 'Limitation' => null, 'BoostFunctions' => null, 'QueryHandler' => 'ezpublish', 'EnableElevation' => true, 'ForceElevation' => true, 'SearchDate' => null, 'DistributedSearch' => null, 'FieldsToReturn' => $fieldsToReturn, 'SearchResultClustering' => null, 'ExtendedAttributeFilter' => array());
     $solrSearch = new eZSolr();
     $tmp = $solrSearch->search($this->query, $solrFetchParams);
     return $tmp;
 }
コード例 #3
0
 /**
  * @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;
 }