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 public static function preProcessCommon(&$form) {
44 $form->_activityHolderIds
= [];
46 $values = $form->controller
->exportValues($form->get('searchFormName'));
48 $form->_task
= $values['task'];
49 $activityTasks = CRM_Activity_Task
::tasks();
50 $form->assign('taskName', $activityTasks[$form->_task
]);
53 if ($values['radio_ts'] == 'ts_sel') {
54 foreach ($values as $name => $value) {
55 if (substr($name, 0, CRM_Core_Form
::CB_PREFIX_LEN
) == CRM_Core_Form
::CB_PREFIX
) {
56 $ids[] = substr($name, CRM_Core_Form
::CB_PREFIX_LEN
);
61 $queryParams = $form->get('queryParams');
62 $query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE,
63 CRM_Contact_BAO_Query
::MODE_ACTIVITY
65 $query->_distinctComponentClause
= '( civicrm_activity.id )';
66 $query->_groupByComponentClause
= " GROUP BY civicrm_activity.id ";
69 $activityClause = NULL;
71 $components = CRM_Core_Component
::getNames();
72 $componentClause = [];
73 foreach ($components as $componentID => $componentName) {
74 if ($componentName != 'CiviCase' && !CRM_Core_Permission
::check("access $componentName")) {
75 $componentClause[] = " (activity_type.component_id IS NULL OR activity_type.component_id <> {$componentID}) ";
78 if (!empty($componentClause)) {
79 $activityClause = implode(' AND ', $componentClause);
81 $result = $query->searchQuery(0, 0, NULL, FALSE, FALSE, FALSE, FALSE, FALSE, $activityClause);
83 while ($result->fetch()) {
84 if (!empty($result->activity_id
)) {
85 $ids[] = $result->activity_id
;
91 $form->_componentClause
= ' civicrm_activity.id IN ( ' . implode(',', $ids) . ' ) ';
92 $form->assign('totalSelectedActivities', count($ids));
95 $form->_activityHolderIds
= $form->_componentIds
= $ids;
97 // Set the context for redirection for any task actions.
98 $qfKey = CRM_Utils_Request
::retrieve('qfKey', 'String', $form);
99 $urlParams = 'force=1';
100 if (CRM_Utils_Rule
::qfKey($qfKey)) {
101 $urlParams .= "&qfKey=$qfKey";
104 $session = CRM_Core_Session
::singleton();
105 $searchFormName = strtolower($form->get('searchFormName'));
106 if ($searchFormName == 'search') {
107 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/activity/search', $urlParams));
110 $session->replaceUserContext(CRM_Utils_System
::url("civicrm/contact/search/$searchFormName",
117 * Given the membership id, compute the contact id
118 * since it's used for things like send email.
120 public function setContactIDs() {
121 $IDs = implode(',', $this->_activityHolderIds
);
123 $activityContacts = CRM_Activity_BAO_ActivityContact
::buildOptions('record_type_id', 'validate');
124 $sourceID = CRM_Utils_Array
::key('Activity Source', $activityContacts);
127 FROM civicrm_activity_contact
128 WHERE activity_id IN ( $IDs ) AND
129 record_type_id = {$sourceID}";
131 $dao = CRM_Core_DAO
::executeQuery($query);
132 while ($dao->fetch()) {
133 $contactIDs[] = $dao->contact_id
;
135 $this->_contactIds
= $contactIDs;
139 * Simple shell that derived classes can call to add buttons to
140 * the form with a customized title for the main Submit
142 * @param string $title
143 * Title of the main button.
144 * @param string $nextType
145 * Button type for the form after processing.
146 * @param string $backType
147 * @param bool $submitOnce
149 public function addDefaultButtons($title, $nextType = 'next', $backType = 'back', $submitOnce = FALSE) {
158 'name' => ts('Cancel'),