/** * Convert custom markup into HTML * * @param Note $note * * @return string */ public static function formatCensusNote(Note $note) { global $WT_TREE; if (preg_match('/(.*)((?:\\n.*)*)\\n\\.start_formatted_area\\.\\n(.+)\\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]); // 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; } } 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) { $tbody .= '<tr>'; foreach (explode('|', $row) as $column) { $tbody .= '<td>' . $column . '</td>'; } $tbody .= '</tr>'; } return $title . "\n" . '<div class="markdown">' . '<p>' . $preamble . '</p>' . '<table>' . '<thead>' . $thead . '</thead>' . '<tbody>' . $tbody . '</tbody>' . '</table>' . '<p>' . $postamble . '</p>' . '</div>'; } else { // Not a census-assistant shared note - apply default formatting return Filter::formatText($note->getNote(), $WT_TREE); } }
/** * Genearate a <select> element, with the dates/places of all known censuses * * * @param string $locale - Sort the censuses for this locale * @param string $xref - The individual for whom we are adding a census */ public static function censusDateSelector($locale, $xref) { global $controller; // Show more likely census details at the top of the list. switch (WT_LOCALE) { case 'cs': $census_places = array(new CensusOfCzechRepublic()); break; case 'en-AU': case 'en-GB': $census_places = array(new CensusOfEngland(), new CensusOfWales(), new CensusOfScotland()); break; case 'en-US': $census_places = array(new CensusOfUnitedStates()); break; case 'fr': case 'fr-CA': $census_places = array(new CensusOfFrance()); break; case 'da': $census_places = array(new CensusOfDenmark()); break; default: $census_places = array(); break; } foreach (Census::allCensusPlaces() as $census_place) { if (!in_array($census_place, $census_places)) { $census_places[] = $census_place; } } $controller->addInlineJavascript(' function selectCensus(el) { var option = jQuery(":selected", el); jQuery("input.DATE", jQuery(el).closest("table")).val(option.val()); jQuery("input.PLAC", jQuery(el).closest("table")).val(option.data("place")); jQuery("input.census-class", jQuery(el).closest("table")).val(option.data("census")); if (option.data("place")) { jQuery("#assistant-link").show(); } else { jQuery("#assistant-link").hide(); } } function set_pid_array(pa) { jQuery("#pid_array").val(pa); } function activateCensusAssistant() { if (jQuery("#newshared_note_img").hasClass("icon-plus")) { expand_layer("newshared_note"); } var field = jQuery("#newshared_note input.NOTE")[0]; var xref = jQuery("input[name=xref]").val(); var census = jQuery(".census-assistant-selector :selected").data("census"); return addnewnote_assisted(field, xref, census); } '); $options = '<option value="">' . I18N::translate('Census date') . '</option>'; foreach ($census_places as $census_place) { $options .= '<option value=""></option>'; foreach ($census_place->allCensusDates() as $census) { $date = new Date($census->censusDate()); $year = $date->minimumDate()->format('%Y'); $place_hierarchy = explode(', ', $census->censusPlace()); $options .= '<option value="' . $census->censusDate() . '" data-place="' . $census->censusPlace() . '" data-census="' . get_class($census) . '">' . $place_hierarchy[0] . ' ' . $year . '</option>'; } } return '<input type="hidden" id="pid_array" name="pid_array" value="">' . '<select class="census-assistant-selector" onchange="selectCensus(this);">' . $options . '</select>'; }