Version: current

      1 <?php
      2 /**
      3  * Represents a type of newsletter, for example the weekly products update.
      4  * The NewsletterType is associated with a recipient list and a bunch of
      5  * Newsletter objects, which are each either Sent or Draft.
      6  *
      7  * @package newsletter
      8  */
      9 class NewsletterType extends DataObject {
     10
     11     static $db = array(
     12         "Title" => "Varchar",
     13         "Template" => "Varchar",
     14         "FromEmail" => "Varchar(100)",
     15         "Sent" => "Datetime"
     16     );
     17
     18     static $has_one = array(
     19         "Parent" => "SiteTree",
     20         "Group" => "Group",
     21     );
     22
     23     static $has_many = array(
     24         "Newsletters" => "Newsletter",
     25     );
     26
     27     static $many_many = array(
     28     );
     29
     30     static $defaults = array(
     31     );
     32
     33     function DraftNewsletters() {
     34         return DataObject::get("Newsletter","ParentID={$this->ID} AND Status ='Draft'");
     35     }
     36
     37     function SentNewsletters() {
     38         return DataObject::get("Newsletter","ParentID={$this->ID} AND Status ='Send'");
     39     }
     40
     41     function MostRecentSentNewsletters() {
     42         $most_recent_seperator = NewsletterAdmin::$most_recent_seperator;
     43         return $do = DataObject::get("Newsletter","ParentID={$this->ID} AND Status ='Send'", "SentDate DESC", "", "0, $most_recent_seperator");
     44     }
     45
     46     function RecentSeperator(){
     47         return NewsletterAdmin::$most_recent_seperator;
     48     }
     49
     50     function OlderSentNewsletters() {
     51         $total = $this->SentNewsletters();
     52         if($total) {
     53             $most_recent_seperator = NewsletterAdmin::$most_recent_seperator;
     54             return $do = DataObject::get("Newsletter","ParentID={$this->ID} AND Status ='Send'", "SentDate DESC", "", "$most_recent_seperator, ".$total->count());
     55         }else{
     56             return null;
     57         }
     58     }
     59
     60     function Recipients() {
     61         return DataObject::get("Member", "Group_Members.GroupID = {$this->GroupID}", "", "JOIN Group_Members on Group_Members.MemberID = Member.ID");
     62     }
     63
     64     function delete() {
     65         if($this->Newsletters()) {
     66             foreach($this->Newsletters() as $newsletter) {
     67                 $newsletter->delete();
     68                 $newsletter->destroy();
     69             }
     70         }
     71
     72         parent::delete();
     73     }
     74
     75     /**
     76      * Get the fieldset to display in the administration section
     77      */
     78     function getCMSFields() {
     79         $groups = DataObject::get('Group', '', 'Sort');
     80         $groupsMap = ($groups) ? $groups->map('ID', 'Title') : array();
     81
     82         $templateSource = singleton("NewsletterAdmin")->templateSource();
     83
     84         $fields = new FieldSet(
     85             new TabSet("Root",
     86                 new Tab('Settings',_t('NewsletterAdmin.NLSETTINGS', 'Newsletter Settings'),
     87                     new TextField("Title", _t('NewsletterAdmin.NEWSLTYPE', 'Newsletter Type')),
     88                     new DropdownField('GroupID', _T('NewsletterAdmin.MAILINGGROUP', 'Mailing list group'), $groupsMap, '', null, _t('NewsletterAdmin.CHOOSEMAILINGGROUP', '(Choose mailing group)')),
     89                     new TextField("FromEmail", _t('NewsletterAdmin.FROMEM', 'From email address')),
     90                     new DropdownField("Template", _t('NewsletterAdmin.TEMPLATE', 'Template'), $templateSource)
     91                 )
     92             )
     93         );
     94         // разрешаем менять шаблон рассылки только в dev-режиме
     95         if (!Director::isDev()) {
     96             $fields->replaceField('Template', $fields->dataFieldByName('Template')->performReadonlyTransformation());
     97         }
     98
     99         $this->extend('updateCMSFields', $fields);
    100
    101         return $fields;
    102     }
    103
    104 }
    105 ?>

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -