xref: /webtrees/app/Module/OnThisDayModule.php (revision 0e62c4b8d0ec6901bfaffd1dc763db37489518a4)
1<?php
2namespace Fisharebest\Webtrees\Module;
3
4/**
5 * webtrees: online genealogy
6 * Copyright (C) 2015 webtrees development team
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18use Fisharebest\Webtrees\Auth;
19use Fisharebest\Webtrees\Filter;
20use Fisharebest\Webtrees\I18N;
21use Fisharebest\Webtrees\Theme;
22
23/**
24 * Class OnThisDayModule
25 */
26class OnThisDayModule extends AbstractModule implements ModuleBlockInterface {
27	/** {@inheritdoc} */
28	public function getTitle() {
29		return /* I18N: Name of a module */ I18N::translate('On this day');
30	}
31
32	/** {@inheritdoc} */
33	public function getDescription() {
34		return /* I18N: Description of the “On this day” module */ I18N::translate('A list of the anniversaries that occur today.');
35	}
36
37	/** {@inheritdoc} */
38	public function getBlock($block_id, $template = true, $cfg = null) {
39		global $ctype, $WT_TREE;
40
41		$filter    = $this->getBlockSetting($block_id, 'filter', '1');
42		$onlyBDM   = $this->getBlockSetting($block_id, 'onlyBDM', '1');
43		$infoStyle = $this->getBlockSetting($block_id, 'infoStyle', 'table');
44		$sortStyle = $this->getBlockSetting($block_id, 'sortStyle', 'alpha');
45		$block     = $this->getBlockSetting($block_id, 'block', '1');
46
47		if ($cfg) {
48			foreach (array('filter', 'onlyBDM', 'infoStyle', 'sortStyle', 'block') as $name) {
49				if (array_key_exists($name, $cfg)) {
50					$$name = $cfg[$name];
51				}
52			}
53		}
54
55		$todayjd = WT_CLIENT_JD;
56
57		$id    = $this->getName() . $block_id;
58		$class = $this->getName() . '_block';
59		if ($ctype === 'gedcom' && Auth::isManager($WT_TREE) || $ctype === 'user' && Auth::check()) {
60			$title = '<a class="icon-admin" title="' . I18N::translate('Configure') . '" href="block_edit.php?block_id=' . $block_id . '&amp;ged=' . $WT_TREE->getNameHtml() . '&amp;ctype=' . $ctype . '"></a>';
61		} else {
62			$title = '';
63		}
64		$title .= $this->getTitle();
65
66		$content = '';
67		switch ($infoStyle) {
68		case 'list':
69			// Output style 1:  Old format, no visible tables, much smaller text.  Better suited to right side of page.
70			$content .= print_events_list($todayjd, $todayjd, $onlyBDM ? 'BIRT MARR DEAT' : '', $filter, $sortStyle);
71			break;
72		case 'table':
73			// Style 2: New format, tables, big text, etc.  Not too good on right side of page
74			ob_start();
75			$content .= print_events_table($todayjd, $todayjd, $onlyBDM ? 'BIRT MARR DEAT' : '', $filter, $sortStyle);
76			$content .= ob_get_clean();
77			break;
78		}
79
80		if ($template) {
81			if ($block) {
82				$class .= ' small_inner_block';
83			}
84
85			return Theme::theme()->formatBlock($id, $title, $class, $content);
86		} else {
87			return $content;
88		}
89	}
90
91	/** {@inheritdoc} */
92	public function loadAjax() {
93		return true;
94	}
95
96	/** {@inheritdoc} */
97	public function isUserBlock() {
98		return true;
99	}
100
101	/** {@inheritdoc} */
102	public function isGedcomBlock() {
103		return true;
104	}
105
106	/** {@inheritdoc} */
107	public function configureBlock($block_id) {
108		if (Filter::postBool('save') && Filter::checkCsrf()) {
109			$this->setBlockSetting($block_id, 'filter', Filter::postBool('filter'));
110			$this->setBlockSetting($block_id, 'onlyBDM', Filter::postBool('onlyBDM'));
111			$this->setBlockSetting($block_id, 'infoStyle', Filter::post('infoStyle', 'list|table', 'table'));
112			$this->setBlockSetting($block_id, 'sortStyle', Filter::post('sortStyle', 'alpha|anniv', 'alpha'));
113			$this->setBlockSetting($block_id, 'block', Filter::postBool('block'));
114		}
115
116		$filter    = $this->getBlockSetting($block_id, 'filter', '1');
117		$onlyBDM   = $this->getBlockSetting($block_id, 'onlyBDM', '1');
118		$infoStyle = $this->getBlockSetting($block_id, 'infoStyle', 'table');
119		$sortStyle = $this->getBlockSetting($block_id, 'sortStyle', 'alpha');
120		$block     = $this->getBlockSetting($block_id, 'block', '1');
121
122		echo '<tr><td class="descriptionbox wrap width33">';
123		echo I18N::translate('Show only events of living individuals?');
124		echo '</td><td class="optionbox">';
125		echo edit_field_yes_no('filter', $filter);
126		echo '</td></tr>';
127
128		echo '<tr><td class="descriptionbox wrap width33">';
129		echo I18N::translate('Show only births, deaths, and marriages?');
130		echo '</td><td class="optionbox">';
131		echo edit_field_yes_no('onlyBDM', $onlyBDM);
132		echo '</td></tr>';
133
134		echo '<tr><td class="descriptionbox wrap width33">';
135		echo I18N::translate('Presentation style');
136		echo '</td><td class="optionbox">';
137		echo select_edit_control('infoStyle', array('list' => I18N::translate('list'), 'table' => I18N::translate('table')), null, $infoStyle, '');
138		echo '</td></tr>';
139
140		echo '<tr><td class="descriptionbox wrap width33">';
141		echo I18N::translate('Sort order');
142		echo '</td><td class="optionbox">';
143		echo select_edit_control('sortStyle', array(
144			/* I18N: An option in a list-box */ 'alpha' => I18N::translate('sort by name'),
145			/* I18N: An option in a list-box */ 'anniv' => I18N::translate('sort by date'),
146		), null, $sortStyle, '');
147		echo '</td></tr>';
148
149		echo '<tr><td class="descriptionbox wrap width33">';
150		echo /* I18N: label for a yes/no option */ I18N::translate('Add a scrollbar when block contents grow');
151		echo '</td><td class="optionbox">';
152		echo edit_field_yes_no('block', $block);
153		echo '</td></tr>';
154	}
155}
156