Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
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 | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
32 | */ |
33 | ||
34 | /** | |
b8c71ffa | 35 | * This class generates task actions for CiviEvent. |
6a488035 TO |
36 | */ |
37 | class CRM_Pledge_Form_Task extends CRM_Core_Form { | |
38 | ||
39 | /** | |
fe482240 | 40 | * The task being performed. |
6a488035 TO |
41 | * |
42 | * @var int | |
43 | */ | |
44 | protected $_task; | |
45 | ||
46 | /** | |
fe482240 | 47 | * The additional clause that we restrict the search with. |
6a488035 TO |
48 | * |
49 | * @var string | |
50 | */ | |
51 | protected $_componentClause = NULL; | |
52 | ||
53 | /** | |
fe482240 | 54 | * The array that holds all the component ids. |
6a488035 TO |
55 | * |
56 | * @var array | |
57 | */ | |
58 | protected $_componentIds; | |
59 | ||
60 | /** | |
fe482240 | 61 | * The array that holds all the pledge ids. |
6a488035 TO |
62 | * |
63 | * @var array | |
64 | */ | |
65 | protected $_pledgeIds; | |
66 | ||
67 | /** | |
fe482240 | 68 | * Build all the data structures needed to build the form. |
6a488035 | 69 | */ |
00be9182 | 70 | public function preProcess() { |
6a488035 TO |
71 | self::preProcessCommon($this); |
72 | } | |
73 | ||
ffd93213 | 74 | /** |
c490a46a | 75 | * @param CRM_Core_Form $form |
ffd93213 EM |
76 | * @param bool $useTable |
77 | */ | |
00be9182 | 78 | public static function preProcessCommon(&$form, $useTable = FALSE) { |
6a488035 TO |
79 | $form->_pledgeIds = array(); |
80 | ||
81 | $values = $form->controller->exportValues('Search'); | |
82 | ||
83 | $form->_task = $values['task']; | |
84 | $pledgeTasks = CRM_Pledge_Task::tasks(); | |
85 | $form->assign('taskName', $pledgeTasks[$form->_task]); | |
86 | ||
87 | $ids = array(); | |
88 | if ($values['radio_ts'] == 'ts_sel') { | |
89 | foreach ($values as $name => $value) { | |
90 | if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) { | |
91 | $ids[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN); | |
92 | } | |
93 | } | |
94 | } | |
95 | else { | |
96 | $queryParams = $form->get('queryParams'); | |
098201d8 | 97 | $sortOrder = NULL; |
353ffa53 | 98 | if ($form->get(CRM_Utils_Sort::SORT_ORDER)) { |
481a74f4 | 99 | $sortOrder = $form->get(CRM_Utils_Sort::SORT_ORDER); |
6a488035 TO |
100 | } |
101 | $query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE, | |
102 | CRM_Contact_BAO_Query::MODE_PLEDGE | |
103 | ); | |
104 | $query->_distinctComponentClause = ' civicrm_pledge.id'; | |
105 | $query->_groupByComponentClause = ' GROUP BY civicrm_pledge.id '; | |
106 | ||
107 | $result = $query->searchQuery(0, 0, $sortOrder); | |
108 | while ($result->fetch()) { | |
109 | $ids[] = $result->pledge_id; | |
110 | } | |
111 | } | |
112 | ||
113 | if (!empty($ids)) { | |
114 | $form->_componentClause = ' civicrm_pledge.id IN ( ' . implode(',', $ids) . ' ) '; | |
115 | $form->assign('totalSelectedPledges', count($ids)); | |
116 | } | |
117 | ||
118 | $form->_pledgeIds = $form->_componentIds = $ids; | |
119 | ||
120 | //set the context for redirection for any task actions | |
121 | $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $form); | |
122 | $urlParams = 'force=1'; | |
123 | if (CRM_Utils_Rule::qfKey($qfKey)) { | |
124 | $urlParams .= "&qfKey=$qfKey"; | |
125 | } | |
126 | ||
127 | $session = CRM_Core_Session::singleton(); | |
128 | $session->replaceUserContext(CRM_Utils_System::url('civicrm/pledge/search', $urlParams)); | |
129 | } | |
130 | ||
131 | /** | |
132 | * Given the signer id, compute the contact id | |
133 | * since its used for things like send email | |
134 | */ | |
135 | public function setContactIDs() { | |
136 | $this->_contactIds = &CRM_Core_DAO::getContactIDsFromComponent($this->_pledgeIds, | |
137 | 'civicrm_pledge' | |
138 | ); | |
139 | } | |
140 | ||
141 | /** | |
100fef9d | 142 | * Simple shell that derived classes can call to add buttons to |
6a488035 TO |
143 | * the form with a customized title for the main Submit |
144 | * | |
3a1617b6 TO |
145 | * @param string $title |
146 | * Title of the main button. | |
dd244018 EM |
147 | * @param string $nextType |
148 | * @param string $backType | |
149 | * @param bool $submitOnce | |
6a488035 | 150 | */ |
00be9182 | 151 | public function addDefaultButtons($title, $nextType = 'next', $backType = 'back', $submitOnce = FALSE) { |
6a488035 TO |
152 | $this->addButtons(array( |
153 | array( | |
154 | 'type' => $nextType, | |
155 | 'name' => $title, | |
156 | 'isDefault' => TRUE, | |
157 | ), | |
158 | array( | |
159 | 'type' => $backType, | |
160 | 'name' => ts('Cancel'), | |
161 | ), | |
162 | ) | |
163 | ); | |
164 | } | |
96025800 | 165 | |
6a488035 | 166 | } |