. */ namespace Fisharebest\Webtrees\Module; use Fisharebest\Webtrees\Census\Census; use Fisharebest\Webtrees\Census\CensusInterface; use Fisharebest\Webtrees\Controller\SimpleController; use Fisharebest\Webtrees\Family; use Fisharebest\Webtrees\Filter; use Fisharebest\Webtrees\Functions\Functions; use Fisharebest\Webtrees\Functions\FunctionsDb; use Fisharebest\Webtrees\GedcomRecord; use Fisharebest\Webtrees\GedcomTag; use Fisharebest\Webtrees\I18N; use Fisharebest\Webtrees\Individual; use Fisharebest\Webtrees\Menu; use Fisharebest\Webtrees\Note; use Fisharebest\Webtrees\Soundex; /** * Class CensusAssistantModule */ class CensusAssistantModule extends AbstractModule { /** {@inheritdoc} */ public function getTitle() { return /* I18N: Name of a module */ I18N::translate('Census assistant'); } /** {@inheritdoc} */ public function getDescription() { return /* I18N: Description of the “Census assistant” module */ I18N::translate('An alternative way to enter census transcripts and link them to individuals.'); } /** * 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 'census_find': self::censusFind(); break; case 'media_find': self::mediaFind(); break; case 'media_query_3a': self::mediaQuery(); break; default: http_response_code(404); } } /** * Find an individual. */ private static function censusFind() { global $WT_TREE; $controller = new SimpleController; $filter = Filter::get('filter'); $action = Filter::get('action'); $census = Filter::get('census'); $census = new $census; $controller ->restrictAccess($census instanceof CensusInterface) ->setPageTitle(I18N::translate('Find an individual')) ->pageHeader(); echo ''; echo ''; echo '
'; echo I18N::translate('Find an individual'); echo '
'; echo '
'; if ($action == 'filter') { $filter = trim($filter); $filter_array = explode(' ', preg_replace('/ {2,}/', ' ', $filter)); // Output Individual for GEDFact Assistant ====================== echo ''; $myindilist = FunctionsDb::searchIndividualNames($filter_array, [$WT_TREE]); if ($myindilist) { echo ''; } else { echo ''; } echo ''; echo '
    '; usort($myindilist, '\Fisharebest\Webtrees\GedcomRecord::compare'); foreach ($myindilist as $indi) { echo '
  • '; echo ''; echo '' . $indi->getFullName() . ''; echo ''; echo $indi->formatFirstMajorFact(WT_EVENTS_BIRT, 1); echo $indi->formatFirstMajorFact(WT_EVENTS_DEAT, 1); echo '
    '; echo '
  • '; } echo '
'; echo I18N::translate('No results found.'); echo '
'; echo ''; echo '
'; } } /** * Find a media object. */ private static function mediaFind() { global $WT_TREE; $controller = new SimpleController; $filter = Filter::get('filter'); $multiple = Filter::getBool('multiple'); $controller ->setPageTitle(I18N::translate('Find an individual')) ->pageHeader(); ?> '; echo ''; echo ''; echo ''; echo '
'; // start column for find text header echo $controller->getPageTitle(); echo '
'; echo '
'; echo ''; echo '
'; $filter = trim($filter); $filter_array = explode(' ', preg_replace('/ {2,}/', ' ', $filter)); echo ''; $myindilist = FunctionsDb::searchIndividualNames($filter_array, [$WT_TREE]); if ($myindilist) { echo ''; } else { echo ""; } echo "
', I18N::translate('Total individuals: %s', count($myindilist)), '
"; echo I18N::translate('No results found.'); echo "
"; echo ''; } /** * Search for a media object. */ private static function mediaQuery() { global $WT_TREE; $iid2 = Filter::get('iid', WT_REGEX_XREF); $controller = new SimpleController; $controller ->setPageTitle(I18N::translate('Link to an existing media object')) ->pageHeader(); $record = GedcomRecord::getInstance($iid2, $WT_TREE); if ($record) { $headjs = ''; if ($record instanceof Family) { if ($record->getHusband()) { $headjs = $record->getHusband()->getXref(); } elseif ($record->getWife()) { $headjs = $record->getWife()->getXref(); } } ?> getNote(), $match)) { // This looks like a census-assistant shared note $title = Filter::escapeHtml($match[1]); $preamble = Filter::escapeHtml($match[2]); $header = Filter::escapeHtml($match[3]); $data = Filter::escapeHtml($match[4]); $postamble = Filter::escapeHtml($match[5]); // Get the column headers for the census to which this note refers // requires the fact place & date to match the specific census // censusPlace() (Soundex match) and censusDate() functions $fmt_headers = []; $linkedRecords = array_merge($note->linkedIndividuals('NOTE'), $note->linkedFamilies('NOTE')); $firstRecord = array_shift($linkedRecords); if ($firstRecord) { $countryCode = ''; $date = ''; foreach ($firstRecord->getFacts('CENS') as $fact) { if (trim($fact->getAttribute('NOTE'), '@') === $note->getXref()) { $date = $fact->getAttribute('DATE'); $place = explode(',', strip_tags($fact->getPlace()->getFullName())); $countryCode = Soundex::daitchMokotoff(array_pop($place)); break; } } foreach (Census::allCensusPlaces() as $censusPlace) { if (Soundex::compare($countryCode, Soundex::daitchMokotoff($censusPlace->censusPlace()))) { foreach ($censusPlace->allCensusDates() as $census) { if ($census->censusDate() == $date) { foreach ($census->columns() as $column) { $abbrev = $column->abbreviation(); if ($abbrev) { $description = $column->title() ? $column->title() : I18N::translate('Description unavailable'); $fmt_headers[$abbrev] = '' . $abbrev . ''; } } break 2; } } } } } // Substitute header labels and format as HTML $thead = '' . strtr(str_replace('|', '', $header), $fmt_headers) . ''; $thead = str_replace('.b.', '', $thead); // Format data as HTML $tbody = ''; foreach (explode("\n", $data) as $row) { $tbody .= ''; foreach (explode('|', $row) as $column) { $tbody .= '' . $column . ''; } $tbody .= ''; } return $title . "\n" . // The newline allows the framework to expand the details and turn the first line into a link '
' . '

' . $preamble . '

' . '' . '' . $thead . '' . '' . $tbody . '' . '
' . '

' . $postamble . '

' . '
'; } else { // Not a census-assistant shared note - apply default formatting return Filter::formatText($note->getNote(), $WT_TREE); } } /** * Generate an HTML row of data for the census header * * Add prefix cell (store XREF and drag/drop) * Add suffix cell (delete button) * * @param CensusInterface $census * * @return string */ public static function censusTableHeader(CensusInterface $census) { $html = ''; foreach ($census->columns() as $column) { $html .= '' . $column->abbreviation() . ''; } return '' . $html . ''; } /** * Generate an HTML row of data for the census * * Add prefix cell (store XREF and drag/drop) * Add suffix cell (delete button) * * @param CensusInterface $census * * @return string */ public static function censusTableEmptyRow(CensusInterface $census) { return '' . str_repeat('', count($census->columns())) . ''; } /** * Generate an HTML row of data for the census * * Add prefix cell (store XREF and drag/drop) * Add suffix cell (delete button) * * @param CensusInterface $census * @param Individual $individual * @param Individual|null $head * * @return string */ public static function censusTableRow(CensusInterface $census, Individual $individual, Individual $head = null) { $html = ''; foreach ($census->columns() as $column) { $html .= ''; } return '' . $individual->getXref() . '' . $html . ''; } /** * Create a family on the census navigator. * * @param CensusInterface $census * @param Family $family * @param Individual $head * * @return string */ public static function censusNavigatorFamily(CensusInterface $census, Family $family, Individual $head) { $headImg2 = ''; foreach ($family->getSpouses() as $spouse) { $menu = new Menu(Functions::getCloseRelationshipName($head, $spouse)); foreach ($spouse->getChildFamilies() as $grandparents) { foreach ($grandparents->getSpouses() as $grandparent) { $submenu = new Menu( Functions::getCloseRelationshipName($head, $grandparent) . ' - ' . $grandparent->getFullName(), '#', '', ['onclick' => 'return appendCensusRow("' . Filter::escapeJs(self::censusTableRow($census, $grandparent, $head)) . '");'] ); $submenu->addClass('submenuitem', ''); $menu->addSubmenu($submenu); $menu->addClass('', 'submenu'); } } ?> getMenu(); ?> getFullName(); ?> getChildren() as $child) { $menu = new Menu(Functions::getCloseRelationshipName($head, $child)); foreach ($child->getSpouseFamilies() as $spouse_family) { foreach ($spouse_family->getSpouses() as $spouse_family_spouse) { if ($spouse_family_spouse != $child) { $submenu = new Menu( Functions::getCloseRelationshipName($head, $spouse_family_spouse) . ' - ' . $spouse_family_spouse->getFullName(), '#', '', ['onclick' => 'return appendCensusRow("' . Filter::escapeJs(self::censusTableRow($census, $spouse_family_spouse, $head)) . '");'] ); $submenu->addClass('submenuitem', ''); $menu->addSubmenu($submenu); $menu->addClass('', 'submenu'); } } foreach ($spouse_family->getChildren() as $spouse_family_child) { $submenu = new Menu( Functions::getCloseRelationshipName($head, $spouse_family_child) . ' - ' . $spouse_family_child->getFullName(), '#', '', ['onclick' => 'return appendCensusRow("' . Filter::escapeJs(self::censusTableRow($census, $spouse_family_child, $head)) . '");'] ); $submenu->addClass('submenuitem', ''); $menu->addSubmenu($submenu); $menu->addClass('', 'submenu'); } } ?> getMenu(); ?> getFullName(); ?>
'; } }