3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
37 * This class provides the functionality to delete a group of
38 * contacts. This class provides functionality for the actual
39 * addition of contacts to groups.
41 class CRM_Contact_Form_Task_AddToTag
extends CRM_Contact_Form_Task
{
51 * All the tags in the system
58 * Build the form object
64 function buildQuickForm() {
66 $this->_tags
= CRM_Core_BAO_Tag
::getTags();
68 foreach ($this->_tags
as $tagID => $tagName) {
69 $this->_tagElement
= &$this->addElement('checkbox', "tag[$tagID]", NULL, $tagName);
72 $parentNames = CRM_Core_BAO_Tag
::getTagSet('civicrm_contact');
73 CRM_Core_Form_Tag
::buildQuickForm($this, $parentNames, 'civicrm_contact');
75 $this->addDefaultButtons(ts('Tag Contacts'));
79 $this->addFormRule(array('CRM_Contact_Form_Task_AddToTag', 'formRule'));
83 * @param CRM_Core_Form $form
88 static function formRule($form, $rule) {
90 if (empty($form['tag']) && empty($form['contact_taglist'])) {
91 $errors['_qf_default'] = ts("Please select at least one tag.");
97 * Process the form after the input has been submitted and validated
103 public function postProcess() {
104 //get the submitted values in an array
105 $params = $this->controller
->exportValues($this->_name
);
106 $contactTags = $tagList = array();
108 // check if contact tags exists
109 if (!empty($params['tag'])) {
110 $contactTags = $params['tag'];
113 // check if tags are selected from taglists
114 if (!empty($params['contact_taglist'])) {
115 foreach ($params['contact_taglist'] as $val) {
117 if (is_numeric($val)) {
121 $tagIDs = explode(',', $val);
122 if (!empty($tagIDs)) {
123 foreach ($tagIDs as $tagID) {
124 if (is_numeric($tagID)) {
125 $tagList[$tagID] = 1;
134 $tagSets = CRM_Core_BAO_Tag
::getTagsUsedFor('civicrm_contact', FALSE, TRUE);
136 foreach ($tagSets as $key => $value) {
137 $this->_tags
[$key] = $value['name'];
140 // merge contact and taglist tags
141 $allTags = CRM_Utils_Array
::crmArrayMerge($contactTags, $tagList);
143 $this->_name
= array();
144 foreach ($allTags as $key => $dnc) {
145 $this->_name
[] = $this->_tags
[$key];
147 list($total, $added, $notAdded) = CRM_Core_BAO_EntityTag
::addEntitiesToTag($this->_contactIds
, $key);
149 $status = array(ts('%count contact tagged', array('count' => $added, 'plural' => '%count contacts tagged')));
151 $status[] = ts('%count contact already had this tag', array('count' => $notAdded, 'plural' => '%count contacts already had this tag'));
153 $status = '<ul><li>' . implode('</li><li>', $status) . '</li></ul>';
154 CRM_Core_Session
::setStatus($status, ts("Added Tag <em>%1</em>", array(1 => $this->_tags
[$key])), 'success', array('expires' => 0));