Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
6b83d5bd | 31 | * @copyright CiviCRM LLC (c) 2004-2019 |
6a488035 TO |
32 | */ |
33 | ||
34 | /** | |
31aaf096 MW |
35 | * Class for pledge form task actions. |
36 | * FIXME: This needs refactoring to properly inherit from CRM_Core_Form_Task and share more functions. | |
6a488035 | 37 | */ |
31aaf096 | 38 | class CRM_Pledge_Form_Task extends CRM_Core_Form_Task { |
6a488035 TO |
39 | |
40 | /** | |
fe482240 | 41 | * The array that holds all the pledge ids. |
6a488035 TO |
42 | * |
43 | * @var array | |
44 | */ | |
45 | protected $_pledgeIds; | |
46 | ||
47 | /** | |
fe482240 | 48 | * Build all the data structures needed to build the form. |
6a488035 | 49 | */ |
00be9182 | 50 | public function preProcess() { |
6a488035 TO |
51 | self::preProcessCommon($this); |
52 | } | |
53 | ||
ffd93213 | 54 | /** |
167bcb5f | 55 | * Common pre-processing. |
56 | * | |
c490a46a | 57 | * @param CRM_Core_Form $form |
ffd93213 | 58 | */ |
2b089ce1 | 59 | public static function preProcessCommon(&$form) { |
be2fb01f | 60 | $form->_pledgeIds = []; |
6a488035 TO |
61 | |
62 | $values = $form->controller->exportValues('Search'); | |
63 | ||
64 | $form->_task = $values['task']; | |
65 | $pledgeTasks = CRM_Pledge_Task::tasks(); | |
66 | $form->assign('taskName', $pledgeTasks[$form->_task]); | |
67 | ||
be2fb01f | 68 | $ids = []; |
6a488035 TO |
69 | if ($values['radio_ts'] == 'ts_sel') { |
70 | foreach ($values as $name => $value) { | |
71 | if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) { | |
72 | $ids[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN); | |
73 | } | |
74 | } | |
75 | } | |
76 | else { | |
77 | $queryParams = $form->get('queryParams'); | |
098201d8 | 78 | $sortOrder = NULL; |
353ffa53 | 79 | if ($form->get(CRM_Utils_Sort::SORT_ORDER)) { |
481a74f4 | 80 | $sortOrder = $form->get(CRM_Utils_Sort::SORT_ORDER); |
6a488035 TO |
81 | } |
82 | $query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE, | |
83 | CRM_Contact_BAO_Query::MODE_PLEDGE | |
84 | ); | |
85 | $query->_distinctComponentClause = ' civicrm_pledge.id'; | |
86 | $query->_groupByComponentClause = ' GROUP BY civicrm_pledge.id '; | |
87 | ||
88 | $result = $query->searchQuery(0, 0, $sortOrder); | |
89 | while ($result->fetch()) { | |
90 | $ids[] = $result->pledge_id; | |
91 | } | |
92 | } | |
93 | ||
94 | if (!empty($ids)) { | |
95 | $form->_componentClause = ' civicrm_pledge.id IN ( ' . implode(',', $ids) . ' ) '; | |
96 | $form->assign('totalSelectedPledges', count($ids)); | |
97 | } | |
98 | ||
99 | $form->_pledgeIds = $form->_componentIds = $ids; | |
100 | ||
cc28438b | 101 | // set the context for redirection for any task actions |
6a488035 TO |
102 | $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $form); |
103 | $urlParams = 'force=1'; | |
104 | if (CRM_Utils_Rule::qfKey($qfKey)) { | |
105 | $urlParams .= "&qfKey=$qfKey"; | |
106 | } | |
107 | ||
108 | $session = CRM_Core_Session::singleton(); | |
109 | $session->replaceUserContext(CRM_Utils_System::url('civicrm/pledge/search', $urlParams)); | |
110 | } | |
111 | ||
112 | /** | |
113 | * Given the signer id, compute the contact id | |
114 | * since its used for things like send email | |
115 | */ | |
116 | public function setContactIDs() { | |
ae18f7d8 | 117 | $this->_contactIds = CRM_Core_DAO::getContactIDsFromComponent($this->_pledgeIds, |
6a488035 TO |
118 | 'civicrm_pledge' |
119 | ); | |
120 | } | |
121 | ||
122 | /** | |
100fef9d | 123 | * Simple shell that derived classes can call to add buttons to |
6a488035 TO |
124 | * the form with a customized title for the main Submit |
125 | * | |
3a1617b6 TO |
126 | * @param string $title |
127 | * Title of the main button. | |
dd244018 EM |
128 | * @param string $nextType |
129 | * @param string $backType | |
130 | * @param bool $submitOnce | |
6a488035 | 131 | */ |
00be9182 | 132 | public function addDefaultButtons($title, $nextType = 'next', $backType = 'back', $submitOnce = FALSE) { |
be2fb01f CW |
133 | $this->addButtons([ |
134 | [ | |
6a488035 TO |
135 | 'type' => $nextType, |
136 | 'name' => $title, | |
137 | 'isDefault' => TRUE, | |
be2fb01f CW |
138 | ], |
139 | [ | |
6a488035 TO |
140 | 'type' => $backType, |
141 | 'name' => ts('Cancel'), | |
be2fb01f | 142 | ], |
c86d4e7c | 143 | ]); |
6a488035 | 144 | } |
96025800 | 145 | |
6a488035 | 146 | } |