Updating api_userhelp.php
[bugdar.git] / includes / api_userhelp.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright ©2002-2007 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
24 require_once('./includes/functions_datastore.php');
25
26 /**
27 * API: User help
28 *
29 * @author Blue Static
30 * @copyright Copyright ©2002 - 2007, Blue Static
31 * @version $Revision$
32 * @package Bugdar
33 *
34 */
35 class UserHelpAPI extends BSApi
36 {
37 /**
38 * Fields
39 * @var array
40 */
41 protected $fields = array(
42 'keystring' => array(TYPE_STR, REQ_AUTO),
43 'title' => array(TYPE_STR, REQ_YES),
44 'body' => array(TYPE_STR, REQ_YES)
45 );
46
47 /**
48 * Database table
49 * @var string
50 */
51 protected $table = 'fieldhelp';
52
53 /**
54 * Table prefix
55 * @var string
56 */
57 protected $prefix = TABLE_PREFIX;
58
59 /**
60 * A static function that returns an array of all the keystrings that
61 * are not allowed to be deleted
62 *
63 * @return array Array of keystrings
64 */
65 public static function not_able_to_delete()
66 {
67 return array(
68 'assignedto',
69 'bugid',
70 'dateline',
71 'dependency',
72 'duplicateof',
73 'priority',
74 'product',
75 'reporter',
76 'resolution',
77 'severity',
78 'status',
79 'summary',
80 'newreply',
81 'columnorder'
82 );
83 }
84
85 /**
86 * Post-insert
87 */
88 protected function post_insert()
89 {
90 build_user_help();
91 }
92
93 /**
94 * Post-update
95 */
96 protected function post_update()
97 {
98 build_user_help();
99 }
100
101 /**
102 * Pre-delete
103 */
104 protected function pre_delete()
105 {
106 if (in_array($this->values['keystring'], self::not_able_to_delete()))
107 {
108 throw new FieldException(T('You cannot delete this user help text because the system needs it.'), 'keystring');
109 }
110 }
111
112 /**
113 * Post-delete
114 */
115 protected function post_delete()
116 {
117 build_user_help();
118 }
119
120 /**
121 * Validate: title
122 */
123 protected function validate_title($field)
124 {
125 return $this->_verifyIsNotEmpty($field);
126 }
127
128 /**
129 * Verify: keystring
130 */
131 protected function validate_keystring($field)
132 {
133 if ($this->_verifyIsNotEmpty('keystring'))
134 {
135 return false;
136 }
137
138 if (preg_match('#[^a-z0-9_]#', $this->values['keystring']))
139 {
140 $this->_error(new FieldException(T('The unique key can only contain lowercase letters, underscores, and numbers.'), $field));
141 return false;
142 }
143
144 if (BSApp::$db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "fieldhelp WHERE keystring = '" . BSApp::$input->escape($this->values['keystring']) . "'"))
145 {
146 $this->_error(new FieldException(T('The unique key must be unique.'), $field));
147 return false;
148 }
149
150 return true;
151 }
152 }
153
154 /*=====================================================================*\
155 || ###################################################################
156 || # $HeadURL$
157 || # $Id$
158 || ###################################################################
159 \*=====================================================================*/
160 ?>