Classes

File phpboost/member/extended-fields/field/AbstractMemberExtendedField.class.php

File phpboost/member/extended-fields/field/AbstractMemberExtendedField.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:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 
<?php
/**
 * Abstract class that proposes a default implementation for the MemberExtendedFieldType interface.
 * @package     PHPBoost
 * @subpackage  Member\extended-fields\field
 * @copyright   &copy; 2005-2019 PHPBoost
 * @license     https://www.gnu.org/licenses/gpl-3.0.html GNU/GPL-3.0
 * @author      Kevin MASSY <reidlos@phpboost.com>
 * @version     PHPBoost 5.2 - last update: 2017 07 06
 * @since       PHPBoost 3.0 - 2010 12 08
 * @contributor Julien BRISWALTER <j1.seth@phpboost.com>
 * @contributor Arnaud GENET <elenwii@phpboost.com>
 * @contributor mipel <mipel@phpboost.com>
*/

abstract class AbstractMemberExtendedField implements MemberExtendedFieldType
{
    protected $lang;
    protected $form;
    protected $field_used_once;
    protected $field_used_phpboost_config;
    protected $disable_fields_configuration = array();
    protected $name;

    /**
     * @var bool
     */
    public function __construct()
    {
        $this->lang = LangLoader::get('user-common');
        $this->field_used_once = false;
        $this->field_used_phpboost_config = false;
        $this->name = 'ExtendedField';
    }

    /**
     * {@inheritdoc}
     */
    public function display_field_create(MemberExtendedField $member_extended_field)
    {
        $fieldset = $member_extended_field->get_fieldset();
        return;
    }

    /**
     * {@inheritdoc}
     */
    public function display_field_update(MemberExtendedField $member_extended_field)
    {
        $fieldset = $member_extended_field->get_fieldset();
        return;
    }

    public function delete_field(MemberExtendedField $member_extended_field)
    {
        return;
    }

    /**
     * {@inheritdoc}
     */
    public function display_field_profile(MemberExtendedField $member_extended_field)
    {
        if ($member_extended_field->get_value())
        {
            return array('name' => $member_extended_field->get_name(), 'value' => $member_extended_field->get_value());
        }
    }

    /**
     * {@inheritdoc}
     */
    public function get_data(HTMLForm $form, MemberExtendedField $member_extended_field)
    {
        $field_name = $member_extended_field->get_field_name();
        return TextHelper::htmlspecialchars($form->get_value($field_name, ''));
    }

    /**
     * {@inheritdoc}
     */
    public function constraint($value)
    {
        if (is_numeric($value))
        {
            switch ($value)
            {
                case 2:
                    return new FormFieldConstraintRegex('`^[a-zA-Z]+$`iu');
                    break;
                case 3:
                    return new FormFieldConstraintRegex('`^[a-zA-Z0-9]+$`iu');
                    break;
                case 7:
                    return new FormFieldConstraintRegex('`^[a-zA-Zàáâãäåçèéêëìíîïðòóôõöùúûüýÿ-]+$`iu');
                    break;
            }
        }
        elseif (is_string($value) && !empty($value))
        {
            return new FormFieldConstraintRegex($value);
        }
    }

    /**
     * {@inheritdoc}
     */
    public function set_disable_fields_configuration(array $names)
    {
        foreach($names as $name)
        {
            $name = TextHelper::strtolower($name);
            switch ($name)
            {
                case 'name':
                    $this->disable_fields_configuration[] = $name;
                    break;
                case 'description':
                    $this->disable_fields_configuration[] = $name;
                    break;
                case 'field_type':
                    $this->disable_fields_configuration[] = $name;
                    break;
                case 'field_required':
                    $this->disable_fields_configuration[] = $name;
                    break;
                case 'regex':
                    $this->disable_fields_configuration[] = $name;
                    break;
                case 'possible_values':
                    $this->disable_fields_configuration[] = $name;
                    break;
                case 'default_value':
                    $this->disable_fields_configuration[] = $name;
                    break;
                case 'authorizations':
                    $this->disable_fields_configuration[] = $name;
                    break;
                default :
                    throw new Exception('Field name ' . $name . ' not exist');
            }
        }
    }

    /**
     * {@inheritdoc}
     */
    public function get_disable_fields_configuration()
    {
        return $this->disable_fields_configuration;
    }

    /**
     * {@inheritdoc}
     */
    public function get_field_used_once()
    {
        return $this->field_used_once;
    }

    /**
     * {@inheritdoc}
     */
    public function set_name($name)
    {
        $this->name = $name;
    }

    /**
     * {@inheritdoc}
     */
    public function get_name()
    {
        return $this->name;
    }

    /**
     * {@inheritdoc}
     */
    public function get_field_used_phpboost_configuration()
    {
        return $this->field_used_phpboost_config;
    }

    public function set_form(HTMLForm $form)
    {
        $this->form = $form;
    }

    public function get_form()
    {
        return $this->form;
    }
}
?>
Annonces