Update api_language.php
authorRobert Sesek <rsesek@bluestatic.org>
Sat, 6 Sep 2008 20:00:15 +0000 (16:00 -0400)
committerRobert Sesek <rsesek@bluestatic.org>
Sat, 6 Sep 2008 20:00:15 +0000 (16:00 -0400)
includes/api_language.php

index d0297a4a39ec2476fdaaaa2e780ee3804b4311dd..0f146deb880307c887f9d600219a98bf59bbb2e8 100644 (file)
@@ -19,8 +19,7 @@
 || ###################################################################
 \*=====================================================================*/
 
-$GLOBALS['isso:callback']->load('api', null);
-
+require_once ISSO . '/Api.php';
 require_once('./includes/functions_datastore.php');
 
 /**
@@ -32,101 +31,102 @@ require_once('./includes/functions_datastore.php');
 * @package             Bugdar
 * 
 */
-class LanguageAPI extends API
+class LanguageAPI extends BSApi
 {
        /**
-       * Fields
-       * @var  array
-       * @access       private
-       */
-       var $fields = array(
-               'languageid'    => array(TYPE_UINT,             REQ_AUTO,       'verify_nozero'),
-               'title'                 => array(TYPE_STR,              REQ_YES,        'verify_noempty'),
+        * Fields
+        * @var array
+        */
+       protected $fields = array(
+               'languageid'    => array(TYPE_UINT,             REQ_AUTO),
+               'title'                 => array(TYPE_STR,              REQ_YES),
                'charset'               => array(TYPE_STR,              REQ_YES),
-               'direction'             => array(TYPE_STR,              REQ_NO,         ':self'),
+               'direction'             => array(TYPE_STR,              REQ_NO),
                'userselect'    => array(TYPE_BOOL,             REQ_NO),
                'langcode'              => array(TYPE_STR,              REQ_YES)
        );
        
        /**
-       * Table
-       * @var  string
-       * @access       private
-       */
-       var $table = 'language';
+        * Table
+        * @var string
+        */
+       protected $table = 'language';
        
        /**
-       * Table prefix
-       * @var  string
-       * @access       private
-       */
-       var $prefix = TABLE_PREFIX;
+        * Table prefix
+        * @var string
+        */
+       protected $prefix = TABLE_PREFIX;
        
-       // ###################################################################
        /**
-       * Post-insert
-       *
-       * @access       private
-       */
-       function post_insert()
+        * Post-insert
+        */
+       protected function post_insert()
        {
                build_languages();
        }
        
-       // ###################################################################
        /**
-       * Post-update
-       *
-       * @access       private
-       */
-       function post_update()
+        * Post-update
+        */
+       protected function post_update()
        {
                build_languages();
        }
        
-       // ###################################################################
        /**
-       * Pre-delete
-       */
-       function pre_delete()
+        * Pre-delete
+        */
+       protected function pre_delete()
        {
-               $count = $this->registry->db->query_first("SELECT COUNT(*) AS count FROM " . TABLE_PREFIX . "language");
+               $count = BSApp::$db->queryFirst("SELECT COUNT(*) AS count FROM " . TABLE_PREFIX . "language");
                if ($count['count'] < 2)
                {
-                       $this->error(T('At least one language needs to be present. Deleting this language would violate that.'));
+                       throw new FieldException(T('At least one language needs to be present. Deleting this language would violate that.'), 'languageid');
                }
                
                if (bugdar::$options['defaultlanguage'] == $this->values['languageid'])
                {
-                       $this->error(T('You cannot delete the default language. Please select another language to be the default language and then delete this one.'));
+                       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');
                }
        }
        
-       // ###################################################################
        /**
-       * Post-delete
-       *
-       * @access       private
-       */
-       function post_delete()
+        * Post-delete
+        */
+       protected function post_delete()
        {
                build_languages();
        }
        
-       // ###################################################################
        /**
-       * Verify: direction
-       *
-       * @access       private
-       */
-       function verify_direction()
+        * Verify: direction
+        */
+       protected function validate_direction($field)
        {
                if (!in_array($this->values['direction'], array('ltr', 'rtl')))
                {
-                       return T('The direction must be ltr (left-to-right) or rtl (right-to-left)');
+                       $this->_error(new FieldError(T('The direction must be ltr (left-to-right) or rtl (right-to-left)'), $field));
+                       return false;
                }
                return true;
        }
+       
+       /**
+        * Validate: languageid
+        */
+       protected function validate_languageid($field)
+       {
+               return $this->_verifyIsNotZero($field);
+       }
+       
+       /**
+        * Validate: title
+        */
+       protected function validate_title($field)
+       {
+               return $this->_verifyIsNotEmpty($field);
+       }
 }
 
 /*=====================================================================*\