Commit | Line | Data |
---|---|---|
2cc569f2 PJ |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
2cc569f2 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
2cc569f2 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
2cc569f2 PJ |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
2cc569f2 PJ |
16 | */ |
17 | ||
18 | /** | |
31aaf096 MW |
19 | * Class for mailing form task actions. |
20 | * FIXME: This needs refactoring to properly inherit from CRM_Core_Form_Task and share more functions. | |
2cc569f2 | 21 | */ |
31aaf096 | 22 | class CRM_Mailing_Form_Task extends CRM_Core_Form_Task { |
2cc569f2 | 23 | |
2cc569f2 | 24 | /** |
fe482240 | 25 | * Build all the data structures needed to build the form. |
2cc569f2 | 26 | */ |
00be9182 | 27 | public function preProcess() { |
2cc569f2 PJ |
28 | self::preProcessCommon($this); |
29 | } | |
30 | ||
e0ef6999 | 31 | /** |
2d09a0c3 | 32 | * @param \CRM_Core_Form_Task $form |
33 | * | |
34 | * @throws \CRM_Core_Exception | |
e0ef6999 | 35 | */ |
2b089ce1 | 36 | public static function preProcessCommon(&$form) { |
2d09a0c3 | 37 | $values = $form->getSearchFormValues(); |
2cc569f2 | 38 | |
9c1bc317 | 39 | $form->_task = $values['task'] ?? NULL; |
2cc569f2 | 40 | |
47546fcf | 41 | // ids are mailing event queue ids |
56752ec0 | 42 | $ids = $form->getSelectedIDs($values); |
43 | ||
44 | if (!$ids) { | |
2cc569f2 | 45 | $queryParams = $form->get('queryParams'); |
35f7561f | 46 | $sortOrder = NULL; |
353ffa53 | 47 | if ($form->get(CRM_Utils_Sort::SORT_ORDER)) { |
481a74f4 | 48 | $sortOrder = $form->get(CRM_Utils_Sort::SORT_ORDER); |
2cc569f2 PJ |
49 | } |
50 | ||
51 | $query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE, | |
52 | CRM_Contact_BAO_Query::MODE_MAILING | |
53 | ); | |
54 | ||
55 | $result = $query->searchQuery(0, 0, $sortOrder); | |
56 | while ($result->fetch()) { | |
335038eb | 57 | $ids[] = $result->mailing_recipients_id; |
2cc569f2 PJ |
58 | } |
59 | $form->assign('totalSelectedMailingRecipients', $form->get('rowCount')); | |
60 | } | |
61 | ||
62 | if (!empty($ids)) { | |
35f7561f | 63 | $form->_componentClause = ' civicrm_mailing_recipients.id IN ( ' . implode(',', $ids) . ' ) '; |
2cc569f2 PJ |
64 | } |
65 | ||
25606795 | 66 | // set the context for redirection for any task actions |
2cc569f2 PJ |
67 | $session = CRM_Core_Session::singleton(); |
68 | ||
69 | $fragment = 'search'; | |
70 | if ($form->_action == CRM_Core_Action::ADVANCED) { | |
71 | $fragment .= '/advanced'; | |
72 | } | |
73 | ||
74 | $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $form); | |
75 | $urlParams = 'force=1'; | |
76 | if (CRM_Utils_Rule::qfKey($qfKey)) { | |
77 | $urlParams .= "&qfKey=$qfKey"; | |
78 | } | |
79 | ||
80 | $url = CRM_Utils_System::url('civicrm/contact/' . $fragment, $urlParams); | |
81 | $session = CRM_Core_Session::singleton(); | |
82 | $session->replaceUserContext($url); | |
83 | } | |
84 | ||
85 | /** | |
100fef9d | 86 | * Simple shell that derived classes can call to add buttons to |
2cc569f2 PJ |
87 | * the form with a customized title for the main Submit |
88 | * | |
90c8230e TO |
89 | * @param string $title |
90 | * Title of the main button. | |
fd31fa4c EM |
91 | * @param string $nextType |
92 | * @param string $backType | |
93 | * @param bool $submitOnce | |
2cc569f2 | 94 | */ |
00be9182 | 95 | public function addDefaultButtons($title, $nextType = 'next', $backType = 'back', $submitOnce = FALSE) { |
be2fb01f | 96 | $this->addButtons([ |
7e8c8317 SL |
97 | [ |
98 | 'type' => $nextType, | |
99 | 'name' => $title, | |
100 | 'isDefault' => TRUE, | |
101 | ], | |
102 | [ | |
103 | 'type' => $backType, | |
104 | 'name' => ts('Cancel'), | |
105 | ], | |
106 | ]); | |
2cc569f2 | 107 | } |
96025800 | 108 | |
fd31fa4c | 109 | } |