1<?php 2/** 3 * webtrees: online genealogy 4 * Copyright (C) 2017 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\FontAwesome; 22use Fisharebest\Webtrees\Functions\FunctionsEdit; 23use Fisharebest\Webtrees\Functions\FunctionsPrintLists; 24use Fisharebest\Webtrees\I18N; 25use Fisharebest\Webtrees\Theme; 26 27/** 28 * Class OnThisDayModule 29 */ 30class OnThisDayModule extends AbstractModule implements ModuleBlockInterface { 31 /** {@inheritdoc} */ 32 public function getTitle() { 33 return /* I18N: Name of a module */ I18N::translate('On this day'); 34 } 35 36 /** {@inheritdoc} */ 37 public function getDescription() { 38 return /* I18N: Description of the “On this day” module */ I18N::translate('A list of the anniversaries that occur today.'); 39 } 40 41 /** 42 * Generate the HTML content of this block. 43 * 44 * @param int $block_id 45 * @param bool $template 46 * @param string[] $cfg 47 * 48 * @return string 49 */ 50 public function getBlock($block_id, $template = true, $cfg = []) { 51 global $ctype, $WT_TREE; 52 53 $filter = $this->getBlockSetting($block_id, 'filter', '1'); 54 $infoStyle = $this->getBlockSetting($block_id, 'infoStyle', 'table'); 55 $sortStyle = $this->getBlockSetting($block_id, 'sortStyle', 'alpha'); 56 57 foreach (['filter', 'infoStyle', 'sortStyle'] as $name) { 58 if (array_key_exists($name, $cfg)) { 59 $$name = $cfg[$name]; 60 } 61 } 62 63 $todayjd = WT_CLIENT_JD; 64 65 $id = $this->getName() . $block_id; 66 $class = $this->getName() . '_block'; 67 if ($ctype === 'gedcom' && Auth::isManager($WT_TREE) || $ctype === 'user' && Auth::check()) { 68 $title = FontAwesome::linkIcon('preferences', I18N::translate('Preferences'), ['class' => 'btn btn-link', 'href' => 'block_edit.php?block_id=' . $block_id . '&ged=' . $WT_TREE->getNameHtml() . '&ctype=' . $ctype]) . ' '; 69 } else { 70 $title = ''; 71 } 72 $title .= $this->getTitle(); 73 74 $content = ''; 75 76 // If we are only showing living individuals, then we don't need to search for DEAT events. 77 $tags = $filter ? 'BIRT MARR' : 'BIRT MARR DEAT'; 78 79 switch ($infoStyle) { 80 case 'list': 81 // Output style 1: Old format, no visible tables, much smaller text. Better suited to right side of page. 82 $content .= FunctionsPrintLists::eventsList($todayjd, $todayjd, $tags, $filter, $sortStyle); 83 break; 84 case 'table': 85 // Style 2: New format, tables, big text, etc. Not too good on right side of page 86 ob_start(); 87 $content .= FunctionsPrintLists::eventsTable($todayjd, $todayjd, $tags, $filter, $sortStyle); 88 $content .= ob_get_clean(); 89 break; 90 } 91 92 if ($template) { 93 return Theme::theme()->formatBlock($id, $title, $class, $content); 94 } else { 95 return $content; 96 } 97 } 98 99 /** {@inheritdoc} */ 100 public function loadAjax() { 101 return true; 102 } 103 104 /** {@inheritdoc} */ 105 public function isUserBlock() { 106 return true; 107 } 108 109 /** {@inheritdoc} */ 110 public function isGedcomBlock() { 111 return true; 112 } 113 114 /** 115 * An HTML form to edit block settings 116 * 117 * @param int $block_id 118 */ 119 public function configureBlock($block_id) { 120 if (Filter::postBool('save') && Filter::checkCsrf()) { 121 $this->setBlockSetting($block_id, 'filter', Filter::postBool('filter')); 122 $this->setBlockSetting($block_id, 'infoStyle', Filter::post('infoStyle', 'list|table', 'table')); 123 $this->setBlockSetting($block_id, 'sortStyle', Filter::post('sortStyle', 'alpha|anniv', 'alpha')); 124 } 125 126 $filter = $this->getBlockSetting($block_id, 'filter', '1'); 127 $infoStyle = $this->getBlockSetting($block_id, 'infoStyle', 'table'); 128 $sortStyle = $this->getBlockSetting($block_id, 'sortStyle', 'alpha'); 129 130 ?> 131 <div class="form-group row"> 132 <label class="col-sm-3 col-form-label" for="filter"> 133 <?= /* I18N: Label for a configuration option */ I18N::translate('Show only events of living individuals') ?> 134 </label> 135 <div class="col-sm-9"> 136 <?= Bootstrap4::radioButtons('filter', FunctionsEdit::optionsNoYes(), $filter, true) ?> 137 </div> 138 </div> 139 140 <div class="form-group row"> 141 <label class="col-sm-3 col-form-label" for="infoStyle"> 142 <?= /* I18N: Label for a configuration option */ I18N::translate('Presentation style') ?> 143 </label> 144 <div class="col-sm-9"> 145 <?= Bootstrap4::select(['list' => I18N::translate('list'), 'table' => I18N::translate('table')], $infoStyle, ['id' => 'infoStyle', 'name' => 'infoStyle']) ?> 146 </div> 147 </div> 148 149 <div class="form-group row"> 150 <label class="col-sm-3 col-form-label" for="sortStyle"> 151 <?= /* I18N: Label for a configuration option */ I18N::translate('Sort order') ?> 152 </label> 153 <div class="col-sm-9"> 154 <?= 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']) ?> 155 </div> 156 </div> 157 <?php 158 } 159} 160