. */ namespace Fisharebest\Webtrees\Module; use Fisharebest\Webtrees\Auth; use Fisharebest\Webtrees\Database; use Fisharebest\Webtrees\Filter; use Fisharebest\Webtrees\I18N; use Fisharebest\Webtrees\Individual; use Fisharebest\Webtrees\Query\QueryName; use Fisharebest\Webtrees\Theme; use Fisharebest\Webtrees\Tree; /** * Class IndividualSidebarModule */ class IndividualSidebarModule extends AbstractModule implements ModuleSidebarInterface { /** {@inheritdoc} */ public function getTitle() { return /* I18N: Name of a module */ I18N::translate('Individual list'); } /** {@inheritdoc} */ public function getDescription() { return /* I18N: Description of “Individuals” module */ I18N::translate('A sidebar showing an alphabetic list of all the individuals in the family tree.'); } /** * This is a general purpose hook, allowing modules to respond to routes * of the form module.php?mod=FOO&mod_action=BAR * * @param string $mod_action */ public function modAction($mod_action) { switch ($mod_action) { case 'ajax': header('Content-Type: text/html; charset=UTF-8'); echo $this->getSidebarAjaxContent(); break; default: http_response_code(404); break; } } /** {@inheritdoc} */ public function defaultSidebarOrder() { return 40; } /** {@inheritdoc} */ public function hasSidebarContent() { return !Auth::isSearchEngine(); } /** {@inheritdoc} */ public function getSidebarAjaxContent() { global $WT_TREE; $alpha = Filter::get('alpha'); // All surnames beginning with this letter where "@"=unknown and ","=none $surname = Filter::get('surname'); // All indis with this surname. $search = Filter::get('search'); if ($search) { return $this->search($WT_TREE, $search); } elseif ($alpha == '@' || $alpha == ',' || $surname) { return $this->getSurnameIndis($WT_TREE, $alpha, $surname); } elseif ($alpha) { return $this->getAlphaSurnames($WT_TREE, $alpha); } else { return ''; } } /** * Load this sidebar synchronously. * * @return string */ public function getSidebarContent() { global $controller, $WT_TREE; // Fetch a list of the initial letters of all surnames in the database $initials = QueryName::surnameAlpha($WT_TREE, true, false, false); $controller->addInlineJavascript(' var loadedNames = new Array(); function isearchQ() { var query = jQuery("#sb_indi_name").val(); if (query.length>1) { jQuery("#sb_indi_content").load("module.php?mod=' . $this->getName() . '&mod_action=ajax&search="+query); } } var timerid = null; jQuery("#sb_indi_name").keyup(function(e) { if (timerid) window.clearTimeout(timerid); timerid = window.setTimeout("isearchQ()", 500); }); jQuery("#sb_content_individuals").on("click", ".sb_indi_letter", function() { jQuery("#sb_indi_content").load(this.href); return false; }); jQuery("#sb_content_individuals").on("click", ".sb_indi_surname", function() { var element = jQuery(this); var surname = element.data("surname"); var alpha = element.data("alpha"); if (!loadedNames[surname]) { jQuery.ajax({ url: "module.php?mod=' . $this->getName() . '&mod_action=ajax&alpha=" + encodeURIComponent(alpha) + "&surname=" + encodeURIComponent(surname), cache: false, success: function(html) { jQuery("div.name_tree_div", element.closest("li")) .html(html) .show("fast") .css("list-style-image", "url(' . Theme::theme()->parameter('image-minus') . ')"); loadedNames[surname]=2; } }); } else if (loadedNames[surname]==1) { loadedNames[surname]=2; jQuery("div.name_tree_div", jQuery(this).closest("li")) .show() .css("list-style-image", "url(' . Theme::theme()->parameter('image-minus') . ')"); } else { loadedNames[surname]=1; jQuery("div.name_tree_div", jQuery(this).closest("li")) .hide("fast") .css("list-style-image", "url(' . Theme::theme()->parameter('image-plus') . ')"); } return false; }); '); $out = '
'; return $out; } /** * Get the initial letters of surnames. * * @param Tree $tree * @param string $alpha * * @return string */ private function getAlphaSurnames(Tree $tree, $alpha) { $surnames = QueryName::surnames($tree, '', $alpha, true, false); $out = '