mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 11:05:53 +02:00
1eca17e0a9
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
99 lines
2.2 KiB
PHP
Executable File
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";
|
|
}
|
|
}
|
|
?>
|