--CRM-13578
authorPradeep Nayak <pradeep.nayak@webaccess.co.in>
Mon, 21 Oct 2013 10:10:42 +0000 (15:40 +0530)
committerPradeep Nayak <pradeep.nayak@webaccess.co.in>
Mon, 21 Oct 2013 10:10:42 +0000 (15:40 +0530)
----------------------------------------
* CRM-13578: Tag Activities (assign tags) Action
  http://issues.civicrm.org/jira/browse/CRM-13578

CRM/Activity/Form/Task/AddToTag.php [new file with mode: 0644]
CRM/Activity/Form/Task/RemoveFromTag.php [new file with mode: 0644]
CRM/Activity/Task.php
CRM/Core/Form/Tag.php
templates/CRM/Activity/Form/Task/AddToTag.tpl [new file with mode: 0644]
templates/CRM/Activity/Form/Task/RemoveFromTag.tpl [new file with mode: 0644]

diff --git a/CRM/Activity/Form/Task/AddToTag.php b/CRM/Activity/Form/Task/AddToTag.php
new file mode 100644 (file)
index 0000000..d2cbed4
--- /dev/null
@@ -0,0 +1,155 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.4                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2013                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+*/
+
+/**
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC (c) 2004-2013
+ * $Id$
+ *
+ */
+
+/**
+ * This class provides the functionality to delete a group of
+ * contacts. This class provides functionality for the actual
+ * addition of contacts to groups.
+ */
+class CRM_Activity_Form_Task_AddToTag extends CRM_Activity_Form_Task {
+
+  /**
+   * name of the tag
+   *
+   * @var string
+   */
+  protected $_name;
+
+  /**
+   * all the tags in the system
+   *
+   * @var array
+   */
+  protected $_tags;
+
+  /**
+   * Build the form
+   *
+   * @access public
+   *
+   * @return void
+   */
+  function buildQuickForm() {
+    // add select for tag
+    $this->_tags = CRM_Core_BAO_Tag::getTags('civicrm_activity');
+
+    foreach ($this->_tags as $tagID => $tagName) {
+      $this->_tagElement = &$this->addElement('checkbox', "tag[$tagID]", NULL, $tagName);
+    }
+
+    $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_activity');
+
+    CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, 'civicrm_activity');
+
+    $this->addDefaultButtons(ts('Tag Activities'));
+  }
+
+  function addRules() {
+    $this->addFormRule(array('CRM_Activity_Form_Task_AddToTag', 'formRule'));
+  }
+
+  static function formRule($form, $rule) {
+    $errors = array();
+    if (empty($form['tag']) && empty($form['activity_taglist'])) {
+      $errors['_qf_default'] = ts("Please select at least one tag.");
+    }
+    return $errors;
+  }
+
+  /**
+   * process the form after the input has been submitted and validated
+   *
+   * @access public
+   *
+   * @return None
+   */
+  public function postProcess() {
+    //get the submitted values in an array
+    $params = $this->controller->exportValues($this->_name);
+    $activityTags = $tagList = array();
+
+    // check if contact tags exists
+    if (CRM_Utils_Array::value('tag', $params)) {
+      $activityTags = $params['tag'];
+    }
+
+    // check if tags are selected from taglists
+    if (CRM_Utils_Array::value('activity_taglist', $params)) {
+      foreach ($params['activity_taglist'] as $val) {
+        if ($val) {
+          if (is_numeric($val)) {
+            $tagList[$val] = 1;
+          }
+          else {
+            $tagIDs = explode(',', $val);
+            if (!empty($tagIDs)) {
+              foreach ($tagIDs as $tagID) {
+                if (is_numeric($tagID)) {
+                  $tagList[$tagID] = 1;
+                }
+              }
+            }
+          }
+        }
+      }
+    }
+
+    $tagSets = CRM_Core_BAO_Tag::getTagsUsedFor('civicrm_activity', FALSE, TRUE);
+
+    foreach ($tagSets as $key => $value) {
+      $this->_tags[$key] = $value['name'];
+    }
+
+    // merge activity and taglist tags
+    $allTags = CRM_Utils_Array::crmArrayMerge($activityTags, $tagList);
+
+    $this->_name = array();
+    foreach ($allTags as $key => $dnc) {
+      $this->_name[] = $this->_tags[$key];
+
+      list($total, $added, $notAdded) = CRM_Core_BAO_EntityTag::addEntitiesToTag($this->_activityHolderIds, $key, 'civicrm_activity');
+
+      $status = array(ts('%count activities tagged', array('count' => $added, 'plural' => '%count activities tagged')));
+      if ($notAdded) {
+        $status[] = ts('%count activities already had this tag', array('count' => $notAdded, 'plural' => '%count activities already had this tag'));
+      }
+      $status = '<ul><li>' . implode('</li><li>', $status) . '</li></ul>';
+      CRM_Core_Session::setStatus($status, ts("Added Tag <em>%1</em>", array(1 => $this->_tags[$key])), 'success', array('expires' => 0));
+    }
+
+  }
+  //end of function
+}
+
diff --git a/CRM/Activity/Form/Task/RemoveFromTag.php b/CRM/Activity/Form/Task/RemoveFromTag.php
new file mode 100644 (file)
index 0000000..dd2c147
--- /dev/null
@@ -0,0 +1,143 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.4                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2013                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+*/
+
+/**
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC (c) 2004-2013
+ * $Id$
+ *
+ */
+
+/**
+ * This class provides the functionality to remove tags of contact(s).
+ */
+class CRM_Activity_Form_Task_RemoveFromTag extends CRM_Activity_Form_Task {
+
+  /**
+   * name of the tag
+   *
+   * @var string
+   */
+  protected $_name;
+
+  /**
+   * all the tags in the system
+   *
+   * @var array
+   */
+  protected $_tags;
+
+  /**
+   * Build the form
+   *
+   * @access public
+   *
+   * @return void
+   */
+  function buildQuickForm() {
+    // add select for tag
+    $this->_tags = CRM_Core_BAO_Tag::getTags('civicrm_activity');
+    foreach ($this->_tags as $tagID => $tagName) {
+      $this->_tagElement = &$this->addElement('checkbox', "tag[$tagID]", NULL, $tagName);
+    }
+
+    $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_activity');
+    CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, 'civicrm_activity', NULL, TRUE, FALSE, TRUE);
+
+    $this->addDefaultButtons(ts('Remove Tags from activities'));
+  }
+
+  function addRules() {
+    $this->addFormRule(array('CRM_Activity_Form_Task_RemoveFromTag', 'formRule'));
+  }
+
+  static function formRule($form, $rule) {
+    $errors = array();
+    if (empty($form['tag']) && empty($form['activity_taglist'])) {
+      $errors['_qf_default'] = "Please select atleast one tag.";
+    }
+    return $errors;
+  }
+
+  /**
+   * process the form after the input has been submitted and validated
+   *
+   * @access public
+   *
+   * @return None
+   */
+  public function postProcess() {
+    //get the submitted values in an array
+    $params = $this->controller->exportValues($this->_name);
+
+    $activityTags = $tagList = array();
+
+    // check if contact tags exists
+    if (CRM_Utils_Array::value('tag', $params)) {
+      $activityTags = $params['tag'];
+    }
+
+    // check if tags are selected from taglists
+    if (CRM_Utils_Array::value('activity_taglist', $params)) {
+      foreach ($params['activity_taglist'] as $val) {
+        if ($val) {
+          if (is_numeric($val)) {
+            $tagList[$val] = 1;
+          }
+          else {
+            list($label, $tagID) = explode(',', $val);
+            $tagList[$tagID] = 1;
+          }
+        }
+      }
+    }
+    $tagSets = CRM_Core_BAO_Tag::getTagsUsedFor('civicrm_activity', FALSE, TRUE);
+
+    foreach ($tagSets as $key => $value) {
+      $this->_tags[$key] = $value['name'];
+    }
+    // merge contact and taglist tags
+    $allTags = CRM_Utils_Array::crmArrayMerge($activityTags, $tagList);
+
+    $this->_name = array();
+    foreach ($allTags as $key => $dnc) {
+      $this->_name[] = $this->_tags[$key];
+
+      list($total, $removed, $notRemoved) = CRM_Core_BAO_EntityTag::removeEntitiesFromTag($this->_activityHolderIds, $key, 'civicrm_activity');
+
+      $status = array(ts('%count activities un-tagged', array('count' => $removed, 'plural' => '%count activities un-tagged')));
+      if ($notRemoved) {
+        $status[] = ts('1 activity already did not have this tag', array('count' => $notRemoved, 'plural' => '%count activities already did not have this tag'));
+      }
+      $status = '<ul><li>' . implode('</li><li>', $status) . '</li></ul>';
+      CRM_Core_Session::setStatus($status, ts("Removed Tag <em>%1</em>", array(1 => $this->_tags[$key])), 'success', array('expires' => 0));
+    }
+  }
+  //end of function
+}
+
index ac011aab9388a001af8b30d48fb9763b264f4fa9..503d8bee90528b8adb444e5b3c01b00e613ea051 100644 (file)
@@ -106,6 +106,16 @@ class CRM_Activity_Task {
           'class' => 'CRM_Activity_Form_Task_SMS',
           'result' => FALSE,
         ),
