Classes

File builder/form/field/constraint/FormFieldConstraintUserExist.class.php

File builder/form/field/constraint/FormFieldConstraintUserExist.class.php

 1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 
<?php
/**
 * @package     Builder
 * @subpackage  Form\field\constraint
 * @copyright   &copy; 2005-2019 PHPBoost
 * @license     https://www.gnu.org/licenses/gpl-3.0.html GNU/GPL-3.0
 * @author      Julien BRISWALTER <j1.seth@phpboost.com>
 * @version     PHPBoost 5.2 - last update: 2016 02 11
 * @since       PHPBoost 4.1 - 2014 01 19
*/

class FormFieldConstraintUserExist extends AbstractFormFieldConstraint
{
    private $error_message;

    public function __construct($error_message = '')
    {
        if (empty($error_message))
        {
            $error_message = LangLoader::get_message('user.not_exists', 'status-messages-common');
        }
        $this->set_validation_error_message($error_message);
        $this->error_message = TextHelper::to_js_string($error_message);
    }

    public function validate(FormField $field)
    {
        return $field->get_value() ? $this->user_exists($field) : true;
    }

    public function user_exists(FormField $field)
    {
        if ($field->get_value())
        {
            return PersistenceContext::get_querier()->row_exists(DB_TABLE_MEMBER, 'WHERE display_name=:display_name', array(
                'display_name' => $field->get_value()
            ));
        }
        return false;
    }

    public function get_js_validation(FormField $field)
    {
        return 'UserExistValidator(' . TextHelper::to_js_string($field->get_id()) .', '. $this->error_message . ')';
    }
}

?>
Annonces