From: Tim Otten Date: Fri, 20 Feb 2015 02:25:57 +0000 (-0800) Subject: CRM-15801 - CiviMail - Change "Schedule/Send Mailing" task to use Angular UI. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=36c74cd65f834b34bfa30dc9b4e282d1938b13bb;p=civicrm-core.git CRM-15801 - CiviMail - Change "Schedule/Send Mailing" task to use Angular UI. --- diff --git a/CRM/Contact/Form/Task.php b/CRM/Contact/Form/Task.php index 1d1228e9f1..c1972e0662 100644 --- a/CRM/Contact/Form/Task.php +++ b/CRM/Contact/Form/Task.php @@ -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); + } + + } + } diff --git a/CRM/Contact/Task.php b/CRM/Contact/Task.php index c6e5825f44..0271dd0a08 100644 --- a/CRM/Contact/Task.php +++ b/CRM/Contact/Task.php @@ -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 index 0000000000..186a501260 --- /dev/null +++ b/CRM/Mailing/Form/Task/AdhocMailing.php @@ -0,0 +1,64 @@ +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'])); + } + +}