CRM-15801 - CiviMail - Change "Schedule/Send Mailing" task to use Angular UI.
authorTim Otten <totten@civicrm.org>
Fri, 20 Feb 2015 02:25:57 +0000 (18:25 -0800)
committerTim Otten <totten@civicrm.org>
Fri, 20 Feb 2015 02:54:47 +0000 (18:54 -0800)
CRM/Contact/Form/Task.php
CRM/Contact/Task.php
CRM/Mailing/Form/Task/AdhocMailing.php [new file with mode: 0644]

index 1d1228e9f12bf5ab10a6fa431399ebb8b6511d76..c1972e0662c8b59bda553dc1fb04d8494a053ae3 100644 (file)
@@ -445,4 +445,65 @@ class CRM_Contact_Form_Task extends CRM_Core_Form {
     }
   }
 
+  /**
+   * Given this task's list of targets, produce a hidden group.
+   *
+   * @return array
+   *   Array(0 => int $groupID, 1 => int|NULL $ssID).
+   * @throws Exception
+   */
+  public function createHiddenGroup() {
+    // Did the user select "All" matches or cherry-pick a few records?
+    $searchParams = $this->controller->exportValues();
+    if ($searchParams['radio_ts'] == 'ts_sel') {
+      // Create a static group.
+
+      $randID = md5(time() . rand(1, 1000)); // groups require a unique name
+      $grpTitle = "Hidden Group {$randID}";
+      $grpID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Group', $grpTitle, 'id', 'title');
+
+      if (!$grpID) {
+        $groupParams = array(
+          'title' => $grpTitle,
+          'is_active' => 1,
+          'is_hidden' => 1,
+          'group_type' => array('2' => 1),
+        );
+
+        $group = CRM_Contact_BAO_Group::create($groupParams);
+        $grpID = $group->id;
+
+        CRM_Contact_BAO_GroupContact::addContactsToGroup($this->_contactIds, $group->id);
+
+        $newGroupTitle = "Hidden Group {$grpID}";
+        $groupParams = array(
+          'id' => $grpID,
+          'name' => CRM_Utils_String::titleToVar($newGroupTitle),
+          'title' => $newGroupTitle,
+          'group_type' => array('2' => 1),
+        );
+        $group = CRM_Contact_BAO_Group::create($groupParams);
+      }
+
+      // note at this point its a static group
+      return array($grpID, NULL);
+    }
+    else {
+      // Create a smart group.
+
+      $ssId = $this->get('ssID');
+      $hiddenSmartParams = array(
+        'group_type' => array('2' => 1),
+        'form_values' => $this->get('formValues'),
+        'saved_search_id' => $ssId,
+        'search_custom_id' => $this->get('customSearchID'),
+        'search_context' => $this->get('context'),
+      );
+
+      list($smartGroupId, $savedSearchId) = CRM_Contact_BAO_Group::createHiddenSmartGroup($hiddenSmartParams);
+      return array($smartGroupId, $savedSearchId);
+    }
+
+  }
+
 }
index c6e5825f44f06dc9e8eb1e9ebde21d3a5d86cd03..0271dd0a0802ba0d7be8466e5863b355683feb69 100644 (file)
@@ -237,32 +237,45 @@ class CRM_Contact_Task {
         );
       }
 
-      if (CRM_Core_Permission::access('CiviMail')) {
-        self::$_tasks[self::CREATE_MAILING] = array(
-          'title' => ts('Schedule/Send a Mass Mailing'),
-          'class' => array(
-            'CRM_Mailing_Form_Group',
-            'CRM_Mailing_Form_Settings',
-            'CRM_Mailing_Form_Upload',
-            'CRM_Mailing_Form_Test',
-            'CRM_Mailing_Form_Schedule',
-          ),
-          'result' => FALSE,
-        );
+      if (defined('CIVICRM_CIVIMAIL_UI_LEGACY')) {
+        if (CRM_Core_Permission::access('CiviMail')) {
+          self::$_tasks[self::CREATE_MAILING] = array(
+            'title' => ts('Schedule/Send a Mass Mailing'),
+            'class' => array(
+              'CRM_Mailing_Form_Group',
+              'CRM_Mailing_Form_Settings',
+              'CRM_Mailing_Form_Upload',
+              'CRM_Mailing_Form_Test',
+              'CRM_Mailing_Form_Schedule',
+            ),
+            'result' => FALSE,
+          );
+        }
+        elseif (CRM_Mailing_Info::workflowEnabled() &&
+          CRM_Core_Permission::check('create mailings')
+        ) {
+          self::$_tasks[self::CREATE_MAILING] = array(
+            'title' => ts('Create a Mass Mailing'),
+            'class' => array(
+              'CRM_Mailing_Form_Group',
+              'CRM_Mailing_Form_Settings',
+              'CRM_Mailing_Form_Upload',
+              'CRM_Mailing_Form_Test',
+            ),
+            'result' => FALSE,
+          );
+        }
       }
-      elseif (CRM_Mailing_Info::workflowEnabled() &&
-        CRM_Core_Permission::check('create mailings')
-      ) {
-        self::$_tasks[self::CREATE_MAILING] = array(
-          'title' => ts('Create a Mass Mailing'),
-          'class' => array(
-            'CRM_Mailing_Form_Group',
-            'CRM_Mailing_Form_Settings',
-            'CRM_Mailing_Form_Upload',
-            'CRM_Mailing_Form_Test',
-          ),
-          'result' => FALSE,
-        );
+      else {
+        if (CRM_Core_Permission::access('CiviMail')
+          || (CRM_Mailing_Info::workflowEnabled() && CRM_Core_Permission::check('create mailings'))
+        ) {
+          self::$_tasks[self::CREATE_MAILING] = array(
+            'title' => ts('Schedule/Send a Mass Mailing'),
+            'class' => 'CRM_Mailing_Form_Task_AdhocMailing',
+            'result' => FALSE,
+          );
+        }
       }
 
       self::$_tasks += CRM_Core_Component::taskList();
diff --git a/CRM/Mailing/Form/Task/AdhocMailing.php b/CRM/Mailing/Form/Task/AdhocMailing.php
new file mode 100644 (file)
index 0000000..186a501
--- /dev/null
@@ -0,0 +1,64 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.6                                                |
+ +--------------------------------------------------------------------+
+ | 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        |
+ +--------------------------------------------------------------------+
+ */
+
+/**
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC (c) 2004-2014
+ * $Id$
+ *
+ */
+
+/**
+ * Given the selected contacts, prepare a mailing with a hidden group.
+ */
+class CRM_Mailing_Form_Task_AdhocMailing extends CRM_Contact_Form_Task {
+
+  public function preProcess() {
+    parent::preProcess();
+    list ($groupId, $ssId) = $this->createHiddenGroup();
+    $mailing = civicrm_api3('Mailing', 'create', array(
+      'name' => "",
+      'campaign_id' => NULL,
+      'replyto_email' => "",
+      'subject' => "",
+      'body_html' => "",
+      'body_text' => "",
+      'groups' => array(
+        'include' => array($groupId),
+        'exclude' => array(),
+      ),
+      'mailings' => array(
+        'include' => array(),
+        'exclude' => array(),
+      ),
+    ));
+
+    CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/a/', NULL, TRUE, '/mailing/' . $mailing['id']));
+  }
+
+}