-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathRepositoryHierarchy.php
1908 lines (1647 loc) · 80.1 KB
/
RepositoryHierarchy.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
/**
* webtrees: online genealogy
* Copyright (C) 2023 webtrees development team
* <http://webtrees.net>
*
* Fancy Research Links (webtrees custom module):
* Copyright (C) 2023 Carmen Just
* <https://justcarmen.nl>
*
* Fancy Simple media display module (webtrees custom module):
* Copyright (C) 2023 Carmen Just
* <https://justcarmen.nl>
*
* RepositoryHierarchy (webtrees custom module):
* Copyright (C) 2023 Markus Hemprich
* <http://www.familienforschung-hemprich.de>
*
* This program 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.
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace Jefferson49\Webtrees\Module\RepositoryHierarchy;
use Exception;
use Fig\Http\Message\RequestMethodInterface;
use Fig\Http\Message\StatusCodeInterface;
use Fisharebest\Localization\Translation;
use Fisharebest\Webtrees\Auth;
use Fisharebest\Webtrees\Contracts\ElementInterface;
use Fisharebest\Webtrees\Contracts\UserInterface;
use Fisharebest\Webtrees\Date;
use Fisharebest\Webtrees\FlashMessages;
use Fisharebest\Webtrees\GedcomRecord;
use Fisharebest\Webtrees\Http\RequestHandlers\FamilyPage;
use Fisharebest\Webtrees\Http\RequestHandlers\IndividualPage;
use Fisharebest\Webtrees\Http\RequestHandlers\MediaPage;
use Fisharebest\Webtrees\Http\RequestHandlers\NotePage;
use Fisharebest\Webtrees\Http\RequestHandlers\RepositoryPage;
use Fisharebest\Webtrees\Http\RequestHandlers\SourcePage;
use Fisharebest\Webtrees\Http\RequestHandlers\SubmitterPage;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Module\AbstractModule;
use Fisharebest\Webtrees\Module\ModuleConfigInterface;
use Fisharebest\Webtrees\Module\ModuleConfigTrait;
use Fisharebest\Webtrees\Module\ModuleCustomInterface;
use Fisharebest\Webtrees\Module\ModuleCustomTrait;
use Fisharebest\Webtrees\Module\ModuleDataFixInterface;
use Fisharebest\Webtrees\Module\ModuleDataFixTrait;
use Fisharebest\Webtrees\Module\ModuleGlobalInterface;
use Fisharebest\Webtrees\Module\ModuleGlobalTrait;
use Fisharebest\Webtrees\Module\ModuleInterface;
use Fisharebest\Webtrees\Module\ModuleListInterface;
use Fisharebest\Webtrees\Module\ModuleListTrait;
use Fisharebest\Webtrees\Registry;
use Fisharebest\Webtrees\Repository;
use Fisharebest\Webtrees\Services\DataFixService;
use Fisharebest\Webtrees\Services\LinkedRecordService;
use Fisharebest\Webtrees\Services\ModuleService;
use Fisharebest\Webtrees\Session;
use Fisharebest\Webtrees\Source;
use Fisharebest\Webtrees\Tree;
use Fisharebest\Webtrees\Validator;
use Fisharebest\Webtrees\View;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Database\Capsule\Manager as DB;
use Illuminate\Support\Collection;
use Jefferson49\Webtrees\Internationalization\MoreI18N;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use RuntimeException;
use function route;
/**
* Main class to create and view a Repository Hierarchy
*/
class RepositoryHierarchy extends AbstractModule implements
MiddlewareInterface,
ModuleConfigInterface,
ModuleCustomInterface,
ModuleDataFixInterface,
ModuleGlobalInterface,
ModuleListInterface,
RequestHandlerInterface
{
use ModuleConfigTrait;
use ModuleCustomTrait;
use ModuleListTrait;
use ModuleGlobalTrait;
use ModuleDataFixTrait;
//Custom module version
public const CUSTOM_VERSION = '1.5.1';
//Routes, attributes
protected const MODULE_NAME_IN_ROUTE = 'repositoryhierarchy';
protected const HELP_TEXTS_IN_ROUTE = 'repositoryhierarchy_helptexts';
protected const CREATE_SOURCE_IN_ROUTE = 'repositoryhierarchy_create_source';
protected const FIX_CALL_NUMBER_IN_ROUTE = 'repositoryhierarchy_fix_callnumbers';
protected const REPO_ACTIONS_IN_ROUTE = 'repositoryhierarchy_repo_actions';
protected const XML_SETTINGS_MODAL_IN_ROUTE = 'repositoryhierarchy_xml_settings_modal';
protected const XML_SETTINGS_ACTION_IN_ROUTE = 'repositoryhierarchy_xml_settings_action';
protected const COPY_SOURCE_CITATION_IN_ROUTE = 'repositoryhierarchy_copy_citation';
protected const PASTE_SOURCE_CITATION_IN_ROUTE = 'repositoryhierarchy_paste_citation';
protected const DELETE_SOURCE_CITATION_IN_ROUTE = 'repositoryhierarchy_delete_citation';
protected const SORT_SOURCE_CITATION_IN_ROUTE = 'repositoryhierarchy_sort_citation';
protected const TREE_ATTRIBUTE_DEFAULT = '{tree}';
protected const XREF_ATTRIBUTE_DEFAULT = '{xref}';
protected const DELIMITER_ATTRIBUTE_DEFAULT = '{delimiter_expression}';
protected const COMMAND_ATTRIBUTE_DEFAULT = '{command}';
protected const TOPIC_ATTRIBUTE_DEFAULT = '{topic}';
protected const SOURCE_CALL_NUMBER_ATTRIBUTE_DEFAULT = '{source_call_number}';
protected const CATEGORY_NAME_ATTRIBUTE_DEFAULT = '{category_name}';
protected const CATEGORY_FULL_NAME_ATTRIBUTE_DEFAULT = '{category_full_name}';
protected const FACT_ID_ATTRIBUTE_DEFAULT = '{fact_id}';
//Strings cooresponding to variable names
public const VAR_DATA_FIX = 'data_fix';
public const VAR_DATA_FIXES = 'data_fixes';
public const VAR_DATA_FIX_TITLE = 'title';
public const VAR_DATA_FIX_TYPES = 'types';
public const VAR_DATA_FIX_CATEGORY_NAME_REPLACE = 'category_name_replace';
public const VAR_DATA_FIX_PENDING_URL = 'pending_url';
//The separator for delimiter expressions and its substitue
public const DELIMITER_SEPARATOR = ';';
public const DELIMITER_ESCAPE = '{delimiter_escape}';
//All the characters, which need to be escaped because of regular expressions
public const ESCAPE_CHARACTERS = '$ ( ) * + . ? [ ] \ | ';
//Prefences, Settings
public const PREF_DELIMITER = 'DELIM_';
public const PREF_REPOSITORY = 'REPO_';
public const PREF_SHOW_HELP_ICON = 'show_help_icon';
public const PREF_SHOW_HELP_LINK = 'show_help_link';
public const PREF_SHOW_CATEGORY_LABEL = 'show_category_label';
public const PREF_SHOW_CATEGORY_TITLE = 'show_category_title';
public const PREF_SHOW_TRUNCATED_CALL_NUMBER = 'show_truncated_call_number';
public const PREF_SHOW_TRUNCATED_CATEGORY = 'show_truncated_category';
public const PREF_SHOW_TITLE = 'show_title';
public const PREF_SHOW_XREF = 'show_xref';
public const PREF_SHOW_AUTHOR = 'show_author';
public const PREF_SHOW_DATE_RANGE = 'show_date_range';
public const PREF_SHOW_CATEGORY_EXPANDED = 'show_category_expanded';
public const PREF_ALLOW_ADMIN_DELIMITER = 'allow_admin_delimiter';
public const PREF_MODULE_VERSION = 'module_version';
public const PREF_START_REPOSITORY = 'start_repository';
public const PREF_VIRTUAL_REPOSITORY = 'virtual_repository';
public const PREF_SHOWN_SOURCE_FACTS_IN_CITATIONS ='shown_source_facts_in_citations';
public const PREF_EXPANDED_SOURCE_FACTS_IN_CITATIONS ='expanded_facts_in_citations';
public const PREF_SHOW_MEDIA_AFTER_CITATIONS = 'show_media_after_citations';
public const PREF_ENABLE_COPY_PASTE_CITATIONS ='enable_copy_paste_citations';
public const PREF_SHOW_DATE_RANGE_FOR_CATEGORY ='show_date_range_for_category';
public const PREF_SHOW_ATOM_LINKS ='show_atom_links';
public const PREF_ATOM_SLUG ='atom_slug';
public const PREF_ATOM_SLUG_TITLE ='title';
public const PREF_ATOM_SLUG_CALL_NUMBER ='call_number';
public const PREF_WEBTREES_BASE_URL = 'webtrees_base_url';
public const PREF_ATOM_BASE_URL = 'atom_base_url';
public const PREF_ATOM_REPOSITORIES = 'atom_repositories';
public const PREF_XML_VERSION = 'xml_version_';
public const PREF_FINDING_AID_TITLE = 'fi_aid_title_';
public const PREF_COUNTRY_CODE = 'country_code_';
public const PREF_MAIN_AGENCY_CODE = 'agency_code_';
public const PREF_FINDING_AID_IDENTIFIER = 'fi_aid_id_';
public const PREF_FINDING_AID_URL = 'fi_aid_url_';
public const PREF_FINDING_AID_PUBLISHER = 'fi_aid_publ_';
public const PREF_ALLOW_ADMIN_XML_SETTINGS = 'allow_admin_xml_settings';
public const PREF_SHOW_FINDING_AID_CATEGORY_TITLE = 'show_finding_aid_category_title';
public const PREF_SHOW_FINDING_AID_ADDRESS = 'show_finding_aid_address';
public const PREF_SHOW_FINDING_AID_TOC = 'show_finding_aid_toc';
public const PREF_SHOW_FINDING_AID_TOC_LINKS = 'show_finding_aid_toc_links';
public const PREF_SHOW_FINDING_AID_TOC_TITLES = 'show_finding_aid_toc_titles';
public const PREF_SHOW_FINDING_AID_WT_LINKS = 'show_finding_aid_wt_links';
public const PREF_USE_META_REPOSITORIES = 'use_meta_repositories';
public const PREF_ALLOW_RENAME = 'allow_rename';
public const PREF_ALLOW_NEW_SOURCE = 'allow_new_source';
public const PREF_CITATION_GEDCOM = 'citation_gedcom';
public const PREF_ENABLE_DELETE_CITATIONS ='enable_delete_citations';
public const PREF_ENABLE_SORT_CITATIONS ='enable_sort_citations';
public const PREF_SHOW_NOTES_FOR_MEDIA_OBJECTS ='show_notes_for_media_objects';
//Old prefences/settings not used any more, but needed for version updates
public const PREF_DELETED = 'deleted';
public const OLD_PREF_FINDING_AID_TITLE = 'finding_aid_title_';
public const OLD_PREF_FINDING_AID_IDENTIFIER = 'finding_aid_id_';
public const OLD_PREF_FINDING_AID_URL = 'finding_aid_url_';
public const OLD_PREF_FINDING_AID_PUBLISHER = 'finding_aid_publ_';
public const OLD_PREF_MAIN_AGENCY_CODE = 'main_agency_code_';
public const OLD_PREF_SHOW_SOURCE_FACTS_IN_CITATIONS = 'show_source_facts_in_citations';
public const OLD_PREF_SHOW_REPO_FACTS_IN_CITATIONS = 'show_repo_facts_in_citations';
public const OLD_PREF_EXPAND_REPOS_IN_CITATIONS ='expand_repos_in_citations';
public const OLD_PREF_SHOW_SOURCE_MEDIA_IN_CITATIONS ='show_source_media_in_citations';
public const OLD_PREF_SHOW_FURTHER_FACTS_IN_CITATIONS ='show_further_facts_in_citations';
public const OLD_PREF_EXPANDED_SOURCE_FACTS_IN_CITATIONS ='explanded_facts_in_citations';
//String for admin for use in preferences names
public const ADMIN_USER_STRING = 'admin';
//Commands to load and save delimiters
public const CMD_NONE = 'none';
public const CMD_LOAD_ADMIN_DELIM = 'load_delimiter_from_admin';
public const CMD_LOAD_DELIM = 'load_delimiter';
public const CMD_SAVE_DELIM = 'save_delimiter';
public const CMD_SAVE_REPO = 'save_repository';
public const CMD_LOAD_REPO = 'load_repository';
public const CMD_DOWNLOAD = 'command_download';
public const CMD_LOAD_ADMIN_XML_SETTINGS = 'load_admin_xml_settings';
//Constants for page names
public const LAST_PAGE_NAME = 'last_page_name';
public const LAST_PAGE_TREE = 'last_page_tree';
public const LAST_PAGE_PARAMETER = 'last_page_parameter';
public const PAGE_NAME_INDIVIDUAL = 'individual.php';
public const PAGE_NAME_FAMILY = 'family.php';
public const PAGE_NAME_OTHER = 'other';
//Comands for repositories
public const CMD_SET_AS_START_REPO = 'set as start repository';
//User reference types in SOUR:REFN:TYPE
public const SOUR_REFN_TYPE_META_REPO = 'META_REPOSITORY';
//Github repository
public const GITHUB_REPO = 'Jefferson49/RepositoryHierarchy';
//Github API URL to get the information about the latest releases
public const GITHUB_API_LATEST_VERSION = 'https://api.github.com/repos/'. self::GITHUB_REPO . '/releases/latest';
public const GITHUB_API_TAG_NAME_PREFIX = '"tag_name":"v';
//Author of custom module
public const CUSTOM_AUTHOR = 'Markus Hemprich';
//Website of author
public const AUTHOR_WEBSITE = 'http://www.familienforschung-hemprich.de';
//The tree, to which the repository hierarchy relates
private Tree $tree;
//The xref string of the repository, to which the repository hierarchy relates
private string $repository_xref;
//The xref string of the meta repository (if available)
private string $meta_repository_xref;
//The repository, to which the repository hierarchy relates
private Repository $repository;
//The meta repository (if available)
private Repository $meta_repository;
//Root element of category hierarchy
private CallNumberCategory $root_category;
//The data fix service
private DataFixService $data_fix_service;
//The full name of the call number category to be fixed
private string $data_fix_category_full_name = '';
//The name of the call number category to be fixed
private string $data_fix_category_name = '';
//The path of the .po files for call number category titles
private string $call_number_category_titles_po_file_path;
//The call number category title service, which is used
private C16Y $call_number_category_title_service;
//A list of custom views, which are registered by the module
private Collection $custom_view_list;
//Tables for fast access to source data
public array $title_of_source;
public array $author_of_source;
public array $call_number_of_source;
public array $truncated_call_number_of_source;
public array $date_range_of_source;
public array $date_range_text_of_source;
public array $iso_date_range_text_of_source;
//All source facts, which can be shown within source citations
public static Collection $ALL_SOURCE_FACTS_IN_CITATIONS;
//All source facts, which can be expanded within source citations
public static Collection $EXPANDABLE_SOURCE_FACTS_IN_CITATIONS;
/**
* Constructor
*/
public function __construct()
{
//Caution: Do not use the shared library jefferson47/webtrees-common within __construct(),
// because it might result in wrong autoload behavior
}
/**
* {@inheritDoc}
*
* @return void
*
* @see \Fisharebest\Webtrees\Module\AbstractModule::boot()
*/
public function boot(): void
{
//Check module version and update preferences etc.
$this->checkModuleVersionUpdate();
//Create data fix service
$this->data_fix_service = new DataFixService();
//Path for .po files (if call number category titles are used)
$this->call_number_category_titles_po_file_path = __DIR__ . '/resources/caln/';
//Initialization of source data tables
$this->title_of_source = [];
$this->author_of_source = [];
$this->call_number_of_source = [];
$this->date_range_of_source = [];
$this->date_range_text_of_source = [];
$this->iso_date_range_text_of_source = [];
//Initialization of the custom view list
$this->custom_view_list = new Collection;
$ignore_facts = ['TITL', 'CHAN'];
//Initialization of all source facts, which can be shown within source citations
self::$ALL_SOURCE_FACTS_IN_CITATIONS = Collection::make(Registry::elementFactory()->make('SOUR')->subtags())
->filter(static fn (string $value, string $key): bool => !in_array($key, $ignore_facts, true))
->mapWithKeys(static fn (string $value, string $key): array => [$key => 'SOUR:' . $key])
->map(static fn (string $tag): ElementInterface => Registry::elementFactory()->make($tag))
->filter(static fn (ElementInterface $element): bool => !$element instanceof UnknownElement)
->map(static fn (ElementInterface $element): string => $element->label())
->sort(I18N::comparator());
//Initialization of source facts, which can expanded within source citations
self::$EXPANDABLE_SOURCE_FACTS_IN_CITATIONS = Collection::make([
'REPO' => MoreI18N::xlate('Repository'),
'OBJE' => MoreI18N::xlate('Media object'),
'DATA' => MoreI18N::xlate('Data'),
'TEXT' => MoreI18N::xlate('Text'),
]);
$router = Registry::routeFactory()->routeMap();
//Register a route for the class
$router ->get(
self::class,
'/tree/'.self::TREE_ATTRIBUTE_DEFAULT.
'/'.self::MODULE_NAME_IN_ROUTE.
'/xref/'.self::XREF_ATTRIBUTE_DEFAULT.
'/command/'.self::COMMAND_ATTRIBUTE_DEFAULT,
$this
)
->allows(RequestMethodInterface::METHOD_POST);
//Register a route for the help texts
$router->get(
RepositoryHierarchyHelpTexts::class,
'/'.self::HELP_TEXTS_IN_ROUTE.
'/topic/'.self::TOPIC_ATTRIBUTE_DEFAULT
)
->allows(RequestMethodInterface::METHOD_POST);
//Register a route for the create source modal
$router ->get(
CreateSourceModal::class,
'/tree/'.self::TREE_ATTRIBUTE_DEFAULT.
'/'.self::CREATE_SOURCE_IN_ROUTE.
'/xref/'.self::XREF_ATTRIBUTE_DEFAULT
)
->allows(RequestMethodInterface::METHOD_POST);
//Register a route for the call number fix action
$router ->get(
CallNumberDataFix::class,
'/tree/'.self::TREE_ATTRIBUTE_DEFAULT.
'/'.self::FIX_CALL_NUMBER_IN_ROUTE.
'/xref/'.self::XREF_ATTRIBUTE_DEFAULT
)
->allows(RequestMethodInterface::METHOD_POST);
//Register a route for the XML export settings modal
$router ->get(
XmlExportSettingsModal::class,
'/tree/'.self::TREE_ATTRIBUTE_DEFAULT.
'/'.self::XML_SETTINGS_MODAL_IN_ROUTE.
'/xref/'.self::XREF_ATTRIBUTE_DEFAULT.
'/command/'.self::COMMAND_ATTRIBUTE_DEFAULT
)
->allows(RequestMethodInterface::METHOD_POST);
//Register a route for the XML export settings action
$router ->get(
XmlExportSettingsAction::class,
'/tree/'.self::TREE_ATTRIBUTE_DEFAULT.
'/'.self::XML_SETTINGS_ACTION_IN_ROUTE.
'/xref/'.self::XREF_ATTRIBUTE_DEFAULT.
'/command/'.self::COMMAND_ATTRIBUTE_DEFAULT
)
->allows(RequestMethodInterface::METHOD_POST);
//Register a route for the copy source citation action
$router ->get(
CopySourceCitation::class,
'/tree/'.self::TREE_ATTRIBUTE_DEFAULT.
'/'.self::COPY_SOURCE_CITATION_IN_ROUTE.
'/xref/'.self::XREF_ATTRIBUTE_DEFAULT
)
->allows(RequestMethodInterface::METHOD_POST);
//Register a route for the paste source citation action
$router ->get(
PasteSourceCitation::class,
'/tree/'.self::TREE_ATTRIBUTE_DEFAULT.
'/'.self::PASTE_SOURCE_CITATION_IN_ROUTE.
'/xref/'.self::XREF_ATTRIBUTE_DEFAULT.
'/fact_id/'.self::FACT_ID_ATTRIBUTE_DEFAULT
)
->allows(RequestMethodInterface::METHOD_POST);
//Register a route for the delete source citation action
$router ->get(
DeleteSourceCitation::class,
'/tree/'.self::TREE_ATTRIBUTE_DEFAULT.
'/'.self::DELETE_SOURCE_CITATION_IN_ROUTE.
'/xref/'.self::XREF_ATTRIBUTE_DEFAULT.
'/fact_id/'.self::FACT_ID_ATTRIBUTE_DEFAULT
)
->allows(RequestMethodInterface::METHOD_POST);
//Register a route for the sort source citation action
$router ->get(
SortSourceCitation::class,
'/tree/'.self::TREE_ATTRIBUTE_DEFAULT.
'/'.self::SORT_SOURCE_CITATION_IN_ROUTE.
'/xref/'.self::XREF_ATTRIBUTE_DEFAULT.
'/fact_id/'.self::FACT_ID_ATTRIBUTE_DEFAULT
)
->allows(RequestMethodInterface::METHOD_POST);
//Register a namespace for the views
View::registerNamespace(self::viewsNamespace(), $this->resourcesFolder() . 'views/');
//Register a custom view for facts in order to show additional source facts in citations, media objects in facts, or AtoM links
//Also used to show additonal icons to copy/delete source citation
//Also used to show media objects with several images (code from jc-simple-media-display)
View::registerCustomView('::fact-gedcom-fields', $this->name() . '::fact-gedcom-fields');
$this->custom_view_list->add($this->name() . '::fact-gedcom-fields');
//Register a custom view for fact edit links in order to allow pasting source citations
View::registerCustomView('::fact-edit-links', $this->name() . '::fact-edit-links');
$this->custom_view_list->add($this->name() . '::fact-edit-links');
//Register a custom view for individual page name in order to allow pasting source citations in names
View::registerCustomView('::individual-page-name', $this->name() . '::individual-page-name');
$this->custom_view_list->add($this->name() . '::individual-page-name');
}
/**
* {@inheritDoc}
*
* @return string
*
* @see \Fisharebest\Webtrees\Module\AbstractModule::title()
*/
public function title(): string
{
return I18n::translate('Repository Hierarchy');
}
/**
* {@inheritDoc}
*
* @return string
*
* @see \Fisharebest\Webtrees\Module\AbstractModule::description()
*/
public function description(): string
{
/* I18N: Description of the “AncestorsChart” module */
return I18N::translate('A hierarchical structured list of the sources of an archive based on the call numbers of the sources');
}
/**
* {@inheritDoc}
*
* @return string
*
* @see \Fisharebest\Webtrees\Module\AbstractModule::resourcesFolder()
*/
public function resourcesFolder(): string
{
return __DIR__ . '/resources/';
}
/**
* {@inheritDoc}
*
* @return string
*
* @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleAuthorName()
*/
public function customModuleAuthorName(): string
{
return self::CUSTOM_AUTHOR;
}
/**
* {@inheritDoc}
*
* @return string
*
* @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
*/
public function customModuleVersion(): string
{
return self::CUSTOM_VERSION;
}
/**
* {@inheritDoc}
*
* @return string
*
* @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleLatestVersion()
*/
public function customModuleLatestVersion(): string
{
// No update URL provided.
if (self::GITHUB_API_LATEST_VERSION === '') {
return $this->customModuleVersion();
}
return Registry::cache()->file()->remember(
$this->name() . '-latest-version',
function (): string {
try {
$client = new Client(
[
'timeout' => 3,
]
);
$response = $client->get(self::GITHUB_API_LATEST_VERSION);
if ($response->getStatusCode() === StatusCodeInterface::STATUS_OK) {
$content = $response->getBody()->getContents();
preg_match_all('/' . self::GITHUB_API_TAG_NAME_PREFIX . '\d+\.\d+\.\d+/', $content, $matches, PREG_OFFSET_CAPTURE);
if(!empty($matches[0]))
{
$version = $matches[0][0][0];
$version = substr($version, strlen(self::GITHUB_API_TAG_NAME_PREFIX));
}
else
{
$version = $this->customModuleVersion();
}
return $version;
}
} catch (GuzzleException $ex) {
// Can't connect to the server?
}
return $this->customModuleVersion();
},
86400
);
}
/**
* {@inheritDoc}
*
* @return string
*
* @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleSupportUrl()
*/
public function customModuleSupportUrl(): string
{
return 'https://github.com/' . self::GITHUB_REPO;
}
/**
* {@inheritDoc}
*
* @param string $language
*
* @return array
*
* @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customTranslations()
*/
public function customTranslations(string $language): array
{
$lang_dir = $this->resourcesFolder() . 'lang/';
$file = $lang_dir . $language . '.mo';
if (file_exists($file)) {
return (new Translation($file))->asArray();
} else {
return [];
}
}
/**
* Get the namespace for the views
*
* @return string
*/
public static function viewsNamespace(): string
{
return '_' . basename(__DIR__) . '_';
}
/**
* Get the active module name, e.g. the name of the currently running module
*
* @return string
*/
public static function activeModuleName(): string
{
return '_' . basename(__DIR__) . '_';
}
/**
* View module settings in control panel
*
* @param ServerRequestInterface $request
*
* @return ResponseInterface
*/
public function getAdminAction(ServerRequestInterface $request): ResponseInterface
{
$this->checkCustomViewAvailability();
$this->layout = 'layouts/administration';
return $this->viewResponse(
self::viewsNamespace() . '::settings',
[
'title' => $this->title(),
self::PREF_SHOW_CATEGORY_LABEL => boolval($this->getPreference(self::PREF_SHOW_CATEGORY_LABEL, '1')),
self::PREF_SHOW_CATEGORY_TITLE => boolval($this->getPreference(self::PREF_SHOW_CATEGORY_TITLE, '0')),
self::PREF_SHOW_HELP_ICON => boolval($this->getPreference(self::PREF_SHOW_HELP_ICON, '1')),
self::PREF_SHOW_HELP_LINK => boolval($this->getPreference(self::PREF_SHOW_HELP_LINK, '1')),
self::PREF_SHOW_TRUNCATED_CALL_NUMBER => boolval($this->getPreference(self::PREF_SHOW_TRUNCATED_CALL_NUMBER, '1')),
self::PREF_SHOW_TRUNCATED_CATEGORY => boolval($this->getPreference(self::PREF_SHOW_TRUNCATED_CATEGORY, '1')),
self::PREF_SHOW_DATE_RANGE_FOR_CATEGORY => boolval($this->getPreference(self::PREF_SHOW_DATE_RANGE_FOR_CATEGORY, '1')),
self::PREF_ALLOW_RENAME => boolval($this->getPreference(self::PREF_ALLOW_RENAME, '1')),
self::PREF_ALLOW_NEW_SOURCE => boolval($this->getPreference(self::PREF_ALLOW_NEW_SOURCE, '1')),
self::PREF_SHOW_TITLE => boolval($this->getPreference(self::PREF_SHOW_TITLE, '1')),
self::PREF_SHOW_XREF => boolval($this->getPreference(self::PREF_SHOW_XREF, '1')),
self::PREF_SHOW_AUTHOR => boolval($this->getPreference(self::PREF_SHOW_AUTHOR, '1')),
self::PREF_SHOW_DATE_RANGE => boolval($this->getPreference(self::PREF_SHOW_DATE_RANGE, '1')),
self::PREF_ALLOW_ADMIN_DELIMITER => boolval($this->getPreference(self::PREF_ALLOW_ADMIN_DELIMITER, '1')),
self::PREF_SHOWN_SOURCE_FACTS_IN_CITATIONS => $this->getPreference(self::PREF_SHOWN_SOURCE_FACTS_IN_CITATIONS, implode(',', self::$ALL_SOURCE_FACTS_IN_CITATIONS->keys()->toArray())),
self::PREF_EXPANDED_SOURCE_FACTS_IN_CITATIONS => $this->getPreference(self::PREF_EXPANDED_SOURCE_FACTS_IN_CITATIONS, ''),
self::PREF_SHOW_MEDIA_AFTER_CITATIONS => boolval($this->getPreference(self::PREF_SHOW_MEDIA_AFTER_CITATIONS, '0')),
self::PREF_ENABLE_COPY_PASTE_CITATIONS => boolval($this->getPreference(self::PREF_ENABLE_COPY_PASTE_CITATIONS, '0')),
self::PREF_ENABLE_DELETE_CITATIONS => boolval($this->getPreference(self::PREF_ENABLE_DELETE_CITATIONS, '0')),
self::PREF_ENABLE_SORT_CITATIONS => boolval($this->getPreference(self::PREF_ENABLE_SORT_CITATIONS, '0')),
self::PREF_SHOW_NOTES_FOR_MEDIA_OBJECTS => boolval($this->getPreference(self::PREF_SHOW_NOTES_FOR_MEDIA_OBJECTS, '1')),
self::PREF_SHOW_FINDING_AID_CATEGORY_TITLE => boolval($this->getPreference(self::PREF_SHOW_FINDING_AID_CATEGORY_TITLE, '0')),
self::PREF_SHOW_FINDING_AID_ADDRESS => boolval($this->getPreference(self::PREF_SHOW_FINDING_AID_ADDRESS, '1')),
self::PREF_SHOW_FINDING_AID_WT_LINKS => boolval($this->getPreference(self::PREF_SHOW_FINDING_AID_WT_LINKS, '1')),
self::PREF_SHOW_FINDING_AID_TOC => boolval($this->getPreference(self::PREF_SHOW_FINDING_AID_TOC, '1')),
self::PREF_SHOW_FINDING_AID_TOC_LINKS => boolval($this->getPreference(self::PREF_SHOW_FINDING_AID_TOC_LINKS, '1')),
self::PREF_SHOW_FINDING_AID_TOC_TITLES => boolval($this->getPreference(self::PREF_SHOW_FINDING_AID_TOC_TITLES, '1')),
self::PREF_ALLOW_ADMIN_XML_SETTINGS => boolval($this->getPreference(self::PREF_ALLOW_ADMIN_XML_SETTINGS, '1')),
self::PREF_USE_META_REPOSITORIES => boolval($this->getPreference(self::PREF_USE_META_REPOSITORIES, '0')),
self::PREF_ATOM_SLUG => $this->getPreference(self::PREF_ATOM_SLUG, self::PREF_ATOM_SLUG_CALL_NUMBER),
self::PREF_SHOW_ATOM_LINKS => boolval($this->getPreference(self::PREF_SHOW_ATOM_LINKS, '0')),
self::PREF_ATOM_BASE_URL => $this->getPreference(self::PREF_ATOM_BASE_URL, ''),
self::PREF_ATOM_REPOSITORIES => $this->getPreference(self::PREF_ATOM_REPOSITORIES, ''),
]
);
}
/**
* Save module settings after returning from control panel
*
* @param ServerRequestInterface $request
*
* @return ResponseInterface
*/
public function postAdminAction(ServerRequestInterface $request): ResponseInterface
{
$params = (array) $request->getParsedBody();
$shown_source_facts_in_citations = Validator::parsedBody($request)->array(self::PREF_SHOWN_SOURCE_FACTS_IN_CITATIONS);
$expanded_facts_in_citations = Validator::parsedBody($request)->array(self::PREF_EXPANDED_SOURCE_FACTS_IN_CITATIONS);
//Save the received settings to the user preferences
if ($params['save'] === '1') {
$this->setPreference(self::PREF_SHOW_CATEGORY_LABEL, isset($params[self::PREF_SHOW_CATEGORY_LABEL]) ? '1' : '0');
$this->setPreference(self::PREF_SHOW_CATEGORY_TITLE, isset($params[self::PREF_SHOW_CATEGORY_TITLE]) ? '1' : '0');
$this->setPreference(self::PREF_SHOW_HELP_ICON, isset($params[self::PREF_SHOW_HELP_ICON]) ? '1' : '0');
$this->setPreference(self::PREF_SHOW_HELP_LINK, isset($params[self::PREF_SHOW_HELP_LINK]) ? '1' : '0');
$this->setPreference(self::PREF_SHOW_TRUNCATED_CALL_NUMBER, isset($params[self::PREF_SHOW_TRUNCATED_CALL_NUMBER]) ? '1' : '0');
$this->setPreference(self::PREF_SHOW_TRUNCATED_CATEGORY, isset($params[self::PREF_SHOW_TRUNCATED_CATEGORY]) ? '1' : '0');
$this->setPreference(self::PREF_SHOW_DATE_RANGE_FOR_CATEGORY, isset($params[self::PREF_SHOW_DATE_RANGE_FOR_CATEGORY]) ? '1' : '0');
$this->setPreference(self::PREF_ALLOW_RENAME, isset($params[self::PREF_ALLOW_RENAME]) ? '1' : '0');
$this->setPreference(self::PREF_ALLOW_NEW_SOURCE, isset($params[self::PREF_ALLOW_NEW_SOURCE]) ? '1' : '0');
$this->setPreference(self::PREF_SHOW_TITLE, isset($params[self::PREF_SHOW_TITLE]) ? '1' : '0');
$this->setPreference(self::PREF_SHOW_XREF, isset($params[self::PREF_SHOW_XREF]) ? '1' : '0');
$this->setPreference(self::PREF_SHOW_AUTHOR, isset($params[self::PREF_SHOW_AUTHOR]) ? '1' : '0');
$this->setPreference(self::PREF_SHOW_DATE_RANGE, isset($params[self::PREF_SHOW_DATE_RANGE]) ? '1' : '0');
$this->setPreference(self::PREF_ALLOW_ADMIN_DELIMITER, isset($params[self::PREF_ALLOW_ADMIN_DELIMITER]) ? '1' : '0');
$this->setPreference(self::PREF_SHOWN_SOURCE_FACTS_IN_CITATIONS, implode(',', $shown_source_facts_in_citations));
$this->setPreference(self::PREF_EXPANDED_SOURCE_FACTS_IN_CITATIONS, implode(',', $expanded_facts_in_citations));
$this->setPreference(self::PREF_SHOW_MEDIA_AFTER_CITATIONS, isset($params[self::PREF_SHOW_MEDIA_AFTER_CITATIONS]) ? '1' : '0');
$this->setPreference(self::PREF_ENABLE_COPY_PASTE_CITATIONS, isset($params[self::PREF_ENABLE_COPY_PASTE_CITATIONS]) ? '1' : '0');
$this->setPreference(self::PREF_ENABLE_DELETE_CITATIONS, isset($params[self::PREF_ENABLE_DELETE_CITATIONS]) ? '1' : '0');
$this->setPreference(self::PREF_ENABLE_SORT_CITATIONS, isset($params[self::PREF_ENABLE_SORT_CITATIONS]) ? '1' : '0');
$this->setPreference(self::PREF_SHOW_NOTES_FOR_MEDIA_OBJECTS, isset($params[self::PREF_SHOW_NOTES_FOR_MEDIA_OBJECTS]) ? '1' : '0');
$this->setPreference(self::PREF_SHOW_FINDING_AID_CATEGORY_TITLE, isset($params[self::PREF_SHOW_FINDING_AID_CATEGORY_TITLE]) ? '1' : '0');
$this->setPreference(self::PREF_SHOW_FINDING_AID_ADDRESS, isset($params[self::PREF_SHOW_FINDING_AID_ADDRESS]) ? '1' : '0');
$this->setPreference(self::PREF_SHOW_FINDING_AID_WT_LINKS, isset($params[self::PREF_SHOW_FINDING_AID_WT_LINKS]) ? '1' : '0');
$this->setPreference(self::PREF_SHOW_FINDING_AID_TOC, isset($params[self::PREF_SHOW_FINDING_AID_TOC]) ? '1' : '0');
$this->setPreference(self::PREF_SHOW_FINDING_AID_TOC_LINKS, isset($params[self::PREF_SHOW_FINDING_AID_TOC_LINKS]) ? '1' : '0');
$this->setPreference(self::PREF_SHOW_FINDING_AID_TOC_TITLES, isset($params[self::PREF_SHOW_FINDING_AID_TOC_TITLES]) ? '1' : '0');
$this->setPreference(self::PREF_ALLOW_ADMIN_XML_SETTINGS, isset($params[self::PREF_ALLOW_ADMIN_XML_SETTINGS]) ? '1' : '0');
$this->setPreference(self::PREF_USE_META_REPOSITORIES, isset($params[self::PREF_USE_META_REPOSITORIES]) ? '1' : '0');
$this->setPreference(self::PREF_SHOW_ATOM_LINKS, isset($params[self::PREF_SHOW_ATOM_LINKS]) ? '1' : '0');
$this->setPreference(self::PREF_ATOM_SLUG, isset($params[self::PREF_ATOM_SLUG]) ? $params[self::PREF_ATOM_SLUG] : self::PREF_ATOM_SLUG_CALL_NUMBER);
//Remove slashes at the end of the URL
if (isset($params[self::PREF_ATOM_BASE_URL])) {
$atom_base_url = $params[self::PREF_ATOM_BASE_URL];
if (substr($atom_base_url, -1) === '/') {
$atom_base_url = substr($atom_base_url, 0, -1);
}
} else {
$atom_base_url = '';
}
$this->setPreference(self::PREF_ATOM_BASE_URL, $atom_base_url);
$this->setPreference(self::PREF_ATOM_REPOSITORIES, isset($params[self::PREF_ATOM_REPOSITORIES]) ? $params[self::PREF_ATOM_REPOSITORIES] : '');
$message = I18N::translate('The preferences for the module “%s” were updated.', $this->title());
FlashMessages::addMessage($message, 'success');
}
return redirect($this->getConfigLink());
}
/**
* Check if module version is new and start update activities if needed
*
* @return void
*/
public function checkModuleVersionUpdate(): void
{
//If new custom module version is detected
if ($this->getPreference(self::PREF_MODULE_VERSION) !== self::CUSTOM_VERSION) {
//Update module files
if (require __DIR__ . '/update_module_files.php') {
$update_result = '';
}
else {
$update_result = I18N::translate('Error during updating the custom module files to a new version.');
}
//Update prefences stored in database
$update_result .= $this->updatePreferences();
//Show flash message for error or sucessful update of preferences
if ($update_result !== '') {
$message = I18N::translate('Error while trying to update the custom module "%s" to the new module version %s: ' . $update_result, $this->title(), self::CUSTOM_VERSION);
FlashMessages::addMessage($message, 'danger');
}
else {
$message = I18N::translate('The preferences for the custom module "%s" were sucessfully updated to the new module version %s.', $this->title(), self::CUSTOM_VERSION);
FlashMessages::addMessage($message, 'success');
//Update custom module version
$this->setPreference(self::PREF_MODULE_VERSION, self::CUSTOM_VERSION);
}
}
}
/**
* Update the preferences (after new module version is detected)
*
* @return string
*/
public function updatePreferences(): string
{
$error = '';
//Rename old preferences
if ( $this->getPreference(self::OLD_PREF_SHOW_REPO_FACTS_IN_CITATIONS) === ''
&& $this->getPreference(self::OLD_PREF_SHOW_SOURCE_FACTS_IN_CITATIONS) !== self::PREF_DELETED) {
//Copy old value to new preference
$this->setPreference(self::OLD_PREF_SHOW_REPO_FACTS_IN_CITATIONS, $this->getPreference(self::OLD_PREF_SHOW_SOURCE_FACTS_IN_CITATIONS));
}
$this->setPreference(self::OLD_PREF_SHOW_SOURCE_FACTS_IN_CITATIONS, self::PREF_DELETED);
if ( $this->getPreference(self::PREF_EXPANDED_SOURCE_FACTS_IN_CITATIONS) === ''
&& $this->getPreference(self::OLD_PREF_EXPANDED_SOURCE_FACTS_IN_CITATIONS) !== self::PREF_DELETED) {
//Copy old value to new preference
$this->setPreference(self::PREF_EXPANDED_SOURCE_FACTS_IN_CITATIONS, $this->getPreference(self::OLD_PREF_EXPANDED_SOURCE_FACTS_IN_CITATIONS));
}
$this->setPreference(self::OLD_PREF_EXPANDED_SOURCE_FACTS_IN_CITATIONS, self::PREF_DELETED);
//Move old preferences for source facts to new preferences
if ( $this->getPreference(self::OLD_PREF_SHOW_FURTHER_FACTS_IN_CITATIONS) !== self::PREF_DELETED
&& boolval($this->getPreference(self::OLD_PREF_SHOW_FURTHER_FACTS_IN_CITATIONS, '0'))) {
$this->setPreference(self::PREF_SHOWN_SOURCE_FACTS_IN_CITATIONS, implode(',', self::$ALL_SOURCE_FACTS_IN_CITATIONS->keys()->toArray()));
$this->setPreference(self::OLD_PREF_SHOW_FURTHER_FACTS_IN_CITATIONS, self::PREF_DELETED);
}
$old_facts_in_citations_preferences = [
[self::OLD_PREF_SHOW_REPO_FACTS_IN_CITATIONS, 'REPO', false],
[self::OLD_PREF_SHOW_SOURCE_MEDIA_IN_CITATIONS, 'OBJE', false],
[self::OLD_PREF_EXPAND_REPOS_IN_CITATIONS, 'REPO', true],
];
foreach($old_facts_in_citations_preferences as $update) {
$this->updateShownFactsInCitationsPreferences($update[0], $update[1], $update[2]);
}
//Delete old preferences, i.e. set old preference value to deleted
$this->setPreference(self::OLD_PREF_SHOW_SOURCE_FACTS_IN_CITATIONS, self::PREF_DELETED);
return $error;
}
/**
* Update preferences to show facts in citations
*
* @return void
*/
public function updateShownFactsInCitationsPreferences(string $old_preference, string $gedcom_tag, $expanded = false) : void {
//Do nothing if old preference was not activated or has already been deleted
if ($this->getPreference($old_preference, '') === self::PREF_DELETED) return;
//If old preference was not activated, delete it and return
if (!boolval($this->getPreference($old_preference, '0'))) {
$this->setPreference($old_preference, self::PREF_DELETED);
return;
}
$new_preference = $expanded ? self::PREF_EXPANDED_SOURCE_FACTS_IN_CITATIONS : self::PREF_SHOWN_SOURCE_FACTS_IN_CITATIONS;
$preference_value =$this->getPreference($new_preference, '');
if (mb_strpos($preference_value, $gedcom_tag) === false) {
if ($preference_value === '') {
$preference_value = $gedcom_tag;
}
else {
$preference_value .= ',' . $gedcom_tag;
}
}
//Copy value to new preference
$this->setPreference($new_preference, $preference_value);
//Delete old preferences, i.e. set old preference value to deleted
$this->setPreference($old_preference, self::PREF_DELETED);
return;
}
/**
* {@inheritDoc}
*
* @return string
*
* @see \Fisharebest\Webtrees\Module\ModuleListInterface::listMenuClass()
*/
public function listMenuClass(): string
{
//CSS class for module Icon (included in CSS file) is returned to be shown in the list menu
return 'menu-list-repository-hierarchy';
}
/**
* {@inheritDoc}
*
* @param Tree $tree
*
* @return bool
*
* @see \Fisharebest\Webtrees\Module\ModuleListInterface::listIsEmpty()
*/
public function listIsEmpty(Tree $tree): bool
{
return !DB::table('other')
->where('o_file', '=', $tree->id())
->where('o_type', '=', Repository::RECORD_TYPE)
->exists();
}
/**
* {@inheritDoc}
*
* @param Tree $tree
* @param array $parameters
*
* @return string
*
* @see \Fisharebest\Webtrees\Module\ModuleListInterface::listUrl()
*/
public function listUrl(Tree $tree, array $parameters = []): string
{
$parameters['tree'] = $tree->name();
$parameters['delimiter_expression'] = '';
return route(RepositoryHierarchy::class, $parameters);
}
/**
* {@inheritDoc}
*
* @return string
*
* @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent()
*/
public function headContent(): string
{
//Include CSS file in head of webtrees HTML to make sure it is always found
return '<link href="' . $this->assetUrl('css/repository-hierarchy.css') . '" type="text/css" rel="stylesheet" />';
}
/**
* {@inheritDoc}
*
* @param Tree $tree
*
* @return string
*
* @see \Fisharebest\Webtrees\Module\ModuleDataFixInterface::fixOptions()
*/
public function fixOptions(Tree $tree): string
{
//If data fix is called from wrong context, show error text
if (!isset($this->repository_xref)) {
$error_text = I18N::translate('The Repository Hierarchy data fix cannot be used in the "control panel".') . ' '.
I18N::translate('The data fix can be called from the user front end by clicking on the link to rename a call number category.');
return view(
self::viewsNamespace() . '::error',
[
'title' => I18N::translate('Error in custom module') . ': ' . $this->getListTitle(),
'text' => $error_text,
]
);
}
//If user is not a manager for this tree, show error text
if (!Auth::isManager($tree)) {
$error_text = I18N::translate('Currently, you do not have the user rights to change call number categories.') . ' ' .
I18N::translate('In order to change call number categories, you need to have a "Manager" role for the corresponding tree.');
return view(
self::viewsNamespace() . '::error',
[
'title' => I18N::translate('Error in custom module') . ': ' . $this->getListTitle(),
'text' => $error_text,
]
);
}
return view(
self::viewsNamespace() . '::options',
[
CallNumberCategory::VAR_REPOSITORY_XREF => $this->repository_xref,
CallNumberCategory::VAR_CATEGORY_FULL_NAME => $this->data_fix_category_full_name,
CallNumberCategory::VAR_CATEGORY_NAME => $this->data_fix_category_name,
self::VAR_DATA_FIX_CATEGORY_NAME_REPLACE => $this->data_fix_category_name,
self::VAR_DATA_FIX_TYPES => [Source::RECORD_TYPE => MoreI18N::xlate('Sources')],
]