-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathClippingsCartEnhanced.php
2035 lines (1813 loc) · 77.8 KB
/
ClippingsCartEnhanced.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 - clippings cart enhanced
*
* based on Vesta module "clippings cart extended"
*
*
*
* Copyright (C) 2022-2024 huhwt. All rights reserved.
* Copyright (C) 2021 Hermann Hartenthaler. All rights reserved.
* Copyright (C) 2021 Richard Cissée. All rights reserved.
*
* webtrees: online genealogy / web based family history software
* Copyright (C) 2021 webtrees development team.
*
* 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/>.
*/
/*
* tbd
* ---
* code: empty cart: show block with "type delete" only if second option is selected
* code: empty cart: button should be labeled "continue" and not "delete" if third option is selected
* code: add specific TRAIT module (?)
* code: show add options only if they will add new elements to the clippings cart otherwise grey them out
* code: when adding global sets: instead of using radio buttons use select buttons?
* translation: translate all new strings to German using po/mo
* issue: new global add function to add longest descendant-ancestor connection in a tree:
* calculate for all individuals in the tree the most distant ancestor (this is maybe a list of individuals),
* select a pair of two individuals with the greatest distance,
* add all their ancestors and descendants (???), remove all the leaves(???)
* issue: new add function for an individual: add chain to most distant ancestor
* issue: new global add function to add all records of a tree
* issue: use GVExport (GraphViz) code for visualization (?)
* issue: implement webtrees 1 module "branch export" with a starting person and several stop persons/families (stored as profile)
* issue: new function to add all circles for an individual or a family
* issue: new action: enhanced list using webtrees standard lists for each type of records
* idea: use TAM to visualize the hierarchy of location records
* test: access rights for members and visitors
* other module - test with all other themes: Rural, Argon, ...
* other module - admin/control panel module "unconnected individuals": add button to each group "send to clippings cart"
* other module - custom modul extended family: send filtered INDI and FAM records to clippings cart
* other module - search: send search results to clippings cart
* other module - list of persons with one surname: send them to clippings cart
*/
declare(strict_types=1);
namespace HuHwt\WebtreesMods\ClippingsCartEnhanced;
use Aura\Router\Map;
use Aura\Router\Route;
use Aura\Router\RouterContainer;
use Fisharebest\Webtrees\Auth;
use Fisharebest\Webtrees\Family;
use Fisharebest\Webtrees\Gedcom;
use Fisharebest\Webtrees\GedcomRecord;
use Fisharebest\Webtrees\Http\RequestHandlers\FamilyPage;
use Fisharebest\Webtrees\Http\RequestHandlers\IndividualPage;
use Fisharebest\Webtrees\Http\RequestHandlers\LocationPage;
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\Module\FamilyListModule;
use Fisharebest\Webtrees\Module\IndividualListModule;
use Fisharebest\Webtrees\Http\RequestHandlers\SearchGeneralPage;
use Fisharebest\Webtrees\Http\RequestHandlers\SearchAdvancedPage;
use Fisharebest\Localization\Translation;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\FlashMessages;
use Fisharebest\Webtrees\Individual;
use Fisharebest\Webtrees\Location;
use Fisharebest\Webtrees\Media;
use Fisharebest\Webtrees\Menu;
use Fisharebest\Webtrees\Module\ModuleGlobalInterface;
use Fisharebest\Webtrees\Note;
use Fisharebest\Webtrees\Registry;
use Fisharebest\Webtrees\Repository;
use Fisharebest\Webtrees\Services\GedcomExportService;
use Fisharebest\Webtrees\Services\LinkedRecordService;
use Fisharebest\Webtrees\Services\UserService;
use Fisharebest\Webtrees\Session;
use Fisharebest\Webtrees\Source;
use Fisharebest\Webtrees\Submitter;
use Fisharebest\Webtrees\Tree;
use Fisharebest\Webtrees\Validator;
use Fisharebest\Webtrees\Webtrees;
use Illuminate\Support\Collection;
use Illuminate\Database\Capsule\Manager as DB;
use League\Flysystem\Filesystem;
use League\Flysystem\FilesystemInterface;
use League\Flysystem\ZipArchive\ZipArchiveAdapter;
use Nyholm\Psr7\Uri;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Fig\Http\Message\RequestMethodInterface;
use Psr\Http\Message\StreamFactoryInterface;
use RuntimeException;
use Fisharebest\Webtrees\Services\ModuleService;
use Fisharebest\Webtrees\Module\ModuleMenuTrait;
use Fisharebest\Webtrees\Module\ClippingsCartModule;
use Fisharebest\Webtrees\Module\ModuleCustomInterface;
use Fisharebest\Webtrees\Module\ModuleCustomTrait;
use Fisharebest\Webtrees\Module\ModuleConfigInterface;
use Fisharebest\Webtrees\Module\ModuleConfigTrait;
use Fisharebest\Webtrees\Module\ModuleMenuInterface;
use Fisharebest\Webtrees\View;
use SebastianBergmann\Type\VoidType;
use Fisharebest\Webtrees\Module\ModuleInterface;
use Fisharebest\Webtrees\Module\ModuleListInterface;
use HuHwt\WebtreesMods\ClippingsCartEnhanced\ListProcessor;
use HuHwt\WebtreesMods\ClippingsCartEnhanced\ClippingsCartEnhancedModule;
use HuHwt\WebtreesMods\ClippingsCartEnhanced\Traits\CCEmodulesTrait;
use HuHwt\WebtreesMods\ClippingsCartEnhanced\Traits\CCEconfigTrait;
use HuHwt\WebtreesMods\ClippingsCartEnhanced\Traits\CC_addActions;
use HuHwt\WebtreesMods\ClippingsCartEnhanced\Traits\CCEaddActions;
use HuHwt\WebtreesMods\ClippingsCartEnhanced\Traits\CCEcartActions;
use HuHwt\WebtreesMods\ClippingsCartEnhanced\Traits\CCEdatabaseActions;
use HuHwt\WebtreesMods\ClippingsCartEnhanced\Traits\CCEtagsActions;
use HuHwt\WebtreesMods\ClippingsCartEnhanced\Traits\CCEvizActions;
use HuHwt\WebtreesMods\TaggingServiceManager\TaggingServiceManager;
use HuHwt\WebtreesMods\TaggingServiceManager\TaggingServiceManagerAdapter;
// control functions
use stdClass;
use function array_filter;
use function array_keys;
use function array_map;
use function array_search;
use function assert;
use function count;
use function array_key_exists;
use function fopen;
use function file_put_contents;
use function in_array;
use function is_string;
use function json_encode;
use function preg_match_all;
use function redirect;
use function rewind;
use function route;
use function str_replace;
use function str_starts_with;
use function stream_get_meta_data;
use function tmpfile;
use function uasort;
use function view;
// string functions
use function strtolower;
use function addcslashes;
use const PREG_SET_ORDER;
/**
* Class ClippingsCartEnhanced
*/
class ClippingsCartEnhanced extends ClippingsCartModule
implements ModuleGlobalInterface, ModuleCustomInterface, ModuleConfigInterface // , ModuleMenuInterface
{ // use ModuleMenuTrait;
use ModuleConfigTrait;
use CCEconfigTrait;
use ModuleCustomTrait;
/** All constants and functions according to ModuleCustomTrait */
use CCEmodulesTrait {
CCEmodulesTrait::customModuleAuthorName insteadof ModuleCustomTrait;
CCEmodulesTrait::customModuleLatestVersionUrl insteadof ModuleCustomTrait;
CCEmodulesTrait::customModuleVersion insteadof ModuleCustomTrait;
CCEmodulesTrait::customModuleSupportUrl insteadof ModuleCustomTrait;
CCEmodulesTrait::title insteadof ModuleCustomTrait;
CCEmodulesTrait::menuTitle insteadof ModuleCustomTrait;
CCEmodulesTrait::resourcesFolder insteadof ModuleCustomTrait;
}
/** All constants and functions related to default ClippingsCartModule */
use CC_addActions;
/** All constants and functions related to enhancements */
use CCEaddActions {
CCEaddActions::addFamilyToCart insteadof CC_addActions;
CCEaddActions::addIndividualToCart insteadof CC_addActions;
}
/** All constants and functions related to handling the Cart */
use CCEcartActions;
use CCEdatabaseActions;
/** All constants and functions related to handling the Tags */
use CCEtagsActions;
/** All constants and functions related to connecting vizualizations */
use CCEvizActions;
protected const ROUTE_URL = '/tree/{tree}/CCE';
/**
* {@inheritDoc}
* @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent()
* CSS class for the URL.
*
* EW.H - MOD ... we need our Script too, so we do a double injection
* @return string
*/
public function headContent(): string
{
$_name = $this->name();
$html_CSS = view("{$_name}::style", [
'path' => $this->assetUrl('css/CCEtable-actions.css'),
]);
$html_JSx = view("{$_name}::script", [
'path' => $this->assetUrl('js/CCEtable-actions.js'),
]);
$html_ = $html_CSS . " " . $html_JSx;
return $html_;
}
/**
* {@inheritDoc}
* @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::bodyContent()
* EW.H - MOD ... - ( see headConten() )
* @return string
*/
public function bodyContent(): string
{
return '';
}
public const SHOW_RECORDS = 'Records in clippings cart - Execute an action on them.';
public const SHOW_ACTIONS = 'Performed actions fo fill the cart.';
// What to execute on records in the clippings cart?
// EW.H mod ... the second-level-keys are tested for actions in function postExecuteAction()
private const EXECUTE_ACTIONS = [
'Download records ...' => [
'EXECUTE_DOWNLOAD_ZIP' => '... as GEDCOM zip-file (including media files)',
'EXECUTE_DOWNLOAD_PLAIN' => '... as GEDCOM file (all Tags, no media files)',
'EXECUTE_DOWNLOAD_IF' => '... as GEDCOM file (only INDI and FAM)',
],
'Visualize records in a diagram ...' => [
'EXECUTE_VISUALIZE_TAM' => '... using TAM',
'EXECUTE_VISUALIZE_LINEAGE' => '... using Lineage',
],
];
// What are the options to delete records in the clippings cart?
private const EMPTY_FORCE = 'Deleta all records';
private const EMPTY_ALL = 'all records';
private const EMPTY_SET = 'set of records by type';
private const EMPTY_CREATED = 'records created by action';
// Routes that have a record which can be added to the clipboard
private const ROUTES_WITH_RECORDS = [
'Family' => FamilyPage::class,
'Individual' => IndividualPage::class,
'Media' => MediaPage::class,
'Location' => LocationPage::class,
'Note' => NotePage::class,
'Repository' => RepositoryPage::class,
'Source' => SourcePage::class,
'Submitter' => SubmitterPage::class,
'FamilyListModule' => FamilyListModule::class,
'IndividualListModule' => IndividualListModule::class,
'Search-General' => SearchGeneralPage::class,
'SearchGeneralPage' => SearchGeneralPage::class,
'Search-Advanced' => SearchAdvancedPage::class,
];
// Modules with lists: which DataTable to grep - what kind of list
// works combined with OTHER_MENU_TYPES
// 'X' -> 'DataTables_Table_X_wrapper'
// 'action-type' -> primary key for clipping action - defines number of menu entries
// 'action-pref' -> optional prefix for clipping action
// 'action-suff' -> optional suffix for clipping action
// 'action-text' -> menu label
// 'grep-id' -> will be used as variable name to grep the datatable functions
// 'listType' -> basic type of information
// 'clipAction' -> will be performed in ClippingsCartEnhancedModule
private const OTHER_MENUES = [
'FamilyListModule' => [
'FL' => [ 'action-type' => 'FAM-LIST', 'action-pref' => '', 'grep-id' => 'dtFLjq'
, 'view' => 'families-table', 'table' => '.wt-table-family' ]
],
'IndividualListModule' => [
'IL' => [ 'action-type' => 'INDI-LIST', 'action-pref' => '', 'grep-id' => 'dtILjq'
, 'view' => 'individuals-table', 'table' => '.wt-table-individual' ]
],
'Search-Advanced' => [
'IL' => [ 'action-type' => 'INDI-LIST', 'action-pref' => 'SEARCH_A-', 'grep-id' => 'dtILjq'
, 'view' => 'individuals-table', 'table' => '.wt-table-individual' ]
],
'Search-General' => [
'IL' => [ 'action-type' => 'INDI-LIST', 'action-pref' => 'SEARCH_G-', 'grep-id' => 'dtILjq'
, 'view' => 'individuals-table', 'table' => '.wt-table-individual' ],
'FL' => [ 'action-type' => 'FAM-LIST', 'action-pref' => 'SEARCH_G-', 'grep-id' => 'dtFLjq'
, 'view' => 'families-table', 'table' => '.wt-table-family' ],
// '2' => [ 'action-type' => 'SOURCE', 'action-pref' => 'SEARCH_G-', 'grep-id' => 'dt2jq' ],
// '3' => [ 'action-type' => 'NOTE', 'action-pref' => 'SEARCH_G-', 'grep-id' => 'dt3jq' ]
],
'SearchGeneralPage' => [
'IL' => [ 'action-type' => 'INDI-LIST', 'action-pref' => 'SEARCH_G-', 'grep-id' => 'dtILjq'
, 'view' => 'individuals-table', 'table' => '.wt-table-individual' ],
'FL' => [ 'action-type' => 'FAM-LIST', 'action-pref' => 'SEARCH_G-', 'grep-id' => 'dtFLjq'
, 'view' => 'families-table', 'table' => '.wt-table-family' ],
],
];
//
private const OTHER_MENUES_TYPES = [
'FAM-LIST' => [
'0' => [ 'listType' => 'family', 'clipAction' => 'clipFamilies'],
'1' => [ 'action-suff' => '', 'action-text' => 'add families and individuals to the clippings cart' ],
'2' => [ 'action-suff' => 'wp', 'action-text' => 'add families and individuals with parents to the clippings cart'],
],
'INDI-LIST' => [
'0' => [ 'listType' => 'individual', 'clipAction' => 'clipIndividuals'],
'1' => [ 'action-suff' => '', 'action-text' => 'add individuals to the clippings cart'],
'2' => [ 'action-suff' => 'wp', 'action-text' => 'add individuals with parents to the clippings cart'],
'3' => [ 'action-suff' => 'ws', 'action-text' => 'add individuals and spouses to the clippings cart'],
'4' => [ 'action-suff' => 'wc', 'action-text' => 'add individuals and children to the clippings cart'],
'5' => [ 'action-suff' => 'wa', 'action-text' => 'add individuals and all relations to the clippings cart'],
]
];
// Types of records
// The order of the Xrefs in the Clippings Cart results from the order
// of the calls during insertion and in this respect is not separated
// according to their origin.
// This can cause problems when passing to interfaces and functions that
// expect a defined sequence of tags.
// This structure determines the order of the categories in which the
// records are displayed or output for further actions ( function getEmptyAction() and showCart.phtml )
private const TYPES_OF_RECORDS = [
'Individual' => Individual::class,
'Family' => Family::class,
'Media' => Media::class,
'Location' => Location::class,
'Note' => Note::class,
'Repository' => Repository::class,
'Source' => Source::class,
'Submitter' => Submitter::class,
];
// Types of records for further visualizing actions
// This structure defines the categories which will be
// relevant in visualizing tools.
private const FILTER_RECORDS = [
'TAM' => [
'Individual' => Individual::class,
'Family' => Family::class,
],
'ONLY_IF' => [
'Individual' => Individual::class,
'Family' => Family::class,
],
'ONLY_IFN' => [
'Individual' => Individual::class,
'Family' => Family::class,
'Note' => Note::class,
],
'ONLY_IFS' => [
'Individual' => Individual::class,
'Family' => Family::class,
'Source' => Source::class,
],
'ONLY_IFL' => [
'Individual' => Individual::class,
'Family' => Family::class,
'Location' => Location::class,
],
];
/** @var int The default access level for this module. It can be changed in the control panel. */
protected int $access_level = Auth::PRIV_USER;
/** @var GedcomExportService */
private GedcomExportService $gedcom_export_service;
/** @var LinkedRecordService */
private LinkedRecordService $linked_record_service;
/** @var UserService */
private $user_service;
/** @var Tree */
private Tree $tree;
/** @var int The number of ancestor generations to be added (0 = proband) */
private int $levelAncestor;
/** @var int The number of descendant generations to add (0 = proband) */
private int $levelDescendant;
// Output to Vizualisation tools
private const VIZdir = Webtrees::DATA_DIR . DIRECTORY_SEPARATOR . '_toVIZ';
// directory for storing CART-structure
private string $userDir;
/**
* @var bool We want to have the GEDCOM-Objects exported as array
*/
private const DO_DUMP_Ritems = true;
/**
* Store the cart
*/
private const CARTdir = Webtrees::DATA_DIR . DIRECTORY_SEPARATOR . '_CART';
/**
* The label ...
* @var string
*/
private string $huh;
/**
* Check for huhwt/huhwt-wttam done?
* @var boolean
*/
private bool $huhwttam_checked;
/**
* Check for huhwt/huhwt-wttam done?
* @var boolean
*/
private bool $huhwtlin_checked;
/**
* Retrieve all Record-Types - casually we want only a subset of R-T
* @var boolean
*/
private bool $all_RecTypes;
/**
* Retrieve shared notes associated with actual item
* @var boolean
*/
private bool $add_sNOTE;
/**
* where 'this' is not $this ...
* @var ClippingsCartEnhanced $instance
*/
private ClippingsCartEnhanced $instance;
/**
* check if this->instance is set
* @var bool $lPdone
*/
private bool $lPdone = false;
/**
* if call is coming from lists we need the origin uri
* @var string $callingURI
*/
private string $callingURI = '';
/**
* the active tag descriptor
* @var string $activeTAG
*/
private string $activeTAG = '';
private ModuleService $module_service;
private bool $TSMok = false;
/**
* ClippingsCartModule constructor.
*
* @param GedcomExportService $gedcom_export_service
* @param LinkedRecordService $linked_record_service
*/
public function __construct(
GedcomExportService $gedcom_export_service,
LinkedRecordService $linked_record_service)
{
// for exporting gedcom we need the parents's function ...
parent::__construct(
$gedcom_export_service,
$linked_record_service);
$this->linked_record_service= $linked_record_service; // ... but for connecting to e.g. (S)NOTEs we need our own instance
$this->levelAncestor = PHP_INT_MAX;
$this->levelDescendant = PHP_INT_MAX;
$this->exportFilenameDOWNL = self::FILENAME_DOWNL;
$this->exportFilenameVIZ = self::FILENAME_VIZ;
$this->huh = json_decode('"\u210D"') . "&" . json_decode('"\u210D"') . "wt";
$this->huhwttam_checked = false;
$this->huhwtlin_checked = false;
$this->all_RecTypes = true;
$this->add_sNOTE = false;
$tagOptions = $this->TAGconfigOptions();
$this->activeTAG = $tagOptions[(int) $this->getPreference('TAG_Option', '0')];
// EW.H mod ... read TAM-Filename from Session, otherwise: Initialize
if (Session::has('FILENAME_VIZ')) {
$this->exportFilenameVIZ = Session::get('FILENAME_VIZ');
} else {
$this->exportFilenameVIZ = 'wt2VIZ';
Session::put('FILENAME_VIZ', $this->exportFilenameVIZ);
}
// EW.H mod ... we want a subdir of Webtrees::DATA_DIR for storing dumps and so on
// - test for and create it if it not exists
if(!is_dir(self::VIZdir)){
//Directory does not exist, so lets create it.
mkdir(self::VIZdir, 0755);
}
// A subdir of Webtrees::DATA_DIR for storing Session::cart-structure
if(!is_dir(self::CARTdir)){
//Directory does not exist, so lets create it.
mkdir(self::CARTdir, 0755);
}
}
/**
* A menu, to be added to the main application menu.
*
* Show: show records in clippings cart and allow deleting some of them
* as defined in ROUTES_WITH_RECORDS
* AddRecord - according to actual class displayed on screen unless otherwise stated -> CC_addActions.php
* AddIndividual: add individual (this record, parents, children, ancestors, descendants, ...) -> CCEaddActions.php
* AddFamily: add family record -> CCEaddActions.php
* AddMedia: add media record
* AddLocation: add location record
* AddNote: add shared note record
* AddRepository: add repository record
* AddSource: add source record
* AddSubmitter: add submitter record
* FamilyList: add collected XREFs -> ClippingsCartEnhancedModule.php
* IndividualList: add collected XREFs -> ClippingsCartEnhancedModule.php
* Search-Advanced: add collected XREFs -> ClippingsCartEnhancedModule.php
* Search-General: add collected XREFs -> ClippingsCartEnhancedModule.php
* Global: add global sets of records (partner chains, circles)
* Empty: delete records in clippings cart
* Execute: execute an action on records in the clippings cart (export to GEDCOM file, visualize)
*
* @param Tree $tree
*
* @return Menu|null
*/
public function getMenu(Tree $tree): ?Menu
{
/** @var ServerRequestInterface $request */
$request = Registry::container()->get(ServerRequestInterface::class);
assert($request instanceof ServerRequestInterface);
$route = Validator::attributes($request)->route();
$params = $_GET;
$this->tree = $tree;
// we need a subdir for each tree ...
$treeDir = self::CARTdir . DIRECTORY_SEPARATOR . $tree->name();
if(!is_dir($treeDir)){
mkdir($treeDir, 0755);
}
// ... and also for each user
$user = Validator::attributes($request)->user();
$userDir = $treeDir . DIRECTORY_SEPARATOR . $user->userName();
if(!is_dir($userDir)){
mkdir($userDir, 0755);
}
Session::put('userDir', $userDir);
// clippings cart is an array in the session specific for each tree
$cart = $this->get_Cart();
$count = count($cart[$tree->name()] ?? []);
$submenus = [$this->addMenuClippingsCart($tree, $cart)]; // add cart-overview - counter
$REQ_URI = rawurldecode($_SERVER['REQUEST_URI']); // we need to do so because some server might have that encoded ...
$TSMok = ($this->TSMok && str_contains($REQ_URI, '/ShowCart/')); // ... and we want to show this entrance only in certain case
if ($TSMok && $count > 0)
$submenus[] = $this->addMenuTaggingService($tree);
$action = array_search($route->name, self::ROUTES_WITH_RECORDS, true);
if ($action !== false) {
$actmenus = $this->addMenuAddThisRecord($tree, $route, $action, $params);
if ($actmenus) {
$actmenus_subs = $actmenus->getSubmenus();
$submenus[] = $actmenus;
if (count($actmenus_subs) > 0) {
foreach($actmenus_subs as $actm_s) {
$submenus[] = $actm_s;
}
}
}
}
$submenus[] = $this->addMenuAddGlobalRecordSets($tree);
if (!$this->isCartEmpty($tree)) {
$submenus[] = $this->addMenuEmptyForce($tree);
$submenus[] = $this->addMenuDeleteRecords($tree);
$submenus[] = $this->addMenuExecuteAction($tree);
}
return new Menu($this->title(), '#', 'menu-clippings CCE_Menue', ['rel' => 'nofollow'], $submenus);
}
/**
* @param Tree $tree
* @param array $cart
*
* @return Menu
*/
private function addMenuClippingsCart (Tree $tree, array $cart): Menu
{
$count = count($cart[$tree->name()] ?? []);
$badge = view('components/badge', ['count' => $count]);
return new Menu(I18N::translate('Records in clippings cart') . $badge,
route('module', [
'module' => $this->name(),
'action' => 'ShowCart',
'tree' => $tree->name(),
]), 'menu-clippings-cart', ['rel' => 'nofollow', 'id' => 'CCEbadge']);
}
/**
* @param Tree $tree
* @param array $cart
*
* @return Menu
*/
private function addMenuTaggingService (Tree $tree): Menu
{
$TSMname = "_huhwt-tsm_"; // app(TaggingServiceManagerModule::class)->name();
return new Menu(I18N::translate('Transfer to tagging service'),
route('module', [
'module' => $TSMname,
'action' => 'TaggingService',
'tree' => $tree->name(),
]), 'menu-clippings-cart', ['rel' => 'nofollow']);
}
/**
* @param Tree $tree
* @param Route $route
* @param string $action
*
* @return Menu|null
*/
private function addMenuAddThisRecord (Tree $tree, Route $route, string $action, array $params): ?Menu {
$attributes = $route->attributes;
if (array_key_exists('xref', $attributes)) {
$xref = $attributes['xref'];
assert(is_string($xref));
return new Menu(I18N::translate('Add this record to the clippings cart'),
route('module', [
'module' => $this->name(),
'action' => 'Add' . $action,
'xref' => $xref,
'tree' => $tree->name(),
]), 'menu-clippings-add', ['rel' => 'nofollow']);
} elseif ($params) {
return $this->addMenuAddOthers($tree, $route, $action, $params);
} else {
return null;
}
}
/**
* @param Tree $tree
* @param Route $route
* @param string $action
*
* @return Menu|null
*/
private function addMenuAddOthers (Tree $tree, Route $route, string $action, array $params): ?Menu {
if ($action === 'FamilyListModule') {
if (array_key_exists('show', $params)) {
// if ($params['show'] == 'indi') {
if ($params['show'] > ' ') {
$_menu = $this->addMenuAddOthersList($tree, $route, $action);
return $_menu;
}
}
}
if ($action === 'IndividualListModule') {
if (array_key_exists('show', $params)) {
// if ($params['show'] == 'indi') {
if ($params['show'] > ' ') {
$_menu = $this->addMenuAddOthersList($tree, $route, $action);
return $_menu;
}
}
}
if ($action === 'Search-General') {
if (array_key_exists('search_individuals', $params)) {
if ($params['search_individuals'] == '1') {
$_menu = $this->addMenuAddOthersList($tree, $route, $action);
return $_menu;
}
} else if (array_key_exists('query', $params)) {
$_menu = $this->addMenuAddOthersList($tree, $route, $action);
return $_menu;
}
}
if ($action === 'Search-Advanced') {
if (array_key_exists('fields', $params)) {
$param_fields = $params['fields'];
$sa_add_cce = false;
foreach($param_fields as $pfk => $pfv) {
if ($pfv > '') {
$sa_add_cce = true;
break;
}
}
if ($sa_add_cce) {
$_menu = $this->addMenuAddOthersList($tree, $route, $action);
return $_menu;
}
}
}
if ($action === 'SearchGeneralPage') {
}
return null;
}
private function addMenuAddOthersList(Tree $tree, Route $route, string $action): ?Menu {
$m_views = [];
$first_opt = true;
$menu_type = self::OTHER_MENUES[$action];
// '0' => [ 'action-type' => 'FAM-LIST', 'action-pref' => '', 'grep-id' => 'dt0jq', 'view' => 'families-table', 'table' => '.wt-table-family' ]
foreach( $menu_type as $dt_id => $mparms) {
// '0' => [ 'listType' => 'family', 'clipAction' => 'clipFamilies'],
// '1' => [ 'action-suff' => '', 'action-text' => I18N::translate('add families and individuals to the clippings cart') ],
$a_type = $mparms['action-type'];
$a_pref = $mparms['action-pref'];
$dt_grep = $mparms['grep-id'];
$list_type = self::OTHER_MENUES_TYPES[$a_type];
foreach($list_type as $lopt => $loparms) {
if ($lopt == '0') {
$listType = $loparms['listType'];
$clipAction = $loparms['clipAction'];
} else {
$a_suff = $loparms['action-suff'];
$a_text = $loparms['action-text'];
$action_key = $a_pref . $a_type . $a_suff;
$menu_opt = 'CCE-Mopt-' . $dt_id . '-' . $lopt;
if ($first_opt) {
$route_ajax = e(route(ClippingsCartEnhancedModule::class, ['module' => $this->name(), 'tree' => $tree->name()]), false);
$_menu = new Menu(I18N::translate($a_text),
'#',
'menu-clippings-add', ['rel' => 'nofollow', 'id' => $menu_opt, 'data-url' => $route_ajax,
'listType' => $listType, 'clipAction' => $clipAction, 'action-key' => $action_key,
'dt_id' => $dt_id, 'dt_grep' => $dt_grep]);
$first_opt = false;
} else {
$route_ajax = e(route(ClippingsCartEnhancedModule::class, ['module' => $this->name(), 'tree' => $tree->name()]));
$_menu_sm = new Menu(I18N::translate($a_text),
'#',
'menu-clippings-add', ['rel' => 'nofollow', 'id' => $menu_opt, 'data-url' => $route_ajax,
'listType' => $listType, 'clipAction' => $clipAction, 'action-key' => $action_key,
'dt_id' => $dt_id, 'dt_grep' => $dt_grep]);
$_menu = $_menu->addSubmenu($_menu_sm);
}
}
}
}
return $_menu;
}
/**
* @param Tree $tree
* @param Route $route
*
* @return Menu|null
*/
private function addMenuEmptyForce (Tree $tree): ?Menu {
$params['called_by'] = rawurldecode($_SERVER["REQUEST_URI"]);
return new Menu(I18N::translate('Delete records in the clippings cart entirely'),
route('module', [
'module' => $this->name(),
'action' => 'EmptyForce',
'tree' => $tree->name(),
'params' => $params,
]), 'menu-clippings-empty', ['rel' => 'nofollow']);
}
/**
* @param Tree $tree
*
* @return Menu
*/
private function addMenuAddGlobalRecordSets (Tree $tree): Menu
{
return new Menu(I18N::translate('Add global record sets to the clippings cart'),
route('module', [
'module' => $this->name(),
'action' => 'Global',
'tree' => $tree->name(),
]), 'menu-clippings-add', ['rel' => 'nofollow']);
}
/**
* @param Tree $tree
*
* @return Menu
*/
private function addMenuDeleteRecords (Tree $tree): Menu
{
return new Menu(I18N::translate('Delete records in the clippings cart with selection option'),
route('module', [
'module' => $this->name(),
'action' => 'Empty',
'tree' => $tree->name(),
]), 'menu-clippings-empty', ['rel' => 'nofollow']);
}
/**
* @param Tree $tree
*
* @return Menu
*/
private function addMenuExecuteAction (Tree $tree): Menu
{
return new Menu(I18N::translate('Execute an action on records in the clippings cart'),
route('module', [
'module' => $this->name(),
'action' => 'Execute',
'tree' => $tree->name(),
]), 'menu-clippings-download', ['rel' => 'nofollow']);
}
/**
* @param ServerRequestInterface $request
*
* @return ResponseInterface
*/
public function getShowCartAction(ServerRequestInterface $request): ResponseInterface
{
$tree = Validator::attributes($request)->tree();
assert($tree instanceof Tree);
$recordTypes = $this->collectRecordsInCart($tree, self::TYPES_OF_RECORDS);
$this->cartXREFs = $this->getXREFstruct($tree);
$cartActs = $this->get_CartActs($tree);
$CAfiles = $this->getCactfilesInCart($tree);
$cAroute_ajax = e(route(ClippingsCartEnhancedModule::class, ['module' => $this->name(), 'tree' => $tree->name()]));
return $this->viewResponse($this->name() . '::' . 'showCart/showCart', [
'module' => $this->name(),
'types' => self::TYPES_OF_RECORDS,
'recordTypes' => $recordTypes,
'title' => I18N::translate('Family tree clippings cart'),
'header_recs' => I18N::translate(self::SHOW_RECORDS),
'header_acts' => I18N::translate(self::SHOW_ACTIONS),
'cartActions' => $cartActs,
'CAfiles' => $CAfiles,
'cArouteAjax' => $cAroute_ajax,
'cartXREFs' => $this->cartXREFs,
'tree' => $tree,
'stylesheet' => $this->assetUrl('css/cce.css'),
'javascript' => $this->assetUrl('js/cce.js'),
]);
}
/**
* Put class-name into options-text for later on increment/decrement value in view
*
* @param string $text
* @param string $subst1
* @param string $subst2
* @param string $tosubst
* @param string $cname
* @param int $value
*
* @return string
*/
private function substText($text, $subst1, $subst2, $tosubst, $cname, $value)
{
$txt_t = I18N::translate($text, $subst1, $subst2);
$txt_c = '<span class="' . $cname . '">' . $value . '</span>';
$txt_r = str_replace($tosubst, $txt_c, $txt_t);
return $txt_r;
}
/**
* @param ServerRequestInterface $request
*
* @return ResponseInterface
*
* HH.mod - additional action
*/
public function getGlobalAction(ServerRequestInterface $request): ResponseInterface
{
$tree = Validator::attributes($request)->tree();
assert($tree instanceof Tree);
$options[self::ADD_ALL_PARTNER_CHAINS] = I18N::translate('all partner chains in this tree');
$options[self::ADD_ALL_CIRCLES] = I18N::translate('all circles of individuals in this tree');
$options[self::ADD_ALL_LINKED_PERSONS] = I18N::translate('all connected persons in this family tree - Caution: probably very high number of persons!');
$options[self::ADD_ALL_LNKD_PRSNS_WO] = I18N::translate('all connected persons in this family tree with options - Caution: probably very high number of persons!');
$options[self::ADD_COMPLETE_GED] = I18N::translate('all persons/families in this family tree - Caution: probably very high number of persons!');
$title = I18N::translate('Add global record sets to the clippings cart');
$label = I18N::translate('Add to the clippings cart');
return $this->viewResponse($this->name() . '::' . 'global', [
'module' => $this->name(),
'options' => $options,
'title' => $title,
'label' => $label,
'tree' => $tree,
]);
}
/**
* @param ServerRequestInterface $request
*
* @return ResponseInterface
* HH.mod - additional action
*/
public function postGlobalAction(ServerRequestInterface $request): ResponseInterface
{
$tree = Validator::attributes($request)->tree();
$user = Validator::attributes($request)->user();
$option = Validator::parsedBody($request)->string('option');
switch ($option) {
case self::ADD_ALL_PARTNER_CHAINS:
$this->put_CartActs($tree, 'ALL_PARTNER_CHAINS', 'allPC');
$_dname = 'wtVIZ-DATA~all partner chains';
$this->putVIZdname($_dname);
$this->addPartnerChainsGlobalToCart($tree);
break;
case self::ADD_COMPLETE_GED:
$this->put_CartActs($tree, 'COMPLETE', 'GED');
$_dname = 'wtVIZ-DATA~complete GED';
$this->putVIZdname($_dname);
$this->addCompleteGEDtoCart($tree);
break;
case self::ADD_ALL_LINKED_PERSONS:
$this->put_CartActs($tree, 'ALL_LINKED', 'allLP');
$_dname = 'wtVIZ-DATA~all linked';
$this->putVIZdname($_dname);
$this->addAllLinked($tree, $user);
break;
case self::ADD_ALL_LNKD_PRSNS_WO:
$this->put_CartActs($tree, 'ALL_LINKED_WO', 'allLPwo');
$_dname = 'wtVIZ-DATA~all linked-wo';
$this->putVIZdname($_dname);
$this->addAllLinked_wo($tree, $user);
break;
default;
case self::ADD_ALL_CIRCLES:
$this->put_CartActs($tree, 'ALL_CIRCLES', 'allC');
$_dname = 'wtVIZ-DATA~all circles';
$this->putVIZdname($_dname);
$this->addAllCirclesToCart($tree);
break;
}
$url = route('module', [
'module' => $this->name(),
'action' => 'ShowCart',
'description' => $this->description(),
'tree' => $tree->name(),
]);