3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2018
35 * Class for activity form task actions.
36 * FIXME: This needs refactoring to properly inherit from CRM_Core_Form_Task and share more functions.
38 class CRM_Activity_Form_Task
extends CRM_Core_Form_Task
{
41 * The array that holds all the member ids.
45 public $_activityHolderIds;
48 * Build all the data structures needed to build the form.
50 public function preProcess() {
51 self
::preProcessCommon($this);
55 * Common pre-process function.
57 * @param CRM_Core_Form $form
59 public static function preProcessCommon(&$form) {
60 $form->_activityHolderIds
= array();
62 $values = $form->controller
->exportValues($form->get('searchFormName'));
64 $form->_task
= $values['task'];
65 $activityTasks = CRM_Activity_Task
::tasks();
66 $form->assign('taskName', $activityTasks[$form->_task
]);
69 if ($values['radio_ts'] == 'ts_sel') {
70 foreach ($values as $name => $value) {
71 if (substr($name, 0, CRM_Core_Form
::CB_PREFIX_LEN
) == CRM_Core_Form
::CB_PREFIX
) {
72 $ids[] = substr($name, CRM_Core_Form
::CB_PREFIX_LEN
);
77 $queryParams = $form->get('queryParams');
78 $query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE,
79 CRM_Contact_BAO_Query
::MODE_ACTIVITY
81 $query->_distinctComponentClause
= '( civicrm_activity.id )';
82 $query->_groupByComponentClause
= " GROUP BY civicrm_activity.id ";
85 $activityClause = NULL;
87 $components = CRM_Core_Component
::getNames();
88 $componentClause = array();
89 foreach ($components as $componentID => $componentName) {
90 if ($componentName != 'CiviCase' && !CRM_Core_Permission
::check("access $componentName")) {
91 $componentClause[] = " (activity_type.component_id IS NULL OR activity_type.component_id <> {$componentID}) ";
94 if (!empty($componentClause)) {
95 $activityClause = implode(' AND ', $componentClause);
97 $result = $query->searchQuery(0, 0, NULL, FALSE, FALSE, FALSE, FALSE, FALSE, $activityClause);
99 while ($result->fetch()) {
100 if (!empty($result->activity_id
)) {
101 $ids[] = $result->activity_id
;
107 $form->_componentClause
= ' civicrm_activity.id IN ( ' . implode(',', $ids) . ' ) ';
108 $form->assign('totalSelectedActivities', count($ids));
111 $form->_activityHolderIds
= $form->_componentIds
= $ids;
113 // Set the context for redirection for any task actions.
114 $qfKey = CRM_Utils_Request
::retrieve('qfKey', 'String', $form);
115 $urlParams = 'force=1';
116 if (CRM_Utils_Rule
::qfKey($qfKey)) {
117 $urlParams .= "&qfKey=$qfKey";
120 $session = CRM_Core_Session
::singleton();
121 $searchFormName = strtolower($form->get('searchFormName'));
122 if ($searchFormName == 'search') {
123 $session->replaceUserContext(CRM_Utils_System
::url('civicrm/activity/search', $urlParams));
126 $session->replaceUserContext(CRM_Utils_System
::url("civicrm/contact/search/$searchFormName",
133 * Given the membership id, compute the contact id
134 * since it's used for things like send email.
136 public function setContactIDs() {
137 $IDs = implode(',', $this->_activityHolderIds
);
139 $activityContacts = CRM_Activity_BAO_ActivityContact
::buildOptions('record_type_id', 'validate');
140 $sourceID = CRM_Utils_Array
::key('Activity Source', $activityContacts);
143 FROM civicrm_activity_contact
144 WHERE activity_id IN ( $IDs ) AND
145 record_type_id = {$sourceID}";
147 $dao = CRM_Core_DAO
::executeQuery($query);
148 while ($dao->fetch()) {
149 $contactIDs[] = $dao->contact_id
;
151 $this->_contactIds
= $contactIDs;
155 * Simple shell that derived classes can call to add buttons to
156 * the form with a customized title for the main Submit
158 * @param string $title
159 * Title of the main button.
160 * @param string $nextType
161 * Button type for the form after processing.
162 * @param string $backType
163 * @param bool $submitOnce
165 public function addDefaultButtons($title, $nextType = 'next', $backType = 'back', $submitOnce = FALSE) {
166 $this->addButtons(array(
174 'name' => ts('Cancel'),