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 remove tags of contact(s).
21 class CRM_Activity_Form_Task_RemoveFromTag
extends CRM_Activity_Form_Task
{
31 * All the tags in the system
38 * Build the form object.
40 public function buildQuickForm() {
42 $this->_tags
= CRM_Core_BAO_Tag
::getTags('civicrm_activity');
43 foreach ($this->_tags
as $tagID => $tagName) {
44 $this->_tagElement
= &$this->addElement('checkbox', "tag[$tagID]", NULL, $tagName);
47 $parentNames = CRM_Core_BAO_Tag
::getTagSet('civicrm_activity');
48 CRM_Core_Form_Tag
::buildQuickForm($this, $parentNames, 'civicrm_activity', NULL, TRUE, FALSE);
50 $this->addDefaultButtons(ts('Remove Tags from activities'));
53 public function addRules() {
54 $this->addFormRule(['CRM_Activity_Form_Task_RemoveFromTag', 'formRule']);
58 * @param CRM_Core_Form $form
63 public static function formRule($form, $rule) {
65 if (empty($form['tag']) && empty($form['activity_taglist'])) {
66 $errors['_qf_default'] = "Please select atleast one tag.";
72 * Process the form after the input has been submitted and validated.
74 public function postProcess() {
75 //get the submitted values in an array
76 $params = $this->controller
->exportValues($this->_name
);
78 $activityTags = $tagList = [];
80 // check if contact tags exists
81 if (!empty($params['tag'])) {
82 $activityTags = $params['tag'];
85 // check if tags are selected from taglists
86 if (!empty($params['activity_taglist'])) {
87 foreach ($params['activity_taglist'] as $val) {
89 if (is_numeric($val)) {
93 list($label, $tagID) = explode(',', $val);
99 $tagSets = CRM_Core_BAO_Tag
::getTagsUsedFor('civicrm_activity', FALSE, TRUE);
101 foreach ($tagSets as $key => $value) {
102 $this->_tags
[$key] = $value['name'];
104 // merge contact and taglist tags
105 $allTags = CRM_Utils_Array
::crmArrayMerge($activityTags, $tagList);
108 foreach ($allTags as $key => $dnc) {
109 $this->_name
[] = $this->_tags
[$key];
111 list($total, $removed, $notRemoved) = CRM_Core_BAO_EntityTag
::removeEntitiesFromTag($this->_activityHolderIds
,
112 $key, 'civicrm_activity', FALSE);
115 ts('%count activity un-tagged', [
117 'plural' => '%count activities un-tagged',
121 $status[] = ts('1 activity already did not have this tag', [
122 'count' => $notRemoved,
123 'plural' => '%count activities already did not have this tag',
126 $status = '<ul><li>' . implode('</li><li>', $status) . '</li></ul>';
127 CRM_Core_Session
::setStatus($status, ts("Removed Tag <em>%1</em>", [1 => $this->_tags
[$key]]), 'success', ['expires' => 0]);