Differences From Artifact [a1455f1902]:

To Artifact [e0994432f7]:


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
		'tel'		=>	'Numéro de téléphone',
		'select'	=>	'Sélecteur de choix',
		'country'	=>	'Sélecteur de pays',
		'text'		=>	'Texte',
		'textarea'	=>	'Texte multi-lignes',
	);













	public function __toString()
	{
		return json_encode($this->champs);
	}

	static public function import()
	{
		$json = file_get_contents(GARRADIN_ROOT . '/include/data/champs_membres.json');
		$json = preg_replace('!/[*].*?[*]/!s', '', $json);
		return new Champs_Membres($json);
	}
























	public function __construct($champs)
	{
		if ($champs instanceOf Champs_Membres)
		{
			$this->champs = $champs->getAll();
		}







>
>
>
>
>
>
>
>
>
>
>
>











>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
		'tel'		=>	'Numéro de téléphone',
		'select'	=>	'Sélecteur de choix',
		'country'	=>	'Sélecteur de pays',
		'text'		=>	'Texte',
		'textarea'	=>	'Texte multi-lignes',
	);

    protected $config_fields = array(
        'type',
        'title',
        'help',
        'editable',
        'mandatory',
        'private',
        'values'
    );

    static protected $presets = null;

	public function __toString()
	{
		return json_encode($this->champs);
	}

	static public function import()
	{
		$json = file_get_contents(GARRADIN_ROOT . '/include/data/champs_membres.json');
		$json = preg_replace('!/[*].*?[*]/!s', '', $json);
		return new Champs_Membres($json);
	}

    static public function importPresets()
    {
        if (is_null(self::$presets))
        {
            $json = file_get_contents(GARRADIN_ROOT . '/include/data/champs_membres.json');
            $json = preg_replace('!/[*].*?[*]/!s', '', $json);
            $champs = json_decode($json, true);

            $json = file_get_contents(GARRADIN_ROOT . '/include/data/champs_membres_supplementaires.json');
            $json = preg_replace('!/[*].*?[*]/!s', '', $json);
            $champs_supplementaires = json_decode($json, true);

            self::$presets = array_merge($champs, $champs_supplementaires);
        }

        return self::$presets;
    }

    static public function listUnusedPresets(Champs_Membres $champs)
    {
        return array_diff_key(self::importPresets(), $champs->getAll());
    }

	public function __construct($champs)
	{
		if ($champs instanceOf Champs_Membres)
		{
			$this->champs = $champs->getAll();
		}
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
	}

	public function getAll()
	{
		return $this->champs;
	}







































































	public function set($champ, $key, $value)
	{
		$this->champs[$champs][$key] = $value;
		return true;
	}






    public function setAll($champs)
    {
        if (!array_key_exists('email', $champs))
        {
            throw new UserException('Le champ E-Mail ne peut être supprimé des fiches membres.');
        }

        foreach ($champs as $key=>$config)
        {
        	if (empty($config['type']) || !array_key_exists($config['type'], $this->types))
	    	{
	    		throw new UserException('Le champ '.$key.' doit être d\'un type connu.');
	    	}

	    	if ($key == 'email')
	    	{
	    		if ($config['type'] != 'email')
	    		{
	    			throw new UserException('Le champ email ne peut être d\'un type différent de email.');
	    		}
	    	}
        }

        $this->champs = $champs;

        return true;
    }

    public function diff()
    {
    	$db = DB::getInstance();
    	//$config
    }






    public function save($copy = true)
    {
    	$db = DB::getInstance();
    	$config = Config::getInstance();

    	// Champs à créer
    	$create = array(
    		'id INTEGER PRIMARY KEY, -- Numéro attribué automatiquement',
    		'id_categorie INTEGER NOT NULL, -- Numéro de catégorie',
    		'passe TEXT NULL, -- Mot de passe',

    	);

    	// Champs à recopier
    	$copy = array(
    		'id',
    		'id_categorie',
    		'passe'

    	);

    	$anciens_champs = $config->get('champs_membres')->getAll();

    	foreach ($this->champs as $key=>$cfg)
    	{
    		if ($cfg['type'] == 'number')







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>






>
>
>
>
>







|

<
<
<
<
|
<
<
<
<
<
<
<













>
>
>
>
>










>






|
>







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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
	}

	public function getAll()
	{
		return $this->champs;
	}

    /**
     * Vérifie la cohérence et la présence des bons éléments pour un champ
     * @param  string $name     Nom du champ
     * @param  array $config    Configuration du champ
     * @return boolean true
     */
    protected function _checkField($name, &$config)
    {
        if (!preg_match('!^\w+(_\w+)*$!', $name))
        {
            throw new UserException('Le nom du champ est invalide.');
        }

         foreach ($config as $key=>&$value)
        {
            if (!in_array($key, $this->config_fields))
            {
                throw new \BadMethodCallException('Champ '.$key.' non valide.');
            }

            if ($key == 'editable' || $key == 'private' || $key == 'mandatory')
            {
                $value = (bool) (int) $value;
            }
            elseif ($key == 'help' || $key == 'title')
            {
                $value = trim((string) $value);
            }
        }

        if (empty($config['title']))
        {
            throw new UserException('Le titre est obligatoire.');
        }

        if (empty($config['type']) || !array_key_exists($config['type'], $this->types))
        {
            throw new UserException('Le type est vide ou non valide.');
        }

        if ($name == 'email' && $config['type'] != 'email')
        {
            throw new UserException('Le champ email ne peut être d\'un type différent de email.');
        }

        return true;
    }

    /**
     * Ajouter un nouveau champ
     * @param string $name Nom du champ
     * @param array $config Configuration du champ
     * @return boolean true
     */
    public function add($name, $config)
    {
        $this->_checkField($name, $config);

        $this->champs[$name] = $config;

        return true;
    }

    /**
     * Modifie un champ particulier
     * @param string $champ Nom du champ
     * @param string $key   Nom de la clé à modifier
     * @param mixed  $value Valeur à affecter
     * @return boolean true
     */
	public function set($champ, $key, $value)
	{
		$this->champs[$champs][$key] = $value;
		return true;
	}

    /**
     * Modifie les champs en interne en vérifiant que tout va bien
     * @param array $champs Liste des champs
     * @return boolean true
     */
    public function setAll($champs)
    {
        if (!array_key_exists('email', $champs))
        {
            throw new UserException('Le champ E-Mail ne peut être supprimé des fiches membres.');
        }

        foreach ($champs as $name=>$config)
        {




            $this->_checkField($name, $config);







        }

        $this->champs = $champs;

        return true;
    }

    public function diff()
    {
    	$db = DB::getInstance();
    	//$config
    }

    /**
     * Enregistre les changements de champs en base de données
     * @param  boolean $copy Recopier les anciennes champs dans les nouveaux ?
     * @return boolean true
     */
    public function save($copy = true)
    {
    	$db = DB::getInstance();
    	$config = Config::getInstance();

    	// Champs à créer
    	$create = array(
    		'id INTEGER PRIMARY KEY, -- Numéro attribué automatiquement',
    		'id_categorie INTEGER NOT NULL, -- Numéro de catégorie',
    		'passe TEXT NULL, -- Mot de passe',
            'date_connexion TEXT NULL, -- Date de dernière connexion',
    	);

    	// Champs à recopier
    	$copy = array(
    		'id',
    		'id_categorie',
    		'passe',
            'date_connexion'
    	);

    	$anciens_champs = $config->get('champs_membres')->getAll();

    	foreach ($this->champs as $key=>$cfg)
    	{
    		if ($cfg['type'] == 'number')