]>
git.agnieray.net Git - galette.git/blob - galette/lib/Galette/Entity/FieldsCategories.php
50a127e597b50e5514c70e5d9a0ed91dfba98579
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * Fields categories handling
10 * Copyright © 2009-2014 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/>.
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 * @copyright 2009-2014 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.7dev - 2009-03-28
38 namespace Galette\Entity
;
44 * Fields categories class for galette
47 * @name FieldsCategories
49 * @author Johan Cwiklinski <johan@x-tnd.be>
50 * @copyright 2009-2014 The Galette Team
51 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
52 * @link http://galette.tuxfamily.org
53 * @since Available since 0.7dev - 2009-03-28
56 class FieldsCategories
58 const TABLE
= 'fields_categories';
59 const PK
= 'id_field_category';
65 const ADH_CATEGORY_IDENTITY
= 1;
66 const ADH_CATEGORY_GALETTE
= 2;
67 const ADH_CATEGORY_CONTACT
= 3;
72 * @param Db $zdb Database
73 * @param array $defaults default values
75 public function __construct(Db
$zdb, $defaults)
78 $this->defaults
= $defaults;
82 * Get list of categories
84 * @param Db $zdb Database
88 public static function getList($zdb)
91 $select = $zdb->select(self
::TABLE
);
92 $select->order('position');
95 $results = $zdb->execute($select);
96 foreach ($results as $result) {
97 $categories[] = $result;
100 } catch (\Exception
$e) {
102 '[' . static::class . '] Cannot get fields categories list | ' .
111 * Store the categories
113 * @param Db $zdb Database
114 * @param array $categories Categories
118 public static function setCategories(Db
$zdb, $categories)
121 $zdb->connection
->beginTransaction();
123 $update = $zdb->update(self
::TABLE
);
126 'position' => ':position'
133 $stmt = $zdb->sql
->prepareStatementForSqlObject($update);
135 foreach ($categories as $k => $v) {
140 $stmt->execute($params);
142 $zdb->connection
->commit();
143 } catch (\Exception
$e) {
144 $zdb->connection
->rollBack();
150 * Set default fields categories at install time
153 * @return boolean|Exception
155 public function installInit()
158 //first, we drop all values
159 $delete = $this->zdb
->delete(self
::TABLE
);
160 $this->zdb
->execute($delete);
162 $insert = $this->zdb
->insert(self
::TABLE
);
166 'table_name' => ':table_name',
167 'category' => ':category',
168 'position' => ':position'
171 $stmt = $this->zdb
->sql
->prepareStatementForSqlObject($insert);
173 foreach ($this->defaults
as $d) {
176 self
::PK
=> $d['id'],
177 'table_name' => $d['table_name'],
178 'category' => $d['category'],
179 'position' => $d['position']
185 'Default fields configurations were successfully stored.',
189 } catch (\Exception
$e) {
191 'Unable to initialize default fields configuration.' .