add status preference dao to ignore list
[civicrm-core.git] / CRM / Admin / Form / Navigation.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2015
32 * $Id$
33 *
34 */
35
36 /**
37 * This class generates form components for Navigation
38 *
39 */
40 class CRM_Admin_Form_Navigation extends CRM_Admin_Form {
41
42 /**
43 * The parent id of the navigation menu.
44 */
45 protected $_currentParentID = NULL;
46
47 /**
48 * Build the form object.
49 *
50 * @return void
51 */
52 public function buildQuickForm() {
53 parent::buildQuickForm();
54
55 if ($this->_action & CRM_Core_Action::DELETE) {
56 return;
57 }
58
59 if (isset($this->_id)) {
60 $params = array('id' => $this->_id);
61 CRM_Core_BAO_Navigation::retrieve($params, $this->_defaults);
62 }
63
64 $this->applyFilter('__ALL__', 'trim');
65 $this->add('text',
66 'label',
67 ts('Title'),
68 CRM_Core_DAO::getAttribute('CRM_Core_DAO_Navigation', 'label'),
69 TRUE
70 );
71
72 $this->add('text', 'url', ts('Url'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_Navigation', 'url'));
73 $permissions = CRM_Core_Permission::basicPermissions(TRUE);
74 $include = &$this->addElement('advmultiselect', 'permission',
75 ts('Permission') . ' ', $permissions,
76 array(
77 'size' => 5,
78 'style' => 'width:auto',
79 'class' => 'advmultiselect',
80 )
81 );
82
83 $include->setButtonAttributes('add', array('value' => ts('Add >>')));
84 $include->setButtonAttributes('remove', array('value' => ts('<< Remove')));
85
86 $operators = array('AND' => 'AND', 'OR' => 'OR');
87 $this->add('select', 'permission_operator', ts('Operator'), $operators);
88
89 //make separator location configurable
90 $separator = array(0 => 'None', 1 => 'After Menu Element', 2 => 'Before Menu Element');
91 $this->add('select', 'has_separator', ts('Separator?'), $separator);
92
93 $active = $this->add('checkbox', 'is_active', ts('Enabled?'));
94
95 if (CRM_Utils_Array::value('name', $this->_defaults) == 'Home') {
96 $active->freeze();
97 }
98 else {
99 $parentMenu = CRM_Core_BAO_Navigation::getNavigationList();
100
101 if (isset($this->_id)) {
102 unset($parentMenu[$this->_id]);
103 }
104
105 // also unset home.
106 $homeMenuId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Navigation', 'Home', 'id', 'name');
107 unset($parentMenu[$homeMenuId]);
108
109 $parent = $this->add('select', 'parent_id', ts('Parent'), array('' => ts('- select -')) + $parentMenu);
110 }
111 }
112
113 /**
114 * @return array
115 */
116 public function setDefaultValues() {
117 $defaults = $this->_defaults;
118 if (isset($this->_id)) {
119 if (!empty($this->_defaults['permission'])) {
120 foreach (explode(',', $this->_defaults['permission']) as $value) {
121 $components[$value] = $value;
122 }
123 $defaults['permission'] = $components;
124 }
125 //Take parent id in object variable to calculate the menu
126 //weight if menu parent id changed
127 $this->_currentParentID = CRM_Utils_Array::value('parent_id', $this->_defaults);
128 }
129 else {
130 $defaults['permission'] = "access CiviCRM";
131 }
132
133 // its ok if there is no element called is_active
134 $defaults['is_active'] = ($this->_id) ? $this->_defaults['is_active'] : 1;
135
136 return $defaults;
137 }
138
139 /**
140 * Process the form submission.
141 *
142 *
143 * @return void
144 */
145 public function postProcess() {
146 // get the submitted form values.
147 $params = $this->controller->exportValues($this->_name);
148
149 if (isset($this->_id)) {
150 $params['id'] = $this->_id;
151 $params['current_parent_id'] = $this->_currentParentID;
152 }
153
154 $navigation = CRM_Core_BAO_Navigation::add($params);
155
156 // also reset navigation
157 CRM_Core_BAO_Navigation::resetNavigation();
158
159 CRM_Core_Session::setStatus(ts('Menu \'%1\' has been saved.',
160 array(1 => $navigation->label)
161 ), ts('Saved'), 'success');
162 }
163
164 }