mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
abb9a61d0d
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@39000 467b73ca-7a2a-4603-9d3b-597d59a354a9
56 lines
1.3 KiB
PHP
Executable File
56 lines
1.3 KiB
PHP
Executable File
<?php
|
|
|
|
class NewsletterType extends DataObject {
|
|
|
|
static $db = array(
|
|
"Title" => "Varchar",
|
|
"Template" => "Varchar",
|
|
"FromEmail" => "Varchar",
|
|
"Sent" => "Datetime"
|
|
);
|
|
static $has_one = array(
|
|
"Parent" => "SiteTree",
|
|
"Group" => "Group",
|
|
);
|
|
static $has_many = array(
|
|
"Newsletters" => "Newsletter",
|
|
);
|
|
|
|
function DraftNewsletters() {
|
|
return DataObject::get("Newsletter","ParentID={$this->ID} AND Status ='Draft'");
|
|
}
|
|
|
|
function SentNewsletters() {
|
|
return DataObject::get("Newsletter","ParentID={$this->ID} AND Status ='Send'");
|
|
}
|
|
|
|
function Recipients() {
|
|
return DataObject::get("Member", "Group_Members.GroupID = {$this->GroupID}", "", "JOIN Group_Members on Group_Members.MemberID = Member.ID");
|
|
}
|
|
|
|
function delete() {
|
|
foreach( $this->Newsletters() as $newsletter )
|
|
$newsletter->delete();
|
|
|
|
parent::delete();
|
|
}
|
|
|
|
/**
|
|
* Updates the group so the security section is also in sync with
|
|
* the curent newsletters.
|
|
*/
|
|
function onBeforeWrite(){
|
|
if($this->ID){
|
|
$group = $this->Group();
|
|
if($group->Title != "$this->Title"){
|
|
$group->Title = "Mailing List: " . $this->Title;
|
|
// Otherwise the code would have mailing list in it too :-(
|
|
$group->Code = SiteTree::generateURLSegment($this->Title);
|
|
$group->write();
|
|
}
|
|
}
|
|
parent::onBeforeWrite();
|
|
}
|
|
}
|
|
?>
|