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 generates form components for Tag.
37 class CRM_Admin_Form_Tag
extends CRM_Admin_Form
{
41 * Explicitly declare the entity api name.
43 public function getDefaultEntity() {
48 * Build the form object.
50 public function buildQuickForm() {
51 $this->setPageTitle($this->_isTagSet ?
ts('Tag Set') : ts('Tag'));
53 if ($this->_action
== CRM_Core_Action
::DELETE
) {
54 if ($this->_id
&& $tag = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_Tag', $this->_id
, 'name', 'parent_id')) {
55 $url = CRM_Utils_System
::url('civicrm/admin/tag', "reset=1");
56 CRM_Core_Error
::statusBounce(ts("This tag cannot be deleted. You must delete all its child tags ('%1', etc) prior to deleting this tag.", array(1 => $tag)), $url);
58 if ($this->_values
['is_reserved'] == 1 && !CRM_Core_Permission
::check('administer reserved tags')) {
59 CRM_Core_Error
::statusBounce(ts("You do not have sufficient permission to delete this reserved tag."));
63 $this->_isTagSet
= CRM_Utils_Request
::retrieve('tagset', 'Positive', $this);
65 if (!$this->_isTagSet
&&
67 CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_Tag', $this->_id
, 'is_tagset')
69 $this->_isTagSet
= TRUE;
72 $allTag = array('' => ts('- select -')) + CRM_Core_BAO_Tag
::getTagsNotInTagset();
75 unset($allTag[$this->_id
]);
78 if (!$this->_isTagSet
) {
79 $this->add('select', 'parent_id', ts('Parent Tag'), $allTag, FALSE, array('class' => 'crm-select2'));
81 // Tagsets are not selectable by definition so only include the selectable field if NOT a tagset.
82 $selectable = $this->add('checkbox', 'is_selectable', ts('Selectable?'));
83 // Selectable should be checked by default when creating a new tag
84 if ($this->_action
== CRM_Core_Action
::ADD
) {
85 $selectable->setValue(1);
90 $this->assign('isTagSet', $this->_isTagSet
);
92 $this->applyFilter('__ALL__', 'trim');
94 $this->add('text', 'name', ts('Name'),
95 CRM_Core_DAO
::getAttribute('CRM_Core_DAO_Tag', 'name'), TRUE
97 $this->addRule('name', ts('Name already exists in Database.'), 'objectExists', array(
102 $this->add('text', 'description', ts('Description'),
103 CRM_Core_DAO
::getAttribute('CRM_Core_DAO_Tag', 'description')
106 $isReserved = $this->add('checkbox', 'is_reserved', ts('Reserved?'));
108 $usedFor = $this->addSelect('used_for', array('multiple' => TRUE, 'option_url' => NULL));
111 CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_Tag', $this->_id
, 'parent_id')
117 if (!CRM_Core_Permission
::check('administer Tagsets')) {
118 $adminTagset = FALSE;
120 $this->assign('adminTagset', $adminTagset);
122 $adminReservedTags = TRUE;
123 if (!CRM_Core_Permission
::check('administer reserved tags')) {
124 $isReserved->freeze();
125 $adminReservedTags = FALSE;
127 $this->assign('adminReservedTags', $adminReservedTags);
130 parent
::buildQuickForm();
134 * Process the form submission.
136 public function postProcess() {
137 $params = $ids = array();
139 // store the submitted values in an array
140 $params = $this->exportValues();
142 $ids['tag'] = $this->_id
;
143 if ($this->_action
== CRM_Core_Action
::ADD ||
144 $this->_action
== CRM_Core_Action
::UPDATE
146 $params['used_for'] = implode(",", $params['used_for']);
149 $params['is_tagset'] = 0;
150 if ($this->_isTagSet
) {
151 $params['is_tagset'] = 1;
154 if (!isset($params['is_reserved'])) {
155 $params['is_reserved'] = 0;
158 if (!isset($params['is_selectable'])) {
159 $params['is_selectable'] = 0;
162 if ($this->_action
== CRM_Core_Action
::DELETE
) {
163 if ($this->_id
> 0) {
164 $tag = civicrm_api3('tag', 'getsingle', array('id' => $this->_id
));
165 CRM_Core_BAO_Tag
::del($this->_id
);
166 CRM_Core_Session
::setStatus(ts('The tag \'%1\' has been deleted.', array(1 => $tag['name'])), ts('Deleted'), 'success');
170 $tag = CRM_Core_BAO_Tag
::add($params, $ids);
171 CRM_Core_Session
::setStatus(ts('The tag \'%1\' has been saved.', array(1 => $tag->name
)), ts('Saved'), 'success');