. */ namespace Fisharebest\Webtrees\Module; use Fisharebest\Webtrees\Auth; use Fisharebest\Webtrees\Bootstrap4; use Fisharebest\Webtrees\Database; use Fisharebest\Webtrees\Filter; use Fisharebest\Webtrees\FontAwesome; use Fisharebest\Webtrees\Functions\FunctionsEdit; use Fisharebest\Webtrees\GedcomRecord; use Fisharebest\Webtrees\GedcomTag; use Fisharebest\Webtrees\Html; use Fisharebest\Webtrees\I18N; use Fisharebest\Webtrees\Individual; use Fisharebest\Webtrees\Tree; use Fisharebest\Webtrees\View; use Ramsey\Uuid\Uuid; /** * Class RecentChangesModule */ class RecentChangesModule extends AbstractModule implements ModuleBlockInterface { const DEFAULT_BLOCK = '1'; const DEFAULT_DAYS = 7; const DEFAULT_HIDE_EMPTY = '0'; const DEFAULT_SHOW_USER = '1'; const DEFAULT_SORT_STYLE = 'date_desc'; const DEFAULT_INFO_STYLE = 'table'; const MAX_DAYS = 90; /** {@inheritdoc} */ public function getTitle() { return /* I18N: Name of a module */ I18N::translate('Recent changes'); } /** {@inheritdoc} */ public function getDescription() { return /* I18N: Description of the “Recent changes” module */ I18N::translate('A list of records that have been updated recently.'); } /** {@inheritdoc} */ public function getBlock($block_id, $template = true, $cfg = []): string { global $ctype, $WT_TREE; $days = $this->getBlockSetting($block_id, 'days', self::DEFAULT_DAYS); $infoStyle = $this->getBlockSetting($block_id, 'infoStyle', self::DEFAULT_INFO_STYLE); $sortStyle = $this->getBlockSetting($block_id, 'sortStyle', self::DEFAULT_SORT_STYLE); $show_user = $this->getBlockSetting($block_id, 'show_user', self::DEFAULT_SHOW_USER); foreach (['days', 'infoStyle', 'sortStyle', 'show_user'] as $name) { if (array_key_exists($name, $cfg)) { $$name = $cfg[$name]; } } $records = $this->getRecentChanges($WT_TREE, $days); $content = ''; // Print block content if (empty($records)) { $content .= I18N::plural('There have been no changes within the last %s day.', 'There have been no changes within the last %s days.', $days, I18N::number($days)); } else { switch ($infoStyle) { case 'list': $content .= $this->changesList($records, $sortStyle, $show_user); break; case 'table': $content .= $this->changesTable($records, $sortStyle, $show_user); break; } } if ($template) { if ($ctype === 'gedcom' && Auth::isManager($WT_TREE) || $ctype === 'user' && Auth::check()) { $config_url = Html::url('block_edit.php', ['block_id' => $block_id, 'ged' => $WT_TREE->getName()]); } else { $config_url = ''; } return View::make('blocks/template', [ 'block' => str_replace('_', '-', $this->getName()), 'id' => $block_id, 'config_url' => $config_url, 'title' => I18N::plural('Changes in the last %s day', 'Changes in the last %s days', $days, I18N::number($days)), 'content' => $content, ]); } else { return $content; } } /** {@inheritdoc} */ public function loadAjax(): bool { return true; } /** {@inheritdoc} */ public function isUserBlock(): bool { return true; } /** {@inheritdoc} */ public function isGedcomBlock(): bool { return true; } /** {@inheritdoc} */ public function configureBlock($block_id) { if (Filter::postBool('save') && Filter::checkCsrf()) { $this->setBlockSetting($block_id, 'days', Filter::postInteger('days', 1, self::MAX_DAYS)); $this->setBlockSetting($block_id, 'infoStyle', Filter::post('infoStyle', 'list|table')); $this->setBlockSetting($block_id, 'sortStyle', Filter::post('sortStyle', 'name|date_asc|date_desc')); $this->setBlockSetting($block_id, 'show_user', Filter::postBool('show_user')); } $days = $this->getBlockSetting($block_id, 'days', self::DEFAULT_DAYS); $infoStyle = $this->getBlockSetting($block_id, 'infoStyle', self::DEFAULT_INFO_STYLE); $sortStyle = $this->getBlockSetting($block_id, 'sortStyle', self::DEFAULT_SORT_STYLE); $show_user = $this->getBlockSetting($block_id, 'show_user', self::DEFAULT_SHOW_USER); echo '
'; $html .= ' | ' . I18N::translate('Record') . ' | '; $html .= '' . I18N::translate('Last change') . ' | '; $html .= '' . GedcomTag::getLabel('_WT_USER') . ' | '; $html .= '
---|---|---|---|
'; switch ($record::RECORD_TYPE) { case 'INDI': $html .= FontAwesome::semanticIcon('individual', I18N::translate('Individual')); break; case 'FAM': $html .= FontAwesome::semanticicon('family', I18N::translate('Family')); break; case 'OBJE': $html .= FontAwesome::semanticIcon('media', I18N::translate('Media')); break; case 'NOTE': $html .= FontAwesome::semanticIcon('note', I18N::translate('Note')); break; case 'SOUR': $html .= FontAwesome::semanticIcon('source', I18N::translate('Source')); break; case 'SUBM': $html .= FontAwesome::semanticIcon('submitter', I18N::translate('Submitter')); break; case 'REPO': $html .= FontAwesome::semanticIcon('repository', I18N::translate('Repository')); break; } $html .= ' | '; $html .= ''; $html .= '' . $record->getFullName() . ''; $addname = $record->getAddName(); if ($addname) { $html .= ''; } $html .= ' | '; $html .= '' . $record->lastChangeTimestamp() . ' | '; $html .= '' . Html::escape($record->lastChangeUser()) . ' | '; $html .= '