. */ namespace Fisharebest\Webtrees\Module; use Fisharebest\Webtrees\Auth; use Fisharebest\Webtrees\Controller\ChartController; use Fisharebest\Webtrees\Filter; use Fisharebest\Webtrees\I18N; use Fisharebest\Webtrees\Individual; use Fisharebest\Webtrees\Menu; use Fisharebest\Webtrees\Module\InteractiveTree\TreeView; /** * Class InteractiveTreeModule * Tip : you could change the number of generations loaded before ajax calls both in individual page and in treeview page to optimize speed and server load */ class InteractiveTreeModule extends AbstractModule implements ModuleTabInterface, ModuleChartInterface { /** {@inheritdoc} */ public function getTitle() { return /* I18N: Name of a module */ I18N::translate('Interactive tree'); } /** {@inheritdoc} */ public function getDescription() { return /* I18N: Description of the “Interactive tree” module */ I18N::translate('An interactive tree, showing all the ancestors and descendants of an individual.'); } /** {@inheritdoc} */ public function defaultTabOrder() { return 68; } /** {@inheritdoc} */ public function getTabContent() { global $controller; $tv = new TreeView('tvTab'); list($html, $js) = $tv->drawViewport($controller->record, 3); return '' . '' . '' . $html; } /** {@inheritdoc} */ public function hasTabContent() { return !Auth::isSearchEngine(); } /** {@inheritdoc} */ public function isGrayedOut() { return false; } /** {@inheritdoc} */ public function canLoadAjax() { return true; } /** * Return a menu item for this chart. * * @return Menu|null */ public function getChartMenu(Individual $individual) { return new Menu( $this->getTitle(), 'module.php?mod=tree&mod_action=treeview&rootid=' . $individual->getXref() . '&ged=' . $individual->getTree()->getNameUrl(), 'menu-chart-tree', array('rel' => 'nofollow') ); } /** * Return a menu item for this chart - for use in individual boxes. * * @return Menu|null */ public function getBoxChartMenu(Individual $individual) { return $this->getChartMenu($individual); } /** {@inheritdoc} */ public function getPreLoadContent() { // We cannot use jQuery("head").append( if (document.createStyleSheet) { document.createStyleSheet("' . $this->css() . '"); // For Internet Explorer } else { var newSheet=document.createElement("link"); newSheet.setAttribute("rel","stylesheet"); newSheet.setAttribute("type","text/css"); newSheet.setAttribute("href","' . $this->css() . '"); document.getElementsByTagName("head")[0].appendChild(newSheet); } '; } /** * 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) { global $controller, $WT_TREE; switch ($mod_action) { case 'treeview': $controller = new ChartController; $tv = new TreeView('tv'); ob_start(); $person = $controller->getSignificantIndividual(); list($html, $js) = $tv->drawViewport($person, 4); $controller ->setPageTitle(I18N::translate('Interactive tree of %s', $person->getFullName())) ->pageHeader() ->addExternalJavascript($this->js()) ->addExternalJavascript(WT_JQUERYUI_TOUCH_PUNCH_URL) ->addInlineJavascript($js) ->addInlineJavascript(' if (document.createStyleSheet) { document.createStyleSheet("' . $this->css() . '"); // For Internet Explorer } else { jQuery("head").append(\'\'); } '); echo $html; break; case 'getDetails': header('Content-Type: text/html; charset=UTF-8'); $pid = Filter::get('pid', WT_REGEX_XREF); $i = Filter::get('instance'); $tv = new TreeView($i); $individual = Individual::getInstance($pid, $WT_TREE); if ($individual) { echo $tv->getDetails($individual); } break; case 'getPersons': header('Content-Type: text/html; charset=UTF-8'); $q = Filter::get('q'); $i = Filter::get('instance'); $tv = new TreeView($i); echo $tv->getPersons($q); break; default: http_response_code(404); break; } } /** * URL for our style sheet. * * @return string */ public function css() { return WT_STATIC_URL . WT_MODULES_DIR . $this->getName() . '/css/treeview.css'; } /** * URL for our JavaScript. * * @return string */ public function js() { return WT_STATIC_URL . WT_MODULES_DIR . $this->getName() . '/js/treeview.js'; } }