. */ namespace Fisharebest\Webtrees\Module; use Fisharebest\Webtrees\Census\CensusInterface; use Fisharebest\Webtrees\Controller\SimpleController; use Fisharebest\Webtrees\Date; 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; /** * 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, 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, 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(); } } ?> 'Age at first marriage', 'Age' => 'Age at last birthday', 'Assets' => 'Assets = Owned,Rented - Value,Rent - Radio - Farm', 'BIC' => 'Born in County', 'BOE' => 'Born outside England', 'BP' => 'Birthplace - (Chapman format)', 'Birthplace' => 'Birthplace (Full format)', 'Bmth' => 'Month of birth - If born within Census year', 'ChB' => 'Children born alive', 'ChD' => 'Children who have died', 'ChL' => 'Children still living', 'DOB' => 'Date of birth', 'Edu' => 'Education - At School, Can Read, Can Write', // or "Cannot Read, Cannot Write" ?? 'EmD' => 'Employed?', 'EmN' => 'Unemployed?', 'EmR' => 'Employer?', 'Employ' => 'Employment', 'Eng?' => 'English spoken?', 'EngL' => 'English spoken?, if not, Native Language', 'FBP' => 'Father’s Birthplace - (Chapman format)', 'Health' => 'Health - 1.Blind, 2.Deaf & Dumb, 3.Idiotic, 4.Insane, 5.Disabled etc', 'Home' => 'Home Ownership - Owned/Rented-Free/Mortgaged-Farm/House-Farm Schedule number', 'Industry' => 'Industry', 'Infirm' => 'Infirmities - 1. Deaf & Dumb, 2. Blind, 3. Lunatic, 4. Imbecile/feeble-minded', 'Lang' => 'If Foreign Born - Native Language', 'MBP' => 'Mother’s Birthplace - (Chapman format)', 'MC' => 'Marital Condition - Married, Single, Unmarried, Widowed or Divorced', 'Mmth' => 'Month of marriage - If married during Census Year', 'MnsE' => 'Months employed during Census Year', 'MnsU' => 'Months unemployed during Census Year', 'N/A' => 'If Foreign Born - Naturalized, Alien', 'NL' => 'If Foreign Born - Native Language', 'Name' => 'Full Name or Married name if married', 'Occupation' => 'Occupation', 'Par' => 'Parentage - Father if foreign born, Mother if foreign born', 'Race' => 'Race or Color - Black, White, Mulatto, Asian, Indian, Chinese etc', 'Relation' => 'Relationship to Head of Household', 'Sex' => 'Male or Female', 'Situ' => 'Situation - Disease, Infirmity, Convict, Pauper etc', 'Ten' => 'Tenure - Owned/Rented, (if owned)Free/Morgaged', 'Vet' => 'War Veteran?', 'WH' => 'Working at Home?', 'War' => 'War or Expedition', 'WksU' => 'Weeks unemployed during Census Year', 'YOI' => 'If Foreign Born - Year of immigration', 'YON' => 'If Foreign Born - Year of naturalization', 'YUS' => 'If Foreign Born - Years in the USA', 'YrsM' => 'Years Married, or Y if married in Census Year', ); if (preg_match('/(.*)((?:\n.*)*)\n\.start_formatted_area\.\n(.*)((?:\n.*)*)\n.end_formatted_area\.((?:\n.*)*)/', $note->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]); $fmt_headers = array(); foreach ($headers as $key => $value) { $fmt_headers[$key] = '' . $key . ''; } // Substitue 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 * * @param CensusInterface $census * * @return string */ public static function censusTableHeader(CensusInterface $census) { $html = ''; // hidden column - used to save data foreach ($census->columns() as $column) { $html .= '' . $column->abbreviation() . ''; } return '' . $html . ''; } /** * Generate an HTML row of data for the census * * @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 * * @param CensusInterface $census * @param Individual $individual * @param Individual|null $head * * @return string */ public static function censusTableRow(CensusInterface $census, Individual $individual, Individual $head = null) { $html = '' . $individual->getXref() . ''; foreach ($census->columns() as $column) { $html .= ''; } return '' . $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(), '#', '', array('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(), '#', '', array('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(), '#', '', array('onclick' => 'return appendCensusRow("' . Filter::escapeJs(self::censusTableRow($census, $spouse_family_child, $head)) . '");') ); $submenu->addClass('submenuitem', ''); $menu->addSubmenu($submenu); $menu->addClass('', 'submenu'); } } ?> getMenu(); ?> getFullName(); ?>
'; } }