INFRA-132 - Batch 14 (g)
[civicrm-core.git] / api / v3 / MailingContact.php
index ce4103b25d4cf223f3957fa3a5d76b7b8a497f75..7bf53d370a870fe51bc33e0c6807899cd4d7638b 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.5                                                |
+ | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
  | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
 /**
  * Get all the mailings and details that a contact was involved with
  *
- * @param array    $params input parameters
- *                    - key: contact_id, value: int - required
- *                    - key: type, value: Delivered | Bounced - optional, defaults to Delivered
- *                    - Future extensions will include: Opened, Clicked, Forwarded
- *
- * @return array API result
- * @static void
- * @access public
- * @example CRM/Mailing/BAO/Mailing.php
+ * @param array $params
+ *   Input parameters - see _spec for details (returned by getfields)
  *
+ * @return array
+ *   API result
  */
 function civicrm_api3_mailing_contact_get($params) {
   return civicrm_api3_create_success(_civicrm_api3_mailing_contact_getresults($params, FALSE));
@@ -57,12 +52,12 @@ function civicrm_api3_mailing_contact_get($params) {
  * This is a wrapper for the functions that return the results from the 'quasi-entity'
  * mailing contact
  * @param array $params
- * @param Boolean $count
+ * @param bool $count
  * @throws Exception
  */
-function _civicrm_api3_mailing_contact_getresults($params, $count){
-  if(empty($params['type'])){
-    //ie. because the api is an anomoly & passing in id is not valid
+function _civicrm_api3_mailing_contact_getresults($params, $count) {
+  if (empty($params['type'])) {
+    //ie. because the api is an anomaly & passing in id is not valid
     throw new Exception('This api call does not accept api as a parameter');
   }
   $options  = _civicrm_api3_get_options_from_params($params, TRUE,'contribution','get');
@@ -78,7 +73,8 @@ function _civicrm_api3_mailing_contact_getresults($params, $count){
 /**
  * Adjust Metadata for Get action
  *
- * @param array $params array or parameters determined by getfields
+ * @param array $params
+ *   Array or parameters determined by getfields.
  */
 function _civicrm_api3_mailing_contact_get_spec(&$params) {
   $params['contact_id']['api.required'] = 1;
@@ -90,12 +86,11 @@ function _civicrm_api3_mailing_contact_get_spec(&$params) {
     'options' => array(
       'Delivered' => 'Delivered',
       'Bounced' => 'Bounced',
-    )
+    ),
   );
 }
 
 /**
- * @param $type
  * @param int $contactID
  * @param $offset
  * @param $limit
@@ -108,7 +103,6 @@ function _civicrm_api3_mailing_contact_get_spec(&$params) {
  * @return array
  */
 function _civicrm_api3_mailing_contact_query(
-  $type,
   $contactID,
   $offset,
   $limit,
@@ -134,15 +128,10 @@ GROUP BY   m.id
 ";
 
     $qParams = array(
-      1 => array($contactID, 'Integer')
+      1 => array($contactID, 'Integer'),
     );
     $dao = CRM_Core_DAO::executeQuery($sql, $qParams);
 
-    $params = array(
-      'type'   => $type,
-      'contact_id' => $contactID
-    );
-
     $results = $dao->N;
   }
   else {
@@ -194,7 +183,7 @@ LIMIT %2, %3
     $qParams = array(
       1 => array($contactID, 'Integer'),
       2 => array($offset, 'Integer'),
-      3 => array($limit, 'Integer')
+      3 => array($limit, 'Integer'),
     );
     $dao = CRM_Core_DAO::executeQuery($sql, $qParams);
 
@@ -237,7 +226,6 @@ AND        meb.id IS NULL
 ";
 
   return _civicrm_api3_mailing_contact_query(
-    'Delivered',
     $contactID,
     $offset,
     $limit,
@@ -270,7 +258,6 @@ INNER JOIN civicrm_mailing_event_bounce meb ON meb.event_queue_id = meq.id
 ";
 
   return _civicrm_api3_mailing_contact_query(
-    'Bounced',
     $contactID,
     $offset,
     $limit,
@@ -285,16 +272,11 @@ INNER JOIN civicrm_mailing_event_bounce meb ON meb.event_queue_id = meq.id
 /**
  * Get count of all the mailings that a contact was involved with
  *
- * @param array    $params input parameters
- *                    - key: contact_id, value: int - required
- *                    - key: type, value: Delivered | Bounced - optional, defaults to Delivered
- *                    - Future extensions will include: Opened, Clicked, Forwarded
- *
- * @return array API result
- * @static void
- * @access public
- * @example CRM/Mailing/BAO/Mailing.php
+ * @param array $params
+ *   Input parameters per getfields
  *
+ * @return array
+ *   API result
  */
 function civicrm_api3_mailing_contact_getcount($params) {
   return _civicrm_api3_mailing_contact_getresults($params, TRUE);