From 562602506b06261198a5bc0772b04f309e9c72f3 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 6 Sep 2008 15:28:08 -0400 Subject: [PATCH] Updating api_userhelp.php --- includes/api_userhelp.php | 132 +++++++++++++++----------------------- 1 file changed, 53 insertions(+), 79 deletions(-) diff --git a/includes/api_userhelp.php b/includes/api_userhelp.php index 5cedef2..fbccf42 100644 --- a/includes/api_userhelp.php +++ b/includes/api_userhelp.php @@ -19,7 +19,7 @@ || ################################################################### \*=====================================================================*/ -$GLOBALS['isso:callback']->load('api', null); +require_once ISSO . '/Api.php'; require_once('./includes/functions_datastore.php'); @@ -32,43 +32,37 @@ require_once('./includes/functions_datastore.php'); * @package Bugdar * */ -class UserHelpAPI extends API +class UserHelpAPI extends BSApi { /** - * Fields - * @var array - * @access private - */ - var $fields = array( + * Fields + * @var array + */ + protected $fields = array( 'keystring' => array(TYPE_STR, REQ_AUTO), - 'title' => array(TYPE_STR, REQ_YES, 'verify_noempty'), + 'title' => array(TYPE_STR, REQ_YES), 'body' => array(TYPE_STR, REQ_YES) ); /** - * Database table - * @var string - * @access private - */ - var $table = 'fieldhelp'; + * Database table + * @var string + */ + protected $table = 'fieldhelp'; /** - * Table prefix - * @var string - * @access private - */ - var $prefix = TABLE_PREFIX; + * Table prefix + * @var string + */ + protected $prefix = TABLE_PREFIX; - // ################################################################### /** - * A static function that returns an array of all the keystrings that - * are not allowed to be deleted - * - * @access public - * - * @return array Array of keystrings - */ - function not_able_to_delete() + * A static function that returns an array of all the keystrings that + * are not allowed to be deleted + * + * @return array Array of keystrings + */ + public static function not_able_to_delete() { return array( 'assignedto', @@ -88,89 +82,69 @@ class UserHelpAPI extends API ); } - // ################################################################### /** - * Pre-insert - * - * @access private - */ - function pre_insert() - { - if (($err = $this->verify_keystring()) !== true) - { - $this->error($err); - } - } - - // ################################################################### - /** - * Post-insert - * - * @access private - */ - function post_insert() + * Post-insert + */ + protected function post_insert() { build_user_help(); } - // ################################################################### /** - * Post-update - * - * @access private - */ - function post_update() + * Post-update + */ + protected function post_update() { build_user_help(); } - // ################################################################### /** - * Pre-delete - * - * @access private - */ - function pre_delete() + * Pre-delete + */ + protected function pre_delete() { - if (in_array($this->values['keystring'], UserHelpAPI::not_able_to_delete())) + if (in_array($this->values['keystring'], self::not_able_to_delete())) { - return false; + throw new FieldException(T('You cannot delete this user help text because the system needs it.'), 'keystring'); } - return true; } - // ################################################################### /** - * Post-delete - * - * @access private - */ - function post_delete() + * Post-delete + */ + protected function post_delete() { build_user_help(); } - // ################################################################### /** - * Verify: keystring - * - * @access private - */ - function verify_keystring() + * Validate: title + */ + protected function validate_title($field) { - if (!is_bool($ne = $this->verify_noempty('keystring'))) + return $this->_verifyIsNotEmpty($field); + } + + /** + * Verify: keystring + */ + protected function validate_keystring($field) + { + if ($this->_verifyIsNotEmpty('keystring')) { - return $ne; + return false; } if (preg_match('#[^a-z0-9_]#', $this->values['keystring'])) { - return T('The unique key can only contain lowercase letters, underscores, and numbers.'); + $this->_error(new FieldException(T('The unique key can only contain lowercase letters, underscores, and numbers.'), $field)); + return false; } - if ($this->registry->db->query_first("SELECT * FROM " . TABLE_PREFIX . "fieldhelp WHERE keystring = '" . $this->registry->escape($this->values['keystring']) . "'")) + if (BSApp::$db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "fieldhelp WHERE keystring = '" . BSApp::$input->escape($this->values['keystring']) . "'")) { - return T('The unique key must be unique.'); + $this->_error(new FieldException(T('The unique key must be unique.'), $field)); + return false; } return true; -- 2.43.5