3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 +--------------------------------------------------------------------+
14 * @copyright CiviCRM LLC https://civicrm.org/licensing
18 * This class generates form task actions for CiviCase.
20 class CRM_Case_Form_Task
extends CRM_Core_Form_Task
{
23 * Must be set to entity table name (eg. civicrm_participant) by child class
26 public static $tableName = 'civicrm_case';
28 * Must be set to entity shortname (eg. event)
31 public static $entityShortname = 'case';
36 public function setContactIDs() {
37 $this->_contactIds
= $this->getContactIDs();
41 * Get the query mode (eg. CRM_Core_BAO_Query::MODE_CASE)
45 public function getQueryMode() {
46 return CRM_Contact_BAO_Query
::MODE_CASE
;
50 * Override of CRM_Core_Form_Task::orderBy()
54 public function orderBy() {
55 if (empty($this->_entityIds
)) {
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';
64 return 'ORDER BY ' . implode(',', $order_array);
68 * Get the rows from the results to be pdf-d.
72 protected function getRows(): array {
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];
79 $rows[] = ['contact_id' => $contactID, 'schema' => ['caseId' => $caseID, 'contactId' => $contactID]];
85 * Get the name of the table for the relevant entity.
89 public function getTableName() {
90 return 'civicrm_case';
94 * Get the entity alias field.
98 public function getEntityAliasField() {
102 protected function getContactIDs(): array {
103 if (isset($this->_contactIds
)) {
104 return $this->_contactIds
;
106 $contactIDSFromUrl = CRM_Utils_Request
::retrieve('cid', 'CommaSeparatedIntegers', $this);
107 if (!empty($contactIDSFromUrl)) {
108 return explode(',', $contactIDSFromUrl);
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'
118 * Get the token processor schema required to list any tokens for this task.
122 protected function getTokenSchema(): array {
123 return ['contactId', 'caseId'];