Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
8c9251b3 | 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
8c9251b3 | 31 | * @copyright CiviCRM LLC (c) 2004-2018 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * This class generates form components for tags | |
38 | * | |
39 | */ | |
40 | class CRM_Tag_Form_Tag extends CRM_Core_Form { | |
41 | ||
42 | /** | |
43 | * The contact id, used when add/edit tag | |
44 | * | |
45 | * @var int | |
46 | */ | |
47 | protected $_entityID; | |
430ae6dd TO |
48 | protected $_entityTable; |
49 | ||
00be9182 | 50 | public function preProcess() { |
6a488035 TO |
51 | if ($this->get('entityID')) { |
52 | $this->_entityID = $this->get('entityID'); | |
53 | } | |
54 | else { | |
55 | $this->_entityID = $this->get('contactId'); | |
56 | } | |
57 | ||
58 | $this->_entityTable = $this->get('entityTable'); | |
59 | ||
60 | if (empty($this->_entityTable)) { | |
61 | $this->_entityTable = 'civicrm_contact'; | |
62 | } | |
63 | ||
64 | $this->assign('entityID', $this->_entityID); | |
65 | $this->assign('entityTable', $this->_entityTable); | |
66 | } | |
67 | ||
68 | /** | |
fe482240 | 69 | * Build the form object. |
6a488035 | 70 | * |
355ba699 | 71 | * @return void |
6a488035 TO |
72 | */ |
73 | public function buildQuickForm() { | |
74 | // get categories for the contact id | |
75 | $entityTag = CRM_Core_BAO_EntityTag::getTag($this->_entityID, $this->_entityTable); | |
76 | $this->assign('tagged', $entityTag); | |
77 | ||
78 | // get the list of all the categories | |
d73974ac | 79 | $allTags = CRM_Core_BAO_Tag::getTagsUsedFor($this->_entityTable, FALSE); |
6a488035 TO |
80 | |
81 | // need to append the array with the " checked " if contact is tagged with the tag | |
d73974ac | 82 | foreach ($allTags as $tagID => $varValue) { |
6a488035 TO |
83 | if (in_array($tagID, $entityTag)) { |
84 | $tagAttribute = array( | |
6a488035 TO |
85 | 'checked' => 'checked', |
86 | 'id' => "tag_{$tagID}", | |
87 | ); | |
88 | } | |
89 | else { | |
90 | $tagAttribute = array( | |
6a488035 TO |
91 | 'id' => "tag_{$tagID}", |
92 | ); | |
93 | } | |
94 | ||
95 | $tagChk[$tagID] = $this->createElement('checkbox', $tagID, '', '', $tagAttribute); | |
96 | } | |
97 | ||
98 | $this->addGroup($tagChk, 'tagList', NULL, NULL, TRUE); | |
99 | ||
100 | $tags = new CRM_Core_BAO_Tag(); | |
101 | $tree = $tags->getTree($this->_entityTable, TRUE); | |
102 | $this->assign('tree', $tree); | |
103 | ||
d73974ac | 104 | $this->assign('allTags', $allTags); |
6a488035 TO |
105 | |
106 | //build tag widget | |
107 | $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_contact'); | |
108 | CRM_Core_Form_Tag::buildQuickForm($this, $parentNames, $this->_entityTable, $this->_entityID); | |
6a488035 TO |
109 | } |
110 | ||
111 | /** | |
6a488035 | 112 | * |
355ba699 | 113 | * @return void |
6a488035 TO |
114 | */ |
115 | public function postProcess() { | |
116 | CRM_Utils_System::flushCache('CRM_Core_DAO_Tag'); | |
117 | ||
118 | // array contains the posted values | |
119 | // exportvalues is not used because its give value 1 of the checkbox which were checked by default, | |
120 | // even after unchecking them before submitting them | |
121 | $entityTag = $_POST['tagList']; | |
122 | ||
123 | CRM_Core_BAO_EntityTag::create($entityTag, $this->_entityTable, $this->_entityID); | |
124 | ||
125 | CRM_Core_Session::setStatus(ts('Your update(s) have been saved.'), ts('Saved'), 'success'); | |
126 | } | |
96025800 | 127 | |
6a488035 | 128 | } |