-
Notifications
You must be signed in to change notification settings - Fork 3
/
SharedPlacesListController.php
86 lines (72 loc) · 2.79 KB
/
SharedPlacesListController.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
<?php
namespace Cissee\Webtrees\Module\SharedPlaces;
use Cissee\WebtreesExt\Http\Controllers\PlaceHierarchyLink;
use Fisharebest\Webtrees\Auth;
use Fisharebest\Webtrees\GedcomRecord;
use Fisharebest\Webtrees\Http\ViewResponseTrait;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Registry;
use Fisharebest\Webtrees\Tree;
use Fisharebest\Webtrees\Webtrees;
use Illuminate\Database\Capsule\Manager as DB;
use Illuminate\Support\Collection;
use Psr\Http\Message\ResponseInterface;
use Vesta\Hook\HookInterfaces\GovIdEditControlsInterface;
use Vesta\Hook\HookInterfaces\GovIdEditControlsUtils;
class SharedPlacesListController {
use ViewResponseTrait;
protected $module;
protected $moduleName;
protected $hasLocationsToFix;
protected $link;
public function __construct(
$module,
bool $hasLocationsToFix,
?PlaceHierarchyLink $link) {
$this->module = $module;
$this->moduleName = $module->name();
$this->hasLocationsToFix = $hasLocationsToFix;
$this->link = $link;
}
public function sharedPlacesList(Tree $tree, $showLinkCounts): ResponseInterface {
$sharedPlaces = SharedPlacesListController::allSharedPlaces($tree);
//select initializers for modal placeholder ajax-modal-vesta.phtml used via CreateSharedPlaceModal, urgh
$select2Initializers = GovIdEditControlsUtils::accessibleModules($tree, Auth::user())
->map(function (GovIdEditControlsInterface $module) {
return $module->govIdEditControlSelectScriptSnippet();
})
->toArray();
return $this->viewResponse($this->moduleName . '::shared-places-list-page', [
'tree' => $tree,
'sharedPlaces' => $sharedPlaces,
'showLinkCounts' => $showLinkCounts,
'title' => I18N::translate('Shared places'),
'moduleName' => $this->moduleName,
'select2Initializers' => $select2Initializers,
'hasLocationsToFix' => $this->hasLocationsToFix,
'link' => $this->link,
]);
}
/**
* Find all the shared place records in a tree.
*
* @param Tree $tree
*
* @return Collection
*/
private function allSharedPlaces(Tree $tree): Collection {
/*
$count = DB::table('other')
->where('o_file', '=', $tree->id())
->where('o_type', '=', '_LOC')
->count();
error_log("count".$count);
*/
return DB::table('other')
->where('o_file', '=', $tree->id())
->where('o_type', '=', '_LOC')
->get()
->map(Registry::locationFactory()->mapper($tree))
->filter(GedcomRecord::accessFilter());
}
}