]> git.agnieray.net Git - galette.git/blob - galette/lib/Galette/DynamicFields/File.php
Handle old filenames for non members dynamic files; refs #1697
[galette.git] / galette / lib / Galette / DynamicFields / File.php
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5 /**
6 * File dynamic field
7 *
8 * PHP version 5
9 *
10 * Copyright © 2013-2014 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 DynamicFields
28 * @package Galette
29 *
30 * @author Guillaume Rousse <guillomovitch@gmail.com>
31 * @copyright 2013-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
33 * @link http://galette.tuxfamily.org
34 * @since Available since 0.8 - 2013-07-27
35 */
36
37 namespace Galette\DynamicFields;
38
39 use Analog\Analog;
40 use Galette\Core\Db;
41
42 /**
43 * File dynamic field
44 *
45 * @name File
46 * @category DynamicFields
47 * @package Galette
48 *
49 * @author Guillaume Rousse <guillomovitch@gmail.com>
50 * @copyright 2013-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 */
54
55 class File extends DynamicField
56 {
57 /**
58 * Default constructor
59 *
60 * @param Db $zdb Database instance
61 * @param int $id Optional field id to load data
62 */
63 public function __construct(Db $zdb, $id = null)
64 {
65 parent::__construct($zdb, $id);
66 $this->has_data = true;
67 $this->has_size = true;
68 }
69
70 /**
71 * Get field type
72 *
73 * @return integer
74 */
75 public function getType(): int
76 {
77 return self::FILE;
78 }
79
80 /**
81 * Get file name on disk
82 *
83 * @param int $id Object (member, contribution, ...) ID
84 * @param int $pos Position in the list of values (0-based)
85 * @param string|null $prefix Forced file prefix; if null (defaults) form_name wil be used verbatim
86 *
87 * @return string
88 */
89 public function getFileName(int $id, int $pos, string $prefix = null): string
90 {
91 $form_name = $this->form;
92 if ($form_name === 'adh') {
93 $form_name = 'member'; //fix expected filename
94 }
95
96 $filename = str_replace(
97 [
98 '%form',
99 '%oid',
100 '%fid',
101 '%pos'
102 ],
103 [
104 $prefix ?? $form_name,
105 $id,
106 $this->id,
107 $pos
108 ],
109 '%form_%oid_field_%fid_value_%pos'
110 );
111
112 return $filename;
113 }
114 }