18c2e8227SGreg Roach<?php 28c2e8227SGreg Roach/** 38c2e8227SGreg Roach * webtrees: online genealogy 46bdf7674SGreg Roach * Copyright (C) 2017 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; 259c6524dcSGreg Roachuse Fisharebest\Webtrees\View; 268c2e8227SGreg Roach 278c2e8227SGreg Roach/** 288c2e8227SGreg Roach * Class OnThisDayModule 298c2e8227SGreg Roach */ 30e2a378d3SGreg Roachclass OnThisDayModule extends AbstractModule implements ModuleBlockInterface { 318c2e8227SGreg Roach /** {@inheritdoc} */ 328c2e8227SGreg Roach public function getTitle() { 338c2e8227SGreg Roach return /* I18N: Name of a module */ I18N::translate('On this day'); 348c2e8227SGreg Roach } 358c2e8227SGreg Roach 368c2e8227SGreg Roach /** {@inheritdoc} */ 378c2e8227SGreg Roach public function getDescription() { 388c2e8227SGreg Roach return /* I18N: Description of the “On this day” module */ I18N::translate('A list of the anniversaries that occur today.'); 398c2e8227SGreg Roach } 408c2e8227SGreg Roach 4176692c8bSGreg Roach /** 4276692c8bSGreg Roach * Generate the HTML content of this block. 4376692c8bSGreg Roach * 4476692c8bSGreg Roach * @param int $block_id 4576692c8bSGreg Roach * @param bool $template 46727f238cSGreg Roach * @param string[] $cfg 4776692c8bSGreg Roach * 4876692c8bSGreg Roach * @return string 4976692c8bSGreg Roach */ 50a9430be8SGreg Roach public function getBlock($block_id, $template = true, $cfg = []): string { 514b9ff166SGreg Roach global $ctype, $WT_TREE; 528c2e8227SGreg Roach 53e2a378d3SGreg Roach $filter = $this->getBlockSetting($block_id, 'filter', '1'); 54e2a378d3SGreg Roach $infoStyle = $this->getBlockSetting($block_id, 'infoStyle', 'table'); 55e2a378d3SGreg Roach $sortStyle = $this->getBlockSetting($block_id, 'sortStyle', 'alpha'); 568c2e8227SGreg Roach 5715d603e7SGreg Roach foreach (['filter', 'infoStyle', 'sortStyle'] as $name) { 588c2e8227SGreg Roach if (array_key_exists($name, $cfg)) { 598c2e8227SGreg Roach $$name = $cfg[$name]; 608c2e8227SGreg Roach } 618c2e8227SGreg Roach } 628c2e8227SGreg Roach 638c2e8227SGreg Roach $todayjd = WT_CLIENT_JD; 648c2e8227SGreg Roach 658c2e8227SGreg Roach $content = ''; 661b9bdb4fSGreg Roach 671b9bdb4fSGreg Roach // If we are only showing living individuals, then we don't need to search for DEAT events. 681b9bdb4fSGreg Roach $tags = $filter ? 'BIRT MARR' : 'BIRT MARR DEAT'; 691b9bdb4fSGreg Roach 708c2e8227SGreg Roach switch ($infoStyle) { 718c2e8227SGreg Roach case 'list': 728c2e8227SGreg Roach // Output style 1: Old format, no visible tables, much smaller text. Better suited to right side of page. 731b9bdb4fSGreg Roach $content .= FunctionsPrintLists::eventsList($todayjd, $todayjd, $tags, $filter, $sortStyle); 748c2e8227SGreg Roach break; 758c2e8227SGreg Roach case 'table': 768c2e8227SGreg Roach // Style 2: New format, tables, big text, etc. Not too good on right side of page 778c2e8227SGreg Roach ob_start(); 781b9bdb4fSGreg Roach $content .= FunctionsPrintLists::eventsTable($todayjd, $todayjd, $tags, $filter, $sortStyle); 798c2e8227SGreg Roach $content .= ob_get_clean(); 808c2e8227SGreg Roach break; 818c2e8227SGreg Roach } 828c2e8227SGreg Roach 838c2e8227SGreg Roach if ($template) { 849c6524dcSGreg Roach if ($ctype === 'gedcom' && Auth::isManager($WT_TREE) || $ctype === 'user' && Auth::check()) { 859c6524dcSGreg Roach $config_url = Html::url('block_edit.php', ['block_id' => $block_id, 'ged' => $WT_TREE->getName()]); 869c6524dcSGreg Roach } else { 879c6524dcSGreg Roach $config_url = ''; 889c6524dcSGreg Roach } 899c6524dcSGreg Roach 909c6524dcSGreg Roach return View::make('blocks/template', [ 919c6524dcSGreg Roach 'block' => str_replace('_', '-', $this->getName()), 929c6524dcSGreg Roach 'id' => $block_id, 939c6524dcSGreg Roach 'config_url' => $config_url, 949c6524dcSGreg Roach 'title' => $this->getTitle(), 959c6524dcSGreg Roach 'content' => $content, 969c6524dcSGreg Roach ]); 978c2e8227SGreg Roach } else { 988c2e8227SGreg Roach return $content; 998c2e8227SGreg Roach } 1008c2e8227SGreg Roach } 1018c2e8227SGreg Roach 1028c2e8227SGreg Roach /** {@inheritdoc} */ 103a9430be8SGreg Roach public function loadAjax(): bool { 1048c2e8227SGreg Roach return true; 1058c2e8227SGreg Roach } 1068c2e8227SGreg Roach 1078c2e8227SGreg Roach /** {@inheritdoc} */ 108a9430be8SGreg Roach public function isUserBlock(): bool { 1098c2e8227SGreg Roach return true; 1108c2e8227SGreg Roach } 1118c2e8227SGreg Roach 1128c2e8227SGreg Roach /** {@inheritdoc} */ 113a9430be8SGreg Roach public function isGedcomBlock(): bool { 1148c2e8227SGreg Roach return true; 1158c2e8227SGreg Roach } 1168c2e8227SGreg Roach 11776692c8bSGreg Roach /** 11876692c8bSGreg Roach * An HTML form to edit block settings 11976692c8bSGreg Roach * 12076692c8bSGreg Roach * @param int $block_id 121a9430be8SGreg Roach * 122a9430be8SGreg Roach * @return void 12376692c8bSGreg Roach */ 124*be9a728cSGreg Roach public function configureBlock($block_id) { 1258c2e8227SGreg Roach if (Filter::postBool('save') && Filter::checkCsrf()) { 126e2a378d3SGreg Roach $this->setBlockSetting($block_id, 'filter', Filter::postBool('filter')); 127e2a378d3SGreg Roach $this->setBlockSetting($block_id, 'infoStyle', Filter::post('infoStyle', 'list|table', 'table')); 128e2a378d3SGreg Roach $this->setBlockSetting($block_id, 'sortStyle', Filter::post('sortStyle', 'alpha|anniv', 'alpha')); 1298c2e8227SGreg Roach } 1308c2e8227SGreg Roach 131e2a378d3SGreg Roach $filter = $this->getBlockSetting($block_id, 'filter', '1'); 132e2a378d3SGreg Roach $infoStyle = $this->getBlockSetting($block_id, 'infoStyle', 'table'); 133e2a378d3SGreg Roach $sortStyle = $this->getBlockSetting($block_id, 'sortStyle', 'alpha'); 1348c2e8227SGreg Roach 13515d603e7SGreg Roach ?> 13615d603e7SGreg Roach <div class="form-group row"> 13715d603e7SGreg Roach <label class="col-sm-3 col-form-label" for="filter"> 13815d603e7SGreg Roach <?= /* I18N: Label for a configuration option */ I18N::translate('Show only events of living individuals') ?> 13915d603e7SGreg Roach </label> 14015d603e7SGreg Roach <div class="col-sm-9"> 14115d603e7SGreg Roach <?= Bootstrap4::radioButtons('filter', FunctionsEdit::optionsNoYes(), $filter, true) ?> 14215d603e7SGreg Roach </div> 14315d603e7SGreg Roach </div> 1448c2e8227SGreg Roach 14515d603e7SGreg Roach <div class="form-group row"> 14615d603e7SGreg Roach <label class="col-sm-3 col-form-label" for="infoStyle"> 14715d603e7SGreg Roach <?= /* I18N: Label for a configuration option */ I18N::translate('Presentation style') ?> 14815d603e7SGreg Roach </label> 14915d603e7SGreg Roach <div class="col-sm-9"> 15015d603e7SGreg Roach <?= Bootstrap4::select(['list' => I18N::translate('list'), 'table' => I18N::translate('table')], $infoStyle, ['id' => 'infoStyle', 'name' => 'infoStyle']) ?> 15115d603e7SGreg Roach </div> 15215d603e7SGreg Roach </div> 1538c2e8227SGreg Roach 15415d603e7SGreg Roach <div class="form-group row"> 15515d603e7SGreg Roach <label class="col-sm-3 col-form-label" for="sortStyle"> 15615d603e7SGreg Roach <?= /* I18N: Label for a configuration option */ I18N::translate('Sort order') ?> 15715d603e7SGreg Roach </label> 15815d603e7SGreg Roach <div class="col-sm-9"> 15915d603e7SGreg 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']) ?> 16015d603e7SGreg Roach </div> 16115d603e7SGreg Roach </div> 16215d603e7SGreg Roach <?php 1638c2e8227SGreg Roach } 1648c2e8227SGreg Roach} 165