3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
21 * This class generates form components for tags
24 class CRM_Tag_Form_Tag
extends CRM_Core_Form
{
27 * The contact id, used when add/edit tag
32 protected $_entityTable;
34 public function preProcess() {
35 if ($this->get('entityID')) {
36 $this->_entityID
= $this->get('entityID');
39 $this->_entityID
= $this->get('contactId');
42 $this->_entityTable
= $this->get('entityTable');
44 if (empty($this->_entityTable
)) {
45 $this->_entityTable
= 'civicrm_contact';
48 $this->assign('entityID', $this->_entityID
);
49 $this->assign('entityTable', $this->_entityTable
);
53 * Build the form object.
57 public function buildQuickForm() {
58 // get categories for the contact id
59 $entityTag = CRM_Core_BAO_EntityTag
::getTag($this->_entityID
, $this->_entityTable
);
60 $this->assign('tagged', $entityTag);
62 // get the list of all the categories
63 $allTags = CRM_Core_BAO_Tag
::getTagsUsedFor($this->_entityTable
, FALSE);
65 // need to append the array with the " checked " if contact is tagged with the tag
66 foreach ($allTags as $tagID => $varValue) {
67 if (in_array($tagID, $entityTag)) {
69 'checked' => 'checked',
70 'id' => "tag_{$tagID}",
75 'id' => "tag_{$tagID}",
79 $tagChk[$tagID] = $this->createElement('checkbox', $tagID, '', '', $tagAttribute);
82 $this->addGroup($tagChk, 'tagList', NULL, NULL, TRUE);
84 $tags = new CRM_Core_BAO_Tag();
85 $tree = $tags->getTree($this->_entityTable
, TRUE);
86 $this->assign('tree', $tree);
88 $this->assign('allTags', $allTags);
91 $parentNames = CRM_Core_BAO_Tag
::getTagSet('civicrm_contact');
92 CRM_Core_Form_Tag
::buildQuickForm($this, $parentNames, $this->_entityTable
, $this->_entityID
);
99 public function postProcess() {
100 CRM_Utils_System
::flushCache();
102 // array contains the posted values
103 // exportvalues is not used because its give value 1 of the checkbox which were checked by default,
104 // even after unchecking them before submitting them
105 $entityTag = $_POST['tagList'];
107 CRM_Core_BAO_EntityTag
::create($entityTag, $this->_entityTable
, $this->_entityID
);
109 CRM_Core_Session
::setStatus(ts('Your update(s) have been saved.'), ts('Saved'), 'success');