-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
Adherent.php
2291 lines (2111 loc) · 70.1 KB
/
Adherent.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
/**
* Member class for galette
*
* PHP version 5
*
* Copyright © 2009-2023 The Galette Team
*
* This file is part of Galette (http://galette.tuxfamily.org).
*
* Galette is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Galette is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Galette. If not, see <http://www.gnu.org/licenses/>.
*
* @category Entity
* @package Galette
*
* @author Johan Cwiklinski <johan@x-tnd.be>
* @copyright 2009-2023 The Galette Team
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
* @link http://galette.tuxfamily.org
* @since Available since 0.7dev - 2009-06-02
*/
namespace Galette\Entity;
use ArrayObject;
use Galette\Events\GaletteEvent;
use Galette\Features\Socials;
use Throwable;
use Analog\Analog;
use Laminas\Db\Sql\Expression;
use Galette\Core\Db;
use Galette\Core\Picture;
use Galette\Core\GaletteMail;
use Galette\Core\Password;
use Galette\Core\Preferences;
use Galette\Core\History;
use Galette\Repository\Groups;
use Galette\Core\Login;
use Galette\Repository\Members;
use Galette\Features\Dynamics;
/**
* Member class for galette
*
* @category Entity
* @name Adherent
* @package Galette
* @author Johan Cwiklinski <johan@x-tnd.be>
* @copyright 2009-2023 The Galette Team
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
* @link http://galette.tuxfamily.org
* @since Available since 0.7dev - 02-06-2009
*
* @property integer $id
* @property integer|Title $title Either a title id or an instance of Title
* @property string $stitle Title label
* @property string $company_name
* @property string $name
* @property string $surname
* @property string $nickname
* @property string $birthdate Localized birthdate
* @property string $rbirthdate Raw birthdate
* @property string $birth_place
* @property integer $gender
* @property string $sgender Gender label
* @property string $job
* @property string $language
* @property integer $status
* @property string $sstatus Status label
* @property string $address
* @property string $zipcode
* @property string $town
* @property string $country
* @property string $phone
* @property string $gsm
* @property string $email
* @property string $gnupgid
* @property string $fingerprint
* @property string $login
* @property string $creation_date Localized creation date
* @property string $modification_date Localized modification date
* @property string $due_date Localized due date
* @property string $others_infos
* @property string $others_infos_admin
* @property Picture $picture
* @property array $groups
* @property array $managed_groups
* @property integer|Adherent $parent Parent id if parent dep is not loaded, Adherent instance otherwise
* @property array $children
* @property boolean $admin better to rely on isAdmin()
* @property boolean $staff better to rely on isStaff()
* @property boolean $due_free better to rely on isDueFree()
* @property boolean $appears_in_list better to rely on appearsInMembersList()
* @property boolean $active better to rely on isActive()
* @property boolean $duplicate better to rely on isDuplicate()
* @property string $sadmin yes/no
* @property string $sstaff yes/no
* @property string $sdue_free yes/no
* @property string $sappears_in_list yes/no
* @property string $sactive yes/no
* @property string $sfullname
* @property string $sname
* @property string $saddress
* @property string $contribstatus State of member contributions
* @property integer $days_remaining
* @property-read integer $parent_id
* @property Social $social Social networks/Contact
* @property string $number Member number
* @property-read bool $self_adh
*/
class Adherent
{
use Dynamics;
use Socials;
public const TABLE = 'adherents';
public const PK = 'id_adh';
public const NC = 0;
public const MAN = 1;
public const WOMAN = 2;
public const AFTER_ADD_DEFAULT = 0;
public const AFTER_ADD_TRANS = 1;
public const AFTER_ADD_NEW = 2;
public const AFTER_ADD_SHOW = 3;
public const AFTER_ADD_LIST = 4;
public const AFTER_ADD_HOME = 5;
private $_id;
//Identity
private $_title;
private $_company_name;
private $_name;
private $_surname;
private $_nickname;
private $_birthdate;
private $_birth_place;
private $_gender;
private $_job;
private $_language;
private $_active;
private $_status;
//Contact information
private $_address;
private $_zipcode;
private $_town;
private $_country;
private $_phone;
private $_gsm;
private $_email;
private $_gnupgid;
private $_fingerprint;
//Galette relative information
private $_appears_in_list;
private $_admin;
private $_staff = false;
private $_due_free;
private $_login;
private $_password;
private $_creation_date;
private $_modification_date;
private $_due_date;
private $_others_infos;
private $_others_infos_admin;
private $_picture;
private $_oldness;
private $_days_remaining;
private $_groups = [];
private $_managed_groups = [];
private $_parent;
private $_children = [];
private $_duplicate = false;
private $_socials;
private $_number;
private $_row_classes;
private $_self_adh = false;
protected array $_deps = array(
'picture' => true,
'groups' => true,
'dues' => true,
'parent' => false,
'children' => false,
'dynamics' => false,
'socials' => false
);
private $zdb;
private $preferences;
private $fields;
private $history;
private $parent_fields = [
'adresse_adh',
'cp_adh',
'ville_adh',
'email_adh'
];
private $errors = [];
private $sendmail = false;
/**
* Default constructor
*
* @param Db $zdb Database instance
* @param mixed $args Either a ResultSet row, its id or its
* login or its email for to load s specific
* member, or null to just instantiate object
* @param false|array|null $deps Dependencies configuration, see Adherent::$_deps
*/
public function __construct(Db $zdb, $args = null, $deps = null)
{
global $i18n;
$this->zdb = $zdb;
if ($deps !== null) {
if (is_array($deps)) {
$this->_deps = array_merge(
$this->_deps,
$deps
);
} elseif ($deps === false) {
//no dependencies
$this->_deps = array_fill_keys(
array_keys($this->_deps),
false
);
} else {
Analog::log(
'$deps should be an array, ' . gettype($deps) . ' given!',
Analog::WARNING
);
}
}
if ($args == null || is_int($args)) {
if (is_int($args) && $args > 0) {
$this->load($args);
} else {
$this->_active = true;
$this->_language = $i18n->getID();
$this->_creation_date = date("Y-m-d");
$this->_status = $this->getDefaultStatus();
$this->_title = null;
$this->_gender = self::NC;
$gp = new Password($this->zdb);
$this->_password = $gp->makeRandomPassword();
$this->_picture = new Picture();
$this->_admin = false;
$this->_staff = false;
$this->_due_free = false;
$this->_appears_in_list = false;
$this->_parent = null;
if ($this->_deps['dynamics'] === true) {
$this->loadDynamicFields();
}
}
} elseif (is_object($args)) {
$this->loadFromRS($args);
} elseif (is_string($args)) {
$this->loadFromLoginOrMail($args);
}
}
/**
* Loads a member from its id
*
* @param int $id the identifier for the member to load
*
* @return bool true if query succeed, false otherwise
*/
public function load(int $id): bool
{
try {
$select = $this->zdb->select(self::TABLE, 'a');
$select->join(
array('b' => PREFIX_DB . Status::TABLE),
'a.' . Status::PK . '=b.' . Status::PK,
array('priorite_statut')
)->where(array(self::PK => $id));
$results = $this->zdb->execute($select);
if ($results->count() === 0) {
return false;
}
/** @var ArrayObject $result */
$result = $results->current();
$this->loadFromRS($result);
return true;
} catch (Throwable $e) {
Analog::log(
'Cannot load member form id `' . $id . '` | ' . $e->getMessage(),
Analog::WARNING
);
throw $e;
}
}
/**
* Loads a member from its login
*
* @param string $login login for the member to load
*
* @return boolean
*/
public function loadFromLoginOrMail(string $login): bool
{
try {
$select = $this->zdb->select(self::TABLE);
if (GaletteMail::isValidEmail($login)) {
//we got a valid email address, use it
$select->where(array('email_adh' => $login));
} else {
///we did not get an email address, consider using login
$select->where(array('login_adh' => $login));
}
$results = $this->zdb->execute($select);
if ($results->count() > 0) {
/** @var ArrayObject $result */
$result = $results->current();
$this->loadFromRS($result);
}
return true;
} catch (Throwable $e) {
Analog::log(
'Cannot load member form login `' . $login . '` | ' .
$e->getMessage(),
Analog::WARNING
);
throw $e;
}
}
/**
* Populate object from a resultset row
*
* @param ArrayObject $r the resultset row
*
* @return void
*/
private function loadFromRS(ArrayObject $r): void
{
$this->_self_adh = false;
$this->_id = $r->id_adh;
//Identity
if ($r->titre_adh !== null) {
$this->_title = new Title((int)$r->titre_adh);
}
$this->_company_name = $r->societe_adh;
$this->_name = $r->nom_adh;
$this->_surname = $r->prenom_adh;
$this->_nickname = $r->pseudo_adh;
if ($r->ddn_adh != '1901-01-01') {
$this->_birthdate = $r->ddn_adh;
}
$this->_birth_place = $r->lieu_naissance;
$this->_gender = (int)$r->sexe_adh;
$this->_job = $r->prof_adh;
$this->_language = $r->pref_lang;
$this->_active = $r->activite_adh == 1;
$this->_status = (int)$r->id_statut;
//Contact information
$this->_address = $r->adresse_adh;
$this->_zipcode = $r->cp_adh;
$this->_town = $r->ville_adh;
$this->_country = $r->pays_adh;
$this->_phone = $r->tel_adh;
$this->_gsm = $r->gsm_adh;
$this->_email = $r->email_adh;
$this->_gnupgid = $r->gpgid;
$this->_fingerprint = $r->fingerprint;
//Galette relative information
$this->_appears_in_list = $r->bool_display_info == 1;
$this->_admin = $r->bool_admin_adh == 1;
if (
isset($r->priorite_statut)
&& $r->priorite_statut < Members::NON_STAFF_MEMBERS
) {
$this->_staff = true;
}
$this->_due_free = $r->bool_exempt_adh == 1;
$this->_login = $r->login_adh;
$this->_password = $r->mdp_adh;
$this->_creation_date = $r->date_crea_adh;
if ($r->date_modif_adh != '1901-01-01') {
$this->_modification_date = $r->date_modif_adh;
} else {
$this->_modification_date = $this->_creation_date;
}
$this->_due_date = $r->date_echeance;
$this->_others_infos = $r->info_public_adh;
$this->_others_infos_admin = $r->info_adh;
$this->_number = $r->num_adh;
if ($r->parent_id !== null) {
$this->_parent = (int)$r->parent_id;
if ($this->_deps['parent'] === true) {
$this->loadParent();
}
}
if ($this->_deps['children'] === true) {
$this->loadChildren();
}
if ($this->_deps['picture'] === true) {
$this->_picture = new Picture($this->_id);
}
if ($this->_deps['groups'] === true) {
$this->loadGroups();
}
if ($this->_deps['dues'] === true) {
$this->checkDues();
}
if ($this->_deps['dynamics'] === true) {
$this->loadDynamicFields();
}
if ($this->_deps['socials'] === true) {
$this->loadSocials();
}
}
/**
* Load member parent
*
* @return void
*/
private function loadParent(): void
{
if ($this->_parent !== null && !$this->_parent instanceof Adherent) {
$deps = array_fill_keys(array_keys($this->_deps), false);
$this->_parent = new Adherent($this->zdb, (int)$this->_parent, $deps);
}
}
/**
* Load member children
*
* @return void
*/
private function loadChildren(): void
{
$this->_children = array();
try {
$id = self::PK;
$select = $this->zdb->select(self::TABLE);
$select->columns(
array($id)
)->where(['parent_id' => $this->_id]);
$results = $this->zdb->execute($select);
if ($results->count() > 0) {
foreach ($results as $row) {
$deps = $this->_deps;
$deps['children'] = false;
$deps['parent'] = false;
$this->_children[] = new Adherent($this->zdb, (int)$row->$id, $deps);
}
}
} catch (Throwable $e) {
Analog::log(
'Cannot load children for member #' . $this->_id . ' | ' .
$e->getMessage(),
Analog::WARNING
);
throw $e;
}
}
/**
* Load member groups
*
* @return void
*/
public function loadGroups(): void
{
$this->_groups = Groups::loadGroups($this->_id);
$this->_managed_groups = Groups::loadManagedGroups($this->_id);
}
/**
* Load member social network/contact information
*
* @return void
*/
public function loadSocials(): void
{
$this->_socials = Social::getListForMember($this->_id);
}
/**
* Retrieve status from preferences
*
* @return integer
*
*/
private function getDefaultStatus(): int
{
global $preferences;
if ($preferences->pref_statut != '') {
return $preferences->pref_statut;
} else {
Analog::log(
'Unable to get pref_statut; is it defined in preferences?',
Analog::ERROR
);
return Status::DEFAULT_STATUS;
}
}
/**
* Check for dues status
*
* @return void
*/
private function checkDues(): void
{
//how many days since our beloved member has been created
$now = new \DateTime();
$this->_oldness = $now->diff(
new \DateTime($this->_creation_date)
)->days;
if ($this->isDueFree()) {
//no fee required, we don't care about dates
$this->_row_classes .= ' cotis-exempt';
} else {
//ok, fee is required. Let's check the dates
if ($this->_due_date == '') {
$this->_row_classes .= ' cotis-never';
} else {
// To count the days remaining, the next begin date is required.
$due_date = new \DateTime($this->_due_date);
$next_begin_date = clone $due_date;
$next_begin_date->add(new \DateInterval('P1D'));
$date_diff = $now->diff($next_begin_date);
$this->_days_remaining = $date_diff->days;
// Active
if ($date_diff->invert == 0 && $date_diff->days >= 0) {
$this->_days_remaining = $date_diff->days;
if ($this->_days_remaining <= 30) {
if ($date_diff->days == 0) {
$this->_row_classes .= ' cotis-lastday';
}
$this->_row_classes .= ' cotis-soon';
} else {
$this->_row_classes .= ' cotis-ok';
}
// Expired
} elseif ($date_diff->invert == 1 && $date_diff->days >= 0) {
$this->_days_remaining = $date_diff->days;
//check if member is still active
$this->_row_classes .= $this->isActive() ? ' cotis-late' : ' cotis-old';
}
}
}
}
/**
* Is member admin?
*
* @return bool
*/
public function isAdmin(): bool
{
return $this->_admin;
}
/**
* Is user member of staff?
*
* @return bool
*/
public function isStaff(): bool
{
return $this->_staff;
}
/**
* Is member freed of dues?
*
* @return bool
*/
public function isDueFree(): bool
{
return $this->_due_free;
}
/**
* Is member in specified group?
*
* @param string $group_name Group name
*
* @return boolean
*/
public function isGroupMember(string $group_name): bool
{
if (!$this->isDepEnabled('groups')) {
$this->loadGroups();
}
foreach ($this->_groups as $g) {
if ($g->getName() == $group_name) {
return true;
}
}
return false;
}
/**
* Is member manager of specified group?
*
* @param string $group_name Group name
*
* @return boolean
*/
public function isGroupManager(string $group_name): bool
{
if (!$this->isDepEnabled('groups')) {
$this->loadGroups();
}
foreach ($this->_managed_groups as $mg) {
if ($mg->getName() == $group_name) {
return true;
}
}
return false;
}
/**
* Does current member represents a company?
*
* @return boolean
*/
public function isCompany(): bool
{
return trim($this->_company_name ?? '') != '';
}
/**
* Is current member a man?
*
* @return boolean
*/
public function isMan(): bool
{
return (int)$this->_gender === self::MAN;
}
/**
* Is current member a woman?
*
* @return boolean
*/
public function isWoman(): bool
{
return (int)$this->_gender === self::WOMAN;
}
/**
* Can member appears in public members list?
*
* @return bool
*/
public function appearsInMembersList(): bool
{
return $this->_appears_in_list;
}
/**
* Is member active?
*
* @return bool
*/
public function isActive(): bool
{
return $this->_active;
}
/**
* Does member have uploaded a picture?
*
* @return bool
*/
public function hasPicture(): bool
{
return $this->_picture->hasPicture();
}
/**
* Does member have a parent?
*
* @return bool
*/
public function hasParent(): bool
{
return !empty($this->_parent);
}
/**
* Does member have children?
*
* @return bool
*/
public function hasChildren(): bool
{
if ($this->_children === null) {
if ($this->id) {
Analog::log(
'Children has not been loaded!',
Analog::WARNING
);
}
return false;
} else {
return count($this->_children) > 0;
}
}
/**
* Get row class related to current fee status
*
* @param boolean $public we want the class for public pages
*
* @return string the class to apply
*/
public function getRowClass(bool $public = false): string
{
$strclass = ($this->isActive()) ? 'active-account' : 'inactive-account';
if ($public === false) {
$strclass .= $this->_row_classes;
}
return $strclass;
}
/**
* Get current member due status
*
* @return string i18n string representing state of due
*/
public function getDues(): string
{
$ret = '';
$never_contributed = false;
$now = new \DateTime();
// To count the days remaining, the next begin date is required.
if ($this->_due_date === null) {
$this->_due_date = $now->format('Y-m-d');
$never_contributed = true;
}
$due_date = new \DateTime($this->_due_date);
$next_begin_date = clone $due_date;
$next_begin_date->add(new \DateInterval('P1D'));
$date_diff = $now->diff($next_begin_date);
if ($this->isDueFree()) {
$ret = _T("Freed of dues");
} elseif ($never_contributed === true) {
$patterns = array('/%days/', '/%date/');
$cdate = new \DateTime($this->_creation_date);
$replace = array(
$this->_oldness,
$cdate->format(__("Y-m-d"))
);
if ($this->_active) {
$ret = preg_replace(
$patterns,
$replace,
_T("Never contributed: Registered %days days ago (since %date)")
);
} else {
$ret = _T("Never contributed");
}
// Last active or first expired day
} elseif ($this->_days_remaining == 0) {
if ($date_diff->invert == 0) {
$ret = _T("Last day!");
} else {
$ret = _T("Late since today!");
}
// Active
} elseif ($date_diff->invert == 0 && $this->_days_remaining > 0) {
$patterns = array('/%days/', '/%date/');
$replace = array(
$this->_days_remaining,
$due_date->format(__("Y-m-d"))
);
$ret = preg_replace(
$patterns,
$replace,
_T("%days days remaining (ending on %date)")
);
// Expired
} elseif ($date_diff->invert == 1 && $this->_days_remaining > 0) {
$patterns = array('/%days/', '/%date/');
$replace = array(
// We need the number of days expired, not the number of days remaining.
$this->_days_remaining + 1,
$due_date->format(__("Y-m-d"))
);
if ($this->_active) {
$ret = preg_replace(
$patterns,
$replace,
_T("Late of %days days (since %date)")
);
} else {
$ret = _T("No longer member");
}
}
return $ret;
}
/**
* Retrieve Full name and surname for the specified member id
*
* @param Db $zdb Database instance
* @param integer $id Member id
* @param boolean $wid Add member id
* @param boolean $wnick Add member nickname
*
* @return string formatted Name and Surname
*/
public static function getSName(Db $zdb, int $id, bool $wid = false, bool $wnick = false): string
{
try {
$select = $zdb->select(self::TABLE);
$select->where([self::PK => $id]);
$results = $zdb->execute($select);
$row = $results->current();
return self::getNameWithCase(
$row->nom_adh,
$row->prenom_adh,
false,
($wid === true ? $row->id_adh : false),
($wnick === true ? $row->pseudo_adh : false)
);
} catch (Throwable $e) {
Analog::log(
'Cannot get formatted name for member form id `' . $id . '` | ' .
$e->getMessage(),
Analog::WARNING
);
throw $e;
}
}
/**
* Get member name with correct case
*
* @param string $name Member name
* @param string $surname Member surname
* @param false|Title $title Member title to show or false
* @param false|integer $id Member id to display or false
* @param false|string $nick Member nickname to display or false
*
* @return string
*/
public static function getNameWithCase(
?string $name,
?string $surname,
$title = false,
$id = false,
$nick = false
): string {
$str = '';
if ($title instanceof Title) {
$str .= $title->tshort . ' ';
}
$str .= mb_strtoupper($name ?? '', 'UTF-8') . ' ' .
ucwords(mb_strtolower($surname ?? '', 'UTF-8'), " \t\r\n\f\v-_|");
if ($id !== false || !empty($nick)) {
$str .= ' (';
}
if (!empty($nick)) {
$str .= $nick;
}
if ($id !== false) {
if (!empty($nick)) {
$str .= ', ';
}
$str .= $id;
}
if ($id !== false || !empty($nick)) {
$str .= ')';
}
return strip_tags($str);
}
/**
* Change password for a given user
*
* @param Db $zdb Database instance
* @param integer $id_adh Member identifier
* @param string $pass New password
*
* @return boolean
*/
public static function updatePassword(Db $zdb, int $id_adh, string $pass): bool
{
try {
$cpass = password_hash($pass, PASSWORD_BCRYPT);
$update = $zdb->update(self::TABLE);
$update->set(
array('mdp_adh' => $cpass)
)->where([self::PK => $id_adh]);
$zdb->execute($update);
Analog::log(
'Password for `' . $id_adh . '` has been updated.',
Analog::DEBUG
);
return true;
} catch (Throwable $e) {
Analog::log(
'An error occurred while updating password for `' . $id_adh .
'` | ' . $e->getMessage(),
Analog::ERROR
);
throw $e;
}
}
/**
* Get field label
*
* @param string $field Field name
*
* @return string
*/
private function getFieldLabel(string $field): string
{
$label = $this->fields[$field]['label'] ?? '';
//replace " "
$label = str_replace(' ', ' ', $label);
//remove trailing ':' and then trim
$label = trim(trim($label, ':'));
return $label;
}
/**
* Retrieve fields from database
*
* @param Db $zdb Database instance
*
* @return array
*/
public static function getDbFields(Db $zdb): array
{
$columns = $zdb->getColumns(self::TABLE);
$fields = array();
foreach ($columns as $col) {
$fields[] = $col->getName();
}
return $fields;
}
/**
* Mark as self membership
*
* @return void
*/
public function setSelfMembership(): void
{
$this->_self_adh = true;
}