/** * Function to set variables up before form is built * * @return void * @access public */ public function preProcess() { //get the activity values $activityId = CRM_Utils_Request::retrieve('id', 'Positive', $this); $context = CRM_Utils_Request::retrieve('context', 'String', $this); $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this); //check for required permissions, CRM-6264 if ($activityId && !CRM_Activity_BAO_Activity::checkPermission($activityId, CRM_Core_Action::VIEW)) { CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); } $session = CRM_Core_Session::singleton(); if (!in_array($context, array('home', 'dashlet', 'dashletFullscreen'))) { $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$cid}&selectedChild=activity"); } else { $url = CRM_Utils_System::url('civicrm/dashboard', 'reset=1'); } $session->pushUserContext($url); $defaults = array(); $params = array('id' => $activityId); CRM_Activity_BAO_Activity::retrieve($params, $defaults); //set activity type name and description to template list($activityTypeName, $activityTypeDescription) = CRM_Core_BAO_OptionValue::getActivityTypeDetails($defaults['activity_type_id']); $this->assign('activityTypeName', $activityTypeName); $this->assign('activityTypeDescription', $activityTypeDescription); if (CRM_Utils_Array::value('mailingId', $defaults)) { $this->_mailing_id = CRM_Utils_Array::value('source_record_id', $defaults); $mailingReport = CRM_Mailing_BAO_Mailing::report($this->_mailing_id, TRUE); CRM_Mailing_BAO_Mailing::getMailingContent($mailingReport, $this); $this->assign('mailingReport', $mailingReport); $full_open_report = CRM_Mailing_Event_BAO_Opened::getRows($this->_mailing_id, NULL, FALSE, NULL, NULL, NULL, $cid); $this->assign('openreport', $full_open_report); $click_thru_report = CRM_Mailing_Event_BAO_TrackableURLOpen::getRows($this->_mailing_id, NULL, FALSE, NULL, NULL, NULL, NULL, $cid); $this->assign('clickreport', $click_thru_report); } foreach ($defaults as $key => $value) { if (substr($key, -3) != '_id') { $values[$key] = $value; } } //get the campaign if ($campaignId = CRM_Utils_Array::value('campaign_id', $defaults)) { $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId); $values['campaign'] = $campaigns[$campaignId]; } if ($engagementLevel = CRM_Utils_Array::value('engagement_level', $defaults)) { $engagementLevels = CRM_Campaign_PseudoConstant::engagementLevel(); $values['engagement_level'] = CRM_Utils_Array::value($engagementLevel, $engagementLevels, $engagementLevel); } $values['attachment'] = CRM_Core_BAO_File::attachmentInfo('civicrm_activity', $activityId); $this->assign('values', $values); }
/** * 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); }
/** * returns all the rows in the given offset and rowCount * * @param enum $action the action being performed * @param int $offset the row number to start from * @param int $rowCount the number of rows to return * @param string $sort the sql string that describes the sort order * @param enum $output what should the result set include (web/email/csv) * * @return int the total number of rows for this action */ function &getRows($action, $offset, $rowCount, $sort, $output = NULL) { switch ($this->_event_type) { case 'queue': return CRM_Mailing_Event_BAO_Queue::getRows($this->_mailing_id, $this->_job_id, $offset, $rowCount, $sort); break; case 'delivered': return CRM_Mailing_Event_BAO_Delivered::getRows($this->_mailing_id, $this->_job_id, $this->_is_distinct, $offset, $rowCount, $sort); break; case 'opened': return CRM_Mailing_Event_BAO_Opened::getRows($this->_mailing_id, $this->_job_id, $this->_is_distinct, $offset, $rowCount, $sort); break; case 'bounce': return CRM_Mailing_Event_BAO_Bounce::getRows($this->_mailing_id, $this->_job_id, $this->_is_distinct, $offset, $rowCount, $sort); break; case 'forward': return CRM_Mailing_Event_BAO_Forward::getRows($this->_mailing_id, $this->_job_id, $this->_is_distinct, $offset, $rowCount, $sort); case 'reply': return CRM_Mailing_Event_BAO_Reply::getRows($this->_mailing_id, $this->_job_id, $this->_is_distinct, $offset, $rowCount, $sort); break; case 'unsubscribe': return CRM_Mailing_Event_BAO_Unsubscribe::getRows($this->_mailing_id, $this->_job_id, $this->_is_distinct, $offset, $rowCount, $sort, TRUE); break; case 'optout': return CRM_Mailing_Event_BAO_Unsubscribe::getRows($this->_mailing_id, $this->_job_id, $this->_is_distinct, $offset, $rowCount, $sort, FALSE); break; case 'click': return CRM_Mailing_Event_BAO_TrackableURLOpen::getRows($this->_mailing_id, $this->_job_id, $this->_is_distinct, $this->_url_id, $offset, $rowCount, $sort); break; default: return NULL; } }
/** * returns all the rows in the given offset and rowCount * * @param enum $action the action being performed * @param int $offset the row number to start from * @param int $rowCount the number of rows to return * @param string $sort the sql string that describes the sort order * @param enum $output what should the result set include (web/email/csv) * * @return int the total number of rows for this action */ function &getRows($action, $offset, $rowCount, $sort, $output = null) { switch ($this->_event_type) { case 'queue': require_once 'CRM/Mailing/Event/BAO/Queue.php'; return CRM_Mailing_Event_BAO_Queue::getRows($this->_mailing_id, $this->_job_id, $offset, $rowCount, $sort); break; case 'delivered': require_once 'CRM/Mailing/Event/BAO/Delivered.php'; return CRM_Mailing_Event_BAO_Delivered::getRows($this->_mailing_id, $this->_job_id, $this->_is_distinct, $offset, $rowCount, $sort); break; case 'opened': require_once 'CRM/Mailing/Event/BAO/Opened.php'; return CRM_Mailing_Event_BAO_Opened::getRows($this->_mailing_id, $this->_job_id, $this->_is_distinct, $offset, $rowCount, $sort); break; case 'bounce': require_once 'CRM/Mailing/Event/BAO/Bounce.php'; return CRM_Mailing_Event_BAO_Bounce::getRows($this->_mailing_id, $this->_job_id, $this->_is_distinct, $offset, $rowCount, $sort); break; case 'forward': require_once 'CRM/Mailing/Event/BAO/Forward.php'; return CRM_Mailing_Event_BAO_Forward::getRows($this->_mailing_id, $this->_job_id, $this->_is_distinct, $offset, $rowCount, $sort); case 'reply': require_once 'CRM/Mailing/Event/BAO/Reply.php'; return CRM_Mailing_Event_BAO_Reply::getRows($this->_mailing_id, $this->_job_id, $this->_is_distinct, $offset, $rowCount, $sort); break; case 'unsubscribe': require_once 'CRM/Mailing/Event/BAO/Unsubscribe.php'; return CRM_Mailing_Event_BAO_Unsubscribe::getRows($this->_mailing_id, $this->_job_id, $this->_is_distinct, $offset, $rowCount, $sort); break; case 'click': require_once 'CRM/Mailing/Event/BAO/TrackableURLOpen.php'; return CRM_Mailing_Event_BAO_TrackableURLOpen::getRows($this->_mailing_id, $this->_job_id, $this->_is_distinct, $this->_url_id, $offset, $rowCount, $sort); break; default: return null; } }