Classes

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

File phpboost/member/extended-fields/field/MemberMultipleChoiceExtendedField.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: 
<?php
/**
 * @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>
*/

class MemberMultipleChoiceExtendedField extends AbstractMemberExtendedField
{
    public function __construct()
    {
        parent::__construct();
        $this->set_disable_fields_configuration(array('regex', 'default_value'));
        $this->set_name(LangLoader::get_message('type.multiple-check','admin-user-common'));
    }

    public function display_field_create(MemberExtendedField $member_extended_field)
    {
        $fieldset = $member_extended_field->get_fieldset();

        $options = array();
        $default_values = array();
        foreach ($member_extended_field->get_possible_values() as $name => $parameters)
        {
            $option = new FormFieldMultipleCheckboxOption($name, stripslashes($parameters['title']));
            $options[] = $option;

            if ($parameters['is_default'])
            {
                $default_values[] = $option;
            }
        }

        $fieldset->add_field(new FormFieldMultipleCheckbox($member_extended_field->get_field_name(), $member_extended_field->get_name(), $default_values, $options, array('required' => (bool)$member_extended_field->get_required(), 'description' => $member_extended_field->get_description())));
    }

    public function display_field_update(MemberExtendedField $member_extended_field)
    {
        $fieldset = $member_extended_field->get_fieldset();

        $options = array();
        $default_values = $this->unserialise_value($member_extended_field->get_value());
        foreach ($member_extended_field->get_possible_values() as $name => $parameters)
        {
            $options[] = new FormFieldMultipleCheckboxOption($name, stripslashes($parameters['title']));
        }

        $fieldset->add_field(new FormFieldMultipleCheckbox($member_extended_field->get_field_name(), $member_extended_field->get_name(), $default_values, $options, array('required' => (bool)$member_extended_field->get_required(), 'description' => $member_extended_field->get_description())));
    }

    public function display_field_profile(MemberExtendedField $member_extended_field)
    {
        $value = implode(', ', $this->unserialise_value($member_extended_field->get_value()));
        if (!empty($value))
        {
            return array('name' => $member_extended_field->get_name(), 'value' => $value);
        }
    }

    public function get_data(HTMLForm $form, MemberExtendedField $member_extended_field)
    {
        $field_name = $member_extended_field->get_field_name();
        $array = array();
        if ($form->has_field($field_name))
        {
            foreach ($form->get_value($field_name) as $field => $value)
            {
                $array[] = $value->get_label();
            }
        }
        return $this->serialise_value($array);
    }

    private function serialise_value(Array $array)
    {
        return implode('|', $array);
    }

    private function unserialise_value($string)
    {
        return explode('|', $string);
    }
}
?>
Annonces