]>
git.agnieray.net Git - galette.git/blob - galette/lib/Galette/Repository/Titles.php
e2b65c4b56b6d0e7bc209d743610b22ca5ae0144
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
6 * Titles repository management
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-04
38 namespace Galette\Repository
;
40 use Galette\Entity\Title
;
44 * Titles repository management
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-04
58 const TABLE
= 'titles';
59 const PK
= 'id_title';
65 private static $defaults = array(
68 'short_label' => 'Mr.',
73 'short_label' => 'Mrs.',
79 * Get the list of all titles as an array
81 * @param Db $zdb Database instance
85 public static function getArrayList($zdb)
87 $otitles = self
::getList($zdb);
89 foreach ($otitles as $t) {
90 $titles[$t->id
] = $t->short
;
96 * Get the list of all titles
98 * @param Db $zdb Database instance
102 public static function getList($zdb)
104 $select = $zdb->select(self
::TABLE
);
105 $select->order(self
::PK
);
107 $results = $zdb->execute($select);
110 foreach ($results as $r) {
112 $pols[$r->$pk] = new Title($r);
119 * Set default titles at install time
121 * @param Db $zdb Database instance
123 * @return boolean|Exception
125 public function installInit($zdb)
128 //first, we drop all values
129 $delete = $zdb->delete(self
::TABLE
);
130 $zdb->execute($delete);
132 $insert = $zdb->insert(self
::TABLE
);
136 'short_label' => ':short',
137 'long_label' => ':long'
140 $stmt = $zdb->sql
->prepareStatementForSqlObject($insert);
142 $zdb->handleSequence(
144 count(self
::$defaults)
147 foreach (self
::$defaults as $d) {
148 $short = _T($d['short_label']);
150 if ($d['long_label'] !== null) {
151 $long = _T($d['long_label']);
155 'id_title' => $d['id_title'],
156 'short_label' => $short,
157 'long_label' => $long
163 'Default titles were successfully stored into database.',
167 } catch (\Exception
$e) {
169 'Unable to initialize default titles. ' . $e->getMessage(),
179 * @param integer $title The title id to retrieve
181 * @return translated title short version
183 public static function getTitle($title)
187 $select = $zdb->select(self
::TABLE
);
189 ->where(array(self
::PK
=> $title));
191 $results = $zdb->execute($select);
192 $result = $results->current();
193 $res = $result->short_label
;