.
*/
/**
* 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 {
/** {@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;
}
/** {@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);
}
';
}
/** {@inheritdoc} */
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;
}
}
/**
* @return string
*/
public function css() {
return WT_STATIC_URL . WT_MODULES_DIR . $this->getName() . '/css/treeview.css';
}
/**
* @return string
*/
public function js() {
return WT_STATIC_URL . WT_MODULES_DIR . $this->getName() . '/js/treeview.js';
}
}