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 * This class provides the functionality to delete a group of
20 * contacts. This class provides functionality for the actual
21 * addition of contacts to groups.
23 class CRM_Activity_Form_Task_AddToTag
extends CRM_Activity_Form_Task
{
33 * All the tags in the system.
40 * Build the form object.
42 public function buildQuickForm() {
44 $this->_tags
= CRM_Core_BAO_Tag
::getTags('civicrm_activity');
46 foreach ($this->_tags
as $tagID => $tagName) {
47 $this->_tagElement
= &$this->addElement('checkbox', "tag[$tagID]", NULL, $tagName);
50 $parentNames = CRM_Core_BAO_Tag
::getTagSet('civicrm_activity');
52 CRM_Core_Form_Tag
::buildQuickForm($this, $parentNames, 'civicrm_activity');
54 $this->addDefaultButtons(ts('Tag Activities'));
57 public function addRules() {
58 $this->addFormRule(['CRM_Activity_Form_Task_AddToTag', 'formRule']);
62 * @param CRM_Core_Form $form
67 public static function formRule($form, $rule) {
69 if (empty($form['tag']) && empty($form['activity_taglist'])) {
70 $errors['_qf_default'] = ts("Please select at least one tag.");
76 * Process the form after the input has been submitted and validated.
78 public function postProcess() {
79 // Get the submitted values in an array.
80 $params = $this->controller
->exportValues($this->_name
);
81 $activityTags = $tagList = [];
83 // check if contact tags exists
84 if (!empty($params['tag'])) {
85 $activityTags = $params['tag'];
88 // check if tags are selected from taglists
89 if (!empty($params['activity_taglist'])) {
90 foreach ($params['activity_taglist'] as $val) {
92 if (is_numeric($val)) {
96 $tagIDs = explode(',', $val);
97 if (!empty($tagIDs)) {
98 foreach ($tagIDs as $tagID) {
99 if (is_numeric($tagID)) {
100 $tagList[$tagID] = 1;
109 $tagSets = CRM_Core_BAO_Tag
::getTagsUsedFor('civicrm_activity', FALSE, TRUE);
111 foreach ($tagSets as $key => $value) {
112 $this->_tags
[$key] = $value['name'];
115 // merge activity and taglist tags
116 $allTags = CRM_Utils_Array
::crmArrayMerge($activityTags, $tagList);
119 foreach ($allTags as $key => $dnc) {
120 $this->_name
[] = $this->_tags
[$key];
122 list($total, $added, $notAdded) = CRM_Core_BAO_EntityTag
::addEntitiesToTag($this->_activityHolderIds
, $key,
123 'civicrm_activity', FALSE);
125 $status = [ts('Activity tagged', ['count' => $added, 'plural' => '%count activities tagged'])];
127 $status[] = ts('1 activity already had this tag', [
128 'count' => $notAdded,
129 'plural' => '%count activities already had this tag',
132 $status = '<ul><li>' . implode('</li><li>', $status) . '</li></ul>';
133 CRM_Core_Session
::setStatus($status, ts("Added Tag <em>%1</em>", [1 => $this->_tags
[$key]]), 'success', ['expires' => 0]);