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 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * Class for activity form task actions.
20 * FIXME: This needs refactoring to properly inherit from CRM_Core_Form_Task and share more functions.
22 class CRM_Activity_Form_Task
extends CRM_Core_Form_Task
{
25 * The array that holds all the member ids.
29 public $_activityHolderIds;
32 * Build all the data structures needed to build the form.
34 public function preProcess() {
35 self
::preProcessCommon($this);
39 * Common pre-process function.
41 * @param CRM_Core_Form $form
43 * @throws \CRM_Core_Exception
45 public static function preProcessCommon(&$form) {
46 $form->_activityHolderIds
= [];
48 $values = $form->controller
->exportValues($form->get('searchFormName'));
50 $form->_task
= $values['task'];
51 $activityTasks = CRM_Activity_Task
::tasks();
52 $form->assign('taskName', $activityTasks[$form->_task
]);
55 if ($values['radio_ts'] == 'ts_sel') {
56 foreach ($values as $name => $value) {
57 if (substr($name, 0, CRM_Core_Form
::CB_PREFIX_LEN
) == CRM_Core_Form
::CB_PREFIX
) {
58 $ids[] = substr($name, CRM_Core_Form
::CB_PREFIX_LEN
);
63 $queryParams = $form->get('queryParams');
64 $query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE,
65 CRM_Contact_BAO_Query
::MODE_ACTIVITY
67 $query->_distinctComponentClause
= '( civicrm_activity.id )';
68 $query->_groupByComponentClause
= " GROUP BY civicrm_activity.id ";
71 $activityClause = NULL;
73 $components = CRM_Core_Component
::getNames();
74 $componentClause = [];
75 foreach ($components as $componentID => $componentName) {
76 if ($componentName != 'CiviCase' && !CRM_Core_Permission
::check("access $componentName")) {
77 $componentClause[] = " (activity_type.component_id IS NULL OR activity_type.component_id <> {$componentID}) ";
80 if (!empty($componentClause)) {
81 $activityClause = implode(' AND ', $componentClause);
83 $result = $query->searchQuery(0, 0, NULL, FALSE, FALSE, FALSE, FALSE, FALSE, $activityClause);
85 while ($result->fetch()) {
86 if (!empty($result->activity_id
)) {
87 $ids[] = $result->activity_id
;
93 $form->_componentClause
= ' civicrm_activity.id IN ( ' . implode(',', $ids) . ' ) ';
94 $form->assign('totalSelectedActivities', count($ids));
97 $form->_activityHolderIds
= $form->_componentIds
= $ids;
99 // Set the context for redirection for any task actions.
100 $qfKey = CRM_Utils_Request
::retrieve('qfKey', 'String', $form);
101 $urlParams = 'force=1';
102 if (CRM_Utils_Rule
::qfKey($qfKey)) {
103 $urlParams .= "&qfKey=$qfKey";
106 $session = CRM_Core_Session
::singleton();
107 $searchFormName = strtolower($form->get('searchFormName'));
108 if ($searchFormName == 'search') {
109 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/activity/search', $urlParams));
112 $session->replaceUserContext(CRM_Utils_System
::url("civicrm/contact/search/$searchFormName",
119 * Given the membership id, compute the contact id
120 * since it's used for things like send email.
122 public function setContactIDs() {
123 $IDs = implode(',', $this->_activityHolderIds
);
125 $activityContacts = CRM_Activity_BAO_ActivityContact
::buildOptions('record_type_id', 'validate');
126 $sourceID = CRM_Utils_Array
::key('Activity Source', $activityContacts);
129 FROM civicrm_activity_contact
130 WHERE activity_id IN ( $IDs ) AND
131 record_type_id = {$sourceID}";
133 $dao = CRM_Core_DAO
::executeQuery($query);
134 while ($dao->fetch()) {
135 $contactIDs[] = $dao->contact_id
;
137 $this->_contactIds
= $contactIDs;
141 * Simple shell that derived classes can call to add buttons to
142 * the form with a customized title for the main Submit
144 * @param string $title
145 * Title of the main button.
146 * @param string $nextType
147 * Button type for the form after processing.
148 * @param string $backType
149 * @param bool $submitOnce
151 public function addDefaultButtons($title, $nextType = 'next', $backType = 'back', $submitOnce = FALSE) {
160 'name' => ts('Cancel'),