1701f5d18SGreg Roach<?php 2701f5d18SGreg Roach 3701f5d18SGreg Roach/** 4701f5d18SGreg Roach * webtrees: online genealogy 5*d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 6701f5d18SGreg Roach * This program is free software: you can redistribute it and/or modify 7701f5d18SGreg Roach * it under the terms of the GNU General Public License as published by 8701f5d18SGreg Roach * the Free Software Foundation, either version 3 of the License, or 9701f5d18SGreg Roach * (at your option) any later version. 10701f5d18SGreg Roach * This program is distributed in the hope that it will be useful, 11701f5d18SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12701f5d18SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13701f5d18SGreg Roach * GNU General Public License for more details. 14701f5d18SGreg Roach * You should have received a copy of the GNU General Public License 15701f5d18SGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 16701f5d18SGreg Roach */ 17701f5d18SGreg Roach 18701f5d18SGreg Roachdeclare(strict_types=1); 19701f5d18SGreg Roach 20701f5d18SGreg Roachnamespace Fisharebest\Webtrees\Elements; 21701f5d18SGreg Roach 22701f5d18SGreg Roachuse Fisharebest\Webtrees\Http\RequestHandlers\CreateNoteModal; 23701f5d18SGreg Roachuse Fisharebest\Webtrees\I18N; 24701f5d18SGreg Roachuse Fisharebest\Webtrees\Registry; 25701f5d18SGreg Roachuse Fisharebest\Webtrees\Tree; 26701f5d18SGreg Roach 27701f5d18SGreg Roachuse function e; 28701f5d18SGreg Roachuse function route; 29701f5d18SGreg Roachuse function trim; 30701f5d18SGreg Roachuse function view; 31701f5d18SGreg Roach 32701f5d18SGreg Roach/** 33701f5d18SGreg Roach * XREF:SNOTE := {Size=1:22} 34701f5d18SGreg Roach * A pointer to, or a cross-reference identifier of, a shared note record. 35701f5d18SGreg Roach */ 36701f5d18SGreg Roachclass XrefSharedNote extends AbstractXrefElement 37701f5d18SGreg Roach{ 38701f5d18SGreg Roach /** 39701f5d18SGreg Roach * An edit control for this data. 40701f5d18SGreg Roach * 41701f5d18SGreg Roach * @param string $id 42701f5d18SGreg Roach * @param string $name 43701f5d18SGreg Roach * @param string $value 44701f5d18SGreg Roach * @param Tree $tree 45701f5d18SGreg Roach * 46701f5d18SGreg Roach * @return string 47701f5d18SGreg Roach */ 48701f5d18SGreg Roach public function edit(string $id, string $name, string $value, Tree $tree): string 49701f5d18SGreg Roach { 50701f5d18SGreg Roach $select = view('components/select-shared-note', [ 51701f5d18SGreg Roach 'id' => $id, 52701f5d18SGreg Roach 'name' => $name, 53701f5d18SGreg Roach 'shared_note' => Registry::sharedNoteFactory()->make(trim($value, '@'), $tree), 54701f5d18SGreg Roach 'tree' => $tree, 55701f5d18SGreg Roach 'at' => '@', 56701f5d18SGreg Roach ]); 57701f5d18SGreg Roach 58701f5d18SGreg Roach return 59701f5d18SGreg Roach '<div class="input-group">' . 60701f5d18SGreg Roach '<button class="btn btn-secondary" type="button" data-bs-toggle="modal" data-bs-backdrop="static" data-bs-target="#wt-ajax-modal" data-wt-href="' . e(route(CreateNoteModal::class, ['tree' => $tree->name()])) . '" data-wt-select-id="' . $id . '" title="' . I18N::translate('Create a shared note') . '">' . 61701f5d18SGreg Roach view('icons/add') . 62701f5d18SGreg Roach '</button>' . 63701f5d18SGreg Roach $select . 64701f5d18SGreg Roach '</div>'; 65701f5d18SGreg Roach } 66701f5d18SGreg Roach 67701f5d18SGreg Roach /** 68701f5d18SGreg Roach * Display the value of this type of element. 69701f5d18SGreg Roach * 70701f5d18SGreg Roach * @param string $value 71701f5d18SGreg Roach * @param Tree $tree 72701f5d18SGreg Roach * 73701f5d18SGreg Roach * @return string 74701f5d18SGreg Roach */ 75701f5d18SGreg Roach public function value(string $value, Tree $tree): string 76701f5d18SGreg Roach { 77701f5d18SGreg Roach return $this->valueXrefLink($value, $tree, Registry::sharedNoteFactory()); 78701f5d18SGreg Roach } 79701f5d18SGreg Roach} 80