1<?php 2/** 3 * webtrees: online genealogy 4 * Copyright (C) 2018 webtrees development team 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 */ 16namespace Fisharebest\Webtrees\Module; 17 18use Fisharebest\Webtrees\Auth; 19use Fisharebest\Webtrees\Bootstrap4; 20use Fisharebest\Webtrees\Filter; 21use Fisharebest\Webtrees\Functions\FunctionsEdit; 22use Fisharebest\Webtrees\Functions\FunctionsPrintLists; 23use Fisharebest\Webtrees\Html; 24use Fisharebest\Webtrees\I18N; 25 26/** 27 * Class OnThisDayModule 28 */ 29class OnThisDayModule extends AbstractModule implements ModuleBlockInterface { 30 /** {@inheritdoc} */ 31 public function getTitle() { 32 return /* I18N: Name of a module */ I18N::translate('On this day'); 33 } 34 35 /** {@inheritdoc} */ 36 public function getDescription() { 37 return /* I18N: Description of the “On this day” module */ I18N::translate('A list of the anniversaries that occur today.'); 38 } 39 40 /** 41 * Generate the HTML content of this block. 42 * 43 * @param int $block_id 44 * @param bool $template 45 * @param string[] $cfg 46 * 47 * @return string 48 */ 49 public function getBlock($block_id, $template = true, $cfg = []): string { 50 global $ctype, $WT_TREE; 51 52 $filter = $this->getBlockSetting($block_id, 'filter', '1'); 53 $infoStyle = $this->getBlockSetting($block_id, 'infoStyle', 'table'); 54 $sortStyle = $this->getBlockSetting($block_id, 'sortStyle', 'alpha'); 55 56 foreach (['filter', 'infoStyle', 'sortStyle'] as $name) { 57 if (array_key_exists($name, $cfg)) { 58 $$name = $cfg[$name]; 59 } 60 } 61 62 $todayjd = WT_CLIENT_JD; 63 64 $content = ''; 65 66 // If we are only showing living individuals, then we don't need to search for DEAT events. 67 $tags = $filter ? 'BIRT MARR' : 'BIRT MARR DEAT'; 68 69 switch ($infoStyle) { 70 case 'list': 71 // Output style 1: Old format, no visible tables, much smaller text. Better suited to right side of page. 72 $content .= FunctionsPrintLists::eventsList($todayjd, $todayjd, $tags, $filter, $sortStyle); 73 break; 74 case 'table': 75 // Style 2: New format, tables, big text, etc. Not too good on right side of page 76 ob_start(); 77 $content .= FunctionsPrintLists::eventsTable($todayjd, $todayjd, $tags, $filter, $sortStyle); 78 $content .= ob_get_clean(); 79 break; 80 } 81 82 if ($template) { 83 if ($ctype === 'gedcom' && Auth::isManager($WT_TREE) || $ctype === 'user' && Auth::check()) { 84 $config_url = Html::url('block_edit.php', ['block_id' => $block_id, 'ged' => $WT_TREE->getName()]); 85 } else { 86 $config_url = ''; 87 } 88 89 return view('blocks/template', [ 90 'block' => str_replace('_', '-', $this->getName()), 91 'id' => $block_id, 92 'config_url' => $config_url, 93 'title' => $this->getTitle(), 94 'content' => $content, 95 ]); 96 } else { 97 return $content; 98 } 99 } 100 101 /** {@inheritdoc} */ 102 public function loadAjax(): bool { 103 return true; 104 } 105 106 /** {@inheritdoc} */ 107 public function isUserBlock(): bool { 108 return true; 109 } 110 111 /** {@inheritdoc} */ 112 public function isGedcomBlock(): bool { 113 return true; 114 } 115 116 /** 117 * An HTML form to edit block settings 118 * 119 * @param int $block_id 120 * 121 * @return void 122 */ 123 public function configureBlock($block_id) { 124 if (Filter::postBool('save') && Filter::checkCsrf()) { 125 $this->setBlockSetting($block_id, 'filter', Filter::postBool('filter')); 126 $this->setBlockSetting($block_id, 'infoStyle', Filter::post('infoStyle', 'list|table', 'table')); 127 $this->setBlockSetting($block_id, 'sortStyle', Filter::post('sortStyle', 'alpha|anniv', 'alpha')); 128 } 129 130 $filter = $this->getBlockSetting($block_id, 'filter', '1'); 131 $infoStyle = $this->getBlockSetting($block_id, 'infoStyle', 'table'); 132 $sortStyle = $this->getBlockSetting($block_id, 'sortStyle', 'alpha'); 133 134 ?> 135 <div class="form-group row"> 136 <label class="col-sm-3 col-form-label" for="filter"> 137 <?= /* I18N: Label for a configuration option */ I18N::translate('Show only events of living individuals') ?> 138 </label> 139 <div class="col-sm-9"> 140 <?= Bootstrap4::radioButtons('filter', FunctionsEdit::optionsNoYes(), $filter, true) ?> 141 </div> 142 </div> 143 144 <div class="form-group row"> 145 <label class="col-sm-3 col-form-label" for="infoStyle"> 146 <?= /* I18N: Label for a configuration option */ I18N::translate('Presentation style') ?> 147 </label> 148 <div class="col-sm-9"> 149 <?= Bootstrap4::select(['list' => I18N::translate('list'), 'table' => I18N::translate('table')], $infoStyle, ['id' => 'infoStyle', 'name' => 'infoStyle']) ?> 150 </div> 151 </div> 152 153 <div class="form-group row"> 154 <label class="col-sm-3 col-form-label" for="sortStyle"> 155 <?= /* I18N: Label for a configuration option */ I18N::translate('Sort order') ?> 156 </label> 157 <div class="col-sm-9"> 158 <?= 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']) ?> 159 </div> 160 </div> 161 <?php 162 } 163} 164