]>
git.agnieray.net Git - galette.git/blob - galette/lib/Galette/Features/Socials.php
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
10 * Copyright © 2021 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 2021 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 https://galette.eu
37 namespace Galette\Features
;
39 use Galette\Entity\Adherent
;
40 use Galette\Entity\Social
;
43 * Replacements feature
48 * @author Johan Cwiklinski <johan@x-tnd.be>
49 * @copyright 2020-2021 The Galette Team
50 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
51 * @link http://galette.eu
57 protected $socials_input = [];
62 * @param array $post User input
66 protected function checkSocials(array $post)
68 $this->socials_input
= [];
69 foreach ($post as $key => $value) {
70 if (str_starts_with($key, 'social_')) {
71 $this->socials_input
[$key] = $value;
77 * Store social networks/contacts
79 * @param int|null $id ID
83 protected function storeSocials(int $id = null): bool
85 $existings = Social
::getListForMember($id);
86 foreach ($this->socials_input
as $key => $value) {
88 str_starts_with($key, 'social_new_type')
90 && isset($this->socials_input
[str_replace('_type', '_value', $key)])
91 && !empty($this->socials_input
[str_replace('_type', '_value', $key)])
94 $new_index = (int)str_replace('social_new_type_', '', $key);
95 $social = new Social($this->zdb
);
98 ->setLinkedMember($id)
99 ->setUrl($this->socials_input
['social_new_value_' . $new_index])
101 } elseif (str_starts_with($key, 'social_') && !str_starts_with($key, 'social_new_')) {
102 //existing social network
103 $social_id = (int)str_replace('social_', '', $key);
104 $social = $existings[$social_id];
105 if ($value != $social->url
) {
110 unset($existings[$social_id]);
114 if (count($existings)) {
115 $social = new Social($this->zdb
);
116 $social->remove(array_keys($existings));
123 * Get core registered types
126 protected function getCoreRegisteredTypes(): array
128 return $this->getRegisteredTypes(true);
132 * Get member registered types
136 public function getMemberRegisteredTypes(): array
138 return $this->getRegisteredTypes(false);
142 * Get registered types
144 * @param bool $core True for core type, false for members ones
148 protected function getRegisteredTypes(bool $core): array
150 $select = $this->zdb
->select(Social
::TABLE
, 's');
151 $select->quantifier('DISTINCT')->columns(['type']);
152 if ($core === true) {
153 $select->where(Adherent
::PK
. ' IS NULL');
155 $select->where(Adherent
::PK
. ' IS NOT NULL');
158 $results = $this->zdb
->execute($select);
160 foreach ($results as $result) {
161 $types[$result->type
] = $result->type
;