summaryrefslogtreecommitdiff
path: root/BitNewsletterEdition.php
diff options
context:
space:
mode:
authorChristian Fowler <spider@viovio.com>2005-12-11 06:34:19 +0000
committerChristian Fowler <spider@viovio.com>2005-12-11 06:34:19 +0000
commit643f1d7f43ef14bb415fd69ba435035d1426a3a9 (patch)
treec89b28e45811025af6a1ad684b6b6e7df5ea96a4 /BitNewsletterEdition.php
parentc0ede787f79de2f5ff07146148676e102d12ba23 (diff)
downloadnewsletters-643f1d7f43ef14bb415fd69ba435035d1426a3a9.tar.gz
newsletters-643f1d7f43ef14bb415fd69ba435035d1426a3a9.tar.bz2
newsletters-643f1d7f43ef14bb415fd69ba435035d1426a3a9.zip
add edition saving and listing, almost to the point of getting send working
Diffstat (limited to 'BitNewsletterEdition.php')
-rw-r--r--BitNewsletterEdition.php79
1 files changed, 59 insertions, 20 deletions
diff --git a/BitNewsletterEdition.php b/BitNewsletterEdition.php
index fd03be4..e043916 100644
--- a/BitNewsletterEdition.php
+++ b/BitNewsletterEdition.php
@@ -1,12 +1,12 @@
<?php
/**
- * $Header: /cvsroot/bitweaver/_bit_newsletters/BitNewsletterEdition.php,v 1.2 2005/12/10 22:39:53 spiderr Exp $
+ * $Header: /cvsroot/bitweaver/_bit_newsletters/BitNewsletterEdition.php,v 1.3 2005/12/11 06:34:19 spiderr Exp $
*
* Copyright (c) 2004 bitweaver.org
* All Rights Reserved. See copyright.txt for details and a complete list of authors.
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details
*
- * $Id: BitNewsletterEdition.php,v 1.2 2005/12/10 22:39:53 spiderr Exp $
+ * $Id: BitNewsletterEdition.php,v 1.3 2005/12/11 06:34:19 spiderr Exp $
*
* Virtual base class (as much as one can have such things in PHP) for all
* derived tikiwiki classes that require database access.
@@ -16,18 +16,18 @@
*
* @author drewslater <andrew@andrewslater.com>, spiderr <spider@steelsun.com>
*
- * @version $Revision: 1.2 $ $Date: 2005/12/10 22:39:53 $ $Author: spiderr $
+ * @version $Revision: 1.3 $ $Date: 2005/12/11 06:34:19 $ $Author: spiderr $
*/
/**
* required setup
*/
require_once( NEWSLETTERS_PKG_PATH.'BitNewsletter.php' );
-require_once( LIBERTY_PKG_PATH.'LibertyContent.php' );
+require_once( LIBERTY_PKG_PATH.'LibertyAttachable.php' );
define( 'BITNEWSLETTEREDITION_CONTENT_TYPE_GUID', 'bitnewsletteredn' );
-class BitNewsletterEdition extends LibertyContent {
+class BitNewsletterEdition extends LibertyAttachable {
function BitNewsletterEdition( $pEditionId=NULL, $pContentId=NULL, $pNlId=NULL ) {
parent::LibertyContent();
$this->registerContentType( BITNEWSLETTEREDITION_CONTENT_TYPE_GUID, array(
@@ -45,11 +45,14 @@ class BitNewsletterEdition extends LibertyContent {
}
function verify( &$pParamHash ) {
+
if( !empty( $pParamHash['nl_id'] ) ) {
$pParamHash['edition_store']["nl_id"] = $pParamHash['nl_id'];
} else {
$this->mErrors['nl_id'] = tra( 'No newsletter was selected for this edition.' );
}
+ $pParamHash['edition_store']['is_draft'] = !empty( $pParamHash['is_draft'] ) ? 'y' : NULL;
+
return( count( $this->mErrors ) == 0 );
}
@@ -64,6 +67,7 @@ class BitNewsletterEdition extends LibertyContent {
$result = $this->mDb->associateInsert( BIT_DB_PREFIX."tiki_newsletters_editions", $pParamHash['edition_store'] );
}
$this->mDb->CompleteTrans();
+ $this->load();
} else {
$this->mDb->RollbackTrans();
}
@@ -72,37 +76,67 @@ class BitNewsletterEdition extends LibertyContent {
}
function load() {
- if( !empty( $this->mNlId ) || !empty( $this->mContentId ) ) {
+ if( !empty( $this->mEditionId ) || !empty( $this->mContentId ) ) {
global $gBitSystem;
$bindVars = array(); $selectSql = ''; $joinSql = ''; $whereSql = '';
- $lookupColumn = !empty( $this->mNlId )? 'nl_id' : 'content_id';
- $lookupId = !empty( $this->mNlId )? $this->mNlId : $this->mContentId;
+ $lookupColumn = !empty( $this->mEditionId )? 'edition_id' : 'content_id';
+ $lookupId = !empty( $this->mEditionId )? $this->mEditionId : $this->mContentId;
array_push( $bindVars, $lookupId );
$this->getServicesSql( 'content_load_function', $selectSql, $joinSql, $whereSql, $bindVars );
- $query = "SELECT *
+ $query = "SELECT tne.*, tc.*
FROM `".BIT_DB_PREFIX."tiki_newsletters_editions` tne
INNER JOIN `".BIT_DB_PREFIX."tiki_content` tc ON( tne.`content_id`=tc.`content_id` )
WHERE `$lookupColumn`=? $whereSql";
$result = $this->mDb->query($query,$bindVars);
if ($result->numRows()) {
$this->mInfo = $result->fetchRow();
- $this->mNlId = $this->mInfo['nl_id'];
+ $this->mEditionId = $this->mInfo['edition_id'];
$this->mContentId = $this->mInfo['content_id'];
$this->mNewsletter = new BitNewsletter( $this->mInfo['nl_id'] );
+ $this->mNewsletter->load();
}
}
return( count( $this->mInfo ) );
}
+ function isValid() {
+ return( !empty( $this->mEditionId ) );
+ }
+
+ /**
+ * Generate a valid url for the Newsletter Edition
+ *
+ * @param object PostId of the item to use
+ * @return object Url String
+ */
+ function getDisplayUrl( $pEditionId=NULL ) {
+ $ret = NULL;
+ if( empty( $pEditionId ) ) {
+ $pEditionId = $this->mEditionId;
+ }
+ global $gBitSystem;
+ if( is_numeric( $pEditionId ) ) {
+ if( $gBitSystem->isFeatureActive( 'pretty_urls' ) ) {
+ $ret = NEWSLETTERS_PKG_URL.'edition/'.$pEditionId;
+ } else {
+ $ret = NEWSLETTERS_PKG_URL.'edition.php?edition_id='.$pEditionId;
+ }
+ } else {
+ $ret = NEWSLETTERS_PKG_URL.'edition.php';
+ }
+ return $ret;
+ }
function getList( &$pListHash ) {
+ global $gBitDb;
+
$bindVars = array();
- $this->prepGetList( $pListHash );
+ BitBase::prepGetList( $pListHash );
$mid = '';
if( $pListHash['find'] ) {
$findesc = '%' . $pListHash['find'] . '%';
@@ -111,16 +145,18 @@ class BitNewsletterEdition extends LibertyContent {
$bindVars[] = $findesc;
}
- $query = "SELECT `edition_id` AS `has_key`, *
- FROM `".BIT_DB_PREFIX."tiki_newsletters` tn
- INNER JOIN `".BIT_DB_PREFIX."tiki_content` tc ON( tc.`content_id`=tn.`content_id` )
- INNER JOIN `".BIT_DB_PREFIX."tiki_newsletters_editions` tsn ON( tn.`nl_id`=tsn.`nl_id` )
+ $query = "SELECT `edition_id` AS `hash_key`, tne.*, tc.*, tc2.`title` AS `newsletter_title`
+ FROM `".BIT_DB_PREFIX."tiki_newsletters_editions` tne
+ INNER JOIN `".BIT_DB_PREFIX."tiki_content` tc ON( tc.`content_id`=tne.`content_id` )
+ LEFT OUTER JOIN `".BIT_DB_PREFIX."tiki_newsletters` tn ON( tne.`nl_id`=tn.`nl_id` )
+ LEFT OUTER JOIN `".BIT_DB_PREFIX."tiki_content` tc2 ON( tn.`content_id`=tc2.`content_id` )
$mid ORDER BY ".$this->mDb->convert_sortmode( $pListHash['sort_mode'] );
-
$query_cant = "select count(*) from `".BIT_DB_PREFIX."tiki_newsletters` tn, `".BIT_DB_PREFIX."tiki_newsletters_editions` tsn where tn.`nl_id`=tsn.`nl_id` $mid";
- $ret = $this->mDb->getAssoc( $query, $bindVars, $pListHash['max_records'], $pListHash['offset'] );
-
- $pListHash['total_records'] = $this->mDb->getOne( $query_cant, $bindVars );
+ $ret = $gBitDb->getAssoc( $query, $bindVars, $pListHash['max_records'], $pListHash['offset'] );
+ foreach( array_keys( $ret ) as $k ) {
+ $ret[$k]['display_url'] = BitNewsletterEdition::getDisplayUrl( $k );
+ }
+ $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 );
@@ -128,11 +164,14 @@ class BitNewsletterEdition extends LibertyContent {
return $ret;
}
- function remove_edition($edition_id) {
+ function expunge($edition_id) {
$query = "delete from `".BIT_DB_PREFIX."tiki_newsletters_editions` where `edition_id`=$edition_id";
$result = $this->mDb->query($query,array((int)$edition_id));
}
+ function isDraft() {
+ return( $this->getField( 'is_draft' ) );
+ }
}
?>