get('entityID')) { $this->_entityID = $this->get('entityID'); } else { $this->_entityID = $this->get('contactId'); } $this->_entityTable = $this->get('entityTable'); if (empty($this->_entityTable)) { $this->_entityTable = 'civicrm_contact'; } $this->assign('entityID', $this->_entityID); $this->assign('entityTable', $this->_entityTable); } /** * Build the form object. * * @return void */ public function buildQuickForm() { // get categories for the contact id $entityTag = CRM_Core_BAO_EntityTag::getTag($this->_entityID, $this->_entityTable); $this->assign('tagged', $entityTag); // get the list of all the categories $allTags = CRM_Core_BAO_Tag::getTagsUsedFor($this->_entityTable, FALSE); // need to append the array with the " checked " if contact is tagged with the tag foreach ($allTags as $tagID => $varValue) { if (in_array($tagID, $entityTag)) { $tagAttribute = array( 'checked' => 'checked', 'id' => "tag_{$tagID}", ); } else { $tagAttribute = array( 'id' => "tag_{$tagID}", ); } $tagChk[$tagID] = $this->createElement('checkbox', $tagID, '', '', $tagAttribute); } $this->addGroup($tagChk, 'tagList', NULL, NULL, TRUE); $tags = new CRM_Core_BAO_Tag(); $tree = $tags->getTree($this->_entityTable, TRUE); // let's not load jstree if there are not children. This also fixes blank // display at the beginning of checkboxes $loadJsTree = CRM_Utils_Array::retrieveValueRecursive($tree, 'children'); $this->assign('loadjsTree', FALSE); if (!empty($loadJsTree)) { CRM_Core_Resources::singleton() ->addScriptFile('civicrm', 'packages/jquery/plugins/jstree/jquery.jstree.js', 0, 'html-header', FALSE) ->addStyleFile('civicrm', 'packages/jquery/plugins/jstree/themes/default/style.css', 0, 'html-header'); $this->assign('loadjsTree', TRUE); } $this->assign('tree', $tree); $this->assign('allTags', $allTags); //build tag widget $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact'); CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, $this->_entityTable, $this->_entityID); } /** * * @return void */ public function postProcess() { CRM_Utils_System::flushCache('CRM_Core_DAO_Tag'); // array contains the posted values // exportvalues is not used because its give value 1 of the checkbox which were checked by default, // even after unchecking them before submitting them $entityTag = $_POST['tagList']; CRM_Core_BAO_EntityTag::create($entityTag, $this->_entityTable, $this->_entityID); CRM_Core_Session::setStatus(ts('Your update(s) have been saved.'), ts('Saved'), 'success'); } }