.
*/
/**
* Class StoriesModule
*/
class StoriesModule extends AbstractModule implements ModuleTabInterface, ModuleConfigInterface, ModuleMenuInterface {
/** {@inheritdoc} */
public function getTitle() {
return /* I18N: Name of a module */ I18N::translate('Stories');
}
/** {@inheritdoc} */
public function getDescription() {
return /* I18N: Description of the “Stories” module */ I18N::translate('Add narrative stories to individuals in the family tree.');
}
/** {@inheritdoc} */
public function modAction($mod_action) {
switch ($mod_action) {
case 'admin_edit':
$this->edit();
break;
case 'admin_delete':
$this->delete();
$this->config();
break;
case 'admin_config':
$this->config();
break;
case 'show_list':
$this->showList();
break;
default:
http_response_code(404);
}
}
/** {@inheritdoc} */
public function getConfigLink() {
return 'module.php?mod=' . $this->getName() . '&mod_action=admin_config';
}
/** {@inheritdoc} */
public function defaultTabOrder() {
return 55;
}
/** {@inheritdoc} */
public function getTabContent() {
global $controller, $WT_TREE;
$block_ids =
Database::prepare(
"SELECT block_id" .
" FROM `##block`" .
" WHERE module_name=?" .
" AND xref=?" .
" AND gedcom_id=?"
)->execute(array(
$this->getName(),
$controller->record->getXref(),
$controller->record->getTree()->getTreeId()
))->fetchOneColumn();
$html = '';
foreach ($block_ids as $block_id) {
// Only show this block for certain languages
$languages = $this->getBlockSetting($block_id, 'languages');
if (!$languages || in_array(WT_LOCALE, explode(',', $languages))) {
$html .= '
' . $this->getBlockSetting($block_id, 'title') . '
';
$html .= '' . $this->getBlockSetting($block_id, 'story_body') . '
';
if (Auth::isEditor($WT_TREE)) {
$html .= '';
}
}
}
if (Auth::isManager($WT_TREE) && !$html) {
$html .= '' . $this->getTitle() . '
';
$html .= ' ';
}
return $html;
}
/** {@inheritdoc} */
public function hasTabContent() {
return $this->getTabContent() <> '';
}
/** {@inheritdoc} */
public function isGrayedOut() {
global $controller;
$count_of_stories =
Database::prepare(
"SELECT COUNT(block_id)" .
" FROM `##block`" .
" WHERE module_name=?" .
" AND xref=?" .
" AND gedcom_id=?"
)->execute(array(
$this->getName(),
$controller->record->getXref(),
$controller->record->getTree()->getTreeId()
))->fetchOne();
return $count_of_stories == 0;
}
/** {@inheritdoc} */
public function canLoadAjax() {
return false;
}
/** {@inheritdoc} */
public function getPreLoadContent() {
return '';
}
/**
* Show and process a form to edit a story.
*/
private function edit() {
global $WT_TREE;
if (Auth::isEditor($WT_TREE)) {
if (Filter::postBool('save') && Filter::checkCsrf()) {
$block_id = Filter::postInteger('block_id');
if ($block_id) {
Database::prepare(
"UPDATE `##block` SET gedcom_id=?, xref=? WHERE block_id=?"
)->execute(array(Filter::postInteger('gedcom_id'), Filter::post('xref', WT_REGEX_XREF), $block_id));
} else {
Database::prepare(
"INSERT INTO `##block` (gedcom_id, xref, module_name, block_order) VALUES (?, ?, ?, ?)"
)->execute(array(
Filter::postInteger('gedcom_id'),
Filter::post('xref', WT_REGEX_XREF),
$this->getName(),
0
));
$block_id = Database::getInstance()->lastInsertId();
}
$this->setBlockSetting($block_id, 'title', Filter::post('title'));
$this->setBlockSetting($block_id, 'story_body', Filter::post('story_body'));
$languages = Filter::postArray('lang');
$this->setBlockSetting($block_id, 'languages', implode(',', $languages));
$this->config();
} else {
$block_id = Filter::getInteger('block_id');
$controller = new PageController;
if ($block_id) {
$controller->setPageTitle(I18N::translate('Edit story'));
$title = $this->getBlockSetting($block_id, 'title');
$story_body = $this->getBlockSetting($block_id, 'story_body');
$xref = Database::prepare(
"SELECT xref FROM `##block` WHERE block_id=?"
)->execute(array($block_id))->fetchOne();
} else {
$controller->setPageTitle(I18N::translate('Add a story'));
$title = '';
$story_body = '';
$xref = Filter::get('xref', WT_REGEX_XREF);
}
$controller
->pageHeader()
->addExternalJavascript(WT_AUTOCOMPLETE_JS_URL)
->addInlineJavascript('autocomplete();');
if (Module::getModuleByName('ckeditor')) {
CkeditorModule::enableEditor($controller);
}
$individual = Individual::getInstance($xref, $WT_TREE);
?>
getTitle(); ?>
getPageTitle(); ?>
getPageTitle(); ?>
execute(array($block_id));
Database::prepare(
"DELETE FROM `##block` WHERE block_id=?"
)->execute(array($block_id));
} else {
header('Location: ' . WT_BASE_URL);
exit;
}
}
/**
* The admin view - list, create, edit, delete stories.
*/
private function config() {
global $WT_TREE;
$controller = new PageController;
$controller
->restrictAccess(Auth::isAdmin())
->setPageTitle($this->getTitle())
->pageHeader()
->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL)
->addExternalJavascript(WT_DATATABLES_BOOTSTRAP_JS_URL)
->addInlineJavascript('
jQuery("#story_table").dataTable({
' . I18N::datatablesI18N() . ',
autoWidth: false,
paging: true,
pagingType: "full_numbers",
lengthChange: true,
filter: true,
info: true,
sorting: [[0,"asc"]],
columns: [
/* 0-name */ null,
/* 1-NAME */ null,
/* 2-NAME */ { sortable:false },
/* 3-NAME */ { sortable:false }
]
});
');
$stories = Database::prepare(
"SELECT block_id, xref" .
" FROM `##block` b" .
" WHERE module_name=?" .
" AND gedcom_id=?" .
" ORDER BY xref"
)->execute(array($this->getName(), $WT_TREE->getTreeId()))->fetchAll();
?>
getPageTitle(); ?>
getPageTitle(); ?>
getName(), 'class="form-control"'); ?>
getBlockSetting($story->block_id, 'title')); ?>
xref, $WT_TREE); ?>
getFullName(); ?>
xref; ?>
setPageTitle($this->getTitle())
->pageHeader()
->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL)
->addInlineJavascript('
jQuery("#story_table").dataTable({
dom: \'<"H"pf<"dt-clear">irl>t<"F"pl>\',
' . I18N::datatablesI18N() . ',
autoWidth: false,
paging: true,
pagingType: "full_numbers",
lengthChange: true,
filter: true,
info: true,
jQueryUI: true,
sorting: [[0,"asc"]],
columns: [
/* 0-name */ null,
/* 1-NAME */ null
]
});
');
$stories = Database::prepare(
"SELECT block_id, xref" .
" FROM `##block` b" .
" WHERE module_name=?" .
" AND gedcom_id=?" .
" ORDER BY xref"
)->execute(array($this->getName(), $WT_TREE->getTreeId()))->fetchAll();
echo '', I18N::translate('Stories'), ' ';
if (count($stories) > 0) {
echo '';
echo '
', I18N::translate('Story title'), '
', I18N::translate('Individual'), '
';
foreach ($stories as $story) {
$indi = Individual::getInstance($story->xref, $WT_TREE);
$story_title = $this->getBlockSetting($story->block_id, 'title');
$languages = $this->getBlockSetting($story->block_id, 'languages');
if (!$languages || in_array(WT_LOCALE, explode(',', $languages))) {
if ($indi) {
if ($indi->canShow()) {
echo '' . $story_title . ' ' . $indi->getFullName() . ' ';
}
} else {
echo '', $story_title, ' ', $story->xref, ' ';
}
}
}
echo '
';
}
}
/** {@inheritdoc} */
public function defaultMenuOrder() {
return 30;
}
/** {@inheritdoc} */
public function defaultAccessLevel() {
return Auth::PRIV_HIDE;
}
/** {@inheritdoc} */
public function getMenu() {
if (Auth::isSearchEngine()) {
return null;
}
$menu = new Menu($this->getTitle(), 'module.php?mod=' . $this->getName() . '&mod_action=show_list', 'menu-story');
return $menu;
}
}