Source for file BitNewsletterEdition.php
Documentation is available at BitNewsletterEdition.php
* @copyright (c) 2004-15 bitweaver.org
* All Rights Reserved. See below for details and a complete list of authors.
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details
* Class that handles editions of newsletters
* @date created 2005/12/08
* @author spiderr <spider@steelsun.com>
require_once( NEWSLETTERS_PKG_PATH. 'BitNewsletter.php' );
require_once( LIBERTY_PKG_PATH. 'LibertyMime.php' );
define( 'BITNEWSLETTEREDITION_CONTENT_TYPE_GUID', 'bitnewsletteredn' );
function __construct( $pEditionId= NULL, $pContentId= NULL, $pNlId= NULL ) {
'content_name' => 'Edition',
'handler_class' => 'BitNewsletterEdition',
'handler_package' => 'newsletters',
'handler_file' => 'BitNewsletterEdition.php',
'maintainer_url' => 'http://www.bitweaver.org'
$this->mEditionId = $pEditionId;
//$this->mViewContentPerm = '';
function verify( &$pParamHash ) {
if( @$this->verifyId( $pParamHash['nl_content_id'] ) ) {
$pParamHash['edition_store']["nl_content_id"] = $pParamHash['nl_content_id'];
$this->mErrors['nl_content_id'] = tra( 'No newsletter was selected for this edition.' );
$pParamHash['edition_store']['is_draft'] = !empty( $pParamHash['is_draft'] ) ? 'y' : NULL;
$pParamHash['edition_store']['reply_to'] = !empty( $pParamHash['reply_to'] ) ? $pParamHash['reply_to'] : NULL;
function store( &$pParamHash ) {
if( $this->verify( $pParamHash ) ) {
$this->mDb->StartTrans();
if( parent::store( $pParamHash ) ) {
if( $this->mEditionId ) {
$result = $this->mDb->associateUpdate( BIT_DB_PREFIX. "newsletters_editions", $pParamHash['edition_store'], array ( "edition_id" => $this->mEditionId ) );
$pParamHash['edition_store']['content_id'] = $pParamHash['content_id'];
$result = $this->mDb->associateInsert( BIT_DB_PREFIX. "newsletters_editions", $pParamHash['edition_store'] );
$this->mDb->CompleteTrans();
$this->mDb->RollbackTrans();
function load( $pContentId = NULL, $pPluginParams = NULL ) {
$bindVars = array(); $selectSql = ''; $joinSql = ''; $whereSql = '';
$lookupColumn = $this->verifyId( $this->mEditionId )? 'edition_id' : 'content_id';
$this->getServicesSql( 'content_load_function', $selectSql, $joinSql, $whereSql, $bindVars );
$query = "SELECT ne.*, lc.*
INNER JOIN `". BIT_DB_PREFIX. "liberty_content` lc ON( ne.`content_id`=lc.`content_id` )
WHERE ne.`$lookupColumn`=? $whereSql";
if ( $result = $this->mDb->query($query,$bindVars) ) {
$this->mInfo = $result->fetchRow();
$this->mEditionId = $this->mInfo['edition_id'];
$this->mNewsletter->load();
unset ( $this->mEditionId );
return( $this->verifyId( $this->mEditionId ) );
* Generate a valid url for the Newsletter Edition
* @param object PostId of the item to use
* @return object Url String
if( BitBase::verifyId( $pParamHash['edition_id'] ) ) {
if( $gBitSystem->isFeatureActive( 'pretty_urls' ) ) {
$ret = NEWSLETTERS_PKG_URL. 'edition/'. $pParamHash['edition_id'];
$ret = NEWSLETTERS_PKG_URL. 'edition.php?edition_id='. $pParamHash['edition_id'];
$ret = NEWSLETTERS_PKG_URL. 'edition.php';
parent::prepGetList( $pListHash );
if( @BitBase::verifyId( $pListHash['nl_id'] ) ) {
$mid .= (empty( $mid ) ? 'WHERE' : 'AND'). ' n.nl_id=? ';
$bindVars[] = $pListHash['nl_id'];
if( $pListHash['find'] ) {
$findesc = '%' . $pListHash['find'] . '%';
$mid .= (empty( $mid ) ? 'WHERE' : 'AND'). ' (lc.`title` like ? or lc.`data` like ?)';
$query = "SELECT `edition_id` AS `hash_key`, ne.*, lc.*, lc2.`title` AS `newsletter_title`
INNER JOIN `". BIT_DB_PREFIX. "liberty_content` lc ON( lc.`content_id`=ne.`content_id` )
INNER JOIN `". BIT_DB_PREFIX. "newsletters` n ON( ne.`nl_content_id`=n.`content_id` )
LEFT OUTER JOIN `". BIT_DB_PREFIX. "liberty_content` lc2 ON( n.`content_id`=lc2.`content_id` )
$mid ORDER BY ". $gBitDb->convertSortmode( $pListHash['sort_mode'] );
$query_cant = "select count(*) from `". BIT_DB_PREFIX. "newsletters` n INNER JOIN `". BIT_DB_PREFIX. "newsletters_editions` ne ON(n.`content_id`=ne.`nl_content_id`) $mid";
$ret = $gBitDb->getAssoc( $query, $bindVars, $pListHash['max_records'], $pListHash['offset'] );
// $ret[$k]['parsed'] = BitNewsletterEdition::parseData( $data, $ret[$k]['format_guid'] );
$pListHash['total_records'] = $gBitDb->getOne( $query_cant, $bindVars );
$pListHash['block_pages'] = 5;
$pListHash['total_pages'] = ceil( $pListHash['total_records'] / $pListHash['max_records'] );
$pListHash['current_page'] = (!empty( $pListHash['offset'] ) ? floor( $pListHash['offset'] / $pListHash['max_records'] ) + 1 : 1 );
$this->mDb->StartTrans();
$query = "DELETE FROM `". BIT_DB_PREFIX. "newsletters_editions` WHERE `content_id`=?";
$result = $this->mDb->query( $query, array( $this->mContentId ) );
$this->mDb->CompleteTrans();
$this->mDb->RollbackTrans();
return( $this->getField( 'is_draft' ) );
function getRecipients( $pGroupArray, $validated = TRUE, $pRequeue = FALSE ) {
foreach( $pGroupArray as $groupId ) {
$ret = array_merge( $ret, $gBitUser->getGroupUserData( $groupId, array( 'email', 'uu.user_id', 'login', 'real_name' ) ) );
if ( array_search( 'send_subs', $pGroupArray ) !== false ) {
$bindvars = array( $this->mNewsletter->mNewsletterId );
$valid = " AND `is_valid`=?";
WHERE `content_id`=? AND `unsubscribe_date` IS NULL AND `unsubscribe_all` IS NULL". $valid;
$subs = $this->mDb->getArray( $query, $bindvars );
foreach( $subs as $sub) {
if (!isset ($ret[$sub['email']]))
$ret[$sub['email']] = $sub;
$query = "SELECT `email`, `user_id` FROM `". BIT_DB_PREFIX. "mail_queue` WHERE `content_id`=?";
if( $dupes = $this->mDb->getAssoc( $query, array( $this->mContentId ) ) ) {
$gBitSmarty->assign_by_ref( 'gContent', $this );
$ret = $gBitSmarty->fetch( 'bitpackage:newsletters/view_edition.tpl' );
|