<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.7 |
+ | CiviCRM version 5 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2017 |
+ | Copyright CiviCRM LLC (c) 2004-2019 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
* @throws API_Exception
*/
function civicrm_api3_mailing_a_b_submit($params) {
- civicrm_api3_verify_mandatory($params, 'CRM_Mailing_DAO_MailingAB', array('id', 'status'));
+ civicrm_api3_verify_mandatory($params, 'CRM_Mailing_DAO_MailingAB', ['id', 'status']);
if (!isset($params['scheduled_date']) && !isset($updateParams['approval_date'])) {
throw new API_Exception("Missing parameter scheduled_date and/or approval_date");
throw new API_Exception("Missing mailing IDs for A/B test");
}
- $submitParams = CRM_Utils_Array::subset($params, array(
+ $submitParams = CRM_Utils_Array::subset($params, [
'scheduled_date',
'approval_date',
'approval_note',
'approval_status_id',
- ));
+ ]);
switch ($params['status']) {
case 'Testing':
if (!empty($dao->status) && $dao->status != 'Draft') {
throw new API_Exception("Cannot transition to state 'Testing'");
}
- civicrm_api3('Mailing', 'submit', $submitParams + array(
- 'id' => $dao->mailing_id_a,
- '_skip_evil_bao_auto_recipients_' => 0,
- ));
- civicrm_api3('Mailing', 'submit', $submitParams + array(
- 'id' => $dao->mailing_id_b,
- '_skip_evil_bao_auto_recipients_' => 1,
- ));
+ civicrm_api3('Mailing', 'submit', $submitParams + [
+ 'id' => $dao->mailing_id_a,
+ '_skip_evil_bao_auto_recipients_' => 0,
+ ]);
+ civicrm_api3('Mailing', 'submit', $submitParams + [
+ 'id' => $dao->mailing_id_b,
+ '_skip_evil_bao_auto_recipients_' => 1,
+ ]);
CRM_Mailing_BAO_MailingAB::distributeRecipients($dao);
break;
if ($dao->status != 'Testing') {
throw new API_Exception("Cannot transition to state 'Final'");
}
- civicrm_api3('Mailing', 'submit', $submitParams + array(
- 'id' => $dao->mailing_id_c,
- '_skip_evil_bao_auto_recipients_' => 1,
- ));
+ civicrm_api3('Mailing', 'submit', $submitParams + [
+ 'id' => $dao->mailing_id_c,
+ '_skip_evil_bao_auto_recipients_' => 1,
+ ]);
break;
default:
throw new API_Exception("Unrecognized submission status");
}
- return civicrm_api3('MailingAB', 'create', array(
+ return civicrm_api3('MailingAB', 'create', [
'id' => $dao->id,
'status' => $params['status'],
- 'options' => array(
+ 'options' => [
'reload' => 1,
- ),
- ));
+ ],
+ ]);
}
/**
* Array of parameters determined by getfields.
*/
function _civicrm_api3_mailing_a_b_graph_stats_spec(&$params) {
- $params['criteria'] = array(
+ $params['criteria'] = [
'title' => 'Criteria',
'default' => 'Open',
'type' => CRM_Utils_Type::T_STRING,
- );
+ ];
// mailing_ab_winner_criteria
$params['target_date']['title'] = 'Target Date';
$params['target_date']['type'] = CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME;
- $params['split_count'] = array(
+ $params['split_count'] = [
'title' => 'Split Count',
'api.default' => 6,
'type' => CRM_Utils_Type::T_INT,
- );
+ ];
$params['split_count_select']['title'] = 'Split Count Select';
$params['split_count_select']['api.required'] = 1;
$params['target_url']['title'] = 'Target URL';
function civicrm_api3_mailing_a_b_graph_stats($params) {
civicrm_api3_verify_mandatory($params,
'CRM_Mailing_DAO_MailingAB',
- array('id'),
+ ['id'],
FALSE
);
- $defaults = array(
+ $defaults = [
'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');
+ $mailingAB = civicrm_api3('MailingAB', 'getsingle', ['id' => $params['id']]);
+ $graphStats = [];
+ $ABFormat = ['A' => 'mailing_id_a', 'B' => 'mailing_id_b'];
foreach ($ABFormat as $name => $column) {
switch (strtolower($params['criteria'])) {
$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(
+ $graphStats[$name] = [
+ $params['split_count_select'] => [
'count' => CRM_Mailing_Event_BAO_Opened::getTotalCount($mailingAB[$column], NULL, TRUE, $toDate),
'time' => CRM_Utils_Date::customFormat($toDate),
- ),
- );
+ ],
+ ];
break;
case 'total unique clicks':
$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(
+ $graphStats[$name] = [
+ $params['split_count_select'] => [
'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':
$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(
+ $graphStats[$name] = [
+ $params['split_count_select'] => [
'count' => CRM_Mailing_Event_BAO_TrackableURLOpen::getTotalCount($params['mailing_id'], NULL, FALSE, $url_id, $toDate),
'time' => CRM_Utils_Date::customFormat($toDate),
- ),
- );
+ ],
+ ];
break;
}
}