]> git.agnieray.net Git - galette.git/blob - galette/lib/Galette/Repository/DynamicFieldsSet.php
9af798e04db5761c65e3c8154996bd8942ef97b3
[galette.git] / galette / lib / Galette / Repository / DynamicFieldsSet.php
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5 /**
6 * Dynamic field descriptors set
7 *
8 * PHP version 5
9 *
10 * Copyright © 2017 The Galette Team
11 *
12 * This file is part of Galette (http://galette.tuxfamily.org).
13 *
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.
18 *
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.
23 *
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/>.
26 *
27 * @category Repository
28 * @package Galette
29 *
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
33 * @version SVN: $Id$
34 * @link http://galette.tuxfamily.org
35 * @since Available since 0.9dev - 2017-05-20
36 */
37
38 namespace Galette\Repository;
39
40 use Analog\Analog;
41 use Galette\Core\Db;
42 use Galette\Core\Authentication;
43 use Galette\Core\Login;
44 use Galette\DynamicFields\DynamicField;
45
46 /**
47 * Dynamic field descriptors set
48 *
49 * @category Repository
50 * @name DynamicFieldsSet
51 * @package Galette
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
57 */
58
59 class DynamicFieldsSet
60 {
61 private $zdb;
62 private $login;
63
64 /**
65 * Main constructor
66 *
67 * @param Db $zdb Database instance
68 * @param Login $login Login instance
69 */
70 public function __construct(Db $zdb, Login $login)
71 {
72 $this->zdb = $zdb;
73 $this->login = $login;
74 }
75
76 /**
77 * Get fields list for one form
78 *
79 * @param string $form_name Form name
80 *
81 * @return DynamicField[]
82 */
83 public function getList($form_name)
84 {
85 $select = $this->zdb->select(DynamicField::TABLE);
86 $where = ['field_form' => $form_name];
87
88 $select
89 ->where($where)
90 ->order('field_index');
91
92 $results = $this->zdb->execute($select);
93 $access_level = $this->login->getAccessLevel();
94
95 $fields = [];
96 if ($results) {
97 foreach ($results as $r) {
98 $perm = $r['field_perm'];
99 if (($perm == DynamicField::PERM_MANAGER &&
100 $access_level < Authentication::ACCESS_MANAGER) ||
101 ($perm == DynamicField::PERM_STAFF &&
102 $access_level < Authentication::ACCESS_STAFF) ||
103 ($perm == DynamicField::PERM_ADMIN &&
104 $access_level < Authentication::ACCESS_ADMIN)
105 ) {
106 continue;
107 }
108 $df = DynamicField::getFieldType($this->zdb, $r['field_type']);
109 $df->loadFromRs($r);
110 $fields[$r[DynamicField::PK]] = $df;
111 }
112 }
113 return $fields;
114 }
115 }