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) {
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 $grouping = $query->_params
[$id][3];
212 self
::whereClauseSingle($query->_params
[$id], $query);
217 static function whereClauseSingle(&$values, &$query) {
218 list($name, $op, $value, $grouping, $wildcard) = $values;
221 case 'pledge_create_date_low':
222 case 'pledge_create_date_high':
223 // process to / from date
224 $query->dateQueryBuilder($values,
225 'civicrm_pledge', 'pledge_create_date', 'create_date', 'Pledge Made'
227 case 'pledge_start_date_low':
228 case 'pledge_start_date_high':
229 // process to / from date
230 $query->dateQueryBuilder($values,
231 'civicrm_pledge', 'pledge_start_date', 'start_date', 'Pledge Start Date'
235 case 'pledge_end_date_low':
236 case 'pledge_end_date_high':
237 // process to / from date
238 $query->dateQueryBuilder($values,
239 'civicrm_pledge', 'pledge_end_date', 'end_date', 'Pledge End Date'
243 case 'pledge_payment_date_low':
244 case 'pledge_payment_date_high':
245 // process to / from date
246 $query->dateQueryBuilder($values,
247 'civicrm_pledge_payment', 'pledge_payment_date', 'scheduled_date', 'Payment Scheduled'
251 case 'pledge_amount':
252 case 'pledge_amount_low':
253 case 'pledge_amount_high':
254 // process min/max amount
255 $query->numberRangeBuilder($values,
256 'civicrm_pledge', 'pledge_amount', 'amount', 'Pledge Amount'
260 case 'pledge_status_id':
261 if (is_array($value)) {
262 foreach ($value as $k => $v) {
268 $status = implode(',', $val);
270 if (count($val) > 1) {
272 $status = "({$status})";
280 $statusValues = CRM_Core_OptionGroup
::values('contribution_status');
283 if (isset($val) && is_array($val)) {
284 foreach ($val as $id => $dontCare) {
285 $names[] = $statusValues[$id];
289 $names[] = $statusValues[$value];
292 $query->_qill
[$grouping][] = ts('Pledge Status %1', array(1 => $op)) . ' ' . implode(' ' . ts('or') . ' ', $names);
293 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause('civicrm_pledge.status_id',
298 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
301 case 'pledge_payment_status_id':
302 if (is_array($value)) {
303 foreach ($value as $k => $v) {
309 $status = implode(',', $val);
311 if (count($val) > 1) {
313 $status = "({$status})";
321 $statusValues = CRM_Core_OptionGroup
::values('contribution_status');
324 if (is_array($val)) {
325 foreach ($val as $id => $dontCare) {
326 $names[] = $statusValues[$id];
330 $names[] = $statusValues[$value];
333 $query->_qill
[$grouping][] = ts('Pledge Payment Status %1', array(1 => $op)) . ' ' . implode(' ' . ts('or') . ' ', $names);
334 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause('civicrm_pledge_payment.status_id',
339 $query->_tables
['civicrm_pledge_payment'] = $query->_whereTables
['civicrm_pledge_payment'] = 1;
343 case 'pledge_is_test':
344 // We dont want to include all tests for sql OR CRM-7827
345 if (!$value ||
$query->getOperator() != 'OR') {
346 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause('civicrm_pledge.is_test',
352 $query->_qill
[$grouping][] = ts('Pledge is a Test');
354 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
358 case 'pledge_financial_type_id':
359 $type = CRM_Contribute_PseudoConstant
::financialType($value);
360 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause('civicrm_pledge.financial_type_id',
365 $query->_qill
[$grouping][] = ts( 'Financial Type - %1', array( 1 => $type ) );
366 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
369 case 'pledge_contribution_page_id':
370 $page = CRM_Contribute_PseudoConstant
::contributionPage($value);
371 $query->_where
[$grouping][] = CRM_Contact_BAO_Query
::buildClause('civicrm_pledge.contribution_page_id',
376 $query->_qill
[$grouping][] = ts('Financial Page - %1', array(1 => $page));
377 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
380 case 'pledge_in_honor_of':
381 $strtolower = function_exists('mb_strtolower') ?
'mb_strtolower' : 'strtolower';
382 $name = trim($value);
383 $newName = str_replace(',', " ", $name);
384 $pieces = explode(' ', $newName);
385 foreach ($pieces as $piece) {
386 $value = $strtolower(CRM_Core_DAO
::escapeString(trim($piece)));
387 $value = "'%$value%'";
388 $sub[] = " ( pledge_contact_b.sort_name LIKE $value )";
391 $query->_where
[$grouping][] = ' ( ' . implode(' OR ', $sub) . ' ) ';
392 $query->_qill
[$grouping][] = ts('Honor name like - \'%1\'', array(1 => $name));
393 $query->_tables
['pledge_contact_b'] = $query->_whereTables
['pledge_contact_b'] = 1;
394 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
398 $query->_where
[$grouping][] = "civicrm_pledge.id $op $value";
399 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
402 case 'pledge_frequency_interval':
403 $query->_where
[$grouping][] = "civicrm_pledge.frequency_interval $op $value";
404 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
407 case 'pledge_frequency_unit':
408 $query->_where
[$grouping][] = "civicrm_pledge.frequency_unit $op $value";
409 $query->_tables
['civicrm_pledge'] = $query->_whereTables
['civicrm_pledge'] = 1;
412 case 'pledge_campaign_id':
415 'campaign' => $value,
416 'grouping' => $grouping,
417 'tableName' => 'civicrm_pledge',
419 CRM_Campaign_BAO_Query
::componentSearchClause($campParams, $query);
424 static function from($name, $mode, $side) {
428 case 'civicrm_pledge':
429 $from = " $side JOIN civicrm_pledge ON civicrm_pledge.contact_id = contact_a.id ";
432 case 'pledge_status':
433 $from .= " $side JOIN civicrm_option_group option_group_pledge_status ON (option_group_pledge_status.name = 'contribution_status')";
434 $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 ) ";
437 case 'pledge_financial_type':
438 $from .= " $side JOIN civicrm_financial_type ON civicrm_pledge.financial_type_id = civicrm_financial_type.id ";
441 case 'pledge_contact_b':
442 $from .= " $side JOIN civicrm_contact pledge_contact_b ON (civicrm_pledge.honor_contact_id = pledge_contact_b.id )";
445 case 'civicrm_pledge_payment':
446 $from .= " $side JOIN civicrm_pledge_payment ON civicrm_pledge_payment.pledge_id = civicrm_pledge.id ";
449 case 'payment_contribution':
450 $from .= " $side JOIN civicrm_contribution payment_contribution ON civicrm_pledge_payment.contribution_id = payment_contribution.id ";
453 case 'payment_status':
454 $from .= " $side JOIN civicrm_option_group option_group_payment_status ON (option_group_payment_status.name = 'contribution_status')";
455 $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 ) ";
463 * getter for the qill object
469 return (isset($this->_qill
)) ?
$this->_qill
: "";
473 * Ideally this function should include fields that are displayed in the selector
475 static function defaultReturnProperties($mode,
476 $includeCustomFields = TRUE
480 if ($mode & CRM_Contact_BAO_Query
::MODE_PLEDGE
) {
483 'contact_sub_type' => 1,
487 'pledge_amount' => 1,
488 'pledge_total_paid' => 1,
489 'pledge_create_date' => 1,
490 'pledge_next_pay_date' => 1,
491 'pledge_next_pay_amount' => 1,
492 'pledge_status' => 1,
493 'pledge_status_id' => 1,
494 'pledge_is_test' => 1,
495 'pledge_contribution_page_id' => 1,
496 'pledge_financial_type' => 1,
497 'pledge_frequency_interval' => 1,
498 'pledge_frequency_unit' => 1,
499 'pledge_currency' => 1,
500 'pledge_campaign_id' => 1,
507 * This includes any extra fields that might need for export etc
509 static function extraReturnProperties($mode) {
512 if ($mode & CRM_Contact_BAO_Query
::MODE_PLEDGE
) {
514 'pledge_balance_amount' => 1,
515 'pledge_payment_id' => 1,
516 'pledge_payment_scheduled_amount' => 1,
517 'pledge_payment_scheduled_date' => 1,
518 'pledge_payment_paid_amount' => 1,
519 'pledge_payment_paid_date' => 1,
520 'pledge_payment_reminder_date' => 1,
521 'pledge_payment_reminder_count' => 1,
522 'pledge_payment_status_id' => 1,
523 'pledge_payment_status' => 1,
526 // also get all the custom pledge properties
527 $fields = CRM_Core_BAO_CustomField
::getFieldsForImport('Pledge');
528 if (!empty($fields)) {
529 foreach ($fields as $name => $dontCare) {
530 $properties[$name] = 1;
537 static function buildSearchForm(&$form) {
538 // pledge related dates
539 CRM_Core_Form_Date
::buildDateRange($form, 'pledge_start_date', 1, '_low', '_high', ts('From'), FALSE);
540 CRM_Core_Form_Date
::buildDateRange($form, 'pledge_end_date', 1, '_low', '_high', ts('From'), FALSE);
541 CRM_Core_Form_Date
::buildDateRange($form, 'pledge_create_date', 1, '_low', '_high', ts('From'), FALSE);
543 // pledge payment related dates
544 CRM_Core_Form_Date
::buildDateRange($form, 'pledge_payment_date', 1, '_low', '_high', ts('From'), FALSE);
546 $form->addYesNo('pledge_test', ts('Pledge is a Test?'));
547 $form->add('text', 'pledge_amount_low', ts('From'), array('size' => 8, 'maxlength' => 8));
548 $form->addRule('pledge_amount_low', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money
::format('9.99', ' '))), 'money');
550 $form->add('text', 'pledge_amount_high', ts('To'), array('size' => 8, 'maxlength' => 8));
551 $form->addRule('pledge_amount_high', ts('Please enter a valid money value (e.g. %1).', array(1 => CRM_Utils_Money
::format('99.99', ' '))), 'money');
553 $statusValues = CRM_Contribute_PseudoConstant
::contributionStatus();
555 // Remove status values that are only used for recurring contributions for now (Failed and In Progress).
556 unset($statusValues['4']);
558 foreach ($statusValues as $key => $val) {
559 $status[] = $form->createElement('advcheckbox', $key, NULL, $val);
562 $form->addGroup($status, 'pledge_status_id', ts('Pledge Status'));
564 //unset in progress for payment
565 unset($statusValues['5']);
567 foreach ($statusValues as $key => $val) {
568 $paymentStatus[] = $form->createElement('advcheckbox', $key, NULL, $val);
571 $form->addGroup($paymentStatus, 'pledge_payment_status_id', ts('Pledge Payment Status'));
573 $form->add('select', 'pledge_financial_type_id',
574 ts( 'Financial Type' ),
576 '' => ts('- select -')) +
577 CRM_Contribute_PseudoConstant
::financialType()
580 $form->add('select', 'pledge_contribution_page_id',
581 ts('Contribution Page'),
583 '' => ts('- any -')) +
584 CRM_Contribute_PseudoConstant
::contributionPage()
587 //add fields for honor search
588 $form->addElement('text', 'pledge_in_honor_of', ts('In Honor Of'));
590 //add fields for pledge frequency
591 $form->add('text', 'pledge_frequency_interval', ts('Every'), array('size' => 8, 'maxlength' => 8));
593 $frequencies = CRM_Core_OptionGroup
::values('recur_frequency_units');
594 foreach ($frequencies as $val => $label) {
595 $freqUnitsDisplay["'{$val}'"] = ts('%1(s)', array(1 => $label));
598 $form->add('select', 'pledge_frequency_unit',
599 ts('Pledge Frequency'),
601 '' => ts('- any -')) +
$freqUnitsDisplay
604 // add all the custom searchable fields
605 $pledge = array('Pledge');
606 $groupDetails = CRM_Core_BAO_CustomGroup
::getGroupDetail(NULL, TRUE, $pledge);
608 $form->assign('pledgeGroupTree', $groupDetails);
609 foreach ($groupDetails as $group) {
610 foreach ($group['fields'] as $field) {
611 $fieldId = $field['id'];
612 $elementName = 'custom_' . $fieldId;
613 CRM_Core_BAO_CustomField
::addQuickFormElement($form,
622 CRM_Campaign_BAO_Campaign
::addCampaignInComponentSearch($form, 'pledge_campaign_id');
624 $form->assign('validCiviPledge', TRUE);
625 $form->setDefaults(array('pledge_test' => 0));
628 static function searchAction(&$row, $id) {}
630 static function tableNames(&$tables) {
632 if (CRM_Utils_Array
::value('pledge_status', $tables) ||
633 CRM_Utils_Array
::value('civicrm_pledge_payment', $tables)
635 $tables = array_merge(array('civicrm_pledge' => 1), $tables);