Version: current

     1 <?php
     2
     3 /**
     4  * Record to keep track of when a {@link Member} has
     5  * unsubscribed from a newsletter.
     6  *
     7  * @TODO Check if that email stuff ($from, $to, $subject, $body) is needed
     8  *       here! (Markus)
     9  *
    10  * @package newsletter
    11  */
    12 class UnsubscribeRecord extends DataObject {
    13
    14     static $has_one = array(
    15         'NewsletterType' => 'NewsletterType',
    16         'Member' => 'Member'
    17     );
    18
    19     /**
    20      * Migrate data from Member_UnsubscribeRecord (the obsolete table)
    21      * to UnsubscribeRecord.
    22      */
    23     function requireDefaultRecords() {
    24         parent::requireDefaultRecords();
    25
    26         if(in_array('Email_BlackList', DB::getConn()->tableList())) {
    27             DB::query("INSERT INTO \"UnsubscribeRecord\" SELECT * FROM \"Member_UnsubscribeRecord\"");
    28             DB::query("RENAME TABLE \"Member_UnsubscribeRecord\" TO \"_obsolete_Member_UnsubscribeRecord\"");
    29
    30             echo("<div style=\"padding:5px; color:white; background-color:blue;\">Data in Member_UnsubscribeRecord has been moved to the new UnsubscribeRecord table. To drop the obsolete table, issue this SQL command: \"DROP TABLE '_obsolete_Member_UnsubscribeRecord'\".</div>");
    31         }
    32     }
    33
    34     /**
    35      * Unsubscribe the member from a specific newsletter type
    36      *
    37      * @param int|Member $member Member object or ID
    38      * @param int|NewsletterType $newsletterType Newsletter type object or ID
    39      */
    40     function unsubscribe($member, $newsletterType) {
    41         if(!class_exists('NewsletterType')) {
    42             user_error("UnsubscribeRecord::unsubscribe() called without the newsletter module available", E_USER_WARNING);
    43             return;
    44         }
    45
    46         // $this->UnsubscribeDate()->setVal( 'now' );
    47         $this->MemberID = (is_numeric($member))
    48             ? $member
    49             : $member->ID;
    50
    51         $this->NewsletterTypeID = (is_numeric($newsletterType))
    52             ? $newsletterType
    53             : $newsletterType->ID;
    54
    55         $this->write();
    56     }
    57
    58
    59     protected
    60         $from = '',  // setting a blank from address uses the site's default administrator email
    61         $to = '$Email',
    62         $subject = '',
    63         $body = '';
    64
    65         function __construct($record = null, $isSingleton = false) {
    66             $this->subject = _t('Member.SUBJECTPASSWORDCHANGED');
    67
    68             $this->body = '
    69                 <h1>' . _t('Member.EMAILPASSWORDINTRO', "Here's your new password") . '</h1>
    70                 <p>
    71                     <strong>' . _t('Member.EMAIL') . ':</strong> $Email<br />
    72                     <strong>' . _t('Member.PASSWORD') . ':</strong> $Password
    73                 </p>
    74                 <p>' . _t('Member.EMAILPASSWORDAPPENDIX', 'Your password has been changed. Please keep this email, for future reference.') . '</p>';
    75
    76             parent::__construct($record, $isSingleton);
    77         }
    78 }
    79
    80 ?>

[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. -