コード例 #1
0
ファイル: Emails.php プロジェクト: kfuchs/fwdcommerce
 /**
  * Model definition.
  */
 function define()
 {
     // Fields.
     $this->fields = array('id', 'type', 'to', 'cc', 'bcc', 'from', 'subject', 'text', 'html', 'date_created');
     $this->search_fields = array('to', 'subject');
     // Validate.
     $this->validate = array('required' => array('type', 'to', 'from', 'subject', 'text'));
     // Indexes.
     $this->indexes = array('id' => 'unique', 'type');
     // Event binds.
     $this->binds = array('POST' => function ($event, $model) {
         $data =& $event['data'];
         // Id as email type.
         $data['type'] = $data['type'] ?: $event['id'];
         unset($event['id']);
         // Prepare data for email message.
         $data = Emails::prepare_post_data($data);
         if (!$model->validate($data)) {
             return false;
             // Trigger special send event.
             /*if (false === trigger('emails', 'send', $data, $model))
             		{
             			return false;
             		}*/
         }
     });
     // Default send event.
     $this->bind('POST', function ($event, $model) {
         try {
             Emails::send_default($event['data']);
             // Indicate default mail gateway.
             $event['data']['gateway'] = 'default';
         } catch (Exception $e) {
             $model->error($e->getMessage());
             return false;
         }
         return true;
     }, 2);
 }