.
*/
namespace Fisharebest\Webtrees\Module;
use Fisharebest\Webtrees\Census\Census;
use Fisharebest\Webtrees\Census\CensusInterface;
use Fisharebest\Webtrees\Family;
use Fisharebest\Webtrees\Filter;
use Fisharebest\Webtrees\FontAwesome;
use Fisharebest\Webtrees\Functions\FunctionsDb;
use Fisharebest\Webtrees\Functions\FunctionsEdit;
use Fisharebest\Webtrees\GedcomRecord;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Individual;
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) {
global $WT_TREE;
switch ($mod_action) {
case 'census-header':
header('Content-Type: text/html; charset=utf8');
$census = Filter::get('census');
echo $this->censusTableHeader(new $census);
break;
case 'census-individual':
header('Content-Type: text/html; charset=utf8');
$census = Filter::get('census');
$individual = Individual::getInstance(Filter::get('xref'), $WT_TREE);
$head = Individual::getInstance(Filter::get('head'), $WT_TREE);
echo $this->censusTableRow(new $census, $individual, $head);
break;
case 'media_find':
self::mediaFind();
break;
case 'media_query_3a':
self::mediaQuery();
break;
default:
http_response_code(404);
}
}
/**
* @param Individual $individual
*/
public function createCensusAssistant(Individual $individual) {
?>
';
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 = [];
/** @var GedcomRecord[] $linkedRecords */
$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(), $note->getTree());
}
}
/**
* 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 $head
*
* @return string
*/
public static function censusTableRow(CensusInterface $census, Individual $individual, Individual $head) {
$html = '';
foreach ($census->columns() as $column) {
$html .= '