2 /*=====================================================================*\
3 || ###################################################################
5 || # Copyright (c)2004-2009 Blue Static
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.
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
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 \*=====================================================================*/
22 require_once ISSO
. '/Api.php';
23 require_once('./includes/functions_datastore.php');
29 * @copyright Copyright (c)2004 - 2009, Blue Static
33 class LanguageAPI
extends BSApi
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
)
52 protected $table = 'language';
58 protected $prefix = TABLE_PREFIX
;
63 protected function post_insert()
71 protected function post_update()
79 protected function pre_delete()
81 $count = BSApp
::$db->queryFirst("SELECT COUNT(*) AS count FROM " . TABLE_PREFIX
. "language");
82 if ($count['count'] < 2)
84 throw new FieldException(T('At least one language needs to be present. Deleting this language would violate that.'), 'languageid');
87 if (bugdar
::$options['defaultlanguage'] == $this->values
['languageid'])
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');
96 protected function post_delete()
104 protected function validate_direction($field)
106 if (!in_array($this->values
['direction'], array('ltr', 'rtl')))
108 $this->_error(new FieldError(T('The direction must be ltr (left-to-right) or rtl (right-to-left)'), $field));
115 * Validate: languageid
117 protected function validate_languageid($field)
119 return $this->_verifyIsNotZero($field);
125 protected function validate_title($field)
127 return $this->_verifyIsNotEmpty($field);