2011-03-05 21:27:20 -08:00
|
|
|
<?php
|
|
|
|
|
class EmailRecipient extends AppModel {
|
|
|
|
|
|
|
|
|
|
var $name = 'EmailRecipient';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var $belongsTo = array(
|
2011-03-09 23:18:26 -08:00
|
|
|
'Email' => array('className'=>'Email', 'foreign_key'=>'email_id'),
|
|
|
|
|
'User' => array('className' => 'User', 'foreign_key' =>'user_id'
|
|
|
|
|
)
|
2011-03-05 21:27:20 -08:00
|
|
|
);
|
2011-03-09 23:18:26 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Given an Email ID, return a formatted array of the Users.
|
|
|
|
|
*
|
|
|
|
|
* $recipients['to']=> array(0=>array('first_name'=>'Bill Smith')) etc.
|
|
|
|
|
* $recipients['from']=> array(...
|
|
|
|
|
*
|
|
|
|
|
* @param <type> $id
|
|
|
|
|
*/
|
|
|
|
|
function getRecipients($id) {
|
|
|
|
|
$recipients = $this->find('all', array(
|
|
|
|
|
'fields' => array('EmailRecipient.id','EmailRecipient.user_id', 'EmailRecipient.type', 'User.id', 'User.first_name', 'User.last_name','User.email', 'User.principle_id','User.type', 'User.customer_id'),
|
|
|
|
|
'conditions'=>array('Email.id'=>$id)));
|
|
|
|
|
|
|
|
|
|
$recipientFormatted = array();
|
|
|
|
|
foreach($recipients as $recipient) {
|
|
|
|
|
switch($recipient['EmailRecipient']['type']) {
|
|
|
|
|
case 'to':
|
|
|
|
|
$recipientFormatted['to'][] = $recipient['User'];
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'cc': $recipientFormatted['cc'][] = $recipient['User'];
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $recipientFormatted;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-03-05 21:27:20 -08:00
|
|
|
}
|
2011-03-09 23:18:26 -08:00
|
|
|
?>
|