silverstripe-cms/code/Newsletter/Newsletter.php
Ingo Schommer 1eca17e0a9 elofgren: USABILITY: Rework the tabs in the Newsletter section to be less confusing as per issue #57 of the Usability Report
Includes the removal of all tabs and submit action buttons when 'Drafts' or 'Sent Items' are clicked and the addition of an 'add one' link on 'Drafts' folder page. 
For more information see: http://www.elijahlofgren.com/silverstripe/newletter-tree-and-tab-row-are-confusing/ 
Includes a few fixes for undefined variables.  (merged from branches/gsoc)


git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@41772 467b73ca-7a2a-4603-9d3b-597d59a354a9
2007-09-14 17:29:08 +00:00

99 lines
2.2 KiB
PHP
Executable File

<?php
class Newsletter extends DataObject {
/**
* Returns a FieldSet with which to create the CMS editing form.
* You can use the extend() method of FieldSet to create customised forms for your other
* data objects.
*/
function getCMSFields($controller = null) {
require_once("forms/Form.php");
$group = DataObject::get_by_id("Group", $this->Parent()->GroupID);
$ret = new FieldSet(
new TabSet("Root",
$mailTab = new Tab("Newsletter",
new TextField("Subject", "Subject", $this->Subject),
new HtmlEditorField("Content", "Content")
)
)
);
if( $this->Status != 'Draft' ) {
$mailTab->push( new ReadonlyField("SendDate", "Sent at", $this->SendDate) );
}
return $ret;
}
function getTitle() {
return $this->getField('Subject');
}
function getNewsletterType() {
return DataObject::get_by_id('NewsletterType', $this->ParentID);
}
static $db = array(
"Status" => "Enum('Draft, Send', 'Draft')",
"Content" => "HTMLText",
"Subject" => "Varchar(255)",
"SentDate" => "Datetime",
);
static $has_one = array(
"Parent" => "NewsletterType",
);
static $has_many = array(
"Recipients" => "Newsletter_Recipient",
);
static function newDraft( $parentID, $subject, $content ) {
if( is_numeric( $parentID ) ) {
$newsletter = new Newsletter();
$newsletter->Status = 'Draft';
$newsletter->Title = $newsletter->Subject = $subject;
$newsletter->ParentID = $parentID;
$newsletter->Content = $content;
$newsletter->write();
} else {
user_error( $parentID, E_USER_ERROR );
}
return $newsletter;
}
}
class Newsletter_Recipient extends DataObject {
static $db = array(
"ParentID" => "Int",
);
static $has_one = array(
"Member" => "Member",
);
}
class Newsletter_Email extends Email_Template {
protected $nlType;
function __construct($nlType) {
$this->nlType = $nlType;
parent::__construct();
}
function setTemplate( $template ) {
$this->ss_template = $template;
}
function UnsubscribeLink(){
$emailAddr = $this->To();
$nlTypeID = $this->nlType->ID;
return Director::absoluteBaseURL()."unsubscribe/$emailAddr/$nlTypeID";
}
}
?>