Merge in 5.20
[civicrm-core.git] / CRM / Activity / 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_Activity_Form_Task_SearchTaskHookSample extends CRM_Activity_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 activity details of all selected contacts
31 $activityIDs = implode(',', $this->_activityHolderIds);
32
33 $activityContacts = CRM_Activity_BAO_ActivityContact::buildOptions('record_type_id', 'validate');
34 $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
35 $query = "
36 SELECT at.subject as subject,
37 ov.label as activity_type,
38 at.activity_date_time as activity_date,
39 ct.display_name as display_name
40 FROM civicrm_activity at
41 LEFT JOIN civicrm_activity_contact ac ON ( ac.activity_id = at.id AND ac.record_type_id = {$sourceID} )
42 INNER JOIN civicrm_contact ct ON ( ac.contact_id = ct.id )
43 LEFT JOIN civicrm_option_group og ON ( og.name = 'activity_type' )
44 LEFT JOIN civicrm_option_value ov ON (at.activity_type_id = ov.value AND og.id = ov.option_group_id )
45 WHERE at.id IN ( $activityIDs )";
46
47 $dao = CRM_Core_DAO::executeQuery($query);
48
49 while ($dao->fetch()) {
50 $rows[] = [
51 'subject' => $dao->subject,
52 'activity_type' => $dao->activity_type,
53 'activity_date' => $dao->activity_date,
54 'display_name' => $dao->display_name,
55 ];
56 }
57 $this->assign('rows', $rows);
58 }
59
60 /**
61 * Build the form object.
62 */
63 public function buildQuickForm() {
64 $this->addButtons([
65 [
66 'type' => 'done',
67 'name' => ts('Done'),
68 'isDefault' => TRUE,
69 ],
70 ]);
71 }
72
73 }