|| ###################################################################
\*=====================================================================*/
-$GLOBALS['isso:callback']->load('api', null);
+require_once ISSO . '/Api.php';
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',
);
}
- // ###################################################################
/**
- * 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;