+        7 => array(
+          'title' => ts('Tag Activities (assign tags)'),
+          'class' => 'CRM_Activity_Form_Task_AddToTag',
+          'result' => FALSE,
+        ),
+        8 => array(
+          'title' => ts('Untag Activities (remove tags)'),
+          'class' => 'CRM_Activity_Form_Task_RemoveFromTag',
+          'result' => FALSE,
+        ),
       );
 
       $config = CRM_Core_Config::singleton();
index f408167d28c478fa44b46c3e81f4ec66960886d1..5eeaec35b03d42d72d2424a4168dcb2b1748b2ff 100644 (file)
@@ -226,6 +226,7 @@ class CRM_Core_Form_Tag {
     }
 
     if (!empty($tagset)) {
+      $form->assign("tagsetType", $mode);
       $form->assign("tagsetInfo_$mode", $tagset);
       $form->assign("isTagset", TRUE);
     }
diff --git a/templates/CRM/Activity/Form/Task/AddToTag.tpl b/templates/CRM/Activity/Form/Task/AddToTag.tpl
new file mode 100644 (file)
index 0000000..e42001c
--- /dev/null
@@ -0,0 +1,52 @@
+{*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.4                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2013                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+*}
+<div class="crm-form-block crm-block crm-activity-task-addtotag-form-block">
+<h3>
+{ts}Tag Activities{/ts}
+</h3>
+<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="top"}</div>
+<table class="form-layout-compressed">
+    <tr class="crm-activity-task-addtotag-form-block-tag">
+        <td>
+            <div class="listing-box">
+            {foreach from=$form.tag item="tag_val"}
+                <div class="{cycle values="odd-row,even-row"}">
+                {$tag_val.html}
+                </div>
+            {/foreach}
+            </div>
+        </td>
+    </tr>
+    <tr>
+        <td>
+            {include file="CRM/common/Tag.tpl"}
+        </td>
+    </tr>
+
+    <tr><td>{include file="CRM/Activity/Form/Task.tpl"}</td></tr>
+</table>
+    <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
+</div>
diff --git a/templates/CRM/Activity/Form/Task/RemoveFromTag.tpl b/templates/CRM/Activity/Form/Task/RemoveFromTag.tpl
new file mode 100644 (file)
index 0000000..8b7d37c
--- /dev/null
@@ -0,0 +1,52 @@
+{*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.4                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2013                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+*}
+{* template to remove tags from activity  *}
+<div class="crm-form-block crm-block crm-activity-task-removefromtag-form-block">
+<h3>
+{ts}Tag Activities (Remove){/ts}
+</h3>
+<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="top"}</div>
+<table class="form-layout-compressed">
+    <tr class="crm-activity-task-removefromtag-form-block-tag">
+        <td>
+            <div class="listing-box">
+            {foreach from=$form.tag item="tag_val"}
+                <div class="{cycle values="odd-row,even-row"}">
+                {$tag_val.html}
+            {/foreach}
+            </div>
+        </td>
+    </tr>
+    <tr>
+        <td>
+            {include file="CRM/common/Tag.tpl"}
+        </td>
+    </tr>
+
+    <tr><td>{include file="CRM/Activity/Form/Task.tpl"}</td></tr>
+</table>
+    <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
+</div>