- Update the copyright notices to use the correct year and not a non-ASCII symbol
[bugdar.git] / includes / api_usergroup.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright (c)2004-2008 Blue Static
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version 2 of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 require_once ISSO . '/Api.php';
23 require_once('./includes/functions_datastore.php');
24
25 /**
26 * API: Usergroup
27 *
28 * @author Blue Static
29 * @copyright Copyright (c)2004 - 2008, Blue Static
30 * @package Bugdar
31 *
32 */
33 class UsergroupAPI extends BSApi
34 {
35 /**
36 * Fields
37 * @var array
38 */
39 protected $fields = array(
40 'usergroupid' => array(TYPE_UINT, REQ_AUTO),
41 'title' => array(TYPE_STR, REQ_YES),
42 'displaytitle' => array(TYPE_STR, REQ_NO),
43 'permissions' => array(TYPE_UINT, REQ_NO)
44 );
45
46 /**
47 * Database table
48 * @var string
49 */
50 protected $table = 'usergroup';
51
52 /**
53 * Table prefix
54 * @var string
55 */
56 protected $prefix = TABLE_PREFIX;
57
58 /**
59 * Post-insert
60 */
61 protected function post_insert()
62 {
63 build_usergroups();
64 }
65
66 /**
67 * Post-update
68 */
69 protected function post_update()
70 {
71 build_usergroups();
72 build_assignedto();
73 }
74
75 /**
76 * Pre-delete
77 */
78 protected function pre_delete()
79 {
80 if ($this->values['usergroupid'] < 7)
81 {
82 throw new FieldException(T('You can\'t delete a default usergroup.'), 'usergroupid');
83 return false;
84 }
85 }
86
87 /**
88 * Post-delete
89 */
90 protected function post_delete()
91 {
92 BSApp::$db->query("DELETE FROM " . TABLE_PREFIX . "permission WHERE usergroupid = " . $this->values['usergroupid']);
93 BSApp::$db->query("DELETE FROM " . TABLE_PREFIX . "bugfieldpermission WHERE usergroupid = " . $this->values['usergroupid']);
94 BSApp::$db->query("UPDATE " . TABLE_PREFIX . "user SET usergroupid = 2 WHERE usergroupid = " . $this->values['usergroupid']);
95 build_usergroups();
96 build_permissions();
97 build_assignedto();
98 }
99
100 /**
101 * Validate: usergroupid
102 */
103 protected function validate_usergroupid($field)
104 {
105 return $this->_verifyIsNotZero($field);
106 }
107
108 /**
109 * Validate: usergroup
110 */
111 protected function validate_usergroup($field)
112 {
113 return $this->_verifyIsNotEmpty($field);
114 }
115 }
116
117 ?>