Merge pull request #17641 from MegaphoneJon/core-1590
[civicrm-core.git] / CRM / Contact / Form / Task / HookSample.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 *
21 * Saved Searches are used for saving frequently used queries
22 */
23 class CRM_Contact_Form_Task_HookSample extends CRM_Contact_Form_Task {
24
25 /**
26 * Build all the data structures needed to build the form.
27 */
28 public function preProcess() {
29 parent::preProcess();
30
31 // display name and email of all contact ids
32 $contactIDs = implode(',', $this->_contactIds);
33 $query = "
34 SELECT c.id as contact_id, c.display_name as name,
35 c.contact_type as contact_type, e.email as email
36 FROM civicrm_contact c, civicrm_email e
37 WHERE e.contact_id = c.id
38 AND e.is_primary = 1
39 AND c.id IN ( $contactIDs )";
40
41 $rows = [];
42 $dao = CRM_Core_DAO::executeQuery($query);
43 while ($dao->fetch()) {
44 $rows[] = [
45 'id' => $dao->contact_id,
46 'name' => $dao->name,
47 'contact_type' => $dao->contact_type,
48 'email' => $dao->email,
49 ];
50 }
51
52 $this->assign('rows', $rows);
53 }
54
55 /**
56 * Build the form object.
57 */
58 public function buildQuickForm() {
59 $this->addDefaultButtons(ts('Back to Search'), 'done');
60 }
61
62 /**
63 * Process the form after the input has been submitted and validated.
64 */
65 public function postProcess() {
66 }
67
68 }