r1051: Finalizing the LanguageAPI and implementing it
[bugdar.git] / includes / api_language.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] 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 [#]gpl[#] 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 $GLOBALS['isso:callback']->load('api', null);
23
24 require_once('./includes/functions_datastore.php');
25
26 /**
27 * API: Language
28 *
29 * @author Blue Static
30 * @copyright Copyright ©2002 - [#]year[#], Blue Static
31 * @version $Revision$
32 * @package Bugdar
33 *
34 */
35 class LanguageAPI extends API
36 {
37 /**
38 * Fields
39 * @var array
40 * @access private
41 */
42 var $fields = array(
43 'languageid' => array(TYPE_UINT, REQ_AUTO, 'verify_nozero'),
44 'title' => array(TYPE_STR, REQ_YES, 'verify_noempty'),
45 'charset' => array(TYPE_STR, REQ_YES),
46 'debug' => array(TYPE_BOOL, REQ_NO),
47 'direction' => array(TYPE_STR, REQ_NO, ':self'),
48 'userselect' => array(TYPE_BOOL, REQ_NO),
49 'filename' => array(TYPE_STR, REQ_YES)
50 );
51
52 /**
53 * Table
54 * @var string
55 * @access private
56 */
57 var $table = 'language';
58
59 /**
60 * Table prefix
61 * @var string
62 * @access private
63 */
64 var $prefix = TABLE_PREFIX;
65
66 // ###################################################################
67 /**
68 * Post-insert
69 *
70 * @access private
71 */
72 function post_insert()
73 {
74 build_languages();
75 build_language_cache($this->insertid);
76 }
77
78 // ###################################################################
79 /**
80 * Post-update
81 *
82 * @access private
83 */
84 function post_update()
85 {
86 build_languages();
87 }
88
89 // ###################################################################
90 /**
91 * Pre-delete
92 */
93 function pre_delete()
94 {
95 $count = $this->registry->db->query_first("SELECT COUNT(*) AS count FROM " . TABLE_PREFIX . "language");
96 if ($count['count'] < 2)
97 {
98 $this->error(_('At least one language needs to be present. Deleting this language would violate that.'));
99 }
100
101 if ($this->registry->options['defaultlanguage'] == $this->values['languageid'])
102 {
103 $this->error(_('You cannot delete the default language. Please select another language to be the default language and then delete this one.'));
104 }
105 }
106
107 // ###################################################################
108 /**
109 * Post-delete
110 *
111 * @access private
112 */
113 function post_delete()
114 {
115 build_languages();
116 $this->registry->db->query("DELETE FROM " . TABLE_PREFIX . "localization WHERE languageid = " . $this->values['languageid']);
117 }
118
119 // ###################################################################
120 /**
121 * Verify: direction
122 *
123 * @access private
124 */
125 function verify_direction()
126 {
127 if (!in_array(array('ltr', 'rtl'), $this->values['direction']))
128 {
129 return _('The direction must be ltr (left-to-right) or rtl (right-to-left)');
130 }
131 return true;
132 }
133 }
134
135 /*=====================================================================*\
136 || ###################################################################
137 || # $HeadURL$
138 || # $Id$
139 || ###################################################################
140 \*=====================================================================*/
141 ?>