18c2e8227SGreg Roach<?php 28c2e8227SGreg Roach/** 38c2e8227SGreg Roach * webtrees: online genealogy 41062a142SGreg Roach * Copyright (C) 2018 webtrees development team 58c2e8227SGreg Roach * This program is free software: you can redistribute it and/or modify 68c2e8227SGreg Roach * it under the terms of the GNU General Public License as published by 78c2e8227SGreg Roach * the Free Software Foundation, either version 3 of the License, or 88c2e8227SGreg Roach * (at your option) any later version. 98c2e8227SGreg Roach * This program is distributed in the hope that it will be useful, 108c2e8227SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 118c2e8227SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 128c2e8227SGreg Roach * GNU General Public License for more details. 138c2e8227SGreg Roach * You should have received a copy of the GNU General Public License 148c2e8227SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 158c2e8227SGreg Roach */ 1676692c8bSGreg Roachnamespace Fisharebest\Webtrees\Module; 1776692c8bSGreg Roach 180e62c4b8SGreg Roachuse Fisharebest\Webtrees\Auth; 1915d603e7SGreg Roachuse Fisharebest\Webtrees\Bootstrap4; 200e62c4b8SGreg Roachuse Fisharebest\Webtrees\Filter; 213d7a8a4cSGreg Roachuse Fisharebest\Webtrees\Functions\FunctionsEdit; 223d7a8a4cSGreg Roachuse Fisharebest\Webtrees\Functions\FunctionsPrintLists; 239c6524dcSGreg Roachuse Fisharebest\Webtrees\Html; 240e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N; 258c2e8227SGreg Roach 268c2e8227SGreg Roach/** 278c2e8227SGreg Roach * Class OnThisDayModule 288c2e8227SGreg Roach */ 29e2a378d3SGreg Roachclass OnThisDayModule extends AbstractModule implements ModuleBlockInterface { 308c2e8227SGreg Roach /** {@inheritdoc} */ 318c2e8227SGreg Roach public function getTitle() { 328c2e8227SGreg Roach return /* I18N: Name of a module */ I18N::translate('On this day'); 338c2e8227SGreg Roach } 348c2e8227SGreg Roach 358c2e8227SGreg Roach /** {@inheritdoc} */ 368c2e8227SGreg Roach public function getDescription() { 378c2e8227SGreg Roach return /* I18N: Description of the “On this day” module */ I18N::translate('A list of the anniversaries that occur today.'); 388c2e8227SGreg Roach } 398c2e8227SGreg Roach 4076692c8bSGreg Roach /** 4176692c8bSGreg Roach * Generate the HTML content of this block. 4276692c8bSGreg Roach * 4376692c8bSGreg Roach * @param int $block_id 4476692c8bSGreg Roach * @param bool $template 45727f238cSGreg Roach * @param string[] $cfg 4676692c8bSGreg Roach * 4776692c8bSGreg Roach * @return string 4876692c8bSGreg Roach */ 49a9430be8SGreg Roach public function getBlock($block_id, $template = true, $cfg = []): string { 504b9ff166SGreg Roach global $ctype, $WT_TREE; 518c2e8227SGreg Roach 52e2a378d3SGreg Roach $filter = $this->getBlockSetting($block_id, 'filter', '1'); 53e2a378d3SGreg Roach $infoStyle = $this->getBlockSetting($block_id, 'infoStyle', 'table'); 54e2a378d3SGreg Roach $sortStyle = $this->getBlockSetting($block_id, 'sortStyle', 'alpha'); 558c2e8227SGreg Roach 5615d603e7SGreg Roach foreach (['filter', 'infoStyle', 'sortStyle'] as $name) { 578c2e8227SGreg Roach if (array_key_exists($name, $cfg)) { 588c2e8227SGreg Roach $$name = $cfg[$name]; 598c2e8227SGreg Roach } 608c2e8227SGreg Roach } 618c2e8227SGreg Roach 628c2e8227SGreg Roach $todayjd = WT_CLIENT_JD; 638c2e8227SGreg Roach 648c2e8227SGreg Roach $content = ''; 651b9bdb4fSGreg Roach 661b9bdb4fSGreg Roach // If we are only showing living individuals, then we don't need to search for DEAT events. 671b9bdb4fSGreg Roach $tags = $filter ? 'BIRT MARR' : 'BIRT MARR DEAT'; 681b9bdb4fSGreg Roach 698c2e8227SGreg Roach switch ($infoStyle) { 708c2e8227SGreg Roach case 'list': 718c2e8227SGreg Roach // Output style 1: Old format, no visible tables, much smaller text. Better suited to right side of page. 721b9bdb4fSGreg Roach $content .= FunctionsPrintLists::eventsList($todayjd, $todayjd, $tags, $filter, $sortStyle); 738c2e8227SGreg Roach break; 748c2e8227SGreg Roach case 'table': 758c2e8227SGreg Roach // Style 2: New format, tables, big text, etc. Not too good on right side of page 768c2e8227SGreg Roach ob_start(); 771b9bdb4fSGreg Roach $content .= FunctionsPrintLists::eventsTable($todayjd, $todayjd, $tags, $filter, $sortStyle); 788c2e8227SGreg Roach $content .= ob_get_clean(); 798c2e8227SGreg Roach break; 808c2e8227SGreg Roach } 818c2e8227SGreg Roach 828c2e8227SGreg Roach if ($template) { 839c6524dcSGreg Roach if ($ctype === 'gedcom' && Auth::isManager($WT_TREE) || $ctype === 'user' && Auth::check()) { 849c6524dcSGreg Roach $config_url = Html::url('block_edit.php', ['block_id' => $block_id, 'ged' => $WT_TREE->getName()]); 859c6524dcSGreg Roach } else { 869c6524dcSGreg Roach $config_url = ''; 879c6524dcSGreg Roach } 889c6524dcSGreg Roach 89*225e381fSGreg Roach return view('blocks/template', [ 909c6524dcSGreg Roach 'block' => str_replace('_', '-', $this->getName()), 919c6524dcSGreg Roach 'id' => $block_id, 929c6524dcSGreg Roach 'config_url' => $config_url, 939c6524dcSGreg Roach 'title' => $this->getTitle(), 949c6524dcSGreg Roach 'content' => $content, 959c6524dcSGreg Roach ]); 968c2e8227SGreg Roach } else { 978c2e8227SGreg Roach return $content; 988c2e8227SGreg Roach } 998c2e8227SGreg Roach } 1008c2e8227SGreg Roach 1018c2e8227SGreg Roach /** {@inheritdoc} */ 102a9430be8SGreg Roach public function loadAjax(): bool { 1038c2e8227SGreg Roach return true; 1048c2e8227SGreg Roach } 1058c2e8227SGreg Roach 1068c2e8227SGreg Roach /** {@inheritdoc} */ 107a9430be8SGreg Roach public function isUserBlock(): bool { 1088c2e8227SGreg Roach return true; 1098c2e8227SGreg Roach } 1108c2e8227SGreg Roach 1118c2e8227SGreg Roach /** {@inheritdoc} */ 112a9430be8SGreg Roach public function isGedcomBlock(): bool { 1138c2e8227SGreg Roach return true; 1148c2e8227SGreg Roach } 1158c2e8227SGreg Roach 11676692c8bSGreg Roach /** 11776692c8bSGreg Roach * An HTML form to edit block settings 11876692c8bSGreg Roach * 11976692c8bSGreg Roach * @param int $block_id 120a9430be8SGreg Roach * 121a9430be8SGreg Roach * @return void 12276692c8bSGreg Roach */ 123be9a728cSGreg Roach public function configureBlock($block_id) { 1248c2e8227SGreg Roach if (Filter::postBool('save') && Filter::checkCsrf()) { 125e2a378d3SGreg Roach $this->setBlockSetting($block_id, 'filter', Filter::postBool('filter')); 126e2a378d3SGreg Roach $this->setBlockSetting($block_id, 'infoStyle', Filter::post('infoStyle', 'list|table', 'table')); 127e2a378d3SGreg Roach $this->setBlockSetting($block_id, 'sortStyle', Filter::post('sortStyle', 'alpha|anniv', 'alpha')); 1288c2e8227SGreg Roach } 1298c2e8227SGreg Roach 130e2a378d3SGreg Roach $filter = $this->getBlockSetting($block_id, 'filter', '1'); 131e2a378d3SGreg Roach $infoStyle = $this->getBlockSetting($block_id, 'infoStyle', 'table'); 132e2a378d3SGreg Roach $sortStyle = $this->getBlockSetting($block_id, 'sortStyle', 'alpha'); 1338c2e8227SGreg Roach 13415d603e7SGreg Roach ?> 13515d603e7SGreg Roach <div class="form-group row"> 13615d603e7SGreg Roach <label class="col-sm-3 col-form-label" for="filter"> 13715d603e7SGreg Roach <?= /* I18N: Label for a configuration option */ I18N::translate('Show only events of living individuals') ?> 13815d603e7SGreg Roach </label> 13915d603e7SGreg Roach <div class="col-sm-9"> 14015d603e7SGreg Roach <?= Bootstrap4::radioButtons('filter', FunctionsEdit::optionsNoYes(), $filter, true) ?> 14115d603e7SGreg Roach </div> 14215d603e7SGreg Roach </div> 1438c2e8227SGreg Roach 14415d603e7SGreg Roach <div class="form-group row"> 14515d603e7SGreg Roach <label class="col-sm-3 col-form-label" for="infoStyle"> 14615d603e7SGreg Roach <?= /* I18N: Label for a configuration option */ I18N::translate('Presentation style') ?> 14715d603e7SGreg Roach </label> 14815d603e7SGreg Roach <div class="col-sm-9"> 14915d603e7SGreg Roach <?= Bootstrap4::select(['list' => I18N::translate('list'), 'table' => I18N::translate('table')], $infoStyle, ['id' => 'infoStyle', 'name' => 'infoStyle']) ?> 15015d603e7SGreg Roach </div> 15115d603e7SGreg Roach </div> 1528c2e8227SGreg Roach 15315d603e7SGreg Roach <div class="form-group row"> 15415d603e7SGreg Roach <label class="col-sm-3 col-form-label" for="sortStyle"> 15515d603e7SGreg Roach <?= /* I18N: Label for a configuration option */ I18N::translate('Sort order') ?> 15615d603e7SGreg Roach </label> 15715d603e7SGreg Roach <div class="col-sm-9"> 15815d603e7SGreg Roach <?= Bootstrap4::select(['alpha' => /* I18N: An option in a list-box */ I18N::translate('sort by name'), 'anniv' => /* I18N: An option in a list-box */ I18N::translate('sort by date')], $sortStyle, ['id' => 'sortStyle', 'name' => 'sortStyle']) ?> 15915d603e7SGreg Roach </div> 16015d603e7SGreg Roach </div> 16115d603e7SGreg Roach <?php 1628c2e8227SGreg Roach } 1638c2e8227SGreg Roach} 164