4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.3 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
32 * @copyright CiviCRM LLC (c) 2004-2013
36 class CRM_Pledge_BAO_Query
{
37 static function &getFields() {
38 $fields = CRM_Pledge_BAO_Pledge
::exportableFields();
43 * build select for Pledge
48 static function select(&$query) {
49 if (($query->_mode
& CRM_Contact_BAO_Query
::MODE_PLEDGE
) ||
50 CRM_Utils_Array
::value('pledge_id', $query->_returnProperties
)
52 $query->_select
['pledge_id'] = 'civicrm_pledge.id as pledge_id';
53 $query->_element
['pledge_id'] = 1;
54 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
58 if (CRM_Utils_Array
::value('pledge_amount', $query->_returnProperties
)) {
59 $query->_select
['pledge_amount'] = 'civicrm_pledge.amount as pledge_amount';
60 $query->_element
['pledge_amount'] = 1;
61 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
64 if (CRM_Utils_Array
::value('pledge_create_date', $query->_returnProperties
)) {
65 $query->_select
['pledge_create_date'] = 'civicrm_pledge.create_date as pledge_create_date';
66 $query->_element
['pledge_create_date'] = 1;
67 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
70 if (CRM_Utils_Array
::value('pledge_status_id', $query->_returnProperties
)) {
71 $query->_select
['pledge_status_id'] = 'pledge_status.value as pledge_status_id';
72 $query->_element
['pledge_status'] = 1;
73 $query->_tables
['pledge_status'] = $query->_whereTables
['pledge_status'] = 1;
74 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
77 if (CRM_Utils_Array
::value('pledge_status', $query->_returnProperties
)) {
78 $query->_select
['pledge_status'] = 'pledge_status.label as pledge_status';
79 $query->_element
['pledge_status'] = 1;
80 $query->_tables
['pledge_status'] = $query->_whereTables
['pledge_status'] = 1;
81 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
84 if (CRM_Utils_Array
::value('pledge_total_paid', $query->_returnProperties
)) {
85 $query->_select
['pledge_total_paid'] = ' (SELECT sum(civicrm_pledge_payment.actual_amount) FROM civicrm_pledge_payment WHERE civicrm_pledge_payment.pledge_id = civicrm_pledge.id AND civicrm_pledge_payment.status_id = 1 ) as pledge_total_paid';
86 $query->_element
['pledge_total_paid'] = 1;
89 if (CRM_Utils_Array
::value('pledge_next_pay_date', $query->_returnProperties
)) {
90 $query->_select
['pledge_next_pay_date'] = " (SELECT civicrm_pledge_payment.scheduled_date FROM civicrm_pledge_payment WHERE civicrm_pledge_payment.pledge_id = civicrm_pledge.id AND civicrm_pledge_payment.status_id IN ( 2, 6 ) ORDER BY civicrm_pledge_payment.scheduled_date ASC LIMIT 0, 1) as pledge_next_pay_date";
91 $query->_element
['pledge_next_pay_date'] = 1;
94 if (CRM_Utils_Array
::value('pledge_next_pay_amount', $query->_returnProperties
)) {
95 $query->_select
['pledge_next_pay_amount'] = " (SELECT civicrm_pledge_payment.scheduled_amount FROM civicrm_pledge_payment WHERE civicrm_pledge_payment.pledge_id = civicrm_pledge.id AND civicrm_pledge_payment.status_id = 2 ORDER BY civicrm_pledge_payment.scheduled_date ASC LIMIT 0, 1) as pledge_next_pay_amount";
96 $query->_element
['pledge_next_pay_amount'] = 1;
98 $query->_select
['pledge_outstanding_amount'] = " (SELECT sum(civicrm_pledge_payment.scheduled_amount) FROM civicrm_pledge_payment WHERE civicrm_pledge_payment.pledge_id = civicrm_pledge.id AND civicrm_pledge_payment.status_id = 6 ) as pledge_outstanding_amount";
99 $query->_element
['pledge_outstanding_amount'] = 1;
102 if (CRM_Utils_Array
::value('pledge_financial_type', $query->_returnProperties
)) {
103 $query->_select
['pledge_financial_type'] = "(SELECT civicrm_financial_type.name FROM civicrm_financial_type WHERE civicrm_financial_type.id = civicrm_pledge.financial_type_id) as pledge_financial_type";
104 $query->_element
['pledge_financial_type'] = 1;
105 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
108 if (CRM_Utils_Array
::value('pledge_contribution_page_id', $query->_returnProperties
)) {
109 $query->_select
['pledge_contribution_page_id'] = 'civicrm_pledge.contribution_page_id as pledge_contribution_page_id';
110 $query->_element
['pledge_contribution_page_id'] = 1;
111 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
114 if (CRM_Utils_Array
::value('pledge_payment_id', $query->_returnProperties
)) {
115 $query->_select
['pledge_payment_id'] = 'civicrm_pledge_payment.id as pledge_payment_id';
116 $query->_element
['pledge_payment_id'] = 1;
117 $query->_tables
['civicrm_pledge_payment'] = $query->_whereTables
['civicrm_pledge_payment'] = 1;
120 if (CRM_Utils_Array
::value('pledge_payment_scheduled_amount', $query->_returnProperties
)) {
121 $query->_select
['pledge_payment_scheduled_amount'] = 'civicrm_pledge_payment.scheduled_amount as pledge_payment_scheduled_amount';
122 $query->_element
['pledge_payment_scheduled_amount'] = 1;
123 $query->_tables
['civicrm_pledge_payment'] = $query->_whereTables
['civicrm_pledge_payment'] = 1;
126 if (CRM_Utils_Array
::value('pledge_payment_scheduled_date', $query->_returnProperties
)) {
127 $query->_select
['pledge_payment_scheduled_date'] = 'civicrm_pledge_payment.scheduled_date as pledge_payment_scheduled_date';
128 $query->_element
['pledge_payment_scheduled_date'] = 1;
129 $query->_tables
['civicrm_pledge_payment'] = $query->_whereTables
['civicrm_pledge_payment'] = 1;
132 if (CRM_Utils_Array
::value('pledge_payment_paid_amount', $query->_returnProperties
)) {
133 $query->_select
['pledge_payment_paid_amount'] = 'civicrm_pledge_payment.actual_amount as pledge_payment_paid_amount';
134 $query->_element
['pledge_payment_paid_amount'] = 1;
135 $query->_tables
['civicrm_pledge_payment'] = $query->_whereTables
['civicrm_pledge_payment'] = 1;
138 if (CRM_Utils_Array
::value('pledge_payment_paid_date', $query->_returnProperties
)) {
139 $query->_select
['pledge_payment_paid_date'] = 'payment_contribution.receive_date as pledge_payment_paid_date';
140 $query->_element
['pledge_payment_paid_date'] = 1;
141 $query->_tables
['civicrm_pledge_payment'] = $query->_whereTables
['civicrm_pledge_payment'] = 1;
142 $query->_tables
['payment_contribution'] = $query->_whereTables
['payment_contribution'] = 1;
145 if (CRM_Utils_Array
::value('pledge_payment_reminder_date', $query->_returnProperties
)) {
146 $query->_select
['pledge_payment_reminder_date'] = 'civicrm_pledge_payment.reminder_date as pledge_payment_reminder_date';
147 $query->_element
['pledge_payment_reminder_date'] = 1;
148 $query->_tables
['civicrm_pledge_payment'] = $query->_whereTables
['civicrm_pledge_payment'] = 1;
151 if (CRM_Utils_Array
::value('pledge_payment_reminder_count', $query->_returnProperties
)) {
152 $query->_select
['pledge_payment_reminder_count'] = 'civicrm_pledge_payment.reminder_count as pledge_payment_reminder_count';
153 $query->_element
['pledge_payment_reminder_count'] = 1;
154 $query->_tables
['civicrm_pledge_payment'] = $query->_whereTables
['civicrm_pledge_payment'] = 1;
157 if (CRM_Utils_Array
::value('pledge_payment_status_id', $query->_returnProperties
)) {
158 $query->_select
['pledge_payment_status_id'] = 'payment_status.name as pledge_payment_status_id';
159 $query->_element
['pledge_payment_status_id'] = 1;
160 $query->_tables
['payment_status'] = $query->_whereTables
['payment_status'] = 1;
161 $query->_tables
['civicrm_pledge_payment'] = $query->_whereTables
['civicrm_pledge_payment'] = 1;
164 if (CRM_Utils_Array
::value('pledge_payment_status', $query->_returnProperties
)) {
165 $query->_select
['pledge_payment_status'] = 'payment_status.label as pledge_payment_status';
166 $query->_element
['pledge_payment_status'] = 1;
167 $query->_tables
['payment_status'] = $query->_whereTables
['payment_status'] = 1;
168 $query->_tables
['civicrm_pledge_payment'] = $query->_whereTables
['civicrm_pledge_payment'] = 1;
171 if (CRM_Utils_Array
::value('pledge_frequency_interval', $query->_returnProperties
)) {
172 $query->_select
['pledge_frequency_interval'] = 'civicrm_pledge.frequency_interval as pledge_frequency_interval';
173 $query->_element
['pledge_frequency_interval'] = 1;
174 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
177 if (CRM_Utils_Array
::value('pledge_frequency_unit', $query->_returnProperties
)) {
178 $query->_select
['pledge_frequency_unit'] = 'civicrm_pledge.frequency_unit as pledge_frequency_unit';
179 $query->_element
['pledge_frequency_unit'] = 1;
180 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
183 if (CRM_Utils_Array
::value('pledge_is_test', $query->_returnProperties
)) {
184 $query->_select
['pledge_is_test'] = 'civicrm_pledge.is_test as pledge_is_test';
185 $query->_element
['pledge_is_test'] = 1;
186 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
188 if (CRM_Utils_Array
::value('pledge_campaign_id', $query->_returnProperties
)) {
189 $query->_select
['pledge_campaign_id'] = 'civicrm_pledge.campaign_id as pledge_campaign_id';
190 $query->_element
['pledge_campaign_id'] = 1;
191 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
194 if (CRM_Utils_Array
::value('pledge_currency', $query->_returnProperties
)) {
195 $query->_select
['pledge_currency'] = 'civicrm_pledge.currency as pledge_currency';
196 $query->_element
['pledge_currency'] = 1;
197 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
201 static function where(&$query) {
202 $testCondition = $grouping = NULL;
203 foreach (array_keys($query->_params
) as $id) {
204 if (!CRM_Utils_Array
::value(0, $query->_params
[$id])) {
207 if (substr($query->_params
[$id][0], 0, 7) == 'pledge_') {
208 if ($query->_mode
== CRM_Contact_BAO_QUERY
::MODE_CONTACTS
) {
209 $query->_useDistinct
= TRUE;
211 if ($query->_params
[$id][0] == 'participant_test') {
212 $testCondition = $id;
215 $grouping = $query->_params
[$id][3];
216 self
::whereClauseSingle($query->_params
[$id], $query);
219 // Only add test condition if other fields are selected
220 if ($grouping !== NULL && $testCondition &&
221 // we dont want to include all tests for sql OR CRM-7827
222 $query->getOperator() != 'OR'
224 self
::whereClauseSingle($query->_params
[$testCondition], $query);
228 static function whereClauseSingle(&$values, &$query) {
229 list($name, $op, $value, $grouping, $wildcard) = $values;
232 case 'pledge_create_date_low':
233 case 'pledge_create_date_high':
234 // process to / from date
235 $query->dateQueryBuilder($values,
236 'civicrm_pledge', 'pledge_create_date', 'create_date', 'Pledge Made'
238 case 'pledge_start_date_low':
239 case 'pledge_start_date_high':
240 // process to / from date
241 $query->dateQueryBuilder($values,
242 'civicrm_pledge', 'pledge_start_date', 'start_date', 'Pledge Start Date'
246 case 'pledge_end_date_low':
247 case 'pledge_end_date_high':
248 // process to / from date
249 $query->dateQueryBuilder($values,
250 'civicrm_pledge', 'pledge_end_date', 'end_date', 'Pledge End Date'
254 case 'pledge_payment_date_low':
255 case 'pledge_payment_date_high':
256 // process to / from date
257 $query->dateQueryBuilder($values,
258 'civicrm_pledge_payment', 'pledge_payment_date', 'scheduled_date', 'Payment Scheduled'
262 case 'pledge_amount':
263 case 'pledge_amount_low':
264 case 'pledge_amount_high':
265 // process min/max amount
266 $query->numberRangeBuilder($values,
267 'civicrm_pledge', 'pledge_amount', 'amount', 'Pledge Amount'
271 case 'pledge_status_id':
272 if (is_array($value)) {
273 foreach ($value as $k => $v) {
279 $status = implode(',', $val);
281 if (count($val) > 1) {
283 $status = "({$status})";
291 $statusValues = CRM_Core_OptionGroup
::values('contribution_status');
294 if (isset($val) && is_array($val)) {
295 foreach ($val as $id => $dontCare) {
296 $names[] = $statusValues[$id];
300 $names[] = $statusValues[$value];
303 $query->_qill
[$grouping][] = ts('Pledge Status %1', array(1 => $op)) . ' ' . implode(' ' . ts('or') . ' ', $names);
304 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause('civicrm_pledge.status_id',
309 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
312 case 'pledge_payment_status_id':
313 if (is_array($value)) {
314 foreach ($value as $k => $v) {
320 $status = implode(',', $val);
322 if (count($val) > 1) {
324 $status = "({$status})";
332 $statusValues = CRM_Core_OptionGroup
::values('contribution_status');
335 if (is_array($val)) {
336 foreach ($val as $id => $dontCare) {
337 $names[] = $statusValues[$id];
341 $names[] = $statusValues[$value];
344 $query->_qill
[$grouping][] = ts('Pledge Payment Status %1', array(1 => $op)) . ' ' . implode(' ' . ts('or') . ' ', $names);
345 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause('civicrm_pledge_payment.status_id',
350 $query->_tables
['civicrm_pledge_payment'] = $query->_whereTables
['civicrm_pledge_payment'] = 1;
354 case 'pledge_is_test':
355 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause('civicrm_pledge.is_test',
361 $query->_qill
[$grouping][] = ts('Pledge is a Test');
363 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
366 case 'pledge_financial_type_id':
367 $type = CRM_Contribute_PseudoConstant
::financialType($value);
368 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause('civicrm_pledge.financial_type_id',
373 $query->_qill
[$grouping][] = ts( 'Financial Type - %1', array( 1 => $type ) );
374 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
377 case 'pledge_contribution_page_id':
378 $page = CRM_Contribute_PseudoConstant
::contributionPage($value);
379 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause('civicrm_pledge.contribution_page_id',
384 $query->_qill
[$grouping][] = ts('Financial Page - %1', array(1 => $page));
385 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
388 case 'pledge_in_honor_of':
389 $strtolower = function_exists('mb_strtolower') ?
'mb_strtolower' : 'strtolower';
390 $name = trim($value);
391 $newName = str_replace(',', " ", $name);
392 $pieces = explode(' ', $newName);
393 foreach ($pieces as $piece) {
394 $value = $strtolower(CRM_Core_DAO
::escapeString(trim($piece)));
395 $value = "'%$value%'";
396 $sub[] = " ( pledge_contact_b.sort_name LIKE $value )";
399 $query->_where
[$grouping][] = ' ( ' . implode(' OR ', $sub) . ' ) ';
400 $query->_qill
[$grouping][] = ts('Honor name like - \'%1\'', array(1 => $name));
401 $query->_tables
['pledge_contact_b'] = $query->_whereTables
['pledge_contact_b'] = 1;
402 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
406 $query->_where
[$grouping][] = "civicrm_pledge.id $op $value";
407 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
410 case 'pledge_frequency_interval':
411 $query->_where
[$grouping][] = "civicrm_pledge.frequency_interval $op $value";
412 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
415 case 'pledge_frequency_unit':
416 $query->_where
[$grouping][] = "civicrm_pledge.frequency_unit $op $value";
417 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
420 case 'pledge_campaign_id':
423 'campaign' => $value,
424 'grouping' => $grouping,
425 'tableName' => 'civicrm_pledge',
427 CRM_Campaign_BAO_Query
::componentSearchClause($campParams, $query);
432 static function from($name, $mode, $side) {
436 case 'civicrm_pledge':
437 $from = " $side JOIN civicrm_pledge ON civicrm_pledge.contact_id = contact_a.id ";
440 case 'pledge_status':
441 $from .= " $side JOIN civicrm_option_group option_group_pledge_status ON (option_group_pledge_status.name = 'contribution_status')";
442 $from .= " $side JOIN civicrm_option_value pledge_status ON (civicrm_pledge.status_id = pledge_status.value AND option_group_pledge_status.id = pledge_status.option_group_id ) ";
445 case 'pledge_financial_type':
446 $from .= " $side JOIN civicrm_financial_type ON civicrm_pledge.financial_type_id = civicrm_financial_type.id ";
449 case 'pledge_contact_b':
450 $from .= " $side JOIN civicrm_contact pledge_contact_b ON (civicrm_pledge.honor_contact_id = pledge_contact_b.id )";
453 case 'civicrm_pledge_payment':
454 $from .= " $side JOIN civicrm_pledge_payment ON civicrm_pledge_payment.pledge_id = civicrm_pledge.id ";
457 case 'payment_contribution':
458 $from .= " $side JOIN civicrm_contribution payment_contribution ON civicrm_pledge_payment.contribution_id = payment_contribution.id ";
461 case 'payment_status':
462 $from .= " $side JOIN civicrm_option_group option_group_payment_status ON (option_group_payment_status.name = 'contribution_status')";
463 $from .= " $side JOIN civicrm_option_value payment_status ON (civicrm_pledge_payment.status_id = payment_status.value AND option_group_payment_status.id = payment_status.option_group_id ) ";
471 * getter for the qill object
477 return (isset($this->_qill
)) ?
$this->_qill
: "";
481 * Ideally this function should include fields that are displayed in the selector
483 static function defaultReturnProperties($mode,
484 $includeCustomFields = TRUE
488 if ($mode & CRM_Contact_BAO_Query
::MODE_PLEDGE
) {
491 'contact_sub_type' => 1,
495 'pledge_amount' => 1,
496 'pledge_total_paid' => 1,
497 'pledge_create_date' => 1,
498 'pledge_next_pay_date' => 1,
499 'pledge_next_pay_amount' => 1,
500 'pledge_status' => 1,
501 'pledge_status_id' => 1,
502 'pledge_is_test' => 1,
503 'pledge_contribution_page_id' => 1,
504 'pledge_financial_type' => 1,
505 'pledge_frequency_interval' => 1,
506 'pledge_frequency_unit' => 1,
507 'pledge_currency' => 1,
508 'pledge_campaign_id' => 1,
515 * This includes any extra fields that might need for export etc
517 static function extraReturnProperties($mode) {
520 if ($mode & CRM_Contact_BAO_Query
::MODE_PLEDGE
) {
522 'pledge_balance_amount' => 1,
523 'pledge_payment_id' => 1,
524 'pledge_payment_scheduled_amount' => 1,
525 'pledge_payment_scheduled_date' => 1,
526 'pledge_payment_paid_amount' => 1,
527 'pledge_payment_paid_date' => 1,
528 'pledge_payment_reminder_date' => 1,
529 'pledge_payment_reminder_count' => 1,
530 'pledge_payment_status_id' => 1,
531 'pledge_payment_status' => 1,
534 // also get all the custom pledge properties
535 $fields = CRM_Core_BAO_CustomField
::getFieldsForImport('Pledge');
536 if (!empty($fields)) {
537 foreach ($fields as $name => $dontCare) {
538 $properties[$name] = 1;
545 static function buildSearchForm(&$form) {
546 // pledge related dates
547 CRM_Core_Form_Date
::buildDateRange($form, 'pledge_start_date', 1, '_low', '_high', ts('From'), FALSE);
548 CRM_Core_Form_Date
::buildDateRange($form, 'pledge_end_date', 1, '_low', '_high', ts('From'), FALSE);
549 CRM_Core_Form_Date
::buildDateRange($form, 'pledge_create_date', 1, '_low', '_high', ts('From'), FALSE);
551 // pledge payment related dates
552 CRM_Core_Form_Date
::buildDateRange($form, 'pledge_payment_date', 1, '_low', '_high', ts('From'), FALSE);
554 $form->addYesNo('pledge_test', ts('Pledge is a Test?'));
555 $form->add('text', 'pledge_amount_low', ts('From'), array('size' => 8, 'maxlength' => 8));
556 $form->addRule('pledge_amount_low', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money
::format('9.99', ' '))), 'money');
558 $form->add('text', 'pledge_amount_high', ts('To'), array('size' => 8, 'maxlength' => 8));
559 $form->addRule('pledge_amount_high', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money
::format('99.99', ' '))), 'money');
561 $statusValues = CRM_Contribute_PseudoConstant
::contributionStatus();
563 // Remove status values that are only used for recurring contributions for now (Failed and In Progress).
564 unset($statusValues['4']);
566 foreach ($statusValues as $key => $val) {
567 $status[] = $form->createElement('advcheckbox', $key, NULL, $val);
570 $form->addGroup($status, 'pledge_status_id', ts('Pledge Status'));
572 //unset in progress for payment
573 unset($statusValues['5']);
575 foreach ($statusValues as $key => $val) {
576 $paymentStatus[] = $form->createElement('advcheckbox', $key, NULL, $val);
579 $form->addGroup($paymentStatus, 'pledge_payment_status_id', ts('Pledge Payment Status'));
581 $form->add('select', 'pledge_financial_type_id',
582 ts( 'Financial Type' ),
584 '' => ts('- select -')) +
585 CRM_Contribute_PseudoConstant
::financialType()
588 $form->add('select', 'pledge_contribution_page_id',
589 ts('Contribution Page'),
591 '' => ts('- any -')) +
592 CRM_Contribute_PseudoConstant
::contributionPage()
595 //add fields for honor search
596 $form->addElement('text', 'pledge_in_honor_of', ts('In Honor Of'));
598 //add fields for pledge frequency
599 $form->add('text', 'pledge_frequency_interval', ts('Every'), array('size' => 8, 'maxlength' => 8));
601 $frequencies = CRM_Core_OptionGroup
::values('recur_frequency_units');
602 foreach ($frequencies as $val => $label) {
603 $freqUnitsDisplay["'{$val}'"] = ts('%1(s)', array(1 => $label));
606 $form->add('select', 'pledge_frequency_unit',
607 ts('Pledge Frequency'),
609 '' => ts('- any -')) +
$freqUnitsDisplay
612 // add all the custom searchable fields
613 $pledge = array('Pledge');
614 $groupDetails = CRM_Core_BAO_CustomGroup
::getGroupDetail(NULL, TRUE, $pledge);
616 $form->assign('pledgeGroupTree', $groupDetails);
617 foreach ($groupDetails as $group) {
618 foreach ($group['fields'] as $field) {
619 $fieldId = $field['id'];
620 $elementName = 'custom_' . $fieldId;
621 CRM_Core_BAO_CustomField
::addQuickFormElement($form,
630 CRM_Campaign_BAO_Campaign
::addCampaignInComponentSearch($form, 'pledge_campaign_id');
632 $form->assign('validCiviPledge', TRUE);
633 $form->setDefaults(array('pledge_test' => 0));
636 static function searchAction(&$row, $id) {}
638 static function tableNames(&$tables) {
640 if (CRM_Utils_Array
::value('pledge_status', $tables) ||
641 CRM_Utils_Array
::value('civicrm_pledge_payment', $tables)
643 $tables = array_merge(array('civicrm_pledge' => 1), $tables);