<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.5 |
+ | CiviCRM version 4.6 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
private $_domain = NULL;
/**
- * class constructor
+ * Class constructor
*/
- function __construct() {
+ public function __construct() {
parent::__construct();
}
/**
- * @param $job_id
- * @param null $mailing_id
+ * @param int $job_id
+ * @param int $mailing_id
* @param null $mode
*
* @return int
*/
- static function &getRecipientsCount($job_id, $mailing_id = NULL, $mode = NULL) {
+ public static function &getRecipientsCount($job_id, $mailing_id = NULL, $mode = NULL) {
// need this for backward compatibility, so we can get count for old mailings
// please do not use this function if possible
$eq = self::getRecipients($job_id, $mailing_id);
// note that $job_id is used only as a variable in the temp table construction
// and does not play a role in the queries generated
/**
- * @param $job_id
- * @param null $mailing_id
+ * @param int $job_id
+ * (misnomer) a nonce value used to name temporary tables.
+ * @param int $mailing_id
* @param null $offset
* @param null $limit
* @param bool $storeRecipients
// the record that comes last that counts. That's because we are
// INSERT'ing INTO a table with a primary id so that last record
// over writes any previous record.
- switch($email_selection_method) {
- case 'location-exclude':
- $location_filter = "($email.location_type_id != $location_type_id)";
- // If there is more than one email that doesn't match the location,
- // prefer the one marked is_bulkmail, followed by is_primary.
- $order_by = "ORDER BY $email.is_bulkmail, $email.is_primary";
- break;
- case 'location-only':
- $location_filter = "($email.location_type_id = $location_type_id)";
- // If there is more than one email of the desired location, prefer
- // the one marked is_bulkmail, followed by is_primary.
- $order_by = "ORDER BY $email.is_bulkmail, $email.is_primary";
- break;
- case 'location-prefer':
- $location_filter = "($email.is_bulkmail = 1 OR $email.is_primary = 1 OR $email.location_type_id = $location_type_id)";
-
- // ORDER BY is more complicated because we have to set an arbitrary
- // order that prefers the location that we want. We do that using
- // the FIELD function. For more info, see:
- // https://dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_field
- // We assign the location type we want the value "1" by putting it
- // in the first position after we name the field. All other location
- // types are left out, so they will be assigned the value 0. That
- // means, they will all be equally tied for first place, with our
- // location being last.
- $order_by = "ORDER BY FIELD($email.location_type_id, $location_type_id), $email.is_bulkmail, $email.is_primary";
- break;
- case 'automatic':
- // fall through to default
- default:
- $location_filter = "($email.is_bulkmail = 1 OR $email.is_primary = 1)";
- $order_by = "ORDER BY $email.is_bulkmail";
+ switch ($email_selection_method) {
+ case 'location-exclude':
+ $location_filter = "($email.location_type_id != $location_type_id)";
+ // If there is more than one email that doesn't match the location,
+ // prefer the one marked is_bulkmail, followed by is_primary.
+ $order_by = "ORDER BY $email.is_bulkmail, $email.is_primary";
+ break;
+
+ case 'location-only':
+ $location_filter = "($email.location_type_id = $location_type_id)";
+ // If there is more than one email of the desired location, prefer
+ // the one marked is_bulkmail, followed by is_primary.
+ $order_by = "ORDER BY $email.is_bulkmail, $email.is_primary";
+ break;
+
+ case 'location-prefer':
+ $location_filter = "($email.is_bulkmail = 1 OR $email.is_primary = 1 OR $email.location_type_id = $location_type_id)";
+
+ // ORDER BY is more complicated because we have to set an arbitrary
+ // order that prefers the location that we want. We do that using
+ // the FIELD function. For more info, see:
+ // https://dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_field
+ // We assign the location type we want the value "1" by putting it
+ // in the first position after we name the field. All other location
+ // types are left out, so they will be assigned the value 0. That
+ // means, they will all be equally tied for first place, with our
+ // location being last.
+ $order_by = "ORDER BY FIELD($email.location_type_id, $location_type_id), $email.is_bulkmail, $email.is_primary";
+ break;
+
+ case 'automatic':
+ // fall through to default
+ default:
+ $location_filter = "($email.is_bulkmail = 1 OR $email.is_primary = 1)";
+ $order_by = "ORDER BY $email.is_bulkmail";
}
/* Create a temp table for contact exclusion */
*
* Returns the regex patterns that are used for preparing the text and html templates
*
- * @access private
*
**/
private function &getPatterns($onlyHrefs = FALSE) {
* returns an array that denotes the type of token that we are dealing with
* we use the type later on when we are doing a token replcement lookup
*
- * @param string $token The token for which we will be doing adata lookup
+ * @param string $token The token for which we will be doing adata lookup
*
- * @return array $funcStruct An array that holds the token itself and the type.
+ * @return array $funcStruct An array that holds the token itself and the type.
* the type will tell us which function to use for the data lookup
* if we need to do a lookup at all
*/
- function &getDataFunc($token) {
+ public function &getDataFunc($token) {
static $_categories = NULL;
static $_categoryString = NULL;
if (!$_categories) {
* for generating the emails and returns a copy of the
* prepared templates
*
- * @access private
*
**/
private function getPreparedTemplates() {
*
*
* @return array reference to an assoc array
- * @access private
*
**/
private function &getTemplates() {
* either text or html for this to have any meaningful impact
*
* @return array reference to an assoc array
- * @access public
*
**/
public function &getTokens() {
* hook in one call and standardizes it across other token workflows
*
* @return array reference to an assoc array
- * @access public
*
**/
public function &getFlattenedTokens() {
* structures to represent the order in which tokens were found from left to right, top to bottom.
*
*
- * @param str $prop name of the property that holds the text that we want to scan for tokens (html, text)
- * @access private
+ * @param string $propName of the property that holds the text that we want to scan for tokens (html, text).
+ * Name of the property that holds the text that we want to scan for tokens (html, text).
*
* @return void
*/
/**
* Generate an event queue for a test job
*
- * @param array $testParams contains form values
+ * @param array $testParams
+ * Contains form values.
*
* @return void
- * @access public
*/
public function getTestRecipients($testParams) {
if (array_key_exists($testParams['test_group'], CRM_Core_PseudoConstant::group())) {
- $contacts = civicrm_api('contact','get', array(
- 'version' =>3,
+ $contacts = civicrm_api('contact', 'get', array(
+ 'version' => 3,
'group' => $testParams['test_group'],
'return' => 'id',
'options' => array('limit' => 100000000000,
* @param void
*
* @return void
- * @access private
*/
private function getHeaderFooter() {
if (!$this->header and $this->header_id) {
* is placed on the values received, so they do not need to follow the verp
* convention.
*
- * @param array $headers Array of message headers to update, in-out
- * @param string $prefix Prefix for the message ID, use same prefixes as verp
+ * @param array $headers
+ * Array of message headers to update, in-out.
+ * @param string $prefix
+ * Prefix for the message ID, use same prefixes as verp.
* wherever possible
- * @param string $job_id Job ID component of the generated message ID
- * @param string $event_queue_id Event Queue ID component of the generated message ID
- * @param string $hash Hash component of the generated message ID.
+ * @param string $job_id
+ * Job ID component of the generated message ID.
+ * @param string $event_queue_id
+ * Event Queue ID component of the generated message ID.
+ * @param string $hash
+ * Hash component of the generated message ID.
*
* @return void
*/
- static function addMessageIdHeader(&$headers, $prefix, $job_id, $event_queue_id, $hash) {
+ public static function addMessageIdHeader(&$headers, $prefix, $job_id, $event_queue_id, $hash) {
$config = CRM_Core_Config::singleton();
$localpart = CRM_Core_BAO_MailSettings::defaultLocalpart();
$emailDomain = CRM_Core_BAO_MailSettings::defaultDomain();
}
/**
- * static wrapper for getting verp and urls
+ * Static wrapper for getting verp and urls
*
- * @param int $job_id ID of the Job associated with this message
- * @param int $event_queue_id ID of the EventQueue
- * @param string $hash Hash of the EventQueue
- * @param string $email Destination address
+ * @param int $job_id
+ * ID of the Job associated with this message.
+ * @param int $event_queue_id
+ * ID of the EventQueue.
+ * @param string $hash
+ * Hash of the EventQueue.
+ * @param string $email
+ * Destination address.
*
* @return array (reference) array array ref that hold array refs to the verp info and urls
*/
- static function getVerpAndUrls($job_id, $event_queue_id, $hash, $email) {
+ public static function getVerpAndUrls($job_id, $event_queue_id, $hash, $email) {
// create a skeleton object and set its properties that are required by getVerpAndUrlsAndHeaders()
$config = CRM_Core_Config::singleton();
$bao = new CRM_Mailing_BAO_Mailing();
}
/**
- * get verp, urls and headers
+ * Get verp, urls and headers
*
- * @param int $job_id ID of the Job associated with this message
- * @param int $event_queue_id ID of the EventQueue
- * @param string $hash Hash of the EventQueue
- * @param string $email Destination address
+ * @param int $job_id
+ * ID of the Job associated with this message.
+ * @param int $event_queue_id
+ * ID of the EventQueue.
+ * @param string $hash
+ * Hash of the EventQueue.
+ * @param string $email
+ * Destination address.
*
* @param bool $isForward
*
/**
* Compose a message
*
- * @param int $job_id ID of the Job associated with this message
- * @param int $event_queue_id ID of the EventQueue
- * @param string $hash Hash of the EventQueue
- * @param string $contactId ID of the Contact
- * @param string $email Destination address
- * @param string $recipient To: of the recipient
- * @param boolean $test Is this mailing a test?
+ * @param int $job_id
+ * ID of the Job associated with this message.
+ * @param int $event_queue_id
+ * ID of the EventQueue.
+ * @param string $hash
+ * Hash of the EventQueue.
+ * @param string $contactId
+ * ID of the Contact.
+ * @param string $email
+ * Destination address.
+ * @param string $recipient
+ * To: of the recipient.
+ * @param bool $test
+ * Is this mailing a test?.
* @param $contactDetails
* @param $attachments
- * @param boolean $isForward Is this mailing compose for forward?
- * @param string $fromEmail email address of who is forwardinf it.
+ * @param bool $isForward
+ * Is this mailing compose for forward?.
+ * @param string $fromEmail
+ * Email address of who is forwardinf it.
*
* @param null $replyToEmail
*
* @return Mail_mime The mail object
- * @access public
*/
- public function &compose($job_id, $event_queue_id, $hash, $contactId,
+ public function &compose(
+ $job_id, $event_queue_id, $hash, $contactId,
$email, &$recipient, $test,
$contactDetails, &$attachments, $isForward = FALSE,
$fromEmail = NULL, $replyToEmail = NULL
elseif ($type == 'url') {
if ($this->url_tracking) {
$data = CRM_Mailing_BAO_TrackableURL::getTrackerURL($token, $this->id, $event_queue_id);
+ if (!empty($html)) {
+ $data = htmlentities($data);
+ }
}
else {
$data = $token;
* prior-mailing targets.
*
* @return array Names of groups receiving this mailing
- * @access public
*/
public function &getGroupNames() {
if (!isset($this->id)) {
}
/**
- * add the mailings
+ * Add the mailings
*
- * @param array $params reference array contains the values submitted by the form
- * @param array $ids reference array contains the id
+ * @param array $params
+ * Reference array contains the values submitted by the form.
+ * @param array $ids
+ * Reference array contains the id.
*
- * @access public
* @static
*
* @return object
*/
- static function add(&$params, $ids = array()) {
+ public static function add(&$params, $ids = array()) {
$id = CRM_Utils_Array::value('mailing_id', $ids, CRM_Utils_Array::value('id', $params));
if ($id) {
CRM_Utils_Hook::pre('create', 'Mailing', NULL, $params);
}
- $mailing = new CRM_Mailing_DAO_Mailing();
+ $mailing = new static();
$mailing->id = $id;
$mailing->domain_id = CRM_Utils_Array::value('domain_id', $params, CRM_Core_Config::domainID());
* Construct a new mailing object, along with job and mailing_group
* objects, from the form values of the create mailing wizard.
*
- * @params array $params Form values
+ * @params array $params
+ * Form values.
*
* @param array $params
* @param array $ids
*
* @return object $mailing The new mailing object
- * @access public
* @static
*/
public static function create(&$params, $ids = array()) {
$mg = new CRM_Mailing_DAO_MailingGroup();
foreach (array('groups', 'mailings') as $entity) {
foreach (array('include', 'exclude', 'base') as $type) {
- if (isset($params[$entity]) && !empty($params[$entity][$type]) &&
- is_array($params[$entity][$type])) {
- foreach ($params[$entity][$type] as $entityId) {
- $mg->reset();
- $mg->mailing_id = $mailing->id;
- $mg->entity_table = ($entity == 'groups') ? $groupTableName : $mailingTableName;
- $mg->entity_id = $entityId;
- $mg->group_type = $type;
- $mg->save();
- }
+ if (isset($params[$entity][$type])) {
+ self::replaceGroups($mailing->id, $type, $entity, $params[$entity][$type]);
}
}
}
$job->status = 'Scheduled';
$job->is_test = 0;
- if ( !$job->find(TRUE) ) {
+ if (!$job->find(TRUE)) {
$job->scheduled_date = $params['scheduled_date'];
$job->save();
}
// Populate the recipients.
- $mailing->getRecipients($job->id, $mailing->id, NULL, NULL, TRUE, FALSE);
+ if (empty($params['_skip_evil_bao_auto_recipients_'])) {
+ self::getRecipients($job->id, $mailing->id, NULL, NULL, TRUE, FALSE);
+ }
}
return $mailing;
}
/**
- * get hash value of the mailing
+ * Replace the list of recipients on a given mailing
*
+ * @param int $mailingId
+ * @param string $type
+ * 'include' or 'exclude'.
+ * @param string $entity
+ * 'groups' or 'mailings'.
+ * @param array<int> $entityIds
+ * @throws CiviCRM_API3_Exception
+ */
+ public static function replaceGroups($mailingId, $type, $entity, $entityIds) {
+ $values = array();
+ foreach ($entityIds as $entityId) {
+ $values[] = array('entity_id' => $entityId);
+ }
+ civicrm_api3('mailing_group', 'replace', array(
+ 'mailing_id' => $mailingId,
+ 'group_type' => $type,
+ 'entity_table' => ($entity == 'groups') ? CRM_Contact_BAO_Group::getTableName() : CRM_Mailing_BAO_Mailing::getTableName(),
+ 'values' => $values,
+ ));
+ }
+
+ /**
+ * Get hash value of the mailing
*/
public static function getMailingHash($id) {
$hash = NULL;
* Generate a report. Fetch event count information, mailing data, and job
* status.
*
- * @param int $id The mailing id to report
- * @param boolean $skipDetails whether return all detailed report
+ * @param int $id
+ * The mailing id to report.
+ * @param bool $skipDetails
+ * Whether return all detailed report.
*
* @param bool $isSMS
*
* @return array Associative array of reporting data
- * @access public
* @static
*/
public static function &report($id, $skipDetails = FALSE, $isSMS = FALSE) {
'delivered' => CRM_Mailing_Event_BAO_Delivered::getTableName(),
'opened' => CRM_Mailing_Event_BAO_Opened::getTableName(),
'reply' => CRM_Mailing_Event_BAO_Reply::getTableName(),
- 'unsubscribe' =>
- CRM_Mailing_Event_BAO_Unsubscribe::getTableName(),
+ 'unsubscribe' => CRM_Mailing_Event_BAO_Unsubscribe::getTableName(),
'bounce' => CRM_Mailing_Event_BAO_Bounce::getTableName(),
'forward' => CRM_Mailing_Event_BAO_Forward::getTableName(),
'url' => CRM_Mailing_BAO_TrackableURL::getTableName(),
'spool' => CRM_Mailing_BAO_Spool::getTableName(),
);
-
$report = array();
$additionalWhereClause = " AND ";
if (!$isSMS) {
),
);
-
$actionLinks = array(CRM_Core_Action::VIEW => array('name' => ts('Report')));
if (CRM_Core_Permission::check('view all contacts')) {
$actionLinks[CRM_Core_Action::ADVANCED] =
* @param
*
* @return int Count
- * @access public
*/
public function getCount() {
$this->selectAdd();
}
/**
- * @param $id
+ * @param int $id
*
* @throws Exception
*/
- static function checkPermission($id) {
+ public static function checkPermission($id) {
if (!$id) {
return;
}
*
* @return string
*/
- static function mailingACL($alias = NULL) {
+ public static function mailingACL($alias = NULL) {
$mailingACL = " ( 0 ) ";
$mailingIDs = self::mailingACLIDs();
}
/**
- * returns all the mailings that this user can access. This is dependent on
+ * Returns all the mailings that this user can access. This is dependent on
* all the groups that the user has access to.
* However since most civi installs dont use ACL's we special case the condition
* where the user has access to ALL groups, and hence ALL mailings and return a
* @return boolean | array - TRUE if the user has access to all mailings, else array of mailing IDs (possibly empty)
* @static
*/
- static function mailingACLIDs() {
+ public static function mailingACLIDs() {
// CRM-11633
// optimize common case where admin has access
// to all mailings
/**
* Get the rows for a browse operation
*
- * @param int $offset The row number to start from
- * @param int $rowCount The nmber of rows to return
- * @param string $sort The sql string that describes the sort order
+ * @param int $offset
+ * The row number to start from.
+ * @param int $rowCount
+ * The nmber of rows to return.
+ * @param string $sort
+ * The sql string that describes the sort order.
*
* @param null $additionalClause
- * @param null $additionalParams
+ * @param array $additionalParams
*
* @return array The rows
- * @access public
*/
public function &getRows($offset, $rowCount, $sort, $additionalClause = NULL, $additionalParams = NULL) {
$mailing = self::getTableName();
}
/**
- * show detail Mailing report
+ * Show detail Mailing report
*
* @param int $id
*
* @return string
* @static
- * @access public
*/
- static function showEmailDetails($id) {
+ public static function showEmailDetails($id) {
return CRM_Utils_System::url('civicrm/mailing/report', "mid=$id");
}
/**
* Delete Mails and all its associated records
*
- * @param int $id id of the mail to delete
+ * @param int $id
+ * Id of the mail to delete.
*
* @return void
- * @access public
* @static
*/
public static function del($id) {
* Delete Jobss and all its associated records
* related to test Mailings
*
- * @param int $id id of the Job to delete
+ * @param int $id
+ * Id of the Job to delete.
*
* @return void
- * @access public
* @static
*/
public static function delJob($id) {
/**
* @return array
*/
- function getReturnProperties() {
+ public function getReturnProperties() {
$tokens = &$this->getTokens();
$properties = array();
}
/**
- * build the compose mail form
+ * Build the compose mail form
*
* @param CRM_Core_Form $form
*
* @return void
- * @access public
*/
public static function commonCompose(&$form) {
//get the tokens.
$form->addWysiwyg('html_message',
ts('HTML Format'),
array(
- 'cols' => '80', 'rows' => '8',
+ 'cols' => '80',
+ 'rows' => '8',
'onkeyup' => "return verify(this)",
)
);
}
$form->add('textarea', $id, $label,
array(
- 'cols' => '80', 'rows' => '8',
+ 'cols' => '80',
+ 'rows' => '8',
'onkeyup' => "return verify(this, '{$prefix}')",
)
);
}
/**
- * Function to build the compose PDF letter form
+ * Build the compose PDF letter form
*
* @param CRM_Core_Form $form
*
* @return void
- * @access public
*/
public static function commonLetterCompose(&$form) {
//get the tokens.
$tokens = array_merge(CRM_Core_SelectValues::contributionTokens(), $tokens);
}
- if(method_exists($form, 'listTokens')) {
+ if (method_exists($form, 'listTokens')) {
$tokens = array_merge($form->listTokens(), $tokens);
}
);
$form->add('text', 'saveTemplateName', ts('Template Title'));
-
$form->addWysiwyg('html_message',
ts('Your Letter'),
array(
- 'cols' => '80', 'rows' => '8',
+ 'cols' => '80',
+ 'rows' => '8',
'onkeyup' => "return verify(this)",
)
);
* Get the search based mailing Ids
*
* @return array $mailingIDs, searched base mailing ids.
- * @access public
*/
public function searchMailingIDs() {
$group = CRM_Mailing_DAO_MailingGroup::getTableName();
/**
* Get the content/components of mailing based on mailing Id
*
- * @param $report array of mailing report
+ * @param $report
+ * Array of mailing report.
*
- * @param $form reference of this
+ * @param $form
+ * Reference of this.
*
* @param bool $isSMS
*
* @return array $report array content/component.@access public
*/
- static function getMailingContent(&$report, &$form, $isSMS = FALSE) {
+ public static function getMailingContent(&$report, &$form, $isSMS = FALSE) {
$htmlHeader = $textHeader = NULL;
$htmlFooter = $textFooter = NULL;
}
/**
- * @param $jobID
+ * @param int $jobID
*
* @return mixed
*/
- static function overrideVerp($jobID) {
+ public static function overrideVerp($jobID) {
static $_cache = array();
if (!isset($_cache[$jobID])) {
* @return bool
* @throws Exception
*/
- static function processQueue($mode = NULL) {
+ public static function processQueue($mode = NULL) {
$config = &CRM_Core_Config::singleton();
if ($mode == NULL && CRM_Core_BAO_MailSettings::defaultDomain() == "EXAMPLE.ORG") {
}
/**
- * @param $mailingID
+ * @param int $mailingID
*/
private static function addMultipleEmails($mailingID) {
$sql = "
*
* @return mixed
*/
- static function getMailingsList($isSMS = FALSE) {
+ public static function getMailingsList($isSMS = FALSE) {
static $list = array();
$where = " WHERE ";
if (!$isSMS) {
}
/**
- * @param $mid
+ * @param int $mid
*
* @return null|string
*/
- static function hiddenMailingGroup($mid) {
+ public static function hiddenMailingGroup($mid) {
$sql = "
SELECT g.id
FROM civicrm_mailing m
AND mg.group_type = 'Include'
AND m.id = %1
";
- $params = array( 1 => array( $mid, 'Integer' ) );
+ $params = array(1 => array($mid, 'Integer'));
return CRM_Core_DAO::singleValueQuery($sql, $params);
}
/**
* This function is a wrapper for ajax activity selector
*
- * @param array $params associated array for params record id.
+ * @param array $params
+ * Associated array for params record id.
*
* @return array $contactActivities associated array of contact activities
- * @access public
*/
public static function getContactMailingSelector(&$params) {
// format the params
"reset=1&cid={$values['creator_id']}");
//CRM-12814
- $contactMailings[$mailingId]['openstats'] = "Opens: ".
- CRM_Utils_Array::value($values['mailing_id'], $openCounts, 0).
- "<br />Clicks: ".
+ $contactMailings[$mailingId]['openstats'] = "Opens: " .
+ CRM_Utils_Array::value($values['mailing_id'], $openCounts, 0) .
+ "<br />Clicks: " .
CRM_Utils_Array::value($values['mailing_id'], $clickCounts, 0);
$actionLinks = array(
'url' => 'civicrm/mailing/report',
'qs' => "mid=%%mid%%&reset=1&cid=%%cid%%&context=mailing",
'title' => ts('View Mailing Report'),
- )
+ ),
);
$mailingKey = $values['mailing_id'];
$contactMailings[$mailingId]['links'] = CRM_Core_Action::formLink(
$actionLinks,
- null,
+ NULL,
array(
'mid' => $values['mailing_id'],
'cid' => $params['contact_id'],
}
/**
- * Function to retrieve contact mailing
+ * Retrieve contact mailing
*
- * @param array $params associated array
+ * @param array $params
+ * Associated array.
*
* @return array of mailings for a contact
*
* @static
- * @access public
*/
static public function getContactMailings(&$params) {
$params['version'] = 3;
}
/**
- * Function to retrieve contact mailing count
+ * Retrieve contact mailing count
*
- * @param array $params associated array
+ * @param array $params
+ * Associated array.
*
* @return int count of mailings for a contact
*
* @static
- * @access public
*/
static public function getContactMailingsCount(&$params) {
$params['version'] = 3;