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