. */ namespace Fisharebest\Webtrees\Module; use Fisharebest\Webtrees\Auth; use Fisharebest\Webtrees\Database; use Fisharebest\Webtrees\Filter; use Fisharebest\Webtrees\FlashMessages; use Fisharebest\Webtrees\Functions\FunctionsEdit; use Fisharebest\Webtrees\Functions\FunctionsPrint; use Fisharebest\Webtrees\GedcomRecord; use Fisharebest\Webtrees\GedcomTag; use Fisharebest\Webtrees\I18N; use Fisharebest\Webtrees\Individual; use Fisharebest\Webtrees\Theme; use PDO; use PDOException; use Rhumsaa\Uuid\Uuid; /** * Class FamilyTreeFavoritesModule * * Note that the user favorites module simply extends this module, so ensure that the * logic works for both. */ class FamilyTreeFavoritesModule extends AbstractModule implements ModuleBlockInterface { // How to update the database schema for this module const SCHEMA_TARGET_VERSION = 4; const SCHEMA_SETTING_NAME = 'FV_SCHEMA_VERSION'; const SCHEMA_MIGRATION_PREFIX = '\Fisharebest\Webtrees\Module\FamilyTreeFavorites\Schema'; /** * Create a new module. * * @param string $directory Where is this module installed */ public function __construct($directory) { parent::__construct($directory); // Create/update the database tables. // NOTE: if we want to set any module-settings, we'll need to move this. Database::updateSchema(self::SCHEMA_MIGRATION_PREFIX, self::SCHEMA_SETTING_NAME, self::SCHEMA_TARGET_VERSION); } /** * How should this module be labelled on tabs, menus, etc.? * * @return string */ public function getTitle() { return /* I18N: Name of a module */ I18N::translate('Favorites'); } /** * A sentence describing what this module does. * * @return string */ public function getDescription() { return /* I18N: Description of the “Favorites” module */ I18N::translate('Display and manage a family tree’s favorite pages.'); } /** * Generate the HTML content of this block. * * @param int $block_id * @param bool $template * @param string[] $cfg * * @return string */ public function getBlock($block_id, $template = true, $cfg = array()) { global $ctype, $controller, $WT_TREE; $action = Filter::get('action'); switch ($action) { case 'deletefav': $favorite_id = Filter::getInteger('favorite_id'); if ($favorite_id) { self::deleteFavorite($favorite_id); } break; case 'addfav': $gid = Filter::get('gid', WT_REGEX_XREF); $favnote = Filter::get('favnote'); $url = Filter::getUrl('url'); $favtitle = Filter::get('favtitle'); if ($gid) { $record = GedcomRecord::getInstance($gid, $WT_TREE); if ($record && $record->canShow()) { self::addFavorite(array( 'user_id' => $ctype === 'user' ? Auth::id() : null, 'gedcom_id' => $WT_TREE->getTreeId(), 'gid' => $record->getXref(), 'type' => $record::RECORD_TYPE, 'url' => null, 'note' => $favnote, 'title' => $favtitle, )); } } elseif ($url) { self::addFavorite(array( 'user_id' => $ctype === 'user' ? Auth::id() : null, 'gedcom_id' => $WT_TREE->getTreeId(), 'gid' => null, 'type' => 'URL', 'url' => $url, 'note' => $favnote, 'title' => $favtitle ? $favtitle : $url, )); } break; } $block = $this->getBlockSetting($block_id, 'block', '0'); foreach (array('block') as $name) { if (array_key_exists($name, $cfg)) { $$name = $cfg[$name]; } } $userfavs = $this->getFavorites($ctype === 'user' ? Auth::id() : $WT_TREE->getTreeId()); if (!is_array($userfavs)) { $userfavs = array(); } $id = $this->getName() . $block_id; $class = $this->getName() . '_block'; $title = $this->getTitle(); if (Auth::check()) { $controller ->addExternalJavascript(WT_AUTOCOMPLETE_JS_URL) ->addInlineJavascript('autocomplete();'); } $content = ''; if ($userfavs) { foreach ($userfavs as $key => $favorite) { if (isset($favorite['id'])) { $key = $favorite['id']; } $removeFavourite = '' . I18N::translate('Remove') . ' '; if ($favorite['type'] == 'URL') { $content .= '