INFRA-132 - Trailing commas for multiline arrays
[civicrm-core.git] / CRM / Mailing / BAO / Mailing.php
index 8fb997358a46d114dff544a77691061e46d0a272..c016b194f34c8d1e3753e1402be5b3454d199e55 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
@@ -89,20 +89,20 @@ class CRM_Mailing_BAO_Mailing extends CRM_Mailing_DAO_Mailing {
   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);
@@ -112,8 +112,9 @@ class CRM_Mailing_BAO_Mailing extends CRM_Mailing_DAO_Mailing {
   // 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
@@ -159,38 +160,41 @@ class CRM_Mailing_BAO_Mailing extends CRM_Mailing_DAO_Mailing {
     // 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 */
@@ -622,7 +626,6 @@ ORDER BY   i.contact_id, i.{$tempColumn}
    *
    * Returns the regex patterns that are used for preparing the text and html templates
    *
-   * @access private
    *
    **/
   private function &getPatterns($onlyHrefs = FALSE) {
@@ -654,13 +657,13 @@ ORDER BY   i.contact_id, i.{$tempColumn}
    *  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) {
@@ -720,7 +723,6 @@ ORDER BY   i.contact_id, i.{$tempColumn}
    * for generating the emails and returns a copy of the
    * prepared templates
    *
-   * @access private
    *
    **/
   private function getPreparedTemplates() {
@@ -766,7 +768,6 @@ ORDER BY   i.contact_id, i.{$tempColumn}
    *
    *
    * @return array reference to an assoc array
-   * @access private
    *
    **/
   private function &getTemplates() {
@@ -834,7 +835,6 @@ ORDER BY   i.contact_id, i.{$tempColumn}
    *  either text or html for this to have any meaningful impact
    *
    * @return array               reference to an assoc array
-   * @access public
    *
    **/
   public function &getTokens() {
@@ -868,7 +868,6 @@ ORDER BY   i.contact_id, i.{$tempColumn}
    * hook in one call and standardizes it across other token workflows
    *
    * @return array               reference to an assoc array
-   * @access public
    *
    **/
   public function &getFlattenedTokens() {
@@ -892,8 +891,8 @@ ORDER BY   i.contact_id, i.{$tempColumn}
    *  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
    */
@@ -915,15 +914,15 @@ ORDER BY   i.contact_id, i.{$tempColumn}
   /**
    * 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,
@@ -965,7 +964,6 @@ ORDER BY   civicrm_email.is_bulkmail DESC
    * @param void
    *
    * @return void
-   * @access private
    */
   private function getHeaderFooter() {
     if (!$this->header and $this->header_id) {
@@ -993,16 +991,21 @@ ORDER BY   civicrm_email.is_bulkmail DESC
    * 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();
@@ -1021,16 +1024,20 @@ ORDER BY   civicrm_email.is_bulkmail DESC
   }
 
   /**
-   * 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();
@@ -1043,12 +1050,16 @@ ORDER BY   civicrm_email.is_bulkmail DESC
   }
 
   /**
-   * 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
    *
@@ -1137,24 +1148,33 @@ ORDER BY   civicrm_email.is_bulkmail DESC
   /**
    * 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
@@ -1444,6 +1464,9 @@ ORDER BY   civicrm_email.is_bulkmail DESC
     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;
@@ -1479,7 +1502,6 @@ ORDER BY   civicrm_email.is_bulkmail DESC
    * prior-mailing targets.
    *
    * @return array        Names of groups receiving this mailing
-   * @access public
    */
   public function &getGroupNames() {
     if (!isset($this->id)) {
@@ -1505,17 +1527,18 @@ ORDER BY   civicrm_email.is_bulkmail DESC
   }
 
   /**
-   * 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) {
@@ -1525,7 +1548,7 @@ ORDER BY   civicrm_email.is_bulkmail DESC
       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());
 
@@ -1553,13 +1576,13 @@ ORDER BY   civicrm_email.is_bulkmail DESC
    * 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()) {
@@ -1652,16 +1675,8 @@ ORDER BY   civicrm_email.is_bulkmail DESC
     $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]);
         }
       }
     }
@@ -1692,21 +1707,46 @@ ORDER BY   civicrm_email.is_bulkmail DESC
       $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;
@@ -1720,13 +1760,14 @@ ORDER BY   civicrm_email.is_bulkmail DESC
    * 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) {
@@ -1743,8 +1784,7 @@ ORDER BY   civicrm_email.is_bulkmail DESC
       '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(),
@@ -1754,7 +1794,6 @@ ORDER BY   civicrm_email.is_bulkmail DESC
       'spool' => CRM_Mailing_BAO_Spool::getTableName(),
     );
 
-
     $report = array();
     $additionalWhereClause = " AND ";
     if (!$isSMS) {
@@ -2115,7 +2154,6 @@ ORDER BY   civicrm_email.is_bulkmail DESC
       ),
     );
 
-
     $actionLinks = array(CRM_Core_Action::VIEW => array('name' => ts('Report')));
     if (CRM_Core_Permission::check('view all contacts')) {
       $actionLinks[CRM_Core_Action::ADVANCED] =
@@ -2201,7 +2239,6 @@ ORDER BY   civicrm_email.is_bulkmail DESC
    * @param
    *
    * @return int              Count
-   * @access public
    */
   public function getCount() {
     $this->selectAdd();
@@ -2214,11 +2251,11 @@ ORDER BY   civicrm_email.is_bulkmail DESC
   }
 
   /**
-   * @param $id
+   * @param int $id
    *
    * @throws Exception
    */
-  static function checkPermission($id) {
+  public static function checkPermission($id) {
     if (!$id) {
       return;
     }
@@ -2239,7 +2276,7 @@ ORDER BY   civicrm_email.is_bulkmail DESC
    *
    * @return string
    */
-  static function mailingACL($alias = NULL) {
+  public static function mailingACL($alias = NULL) {
     $mailingACL = " ( 0 ) ";
 
     $mailingIDs = self::mailingACLIDs();
@@ -2256,7 +2293,7 @@ ORDER BY   civicrm_email.is_bulkmail DESC
   }
 
   /**
-   * 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
@@ -2265,7 +2302,7 @@ ORDER BY   civicrm_email.is_bulkmail DESC
    * @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
@@ -2306,15 +2343,17 @@ LEFT JOIN civicrm_mailing_group g ON g.mailing_id   = m.id
   /**
    * 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();
@@ -2398,25 +2437,24 @@ LEFT JOIN civicrm_mailing_group g ON g.mailing_id   = m.id
   }
 
   /**
-   * 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) {
@@ -2444,10 +2482,10 @@ LEFT JOIN civicrm_mailing_group g ON g.mailing_id   = m.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) {
@@ -2463,7 +2501,7 @@ LEFT JOIN civicrm_mailing_group g ON g.mailing_id   = m.id
   /**
    * @return array
    */
-  function getReturnProperties() {
+  public function getReturnProperties() {
     $tokens = &$this->getTokens();
 
     $properties = array();
@@ -2496,12 +2534,11 @@ LEFT JOIN civicrm_mailing_group g ON g.mailing_id   = m.id
   }
 
   /**
-   * 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.
@@ -2534,7 +2571,8 @@ LEFT JOIN civicrm_mailing_group g ON g.mailing_id   = m.id
       $form->addWysiwyg('html_message',
         ts('HTML Format'),
         array(
-          'cols' => '80', 'rows' => '8',
+          'cols' => '80',
+      'rows' => '8',
           'onkeyup' => "return verify(this)",
         )
       );
@@ -2557,7 +2595,8 @@ LEFT JOIN civicrm_mailing_group g ON g.mailing_id   = m.id
       }
       $form->add('textarea', $id, $label,
         array(
-          'cols' => '80', 'rows' => '8',
+          'cols' => '80',
+      'rows' => '8',
           'onkeyup' => "return verify(this, '{$prefix}')",
         )
       );
@@ -2589,12 +2628,11 @@ LEFT JOIN civicrm_mailing_group g ON g.mailing_id   = m.id
   }
 
   /**
-   * 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.
@@ -2607,7 +2645,7 @@ LEFT JOIN civicrm_mailing_group g ON g.mailing_id   = m.id
       $tokens = array_merge(CRM_Core_SelectValues::contributionTokens(), $tokens);
     }
 
-    if(method_exists($form, 'listTokens')) {
+    if (method_exists($form, 'listTokens')) {
       $tokens = array_merge($form->listTokens(), $tokens);
     }
 
@@ -2629,11 +2667,11 @@ LEFT JOIN civicrm_mailing_group g ON g.mailing_id   = m.id
     );
     $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)",
       )
     );
@@ -2649,7 +2687,6 @@ LEFT JOIN civicrm_mailing_group g ON g.mailing_id   = m.id
    * Get the search based mailing Ids
    *
    * @return array $mailingIDs, searched base mailing ids.
-   * @access public
    */
   public function searchMailingIDs() {
     $group = CRM_Mailing_DAO_MailingGroup::getTableName();
@@ -2673,15 +2710,17 @@ SELECT  $mailing.id as mailing_id
   /**
    * 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;
 
@@ -2729,11 +2768,11 @@ SELECT  $mailing.id as mailing_id
   }
 
   /**
-   * @param $jobID
+   * @param int $jobID
    *
    * @return mixed
    */
-  static function overrideVerp($jobID) {
+  public static function overrideVerp($jobID) {
     static $_cache = array();
 
     if (!isset($_cache[$jobID])) {
@@ -2755,7 +2794,7 @@ WHERE  civicrm_mailing_job.id = %1
    * @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") {
@@ -2807,7 +2846,7 @@ WHERE  civicrm_mailing_job.id = %1
   }
 
   /**
-   * @param $mailingID
+   * @param int $mailingID
    */
   private static function addMultipleEmails($mailingID) {
     $sql = "
@@ -2830,7 +2869,7 @@ AND    e.id NOT IN ( SELECT email_id FROM civicrm_mailing_recipients mr WHERE ma
    *
    * @return mixed
    */
-  static function getMailingsList($isSMS = FALSE) {
+  public static function getMailingsList($isSMS = FALSE) {
     static $list = array();
     $where = " WHERE ";
     if (!$isSMS) {
@@ -2857,11 +2896,11 @@ ORDER BY civicrm_mailing.name";
   }
 
   /**
-   * @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
@@ -2871,17 +2910,17 @@ WHERE      g.is_hidden = 1
 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
@@ -2916,9 +2955,9 @@ AND        m.id = %1
         "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(
@@ -2934,7 +2973,7 @@ AND        m.id = %1
           'url' => 'civicrm/mailing/report',
           'qs' => "mid=%%mid%%&reset=1&cid=%%cid%%&context=mailing",
           'title' => ts('View Mailing Report'),
-        )
+        ),
       );
 
       $mailingKey = $values['mailing_id'];
@@ -2944,7 +2983,7 @@ AND        m.id = %1
 
       $contactMailings[$mailingId]['links'] = CRM_Core_Action::formLink(
         $actionLinks,
-        null,
+        NULL,
         array(
           'mid' => $values['mailing_id'],
           'cid' => $params['contact_id'],
@@ -2962,14 +3001,14 @@ AND        m.id = %1
   }
 
   /**
-   * 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;
@@ -2982,14 +3021,14 @@ AND        m.id = %1
   }
 
   /**
-   * 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;