From 425723d9ea5bb74bf7f28c80e42749d377ae1dff Mon Sep 17 00:00:00 2001 From: aditya-nambiar Date: Sat, 9 Aug 2014 11:34:12 +0530 Subject: [PATCH] Lisitng Page Fixes --- api/v3/Mailing.php | 69 +++++++++++++++++++++++++++++++++ api/v3/MailingEventQueue.php | 74 ++++++++++++++++++++++++++++++++++++ js/angular-crmMailingAB.js | 60 ++++++++++++++++++++++++----- partials/abtesting/list.html | 51 +++++++++++++++---------- partials/abtesting/main.html | 8 ++-- 5 files changed, 228 insertions(+), 34 deletions(-) create mode 100644 api/v3/MailingEventQueue.php diff --git a/api/v3/Mailing.php b/api/v3/Mailing.php index 9908539961..dfcb41cabb 100644 --- a/api/v3/Mailing.php +++ b/api/v3/Mailing.php @@ -387,4 +387,73 @@ function civicrm_api3_mailing_update_email_resetdate($params) { 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; +} + diff --git a/api/v3/MailingEventQueue.php b/api/v3/MailingEventQueue.php new file mode 100644 index 0000000000..acfc28d58c --- /dev/null +++ b/api/v3/MailingEventQueue.php @@ -0,0 +1,74 @@ +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; +} diff --git a/js/angular-crmMailingAB.js b/js/angular-crmMailingAB.js index 68cf7f5b9a..59d41596c4 100644 --- a/js/angular-crmMailingAB.js +++ b/js/angular-crmMailingAB.js @@ -21,7 +21,7 @@ function ($routeProvider) { $routeProvider.when('/mailing/abtesting', { templateUrl: partialUrl('list.html'), - controller: 'ListingCtrl', + controller: 'ABListingCtrl', resolve: { mailingList: function ($route, crmApi) { return crmApi('Mailing', 'get', {}); @@ -63,12 +63,12 @@ //----------------------------------------- // Add a new record by name. // Ex: - 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) { @@ -156,6 +156,7 @@ $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={}; @@ -246,7 +247,9 @@ return false; } - + $scope.sen = function(){ + $scope.sendtest=true; + } $scope.isHeader= function(hf){ return hf.component_type == "Header"; @@ -333,7 +336,7 @@ $scope.apply(); }; - + $scope.testmailid =""; $scope.incGroup = []; $scope.excGroup = []; $scope.incGroupids =[]; @@ -746,11 +749,6 @@ // 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){ @@ -780,6 +778,48 @@ }; }); + 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', diff --git a/partials/abtesting/list.html b/partials/abtesting/list.html index 5ebd02c3f6..7c1b708a8d 100644 --- a/partials/abtesting/list.html +++ b/partials/abtesting/list.html @@ -1,32 +1,41 @@
- A/B Testing + A/B Testing list
- - - - - - +
+
TitleId
+ + + + + - - - - - - - - + + + + + + + + + + + +
TitleId
{{ab.name}}{{ab.id}}Edit  - Results
{{ab.name}}{{ab.id}}Edit  + Results
+ + +
+
+ You have no A/B mailings +
- - - \ No newline at end of file diff --git a/partials/abtesting/main.html b/partials/abtesting/main.html index 11b2dcbcf3..8ec8210cfa 100644 --- a/partials/abtesting/main.html +++ b/partials/abtesting/main.html @@ -187,9 +187,11 @@ -
-

Send Test Mails

- + +

Send Test Mails

+ + +

When to Start


-- 2.25.1