xref: /webtrees/app/Module/OnThisDayModule.php (revision 15d603e7c7c15d20f055d3d9c38d6b133453c5be)
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;
19*15d603e7SGreg Roachuse Fisharebest\Webtrees\Bootstrap4;
200e62c4b8SGreg Roachuse Fisharebest\Webtrees\Filter;
21*15d603e7SGreg Roachuse Fisharebest\Webtrees\FontAwesome;
223d7a8a4cSGreg Roachuse Fisharebest\Webtrees\Functions\FunctionsEdit;
233d7a8a4cSGreg Roachuse Fisharebest\Webtrees\Functions\FunctionsPrintLists;
240e62c4b8SGreg Roachuse Fisharebest\Webtrees\I18N;
250e62c4b8SGreg Roachuse Fisharebest\Webtrees\Theme;
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	 */
5013abd6f3SGreg Roach	public function getBlock($block_id, $template = true, $cfg = []) {
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
57*15d603e7SGreg 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		$id    = $this->getName() . $block_id;
668c2e8227SGreg Roach		$class = $this->getName() . '_block';
674b9ff166SGreg Roach		if ($ctype === 'gedcom' && Auth::isManager($WT_TREE) || $ctype === 'user' && Auth::check()) {
68*15d603e7SGreg Roach			$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]) . ' ';
698c2e8227SGreg Roach		} else {
708c2e8227SGreg Roach			$title = '';
718c2e8227SGreg Roach		}
728c2e8227SGreg Roach		$title .= $this->getTitle();
738c2e8227SGreg Roach
748c2e8227SGreg Roach		$content = '';
751b9bdb4fSGreg Roach
761b9bdb4fSGreg Roach		// If we are only showing living individuals, then we don't need to search for DEAT events.
771b9bdb4fSGreg Roach		$tags = $filter ? 'BIRT MARR' : 'BIRT MARR DEAT';
781b9bdb4fSGreg Roach
798c2e8227SGreg Roach		switch ($infoStyle) {
808c2e8227SGreg Roach		case 'list':
818c2e8227SGreg Roach			// Output style 1:  Old format, no visible tables, much smaller text. Better suited to right side of page.
821b9bdb4fSGreg Roach			$content .= FunctionsPrintLists::eventsList($todayjd, $todayjd, $tags, $filter, $sortStyle);
838c2e8227SGreg Roach			break;
848c2e8227SGreg Roach		case 'table':
858c2e8227SGreg Roach			// Style 2: New format, tables, big text, etc. Not too good on right side of page
868c2e8227SGreg Roach			ob_start();
871b9bdb4fSGreg Roach			$content .= FunctionsPrintLists::eventsTable($todayjd, $todayjd, $tags, $filter, $sortStyle);
888c2e8227SGreg Roach			$content .= ob_get_clean();
898c2e8227SGreg Roach			break;
908c2e8227SGreg Roach		}
918c2e8227SGreg Roach
928c2e8227SGreg Roach		if ($template) {
938c2e8227SGreg Roach			return Theme::theme()->formatBlock($id, $title, $class, $content);
948c2e8227SGreg Roach		} else {
958c2e8227SGreg Roach			return $content;
968c2e8227SGreg Roach		}
978c2e8227SGreg Roach	}
988c2e8227SGreg Roach
998c2e8227SGreg Roach	/** {@inheritdoc} */
1008c2e8227SGreg Roach	public function loadAjax() {
1018c2e8227SGreg Roach		return true;
1028c2e8227SGreg Roach	}
1038c2e8227SGreg Roach
1048c2e8227SGreg Roach	/** {@inheritdoc} */
1058c2e8227SGreg Roach	public function isUserBlock() {
1068c2e8227SGreg Roach		return true;
1078c2e8227SGreg Roach	}
1088c2e8227SGreg Roach
1098c2e8227SGreg Roach	/** {@inheritdoc} */
1108c2e8227SGreg Roach	public function isGedcomBlock() {
1118c2e8227SGreg Roach		return true;
1128c2e8227SGreg Roach	}
1138c2e8227SGreg Roach
11476692c8bSGreg Roach	/**
11576692c8bSGreg Roach	 * An HTML form to edit block settings
11676692c8bSGreg Roach	 *
11776692c8bSGreg Roach	 * @param int $block_id
11876692c8bSGreg Roach	 */
1198c2e8227SGreg Roach	public function configureBlock($block_id) {
1208c2e8227SGreg Roach		if (Filter::postBool('save') && Filter::checkCsrf()) {
121e2a378d3SGreg Roach			$this->setBlockSetting($block_id, 'filter', Filter::postBool('filter'));
122e2a378d3SGreg Roach			$this->setBlockSetting($block_id, 'infoStyle', Filter::post('infoStyle', 'list|table', 'table'));
123e2a378d3SGreg Roach			$this->setBlockSetting($block_id, 'sortStyle', Filter::post('sortStyle', 'alpha|anniv', 'alpha'));
1248c2e8227SGreg Roach		}
1258c2e8227SGreg Roach
126e2a378d3SGreg Roach		$filter    = $this->getBlockSetting($block_id, 'filter', '1');
127e2a378d3SGreg Roach		$infoStyle = $this->getBlockSetting($block_id, 'infoStyle', 'table');
128e2a378d3SGreg Roach		$sortStyle = $this->getBlockSetting($block_id, 'sortStyle', 'alpha');
1298c2e8227SGreg Roach
130*15d603e7SGreg Roach		?>
131*15d603e7SGreg Roach		<div class="form-group row">
132*15d603e7SGreg Roach			<label class="col-sm-3 col-form-label" for="filter">
133*15d603e7SGreg Roach				<?= /* I18N: Label for a configuration option */ I18N::translate('Show only events of living individuals') ?>
134*15d603e7SGreg Roach			</label>
135*15d603e7SGreg Roach			<div class="col-sm-9">
136*15d603e7SGreg Roach				<?= Bootstrap4::radioButtons('filter', FunctionsEdit::optionsNoYes(), $filter, true) ?>
137*15d603e7SGreg Roach			</div>
138*15d603e7SGreg Roach		</div>
1398c2e8227SGreg Roach
140*15d603e7SGreg Roach		<div class="form-group row">
141*15d603e7SGreg Roach			<label class="col-sm-3 col-form-label" for="infoStyle">
142*15d603e7SGreg Roach				<?= /* I18N: Label for a configuration option */ I18N::translate('Presentation style') ?>
143*15d603e7SGreg Roach			</label>
144*15d603e7SGreg Roach			<div class="col-sm-9">
145*15d603e7SGreg Roach				<?= Bootstrap4::select(['list' => I18N::translate('list'), 'table' => I18N::translate('table')], $infoStyle, ['id' => 'infoStyle', 'name' => 'infoStyle']) ?>
146*15d603e7SGreg Roach			</div>
147*15d603e7SGreg Roach		</div>
1488c2e8227SGreg Roach
149*15d603e7SGreg Roach		<div class="form-group row">
150*15d603e7SGreg Roach			<label class="col-sm-3 col-form-label" for="sortStyle">
151*15d603e7SGreg Roach				<?= /* I18N: Label for a configuration option */ I18N::translate('Sort order') ?>
152*15d603e7SGreg Roach			</label>
153*15d603e7SGreg Roach			<div class="col-sm-9">
154*15d603e7SGreg 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']) ?>
155*15d603e7SGreg Roach			</div>
156*15d603e7SGreg Roach		</div>
157*15d603e7SGreg Roach		<?php
1588c2e8227SGreg Roach	}
1598c2e8227SGreg Roach}
160