Merge pull request #15837 from totten/master-prtmpl
[civicrm-core.git] / CRM / Case / 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_Case_Form_Task_SearchTaskHookSample extends CRM_Case_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 email of all contact ids
31 $caseIDs = implode(',', $this->_entityIds);
32 $statusId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'case_status', 'id', 'name');
33 $query = "
34 SELECT ct.display_name as display_name,
35 cs.start_date as start_date,
36 ov.label as status
37
38 FROM civicrm_case cs
39 INNER JOIN civicrm_case_contact cc ON ( cs.id = cc.case_id)
40 INNER JOIN civicrm_contact ct ON ( cc.contact_id = ct.id)
41 LEFT JOIN civicrm_option_value ov ON (cs.status_id = ov.value AND ov.option_group_id = {$statusId} )
42 WHERE cs.id IN ( {$caseIDs} )";
43
44 $dao = CRM_Core_DAO::executeQuery($query);
45 while ($dao->fetch()) {
46 $rows[] = [
47 'display_name' => $dao->display_name,
48 'start_date' => CRM_Utils_Date::customFormat($dao->start_date),
49 'status' => $dao->status,
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 }