3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
35 * This class provides the functionality to remove tags of contact(s).
37 class CRM_Activity_Form_Task_RemoveFromTag
extends CRM_Activity_Form_Task
{
47 * All the tags in the system
54 * Build the form object.
56 public function buildQuickForm() {
58 $this->_tags
= CRM_Core_BAO_Tag
::getTags('civicrm_activity');
59 foreach ($this->_tags
as $tagID => $tagName) {
60 $this->_tagElement
= &$this->addElement('checkbox', "tag[$tagID]", NULL, $tagName);
63 $parentNames = CRM_Core_BAO_Tag
::getTagSet('civicrm_activity');
64 CRM_Core_Form_Tag
::buildQuickForm($this, $parentNames, 'civicrm_activity', NULL, TRUE, FALSE);
66 $this->addDefaultButtons(ts('Remove Tags from activities'));
69 public function addRules() {
70 $this->addFormRule(array('CRM_Activity_Form_Task_RemoveFromTag', 'formRule'));
74 * @param CRM_Core_Form $form
79 public static function formRule($form, $rule) {
81 if (empty($form['tag']) && empty($form['activity_taglist'])) {
82 $errors['_qf_default'] = "Please select atleast one tag.";
88 * Process the form after the input has been submitted and validated.
90 public function postProcess() {
91 //get the submitted values in an array
92 $params = $this->controller
->exportValues($this->_name
);
94 $activityTags = $tagList = array();
96 // check if contact tags exists
97 if (!empty($params['tag'])) {
98 $activityTags = $params['tag'];
101 // check if tags are selected from taglists
102 if (!empty($params['activity_taglist'])) {
103 foreach ($params['activity_taglist'] as $val) {
105 if (is_numeric($val)) {
109 list($label, $tagID) = explode(',', $val);
110 $tagList[$tagID] = 1;
115 $tagSets = CRM_Core_BAO_Tag
::getTagsUsedFor('civicrm_activity', FALSE, TRUE);
117 foreach ($tagSets as $key => $value) {
118 $this->_tags
[$key] = $value['name'];
120 // merge contact and taglist tags
121 $allTags = CRM_Utils_Array
::crmArrayMerge($activityTags, $tagList);
123 $this->_name
= array();
124 foreach ($allTags as $key => $dnc) {
125 $this->_name
[] = $this->_tags
[$key];
127 list($total, $removed, $notRemoved) = CRM_Core_BAO_EntityTag
::removeEntitiesFromTag($this->_activityHolderIds
, $key, 'civicrm_activity');
130 ts('%count activity un-tagged', array(
132 'plural' => '%count activities un-tagged',
136 $status[] = ts('1 activity already did not have this tag', array(
137 'count' => $notRemoved,
138 'plural' => '%count activities already did not have this tag',
141 $status = '<ul><li>' . implode('</li><li>', $status) . '</li></ul>';
142 CRM_Core_Session
::setStatus($status, ts("Removed Tag <em>%1</em>", array(1 => $this->_tags
[$key])), 'success', array('expires' => 0));