3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * Dynamic field descriptors set
10 * Copyright © 2017 The Galette Team
12 * This file is part of Galette (http://galette.tuxfamily.org).
14 * Galette is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * Galette is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
27 * @category Repository
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 * @copyright 2017 The Galette Team
32 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
34 * @link http://galette.tuxfamily.org
35 * @since Available since 0.9dev - 2017-05-20
38 namespace Galette\Repository
;
42 use Galette\Core\Authentication
;
43 use Galette\Core\Login
;
44 use Galette\DynamicFields\DynamicField
;
47 * Dynamic field descriptors set
49 * @category Repository
50 * @name DynamicFieldsSet
52 * @author Johan Cwiklinski <johan@x-tnd.be>
53 * @copyright 2017 The Galette Team
54 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
55 * @link http://galette.tuxfamily.org
56 * @since Available since 0.9dev - 2017-05-20
59 class DynamicFieldsSet
67 * @param Db $zdb Database instance
68 * @param Login $login Login instance
70 public function __construct(Db
$zdb, Login
$login)
73 $this->login
= $login;
77 * Get fields list for one form
79 * @param string $form_name Form name
81 * @return DynamicField[]
83 public function getList($form_name)
85 $select = $this->zdb
->select(DynamicField
::TABLE
);
86 $where = ['field_form' => $form_name];
90 ->order('field_index');
92 $results = $this->zdb
->execute($select);
93 $access_level = $this->login
->getAccessLevel();
97 foreach ($results as $r) {
98 $perm = $r['field_perm'];
100 ($perm == DynamicField
::PERM_MANAGER
&&
101 $access_level < Authentication
::ACCESS_MANAGER
) ||
102 ($perm == DynamicField
::PERM_STAFF
&&
103 $access_level < Authentication
::ACCESS_STAFF
) ||
104 ($perm == DynamicField
::PERM_ADMIN
&&
105 $access_level < Authentication
::ACCESS_ADMIN
)
109 $df = DynamicField
::getFieldType($this->zdb
, $r['field_type']);
111 $fields[$r[DynamicField
::PK
]] = $df;