/** * Send graph detail for A/B tests mail. * * @param array $params * * @return array * @throws API_Exception */ function civicrm_api3_mailing_a_b_graph_stats($params) { civicrm_api3_verify_mandatory($params, 'CRM_Mailing_DAO_MailingAB', array('id'), FALSE); $defaults = array('criteria' => 'Open', 'target_date' => CRM_Utils_Time::getTime('YmdHis'), 'split_count' => 6, 'split_count_select' => 1); $params = array_merge($defaults, $params); $mailingAB = civicrm_api3('MailingAB', 'getsingle', array('id' => $params['id'])); $graphStats = array(); $ABFormat = array('A' => 'mailing_id_a', 'B' => 'mailing_id_b'); foreach ($ABFormat as $name => $column) { switch (strtolower($params['criteria'])) { case 'open': $result = CRM_Mailing_Event_BAO_Opened::getRows($mailingAB['mailing_id_a'], NULL, TRUE, 0, 1, "civicrm_mailing_event_opened.time_stamp ASC"); $startDate = CRM_Utils_Date::processDate($result[0]['date']); $targetDate = CRM_Utils_Date::processDate($params['target_date']); $dateDuration = round(round(strtotime($targetDate) - strtotime($startDate)) / $params['split_count']); $toDate = strtotime($startDate) + $dateDuration * $params['split_count_select']; $toDate = date('YmdHis', $toDate); $graphStats[$name] = array($params['split_count_select'] => array('count' => CRM_Mailing_Event_BAO_Opened::getTotalCount($mailingAB[$column], NULL, TRUE, $toDate), 'time' => CRM_Utils_Date::customFormat($toDate))); break; case 'total unique clicks': $result = CRM_Mailing_Event_BAO_TrackableURLOpen::getRows($mailingAB['mailing_id_a'], NULL, TRUE, 0, 1, "civicrm_mailing_event_trackable_url_open.time_stamp ASC"); $startDate = CRM_Utils_Date::processDate($result[0]['date']); $targetDate = CRM_Utils_Date::processDate($params['target_date']); $dateDuration = round(abs(strtotime($targetDate) - strtotime($startDate)) / $params['split_count']); $toDate = strtotime($startDate) + $dateDuration * $params['split_count_select']; $toDate = date('YmdHis', $toDate); $graphStats[$name] = array($params['split_count_select'] => array('count' => CRM_Mailing_Event_BAO_TrackableURLOpen::getTotalCount($params['mailing_id'], NULL, FALSE, NULL, $toDate), 'time' => CRM_Utils_Date::customFormat($toDate))); break; case 'total clicks on a particular link': if (empty($params['target_url'])) { throw new API_Exception("Provide url to get stats result for total clicks on a particular link"); } // FIXME: doesn't make sense to get url_id mailing_id_(a|b) while getting start date in mailing_id_a $url_id = CRM_Mailing_BAO_TrackableURL::getTrackerURLId($mailingAB[$column], $params['target_url']); $result = CRM_Mailing_Event_BAO_TrackableURLOpen::getRows($mailingAB['mailing_id_a'], NULL, FALSE, $url_id, 0, 1, "civicrm_mailing_event_trackable_url_open.time_stamp ASC"); $startDate = CRM_Utils_Date::processDate($result[0]['date']); $targetDate = CRM_Utils_Date::processDate($params['target_date']); $dateDuration = round(abs(strtotime($targetDate) - strtotime($startDate)) / $params['split_count']); $toDate = strtotime($startDate) + $dateDuration * $params['split_count_select']; $toDate = CRM_Utils_Date::processDate($toDate); $graphStats[$name] = array($params['split_count_select'] => array('count' => CRM_Mailing_Event_BAO_TrackableURLOpen::getTotalCount($params['mailing_id'], NULL, FALSE, $url_id, $toDate), 'time' => CRM_Utils_Date::customFormat($toDate))); break; } } return civicrm_api3_create_success($graphStats); }
/** * Function which needs to be explained. * * @param array $params * * @return array * @throws \API_Exception */ function civicrm_api3_mailing_stats($params) { civicrm_api3_verify_mandatory($params, 'CRM_Mailing_DAO_MailingJob', array('mailing_id'), FALSE); if ($params['date'] == 'now') { $params['date'] = date('YmdHis'); } else { $params['date'] = CRM_Utils_Date::processDate($params['date'] . ' ' . $params['date_time']); } $stats[$params['mailing_id']] = array(); if (empty($params['job_id'])) { $params['job_id'] = NULL; } foreach (array('Delivered', 'Bounces', 'Unsubscribers', 'Unique Clicks', 'Opened') as $detail) { switch ($detail) { case 'Delivered': $stats[$params['mailing_id']] += array($detail => CRM_Mailing_Event_BAO_Delivered::getTotalCount($params['mailing_id'], $params['job_id'], FALSE, $params['date'])); break; case 'Bounces': $stats[$params['mailing_id']] += array($detail => CRM_Mailing_Event_BAO_Bounce::getTotalCount($params['mailing_id'], $params['job_id'], FALSE, $params['date'])); break; case 'Unsubscribers': $stats[$params['mailing_id']] += array($detail => CRM_Mailing_Event_BAO_Unsubscribe::getTotalCount($params['mailing_id'], $params['job_id'], FALSE, NULL, $params['date'])); break; case 'Unique Clicks': $stats[$params['mailing_id']] += array($detail => CRM_Mailing_Event_BAO_TrackableURLOpen::getTotalCount($params['mailing_id'], $params['job_id'], FALSE, NULL, $params['date'])); break; case 'Opened': $stats[$params['mailing_id']] += array($detail => CRM_Mailing_Event_BAO_Opened::getTotalCount($params['mailing_id'], $params['job_id'], FALSE, $params['date'])); break; } } return civicrm_api3_create_success($stats); }
/** * Returns total number of rows for the query. * * @param * * @return int Total number of rows * @access public */ function getTotalCount($action) { switch ($this->_event_type) { case 'queue': $event = new CRM_Mailing_Event_BAO_Queue(); return $event->getTotalCount($this->_mailing_id, $this->_job_id); break; case 'delivered': $event = new CRM_Mailing_Event_BAO_Delivered(); return $event->getTotalCount($this->_mailing_id, $this->_job_id, $this->_is_distinct); break; case 'opened': $event = new CRM_Mailing_Event_BAO_Opened(); return $event->getTotalCount($this->_mailing_id, $this->_job_id, $this->_is_distinct); break; case 'bounce': $event = new CRM_Mailing_Event_BAO_Bounce(); return $event->getTotalCount($this->_mailing_id, $this->_job_id, $this->_is_distinct); break; case 'forward': $event = new CRM_Mailing_Event_BAO_Forward(); return $event->getTotalCount($this->_mailing_id, $this->_job_id, $this->_is_distinct); break; case 'reply': $event = new CRM_Mailing_Event_BAO_Reply(); return $event->getTotalCount($this->_mailing_id, $this->_job_id, $this->_is_distinct); break; case 'unsubscribe': $event = new CRM_Mailing_Event_BAO_Unsubscribe(); return $event->getTotalCount($this->_mailing_id, $this->_job_id, $this->_is_distinct); break; case 'optout': $event = new CRM_Mailing_Event_BAO_Unsubscribe(); return $event->getTotalCount($this->_mailing_id, $this->_job_id, $this->_is_distinct, FALSE); break; case 'click': $event = new CRM_Mailing_Event_BAO_TrackableURLOpen(); return $event->getTotalCount($this->_mailing_id, $this->_job_id, $this->_is_distinct, $this->_url_id); break; default: return 0; } }
/** * Returns total number of rows for the query. * * @param * @return int Total number of rows * @access public */ function getTotalCount($action) { switch ($this->_event_type) { case 'queue': require_once 'CRM/Mailing/Event/BAO/Queue.php'; $event = new CRM_Mailing_Event_BAO_Queue(); return $event->getTotalCount($this->_mailing_id, $this->_job_id); break; case 'delivered': require_once 'CRM/Mailing/Event/BAO/Delivered.php'; $event = new CRM_Mailing_Event_BAO_Delivered(); return $event->getTotalCount($this->_mailing_id, $this->_job_id, $this->_is_distinct); break; case 'opened': require_once 'CRM/Mailing/Event/BAO/Opened.php'; $event = new CRM_Mailing_Event_BAO_Opened(); return $event->getTotalCount($this->_mailing_id, $this->_job_id, $this->_is_distinct); break; case 'bounce': require_once 'CRM/Mailing/Event/BAO/Bounce.php'; $event = new CRM_Mailing_Event_BAO_Bounce(); return $event->getTotalCount($this->_mailing_id, $this->_job_id, $this->_is_distinct); break; case 'forward': require_once 'CRM/Mailing/Event/BAO/Forward.php'; $event = new CRM_Mailing_Event_BAO_Forward(); return $event->getTotalCount($this->_mailing_id, $this->_job_id, $this->_is_distinct); break; case 'reply': require_once 'CRM/Mailing/Event/BAO/Reply.php'; $event = new CRM_Mailing_Event_BAO_Reply(); return $event->getTotalCount($this->_mailing_id, $this->_job_id, $this->_is_distinct); break; case 'unsubscribe': require_once 'CRM/Mailing/Event/BAO/Unsubscribe.php'; $event = new CRM_Mailing_Event_BAO_Unsubscribe(); return $event->getTotalCount($this->_mailing_id, $this->_job_id, $this->_is_distinct); break; case 'click': require_once 'CRM/Mailing/Event/BAO/TrackableURLOpen.php'; $event = new CRM_Mailing_Event_BAO_TrackableURLOpen(); return $event->getTotalCount($this->_mailing_id, $this->_job_id, $this->_is_distinct, $this->_url_id); break; default: return 0; } }