Merge pull request #18078 from eileenmcnaughton/directp
[civicrm-core.git] / CRM / Contribute / Form / Task / SearchTaskHookSample.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
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 |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * This class provides the functionality to save a search
20 * Saved Searches are used for saving frequently used queries
21 */
22 class CRM_Contribute_Form_Task_SearchTaskHookSample extends CRM_Contribute_Form_Task {
23
24 /**
25 * Build all the data structures needed to build the form.
26 */
27 public function preProcess() {
28 parent::preProcess();
29 $rows = [];
30 // display name and contribution details of all selected contacts
31 $contribIDs = implode(',', $this->_contributionIds);
32
33 $query = "
34 SELECT co.total_amount as amount,
35 co.receive_date as receive_date,
36 co.source as source,
37 ct.display_name as display_name
38 FROM civicrm_contribution co
39 INNER JOIN civicrm_contact ct ON ( co.contact_id = ct.id )
40 WHERE co.id IN ( $contribIDs )";
41
42 $dao = CRM_Core_DAO::executeQuery($query);
43
44 while ($dao->fetch()) {
45 $rows[] = [
46 'display_name' => $dao->display_name,
47 'amount' => $dao->amount,
48 'source' => $dao->source,
49 'receive_date' => $dao->receive_date,
50 ];
51 }
52 $this->assign('rows', $rows);
53 }
54
55 /**
56 * Build the form object.
57 */
58 public function buildQuickForm() {
59 $this->addButtons([
60 [
61 'type' => 'done',
62 'name' => ts('Done'),
63 'isDefault' => TRUE,
64 ],
65 ]);
66 }
67
68 }