diff options
| author | David Drury <david@drury.me.uk> | 2016-02-24 20:35:37 +0000 |
|---|---|---|
| committer | Greg Roach <fisharebest@gmail.com> | 2016-02-28 17:25:55 +0000 |
| commit | dc46b57449e335587417319b1bb980729dfe17aa (patch) | |
| tree | 5c4fca6ee64be3c1244ac1276a022b7d258b7acc /app | |
| parent | 4b207177137d933a7ecf26b2ec91aaebe8e8cd7a (diff) | |
| download | webtrees-dc46b57449e335587417319b1bb980729dfe17aa.tar.gz webtrees-dc46b57449e335587417319b1bb980729dfe17aa.tar.bz2 webtrees-dc46b57449e335587417319b1bb980729dfe17aa.zip | |
Added styling for Census Assistant notes (same as markdown).
census-edit.php fixed bug in function updateCensusText whereby hidden <th> elements were included in the column count when generating the note text.
fixed bug in CensusAssistantModule.php function formatCensusNote to remove leading \n char from $data (real solution would be to change regex on line 294 but I go cross eyed looking at that).
Accomodate censuses with many columns (eg US 1930). To do this it was necessary to move the "Events of close relatives etc." line outside the facts table as colspan and table-layout: fixed don't play well together
NotesTabModule.php also need some work to properly show censuses with many columns
Select the correct census from which to derive the column headers
Use Soundex to perform place matching
Safety first programming
Diffstat (limited to 'app')
| -rw-r--r-- | app/Module/CensusAssistantModule.php | 63 | ||||
| -rw-r--r-- | app/Module/IndividualFactsTabModule.php | 15 | ||||
| -rw-r--r-- | app/Module/NotesTabModule.php | 11 |
3 files changed, 54 insertions, 35 deletions
diff --git a/app/Module/CensusAssistantModule.php b/app/Module/CensusAssistantModule.php index 812c794e8f..bf5f1addd6 100644 --- a/app/Module/CensusAssistantModule.php +++ b/app/Module/CensusAssistantModule.php @@ -28,6 +28,7 @@ use Fisharebest\Webtrees\I18N; use Fisharebest\Webtrees\Individual; use Fisharebest\Webtrees\Menu; use Fisharebest\Webtrees\Note; +use Fisharebest\Webtrees\Soundex; /** * Class CensusAssistantModule @@ -279,18 +280,6 @@ class CensusAssistantModule extends AbstractModule { public static function formatCensusNote(Note $note) { global $WT_TREE; - - $headers = array(); - foreach (Census::allCensusPlaces() as $allCensusesOfPlace) { - foreach ($allCensusesOfPlace->allCensusDates() as $census) { - foreach ($census->columns() as $column) { - if ($column->abbreviation()) { - $headers[$column->abbreviation()] = $column->title(); - } - } - } - } - 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]); @@ -299,18 +288,48 @@ class CensusAssistantModule extends AbstractModule { $data = Filter::escapeHtml($match[4]); $postamble = Filter::escapeHtml($match[5]); - $fmt_headers = array(); - foreach ($headers as $key => $value) { - $fmt_headers[$key] = '<span title="' . Filter::escapeHtml($value) . '">' . $key . '</span>'; - } + // 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 = array(); + $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; + } + } - // Substitue header labels and format as HTML + 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] = '<span title="' . $description . '">' . $abbrev . '</span>'; + } + } + break 2; + } + } + } + } + } + // Substitute header labels and format as HTML $thead = '<tr><th>' . strtr(str_replace('|', '</th><th>', $header), $fmt_headers) . '</th></tr>'; $thead = str_replace('.b.', '', $thead); // Format data as HTML $tbody = ''; - foreach (explode("\n", $data) as $row) { + foreach (explode("\n", ltrim($data)) as $row) { $tbody .= '<tr>'; foreach (explode('|', $row) as $column) { $tbody .= '<td>' . $column . '</td>'; @@ -320,12 +339,14 @@ class CensusAssistantModule extends AbstractModule { return $title . "\n" . // The newline allows the framework to expand the details and turn the first line into a link + '<div class="markdown census-assistant-note">' . '<p>' . $preamble . '</p>' . - '<table class="table-census-assistant">' . + '<table>' . '<thead>' . $thead . '</thead>' . '<tbody>' . $tbody . '</tbody>' . '</table>' . - '<p>' . $postamble . '</p>'; + '<p>' . $postamble . '</p>' . + '</div>'; } else { // Not a census-assistant shared note - apply default formatting return Filter::formatText($note->getNote(), $WT_TREE); @@ -348,7 +369,7 @@ class CensusAssistantModule extends AbstractModule { $html .= '<th title="' . $column->title() . '">' . $column->abbreviation() . '</th>'; } - return '<tr><th hidden></th>' . $html . '<th></th></th></tr>'; + return '<tr><th hidden></th>' . $html . '<th></th></tr>'; } /** diff --git a/app/Module/IndividualFactsTabModule.php b/app/Module/IndividualFactsTabModule.php index 1065686373..8d36b0891d 100644 --- a/app/Module/IndividualFactsTabModule.php +++ b/app/Module/IndividualFactsTabModule.php @@ -120,13 +120,7 @@ class IndividualFactsTabModule extends AbstractModule implements ModuleTabInterf ob_start(); - echo '<table class="facts_table">'; - echo '<tbody>'; - if (!$indifacts) { - echo '<tr><td colspan="2" class="facts_value">', I18N::translate('There are no facts for this individual.'), '</td></tr>'; - } - - echo '<tr><td colspan="2" class="descriptionbox rela"><form action="?"><input id="checkbox_rela_facts" type="checkbox" '; + echo '<div class="descriptionbox rela"><form action="?"><input id="checkbox_rela_facts" type="checkbox" '; echo $controller->record->getTree()->getPreference('EXPAND_RELATIVES_EVENTS') ? 'checked' : ''; echo ' onclick="jQuery(\'tr.rela\').toggle();"><label for="checkbox_rela_facts">', I18N::translate('Events of close relatives'), '</label>'; if (file_exists(Site::getPreference('INDEX_DIRECTORY') . 'histo.' . WT_LOCALE . '.php')) { @@ -134,7 +128,12 @@ class IndividualFactsTabModule extends AbstractModule implements ModuleTabInterf echo $EXPAND_HISTO_EVENTS ? 'checked' : ''; echo ' onclick="jQuery(\'tr.histo\').toggle();"><label for="checkbox_histo">', I18N::translate('Historical facts'), '</label>'; } - echo '</form></td></tr>'; + echo '</form></div>'; + echo '<table class="facts_table">'; + echo '<tbody>'; + if (!$indifacts) { + echo '<tr><td colspan="2" class="facts_value">', I18N::translate('There are no facts for this individual.'), '</td></tr>'; + } foreach ($indifacts as $fact) { FunctionsPrintFacts::printFact($fact, $controller->record); diff --git a/app/Module/NotesTabModule.php b/app/Module/NotesTabModule.php index 1bab581a22..5b4e31037f 100644 --- a/app/Module/NotesTabModule.php +++ b/app/Module/NotesTabModule.php @@ -61,14 +61,13 @@ class NotesTabModule extends AbstractModule implements ModuleTabInterface { global $WT_TREE, $controller; ob_start(); - echo '<table class="facts_table">'; ?> - <tr> - <td colspan="2" class="descriptionbox rela"> + <div class="descriptionbox rela"> <input id="checkbox_note2" type="checkbox" <?php echo $WT_TREE->getPreference('SHOW_LEVEL2_NOTES') ? 'checked' : ''; ?> onclick="jQuery('tr.row_note2').toggle();"> - <label for="checkbox_note2"><?php echo I18N::translate('Show all notes'); ?></label> - </td> - </tr> + <label for="checkbox_note2"><?php echo I18N::translate('Show all notes'); ?></label> + </div> + <table class="facts_table"> + <?php foreach ($this->getFactsWithNotes() as $fact) { if ($fact->getTag() == 'NOTE') { |
