Merge pull request #21729 from MegaphoneJon/financial-181-rc
[civicrm-core.git] / CRM / Case / Form / Task.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 * @package CRM
14 * @copyright CiviCRM LLC https://civicrm.org/licensing
15 */
16
17 /**
18 * This class generates form task actions for CiviCase.
19 */
20 class CRM_Case_Form_Task extends CRM_Core_Form_Task {
21
22 /**
23 * Must be set to entity table name (eg. civicrm_participant) by child class
24 * @var string
25 */
26 public static $tableName = 'civicrm_case';
27 /**
28 * Must be set to entity shortname (eg. event)
29 * @var string
30 */
31 public static $entityShortname = 'case';
32
33 /**
34 * @inheritDoc
35 */
36 public function setContactIDs() {
37 // @todo Parameters shouldn't be needed and should be class member
38 // variables instead, set appropriately by each subclass.
39 $this->_contactIds = $this->getContactIDsFromComponent($this->_entityIds,
40 'civicrm_case_contact', 'case_id'
41 );
42 }
43
44 /**
45 * Get the query mode (eg. CRM_Core_BAO_Query::MODE_CASE)
46 *
47 * @return int
48 */
49 public function getQueryMode() {
50 return CRM_Contact_BAO_Query::MODE_CASE;
51 }
52
53 /**
54 * Override of CRM_Core_Form_Task::orderBy()
55 *
56 * @return string
57 */
58 public function orderBy() {
59 if (empty($this->_entityIds)) {
60 return '';
61 }
62 $order_array = [];
63 foreach ($this->_entityIds as $item) {
64 // Ordering by conditional in mysql. This evaluates to 0 or 1, so we
65 // need to order DESC to get the '1'.
66 $order_array[] = 'case_id = ' . CRM_Core_DAO::escapeString($item) . ' DESC';
67 }
68 return 'ORDER BY ' . implode(',', $order_array);
69 }
70
71 /**
72 * Get the rows from the results to be pdf-d.
73 *
74 * @return array
75 */
76 protected function getRows(): array {
77 $rows = [];
78 foreach ($this->_contactIds as $index => $contactID) {
79 $caseID = $this->getVar('_caseId');
80 if (empty($caseID) && !empty($this->_caseIds[$index])) {
81 $caseID = $this->_caseIds[$index];
82 }
83 $rows[] = ['contactId' => $contactID, 'caseId' => $caseID];
84 }
85 return $rows;
86 }
87
88 /**
89 * Get the name of the table for the relevant entity.
90 *
91 * @return string
92 */
93 public function getTableName() {
94 return 'civicrm_case';
95 }
96
97 /**
98 * Get the entity alias field.
99 *
100 * @return string
101 */
102 public function getEntityAliasField() {
103 return 'case_id';
104 }
105
106 }