function fetchDeliveryCount($newsletterIssueObjectID, $status = null) { $conds = array('newsletter_issue_id' => $newsletterIssueObjectID); if (is_string($status) || is_int($status)) { $conds['jajdelivery.status'] = $status; } elseif (is_array($status)) { $conds['jajdelivery.status'] = array($status); } $def = JAJDelivery::definition(); $field = 'jajdelivery.id'; $customFields = array(array('operation' => 'COUNT( ' . $field . ' )', 'name' => 'row_count')); $custom_tables = array("ezcontentobject"); $custom_conds = ' AND jajdelivery.subscription_user_id = ezcontentobject.id'; $rows = eZPersistentObject::fetchObjectList($def, array(), $conds, null, null, false, false, $customFields, $custom_tables, $custom_conds); return array('result' => $rows[0]['row_count']); }
if (!$object->canRead() || !$userObject->canRead()) { return $Module->handleError(KERNEL_ACCESS_DENIED, 'kernel', array('AccessList' => $object->accessList('read'))); } $dataMap =& $object->dataMap(); // Build array of object_ids for the lists we should deliver to $relationList = $dataMap['subscription_lists']->content(); $relationList = $relationList['relation_list']; $distributionLists = array(); if (count($relationList) == 0) { return $Module->handleError(JAJ_ERROR_NEWSLETTER_EMPTY_SUBSCRIPTION_LISTS, 'newsletter'); } foreach ($relationList as $relation) { array_push($distributionLists, $relation['contentobject_id']); } // Get list of users the newsletter allready has been delivered to $rows = eZPersistentObject::fetchObjectList(JAJDelivery::definition(), array('subscription_user_id'), array('newsletter_issue_id' => $object->ID), array('subscription_user_id' => 'asc'), null, false); // Extract user_ids $delivered = array(); foreach ($rows as $row) { array_push($delivered, $row['subscription_user_id']); } // Status for users we should send newsletter to $valid_status = array(JAJ_USER_STATUS_PENDING, JAJ_USER_STATUS_CONFIRMED, JAJ_USER_STATUS_APPROVED); $limit = 50; $offset = 0; // Loop through users, 50 at a time to avoid excessive memory usage $recipient_count = 0; while (true) { //$users =& eZContentObjectTreeNode::subTreeByNodeID( $users =& eZContentObjectTreeNode::subTree(array('ClassFilterType' => 'include', 'ClassFilterArray' => array('subscription_user'), 'AttributeFilter' => array(array('subscription_user/status', 'in', $valid_status)), 'ExtendedAttributeFilter' => array(id => 'eorfilter', params => array(array('subscription_user/subscriptions', $distributionLists, 'or'))), 'Limit' => $limit, 'Offset' => $offset, 'LoadDataMap' => false), $subscriptionUsersNode); foreach ($users as $user) {