xref: /webtrees/app/Module/OnThisDayModule.php (revision 1e6d38482cc472a0193e9887cf587e97097024a6)
18c2e8227SGreg Roach<?php
28c2e8227SGreg Roach/**
38c2e8227SGreg Roach * webtrees: online genealogy
4369c0ce6SGreg Roach * Copyright (C) 2016 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;
190e62c4b8SGreg Roachuse Fisharebest\Webtrees\Filter;
203d7a8a4cSGreg Roachuse Fisharebest\Webtrees\Functions\FunctionsEdit;
213d7a8a4cSGreg Roachuse Fisharebest\Webtrees\Functions\FunctionsPrintLists;
220e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N;
230e62c4b8SGreg Roachuse Fisharebest\Webtrees\Theme;
248c2e8227SGreg Roach
258c2e8227SGreg Roach/**
268c2e8227SGreg Roach * Class OnThisDayModule
278c2e8227SGreg Roach */
28e2a378d3SGreg Roachclass OnThisDayModule extends AbstractModule implements ModuleBlockInterface {
298c2e8227SGreg Roach	/** {@inheritdoc} */
308c2e8227SGreg Roach	public function getTitle() {
318c2e8227SGreg Roach		return /* I18N: Name of a module */ I18N::translate('On this day');
328c2e8227SGreg Roach	}
338c2e8227SGreg Roach
348c2e8227SGreg Roach	/** {@inheritdoc} */
358c2e8227SGreg Roach	public function getDescription() {
368c2e8227SGreg Roach		return /* I18N: Description of the “On this day” module */ I18N::translate('A list of the anniversaries that occur today.');
378c2e8227SGreg Roach	}
388c2e8227SGreg Roach
3976692c8bSGreg Roach	/**
4076692c8bSGreg Roach	 * Generate the HTML content of this block.
4176692c8bSGreg Roach	 *
4276692c8bSGreg Roach	 * @param int      $block_id
4376692c8bSGreg Roach	 * @param bool     $template
44727f238cSGreg Roach	 * @param string[] $cfg
4576692c8bSGreg Roach	 *
4676692c8bSGreg Roach	 * @return string
4776692c8bSGreg Roach	 */
4813abd6f3SGreg Roach	public function getBlock($block_id, $template = true, $cfg = []) {
494b9ff166SGreg Roach		global $ctype, $WT_TREE;
508c2e8227SGreg Roach
51e2a378d3SGreg Roach		$filter    = $this->getBlockSetting($block_id, 'filter', '1');
52e2a378d3SGreg Roach		$infoStyle = $this->getBlockSetting($block_id, 'infoStyle', 'table');
53e2a378d3SGreg Roach		$sortStyle = $this->getBlockSetting($block_id, 'sortStyle', 'alpha');
54e2a378d3SGreg Roach		$block     = $this->getBlockSetting($block_id, 'block', '1');
558c2e8227SGreg Roach
5613abd6f3SGreg Roach		foreach (['filter', 'infoStyle', 'sortStyle', 'block'] 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		$id    = $this->getName() . $block_id;
658c2e8227SGreg Roach		$class = $this->getName() . '_block';
664b9ff166SGreg Roach		if ($ctype === 'gedcom' && Auth::isManager($WT_TREE) || $ctype === 'user' && Auth::check()) {
676d1c8039SGreg Roach			$title = '<a class="icon-admin" title="' . I18N::translate('Preferences') . '" href="block_edit.php?block_id=' . $block_id . '&amp;ged=' . $WT_TREE->getNameHtml() . '&amp;ctype=' . $ctype . '"></a>';
688c2e8227SGreg Roach		} else {
698c2e8227SGreg Roach			$title = '';
708c2e8227SGreg Roach		}
718c2e8227SGreg Roach		$title .= $this->getTitle();
728c2e8227SGreg Roach
738c2e8227SGreg Roach		$content = '';
741b9bdb4fSGreg Roach
751b9bdb4fSGreg Roach		// If we are only showing living individuals, then we don't need to search for DEAT events.
761b9bdb4fSGreg Roach		$tags = $filter ? 'BIRT MARR' : 'BIRT MARR DEAT';
771b9bdb4fSGreg Roach
788c2e8227SGreg Roach		switch ($infoStyle) {
798c2e8227SGreg Roach		case 'list':
808c2e8227SGreg Roach			// Output style 1:  Old format, no visible tables, much smaller text. Better suited to right side of page.
811b9bdb4fSGreg Roach			$content .= FunctionsPrintLists::eventsList($todayjd, $todayjd, $tags, $filter, $sortStyle);
828c2e8227SGreg Roach			break;
838c2e8227SGreg Roach		case 'table':
848c2e8227SGreg Roach			// Style 2: New format, tables, big text, etc. Not too good on right side of page
858c2e8227SGreg Roach			ob_start();
861b9bdb4fSGreg Roach			$content .= FunctionsPrintLists::eventsTable($todayjd, $todayjd, $tags, $filter, $sortStyle);
878c2e8227SGreg Roach			$content .= ob_get_clean();
888c2e8227SGreg Roach			break;
898c2e8227SGreg Roach		}
908c2e8227SGreg Roach
918c2e8227SGreg Roach		if ($template) {
92*1e6d3848SGreg Roach			if ($block === '1') {
938c2e8227SGreg Roach				$class .= ' small_inner_block';
948c2e8227SGreg Roach			}
95cbc1590aSGreg Roach
968c2e8227SGreg Roach			return Theme::theme()->formatBlock($id, $title, $class, $content);
978c2e8227SGreg Roach		} else {
988c2e8227SGreg Roach			return $content;
998c2e8227SGreg Roach		}
1008c2e8227SGreg Roach	}
1018c2e8227SGreg Roach
1028c2e8227SGreg Roach	/** {@inheritdoc} */
1038c2e8227SGreg Roach	public function loadAjax() {
1048c2e8227SGreg Roach		return true;
1058c2e8227SGreg Roach	}
1068c2e8227SGreg Roach
1078c2e8227SGreg Roach	/** {@inheritdoc} */
1088c2e8227SGreg Roach	public function isUserBlock() {
1098c2e8227SGreg Roach		return true;
1108c2e8227SGreg Roach	}
1118c2e8227SGreg Roach
1128c2e8227SGreg Roach	/** {@inheritdoc} */
1138c2e8227SGreg Roach	public function isGedcomBlock() {
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
12176692c8bSGreg Roach	 */
1228c2e8227SGreg Roach	public function configureBlock($block_id) {
1238c2e8227SGreg Roach		if (Filter::postBool('save') && Filter::checkCsrf()) {
124e2a378d3SGreg Roach			$this->setBlockSetting($block_id, 'filter', Filter::postBool('filter'));
125e2a378d3SGreg Roach			$this->setBlockSetting($block_id, 'infoStyle', Filter::post('infoStyle', 'list|table', 'table'));
126e2a378d3SGreg Roach			$this->setBlockSetting($block_id, 'sortStyle', Filter::post('sortStyle', 'alpha|anniv', 'alpha'));
127e2a378d3SGreg Roach			$this->setBlockSetting($block_id, 'block', Filter::postBool('block'));
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');
133e2a378d3SGreg Roach		$block     = $this->getBlockSetting($block_id, 'block', '1');
1348c2e8227SGreg Roach
1358c2e8227SGreg Roach		echo '<tr><td class="descriptionbox wrap width33">';
136a4d5a9c2SGreg Roach		echo /* I18N: Label for a configuration option */ I18N::translate('Show only events of living individuals');
1378c2e8227SGreg Roach		echo '</td><td class="optionbox">';
1383d7a8a4cSGreg Roach		echo FunctionsEdit::editFieldYesNo('filter', $filter);
1398c2e8227SGreg Roach		echo '</td></tr>';
1408c2e8227SGreg Roach
1418c2e8227SGreg Roach		echo '<tr><td class="descriptionbox wrap width33">';
142a4d5a9c2SGreg Roach		echo /* I18N: Label for a configuration option */ I18N::translate('Presentation style');
1438c2e8227SGreg Roach		echo '</td><td class="optionbox">';
14413abd6f3SGreg Roach		echo FunctionsEdit::selectEditControl('infoStyle', ['list' => I18N::translate('list'), 'table' => I18N::translate('table')], null, $infoStyle, '');
1458c2e8227SGreg Roach		echo '</td></tr>';
1468c2e8227SGreg Roach
1478c2e8227SGreg Roach		echo '<tr><td class="descriptionbox wrap width33">';
148a4d5a9c2SGreg Roach		echo /* I18N: Label for a configuration option */ I18N::translate('Sort order');
1498c2e8227SGreg Roach		echo '</td><td class="optionbox">';
15013abd6f3SGreg Roach		echo FunctionsEdit::selectEditControl('sortStyle', [
1518c2e8227SGreg Roach			/* I18N: An option in a list-box */ 'alpha' => I18N::translate('sort by name'),
1528c2e8227SGreg Roach			/* I18N: An option in a list-box */ 'anniv' => I18N::translate('sort by date'),
15313abd6f3SGreg Roach		], null, $sortStyle, '');
1548c2e8227SGreg Roach		echo '</td></tr>';
1558c2e8227SGreg Roach
1568c2e8227SGreg Roach		echo '<tr><td class="descriptionbox wrap width33">';
1578c2e8227SGreg Roach		echo /* I18N: label for a yes/no option */ I18N::translate('Add a scrollbar when block contents grow');
1588c2e8227SGreg Roach		echo '</td><td class="optionbox">';
1593d7a8a4cSGreg Roach		echo FunctionsEdit::editFieldYesNo('block', $block);
1608c2e8227SGreg Roach		echo '</td></tr>';
1618c2e8227SGreg Roach	}
1628c2e8227SGreg Roach}
163