]> src.bluestatic.org Git - bugdar.git/blob - includes/api_language.php
Fix an issue where after creating a Bugdar user in _fetchBugdarUserFromAuthUser(...
[bugdar.git] / includes / api_language.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright (c)2004-2009 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: Language
27 *
28 * @author Blue Static
29 * @copyright Copyright (c)2004 - 2009, Blue Static
30 * @package Bugdar
31 *
32 */
33 class LanguageAPI extends BSApi
34 {
35 /**
36 * Fields
37 * @var array
38 */
39 protected $fields = array(
40 'languageid' => array(TYPE_UINT, REQ_AUTO),
41 'title' => array(TYPE_STR, REQ_YES),
42 'charset' => array(TYPE_STR, REQ_YES),
43 'direction' => array(TYPE_STR, REQ_NO),
44 'userselect' => array(TYPE_BOOL, REQ_NO),
45 'langcode' => array(TYPE_STR, REQ_YES)
46 );
47
48 /**
49 * Table
50 * @var string
51 */
52 protected $table = 'language';
53
54 /**
55 * Table prefix
56 * @var string
57 */
58 protected $prefix = TABLE_PREFIX;
59
60 /**
61 * Post-insert
62 */
63 protected function post_insert()
64 {
65 build_languages();
66 }
67
68 /**
69 * Post-update
70 */
71 protected function post_update()
72 {
73 build_languages();
74 }
75
76 /**
77 * Pre-delete
78 */
79 protected function pre_delete()
80 {
81 $count = BSApp::$db->queryFirst("SELECT COUNT(*) AS count FROM " . TABLE_PREFIX . "language");
82 if ($count['count'] < 2)
83 {
84 throw new FieldException(T('At least one language needs to be present. Deleting this language would violate that.'), 'languageid');
85 }
86
87 if (bugdar::$options['defaultlanguage'] == $this->values['languageid'])
88 {
89 throw new FieldException(T('You cannot delete the default language. Please select another language to be the default language and then delete this one.'), 'languageid');
90 }
91 }
92
93 /**
94 * Post-delete
95 */
96 protected function post_delete()
97 {
98 build_languages();
99 }
100
101 /**
102 * Verify: direction
103 */
104 protected function validate_direction($field)
105 {
106 if (!in_array($this->values['direction'], array('ltr', 'rtl')))
107 {
108 $this->_error(new FieldError(T('The direction must be ltr (left-to-right) or rtl (right-to-left)'), $field));
109 return false;
110 }
111 return true;
112 }
113
114 /**
115 * Validate: languageid
116 */
117 protected function validate_languageid($field)
118 {
119 return $this->_verifyIsNotZero($field);
120 }
121
122 /**
123 * Validate: title
124 */
125 protected function validate_title($field)
126 {
127 return $this->_verifyIsNotEmpty($field);
128 }
129 }
130
131 ?>