Fix plural strings
[civicrm-core.git] / CRM / Activity / Form / Task / RemoveFromTag.php
CommitLineData
f70ca446
PN
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
f70ca446 5 +--------------------------------------------------------------------+
06b69b18 6 | Copyright CiviCRM LLC (c) 2004-2014 |
f70ca446
PN
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
d25dd0ee 26 */
f70ca446
PN
27
28/**
29 *
30 * @package CRM
06b69b18 31 * @copyright CiviCRM LLC (c) 2004-2014
f70ca446
PN
32 * $Id$
33 *
34 */
35
36/**
37 * This class provides the functionality to remove tags of contact(s).
38 */
39class CRM_Activity_Form_Task_RemoveFromTag extends CRM_Activity_Form_Task {
40
41 /**
100fef9d 42 * Name of the tag
f70ca446
PN
43 *
44 * @var string
45 */
46 protected $_name;
47
48 /**
100fef9d 49 * All the tags in the system
f70ca446
PN
50 *
51 * @var array
52 */
53 protected $_tags;
54
55 /**
c490a46a 56 * Build the form object
f70ca446 57 *
f70ca446
PN
58 *
59 * @return void
60 */
00be9182 61 public function buildQuickForm() {
f70ca446
PN
62 // add select for tag
63 $this->_tags = CRM_Core_BAO_Tag::getTags('civicrm_activity');
64 foreach ($this->_tags as $tagID => $tagName) {
65 $this->_tagElement = &$this->addElement('checkbox', "tag[$tagID]", NULL, $tagName);
66 }
67
68 $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_activity');
4dff5e17 69 CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, 'civicrm_activity', NULL, TRUE, FALSE);
f70ca446
PN
70
71 $this->addDefaultButtons(ts('Remove Tags from activities'));
72 }
73
00be9182 74 public function addRules() {
f70ca446
PN
75 $this->addFormRule(array('CRM_Activity_Form_Task_RemoveFromTag', 'formRule'));
76 }
77
ffd93213 78 /**
c490a46a 79 * @param CRM_Core_Form $form
ffd93213
EM
80 * @param $rule
81 *
82 * @return array
83 */
00be9182 84 public static function formRule($form, $rule) {
f70ca446
PN
85 $errors = array();
86 if (empty($form['tag']) && empty($form['activity_taglist'])) {
87 $errors['_qf_default'] = "Please select atleast one tag.";
88 }
89 return $errors;
90 }
91
92 /**
fe482240 93 * Process the form after the input has been submitted and validated.
f70ca446 94 *
f70ca446 95 *
355ba699 96 * @return void
f70ca446
PN
97 */
98 public function postProcess() {
99 //get the submitted values in an array
100 $params = $this->controller->exportValues($this->_name);
101
102 $activityTags = $tagList = array();
103
104 // check if contact tags exists
a7488080 105 if (!empty($params['tag'])) {
f70ca446
PN
106 $activityTags = $params['tag'];
107 }
108
109 // check if tags are selected from taglists
a7488080 110 if (!empty($params['activity_taglist'])) {
f70ca446
PN
111 foreach ($params['activity_taglist'] as $val) {
112 if ($val) {
113 if (is_numeric($val)) {
114 $tagList[$val] = 1;
115 }
116 else {
117 list($label, $tagID) = explode(',', $val);
118 $tagList[$tagID] = 1;
119 }
120 }
121 }
122 }
123 $tagSets = CRM_Core_BAO_Tag::getTagsUsedFor('civicrm_activity', FALSE, TRUE);
124
125 foreach ($tagSets as $key => $value) {
126 $this->_tags[$key] = $value['name'];
127 }
128 // merge contact and taglist tags
129 $allTags = CRM_Utils_Array::crmArrayMerge($activityTags, $tagList);
130
131 $this->_name = array();
132 foreach ($allTags as $key => $dnc) {
133 $this->_name[] = $this->_tags[$key];
134
135 list($total, $removed, $notRemoved) = CRM_Core_BAO_EntityTag::removeEntitiesFromTag($this->_activityHolderIds, $key, 'civicrm_activity');
136
353ffa53 137 $status = array(
99483ce8 138 ts('%count activity un-tagged', array(
353ffa53 139 'count' => $removed,
28a04ea9 140 'plural' => '%count activities un-tagged',
141 )),
353ffa53 142 );
f70ca446 143 if ($notRemoved) {
353ffa53
TO
144 $status[] = ts('1 activity already did not have this tag', array(
145 'count' => $notRemoved,
28a04ea9 146 'plural' => '%count activities already did not have this tag',
353ffa53 147 ));
f70ca446
PN
148 }
149 $status = '<ul><li>' . implode('</li><li>', $status) . '</li></ul>';
150 CRM_Core_Session::setStatus($status, ts("Removed Tag <em>%1</em>", array(1 => $this->_tags[$key])), 'success', array('expires' => 0));
151 }
152 }
96025800 153
f70ca446 154}