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 delete a group of
36 * contacts. This class provides functionality for the actual
37 * addition of contacts to groups.
39 class CRM_Activity_Form_Task_AddToTag
extends CRM_Activity_Form_Task
{
49 * All the tags in the system.
56 * Build the form object.
58 public function buildQuickForm() {
60 $this->_tags
= CRM_Core_BAO_Tag
::getTags('civicrm_activity');
62 foreach ($this->_tags
as $tagID => $tagName) {
63 $this->_tagElement
= &$this->addElement('checkbox', "tag[$tagID]", NULL, $tagName);
66 $parentNames = CRM_Core_BAO_Tag
::getTagSet('civicrm_activity');
68 CRM_Core_Form_Tag
::buildQuickForm($this, $parentNames, 'civicrm_activity');
70 $this->addDefaultButtons(ts('Tag Activities'));
73 public function addRules() {
74 $this->addFormRule(array('CRM_Activity_Form_Task_AddToTag', 'formRule'));
78 * @param CRM_Core_Form $form
83 public static function formRule($form, $rule) {
85 if (empty($form['tag']) && empty($form['activity_taglist'])) {
86 $errors['_qf_default'] = ts("Please select at least one tag.");
92 * Process the form after the input has been submitted and validated.
94 public function postProcess() {
95 //get the submitted values in an array
96 $params = $this->controller
->exportValues($this->_name
);
97 $activityTags = $tagList = array();
99 // check if contact tags exists
100 if (!empty($params['tag'])) {
101 $activityTags = $params['tag'];
104 // check if tags are selected from taglists
105 if (!empty($params['activity_taglist'])) {
106 foreach ($params['activity_taglist'] as $val) {
108 if (is_numeric($val)) {
112 $tagIDs = explode(',', $val);
113 if (!empty($tagIDs)) {
114 foreach ($tagIDs as $tagID) {
115 if (is_numeric($tagID)) {
116 $tagList[$tagID] = 1;
125 $tagSets = CRM_Core_BAO_Tag
::getTagsUsedFor('civicrm_activity', FALSE, TRUE);
127 foreach ($tagSets as $key => $value) {
128 $this->_tags
[$key] = $value['name'];
131 // merge activity and taglist tags
132 $allTags = CRM_Utils_Array
::crmArrayMerge($activityTags, $tagList);
134 $this->_name
= array();
135 foreach ($allTags as $key => $dnc) {
136 $this->_name
[] = $this->_tags
[$key];
138 list($total, $added, $notAdded) = CRM_Core_BAO_EntityTag
::addEntitiesToTag($this->_activityHolderIds
, $key, 'civicrm_activity');
140 $status = array(ts('Activity tagged', array('count' => $added, 'plural' => '%count activities tagged')));
142 $status[] = ts('1 activity already had this tag', array(
143 'count' => $notAdded,
144 'plural' => '%count activities already had this tag',
147 $status = '<ul><li>' . implode('</li><li>', $status) . '</li></ul>';
148 CRM_Core_Session
::setStatus($status, ts("Added Tag <em>%1</em>", array(1 => $this->_tags
[$key])), 'success', array('expires' => 0));