return civicrm_api3_create_success();
}
+function civicrm_api3_mailing_send_test($params) {
+ if (!array_key_exists('test_group', $params) && !array_key_exists('test_email', $params)) {
+ throw new API_Exception("Mandatory key(s) missing from params array: test_group and/or test_email field are required" );
+ }
+ civicrm_api3_verify_mandatory($params,
+ 'CRM_Mailing_DAO_MailingJob',
+ array('mailing_id'),
+ FALSE
+ );
+ $testEmailParams = _civicrm_api3_generic_replace_base_params($params);
+ $job = civicrm_api3('MailingJob', 'create', array('mailing_id' => $testEmailParams['mailing_id'], 'is_test' => 1));
+ $testEmailParams['job_id'] = $job['id'];
+ $testEmailParams['emails'] = explode(',', $testEmailParams['test_email']);
+ if (!empty($params['test_email'])) {
+ $query = "
+SELECT e.id, e.contact_id, e.email
+FROM civicrm_email e
+INNER JOIN civicrm_contact c ON e.contact_id = c.id
+WHERE e.email IN ('" . implode("','", $testEmailParams['emails']) . "')
+AND e.on_hold = 0
+AND c.is_opt_out = 0
+AND c.do_not_email = 0
+AND c.is_deceased = 0
+GROUP BY e.id
+ORDER BY e.is_bulkmail DESC, e.is_primary DESC
+";
+ $dao = CRM_Core_DAO::executeQuery($query);
+ $emailDetail = array();
+ // fetch contact_id and email id for all existing emails
+ while ($dao->fetch()) {
+ $emailDetail[$dao->email] = array(
+ 'contact_id' => $dao->contact_id,
+ 'email_id' => $dao->id,
+ );
+ }
+ $dao->free();
+ foreach ($testEmailParams['emails'] as $key => $email) {
+ $email = trim($email);
+ $contactId = $emailId = NULL;
+ if (array_key_exists($email, $emailDetail)) {
+ $emailId = $emailDetail[$email]['email_id'];
+ $contactId = $emailDetail[$email]['contact_id'];
+ }
+ if (!$contactId) {
+ //create new contact.
+ $contact = civicrm_api3('Contact', 'create',
+ array('contact_type' => 'Individual',
+ 'email' => $email,
+ 'api.Email.get' => array('return' => 'id')
+ )
+ );
+ $contactId = $contact['id'];
+ $emailId = $contact['values'][$contactId]['api.Email.get']['id'];
+ }
+ civicrm_api3('MailingEventQueue', 'create',
+ array('job_id' => $job['id'],
+ 'email_id' => $emailId,
+ 'contact_id' => $contactId
+ )
+ );
+ }
+ }
+ $isComplete = FALSE;
+ while (!$isComplete) {
+ $isComplete = CRM_Mailing_BAO_MailingJob::runJobs($testEmailParams);
+ }
+ return $isComplete;
+}
+
--- /dev/null
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.5 |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2014 |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM. |
+ | |
+ | CiviCRM is free software; you can copy, modify, and distribute it |
+ | under the terms of the GNU Affero General Public License |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
+ | |
+ | CiviCRM is distributed in the hope that it will be useful, but |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
+ | See the GNU Affero General Public License for more details. |
+ | |
+ | You should have received a copy of the GNU Affero General Public |
+ | License and the CiviCRM Licensing Exception along |
+ | with this program; if not, contact CiviCRM LLC |
+ | at info[AT]civicrm[DOT]org. If you have questions about the |
+ | GNU Affero General Public License or the licensing of CiviCRM, |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing |
+ +--------------------------------------------------------------------+
+*/
+/**
+ *
+ * APIv3 functions for registering/processing mailing group events.
+ *
+ * @package CiviCRM_APIv3
+ * @subpackage API_MailerGroup
+ * @copyright CiviCRM LLC (c) 2004-2014
+ * $Id$
+ *
+ */
+/**
+ * Handle a confirm event
+ *
+ * @param array $params Associative array of property
+ * name/value pairs to insert in new 'survey'
+ *
+ * @throws Exception
+ * @return array api result array
+ * {@getfields mailing_event_confirm_create}
+ * @access public
+ */
+function civicrm_api3_mailing_event_queue_create($params) {
+ if (!array_key_exists('email_id', $params) && !array_key_exists('phone_id', $params)) {
+ throw new API_Exception("Mandatory key(s) missing from params array: email_id or phone_id field are required" );
+ }
+ civicrm_api3_verify_mandatory($params,
+ 'CRM_Mailing_DAO_MailingJob',
+ array('job_id','contact_id'),
+ FALSE
+ );
+ $mailingEventQueueArray = array();
+ $mailingEventQueueBAO = CRM_Mailing_Event_BAO_Queue::create($params);
+ _civicrm_api3_object_to_array($mailingEventQueueBAO, $mailingEventQueueArray[$mailingEventQueueBAO->id]);
+ return civicrm_api3_create_success($mailingEventQueueArray);
+}
+function civicrm_api3_mailing_event_queue_get($params) {
+ return _civicrm_api3_basic_get('CRM_Mailing_Event_BAO_Queue', $params);
+}
+/**
+ * Adjust Metadata for Create action
+ *
+ * The metadata is used for setting defaults, documentation & validation
+ * @param array $params array or parameters determined by getfields
+ */
+function _civicrm_api3_mailing_event_queue_create_spec(&$params) {
+ $params['job_id']['api.required'] = 1;
+ $params['contact_id']['api.required'] = 1;
+}
function ($routeProvider) {
$routeProvider.when('/mailing/abtesting', {
templateUrl: partialUrl('list.html'),
- controller: 'ListingCtrl',
+ controller: 'ABListingCtrl',
resolve: {
mailingList: function ($route, crmApi) {
return crmApi('Mailing', 'get', {});
//-----------------------------------------
// Add a new record by name.
// Ex: <crmAddName crm-options="['Alpha','Beta','Gamma']" crm-var="newItem" crm-on-add="callMyCreateFunction(newItem)" />
- crmMailingAB.controller('ListingCtrl', function ($scope, crmApi) {
+ crmMailingAB.controller('ABListingCtrl', function ($scope, crmApi) {
$scope.abmailList = CRM.crmMailing.mailingabNames;
console.log($scope.abmailList);
- })
+ });
crmMailingAB.controller('ReportCtrl', function ($scope, crmApi,selectedABTest) {
$scope.mailC = {};
}
+ $scope.sendtest=false;
if(typeof $scope.mailA == 'undefined')$scope.mailA={};
if(typeof $scope.mailB == 'undefined')$scope.mailB={};
if(typeof $scope.mailB == 'undefined')$scope.mailC={};
return false;
}
-
+ $scope.sen = function(){
+ $scope.sendtest=true;
+ }
$scope.isHeader= function(hf){
return hf.component_type == "Header";
$scope.apply();
};
-
+ $scope.testmailid ="";
$scope.incGroup = [];
$scope.excGroup = [];
$scope.incGroupids =[];
// responsible for registering DOM listeners as well as updating the DOM
link: function (scope, element, attrs) {
-
-
-/*
- $(element).children().tabs( "enable", 2 );*/
-
scope.$watch('preview', function () {
if(scope.preview == true){
};
});
+ crmMailingAB.directive('sendmailtest', function () {
+ return {
+ // Restrict it to be an attribute in this case
+ restrict: 'AE',
+
+ link: function (scope, element, attrs) {
+
+ scope.$watch('sendtest', function () {
+ if(scope.sendtest == true){
+
+ $(element).dialog({
+ title: 'Send Test Mails',
+ width: 1080,
+ height: 800,
+ closed: false,
+ cache: false,
+ modal: true,
+ button:{
+ 'Send': function() {
+ /* Do stuff */
+ $(this).dialog('close');
+ }
+ },
+ close :function(){console.log("close");
+ scope.sendtest = false;scope.$apply()}
+
+
+ });
+ }
+
+ });
+
+
+ $(element).find("#closebutton").on("click", function () {
+ console.log("close");
+ scope.preview = false;
+ $(element).dialog("close");
+ });
+ }
+ };
+ });
+
crmMailingAB.directive('numbar', function () {
return{
restrict: 'AE',
<!--
-Controller: CaseTypeListsCtrl
-Required vars: caseTypes
+Controller: ABListingCtrl
+Required vars: abmailList
-->
<div id="help">
- A/B Testing
+ A/B Testing list
</div>
-<table class="display">
- <thead>
- <tr>
- <th>Title</th>
- <th>Id</th>
- <th></th>
+<div ng-show="abmailList.length > 0">
+ <table class="display">
+ <thead>
+ <tr>
+ <th>Title</th>
+ <th>Id</th>
+ <th></th>
- <th></th>
- </tr>
- </thead>
- <tbody>
- <tr ng-repeat="ab in abmailList">
- <td>{{ab.name}}</td>
- <td>{{ab.id}}</td>
- <td><a class="action-item crm-hover-button" ng-href="#/mailing/abtesting/{{ab.id}}">Edit</a> 
- <a class="action-item crm-hover-button" ng-href="#/mailing/abtesting/report/{{ab.id}}">Results</a></td>
+ <th></th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr ng-repeat="ab in abmailList">
+ <td>{{ab.name}}</td>
+ <td>{{ab.id}}</td>
+ <td><a class="action-item crm-hover-button" ng-href="#/mailing/abtesting/{{ab.id}}">Edit</a> 
+ <a class="action-item crm-hover-button" ng-href="#/mailing/abtesting/report/{{ab.id}}">Results</a></td>
+
+ </tr>
+ </tbody>
+ </table>
+</div>
+
+<div ng-show="abmailList.length == 0" class="messages status no-popup">
+ <div class="icon inform-icon"></div>
+ You have no A/B mailings
+</div>
- </tr>
- </tbody>
-</table>
<div class="crm-submit-buttons">
+ <br>
<a ng-href="#/mailing/abtesting/new" class="button"><span><div class="icon add-icon"></div>New A/B Test</span></a>
</div>
\ No newline at end of file
</div>
- </previewmail><br>
- <h3>Send Test Mails</h3>
-
+ </previewmail>
+ <h3 ng-click="sen()">Send Test Mails</h3>
+ <sendmailtest ng-show="sendtest">
+ <input type="text" ng-model="testmailid">
+ </sendmailtest>
<h3>When to Start</h3><br>