Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
6a488035 | 13 | * @package CRM |
ca5cec67 | 14 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
15 | */ |
16 | ||
17 | /** | |
888da08c | 18 | * This class generates form task actions for CiviCase. |
6a488035 | 19 | */ |
888da08c | 20 | class CRM_Case_Form_Task extends CRM_Core_Form_Task { |
6a488035 | 21 | |
f157740d SL |
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'; | |
96025800 | 32 | |
d94a02b4 CW |
33 | /** |
34 | * @inheritDoc | |
35 | */ | |
36 | public function setContactIDs() { | |
dcecc495 | 37 | $this->_contactIds = $this->getContactIDs(); |
d94a02b4 CW |
38 | } |
39 | ||
a0174743 MW |
40 | /** |
41 | * Get the query mode (eg. CRM_Core_BAO_Query::MODE_CASE) | |
42 | * | |
43 | * @return int | |
44 | */ | |
45 | public function getQueryMode() { | |
46 | return CRM_Contact_BAO_Query::MODE_CASE; | |
47 | } | |
48 | ||
2e9051c7 D |
49 | /** |
50 | * Override of CRM_Core_Form_Task::orderBy() | |
51 | * | |
52 | * @return string | |
53 | */ | |
54 | public function orderBy() { | |
55 | if (empty($this->_entityIds)) { | |
56 | return ''; | |
57 | } | |
58 | $order_array = []; | |
59 | foreach ($this->_entityIds as $item) { | |
60 | // Ordering by conditional in mysql. This evaluates to 0 or 1, so we | |
61 | // need to order DESC to get the '1'. | |
62 | $order_array[] = 'case_id = ' . CRM_Core_DAO::escapeString($item) . ' DESC'; | |
63 | } | |
64 | return 'ORDER BY ' . implode(',', $order_array); | |
65 | } | |
66 | ||
c32592e1 EM |
67 | /** |
68 | * Get the rows from the results to be pdf-d. | |
69 | * | |
70 | * @return array | |
71 | */ | |
72 | protected function getRows(): array { | |
73 | $rows = []; | |
74 | foreach ($this->_contactIds as $index => $contactID) { | |
75 | $caseID = $this->getVar('_caseId'); | |
76 | if (empty($caseID) && !empty($this->_caseIds[$index])) { | |
77 | $caseID = $this->_caseIds[$index]; | |
78 | } | |
79 | $rows[] = ['contactId' => $contactID, 'caseId' => $caseID]; | |
80 | } | |
81 | return $rows; | |
82 | } | |
83 | ||
b4f826fe | 84 | /** |
85 | * Get the name of the table for the relevant entity. | |
86 | * | |
87 | * @return string | |
88 | */ | |
89 | public function getTableName() { | |
90 | return 'civicrm_case'; | |
91 | } | |
92 | ||
93 | /** | |
94 | * Get the entity alias field. | |
95 | * | |
96 | * @return string | |
97 | */ | |
98 | public function getEntityAliasField() { | |
99 | return 'case_id'; | |
100 | } | |
101 | ||
dcecc495 EM |
102 | protected function getContactIDs(): array { |
103 | if (isset($this->_contactIds)) { | |
104 | return $this->_contactIds; | |
105 | } | |
106 | $contactIDSFromUrl = CRM_Utils_Request::retrieve('cid', 'CommaSeparatedIntegers', $this); | |
107 | if (!empty($contactIDSFromUrl)) { | |
108 | return explode(',', $contactIDSFromUrl); | |
109 | } | |
110 | // @todo Parameters shouldn't be needed and should be class member | |
111 | // variables instead, set appropriately by each subclass. | |
112 | return $this->getContactIDsFromComponent($this->_entityIds, | |
113 | 'civicrm_case_contact', 'case_id' | |
114 | ); | |
115 | } | |
116 | ||
6a488035 | 117 | } |