Fisharebest\Webtrees\Functions\FunctionsPrintLists::surnameTable PHP Method

surnameTable() public static method

Print a table of surnames, for the top surnames block, the indi/fam lists, etc.
public static surnameTable ( string[][] $surnames, string $script, Fisharebest\Webtrees\Tree $tree ) : string
$surnames string[][] array (of SURN, of array of SPFX_SURN, of array of PID)
$script string "indilist.php" (counts of individuals) or "famlist.php" (counts of spouses)
$tree Fisharebest\Webtrees\Tree generate links for this tree
return string
    public static function surnameTable($surnames, $script, Tree $tree)
    {
        global $controller;
        $html = '';
        $controller->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL)->addInlineJavascript('
				jQuery.fn.dataTableExt.oSort["text-asc"] = textCompareAsc;
				jQuery.fn.dataTableExt.oSort["text-desc"] = textCompareDesc;
				jQuery(".surname-list").dataTable({
					dom: "t",
					jQueryUI: true,
					autoWidth: false,
					' . I18N::datatablesI18N() . ',
					paging: false,
					sorting: [[0, "asc"]],
					columns: [
						/* Surname */ { type: "text" },
						/* Count   */ { type: "num" } 
					]
				});
			');
        if ($script == 'famlist.php') {
            $col_heading = I18N::translate('Spouses');
        } else {
            $col_heading = I18N::translate('Individuals');
        }
        $html .= '<table class="surname-list">' . '<thead>' . '<tr>' . '<th>' . GedcomTag::getLabel('SURN') . '</th>' . '<th>' . $col_heading . '</th>' . '</tr>' . '</thead>';
        $html .= '<tbody>';
        foreach ($surnames as $surn => $surns) {
            // Each surname links back to the indi/fam surname list
            if ($surn) {
                $url = $script . '?surname=' . rawurlencode($surn) . '&amp;ged=' . $tree->getNameUrl();
            } else {
                $url = $script . '?alpha=,&amp;ged=' . $tree->getNameUrl();
            }
            $html .= '<tr>';
            // Surname
            $html .= '<td data-sort="' . Filter::escapeHtml($surn) . '">';
            // Multiple surname variants, e.g. von Groot, van Groot, van der Groot, etc.
            foreach ($surns as $spfxsurn => $indis) {
                if ($spfxsurn) {
                    $html .= '<a href="' . $url . '" dir="auto">' . Filter::escapeHtml($spfxsurn) . '</a><br>';
                } else {
                    // No surname, but a value from "2 SURN"? A common workaround for toponyms, etc.
                    $html .= '<a href="' . $url . '" dir="auto">' . Filter::escapeHtml($surn) . '</a><br>';
                }
            }
            $html .= '</td>';
            // Surname count
            $subtotal = 0;
            foreach ($surns as $indis) {
                $subtotal += count($indis);
            }
            $html .= '<td class="center" data-sort="' . $subtotal . '">';
            foreach ($surns as $indis) {
                $html .= I18N::number(count($indis)) . '<br>';
            }
            if (count($surns) > 1) {
                // More than one surname variant? Show a subtotal
                $html .= I18N::number($subtotal);
            }
            $html .= '</td>';
            $html .= '</tr>';
        }
        $html .= '</tbody></table>';
        return $html;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * {@inhericDoc}
  * @see \MyArtJaub\Webtrees\Mvc\View\AbstractView::renderContent()
  */
 protected function renderContent()
 {
     /** @var \Fisharebest\Webtrees\Tree $tree */
     $tree = $this->data->get('tree');
     echo '<h2 class="center">', $this->data->get('title'), '</h2>';
     echo '<p class="center alpha_index">', implode(' | ', $this->getInitialLettersList()), '</p>';
     if ($this->data->get('issurnames', false)) {
         $surns = $this->data->get('surnameslist', array());
         $extra_params = array('mod' => Constants::MODULE_MAJ_PATROLIN_NAME, 'mod_action' => 'Lineage');
         // Show the surname list
         switch ($tree->getPreference('SURNAME_LIST_STYLE')) {
             case 'style1':
                 echo FunctionsPrintLists::surnameList($surns, 3, true, WT_SCRIPT_NAME, $tree, $extra_params);
                 break;
             case 'style3':
                 echo FunctionsPrintLists::surnameTagCloud($surns, WT_SCRIPT_NAME, true, $tree, $extra_params);
                 break;
             case 'style2':
             default:
                 echo FunctionsPrintLists::surnameTable($surns, WT_SCRIPT_NAME, $tree, $extra_params);
                 break;
         }
     } else {
         if ($this->data->get('islineages', false)) {
             //Link to indilist
             echo '<p class="center"><strong>' . '<a href="indilist.php?ged=' . $tree->getNameUrl() . '&surname=' . rawurlencode($this->data->get('surname')) . '">' . I18N::translate('Go to the list of individuals with surname %s', $this->data->get('legend')) . '</a></strong></p>';
             $lineages = $this->data->get('lineages', null);
             $nb_lineages = count($lineages);
             if (is_null($lineages) || $nb_lineages == 0) {
                 echo '<p class="center"><span class="warning">', I18N::translate('No individuals with surname %s has been found. Please try another name.', '<span dir="auto">' . $this->data->get('legend') . '</span>'), '</span></p>';
             } else {
                 echo '<div id="patronymiclineages">' . '<div class="list_label">', $this->data->get('table_title'), '</div>';
                 echo '<div class="list_value_wrap">';
                 foreach ($lineages as $i => $lineage) {
                     $this->printRootLineage($lineage);
                     if ($i < $nb_lineages - 1) {
                         echo '<hr />';
                     }
                 }
                 echo '</div>';
                 echo '<div class="list_label">', I18N::translate('%s lineages found', $nb_lineages), '</div>' . '</div>';
             }
         }
     }
 }
All Usage Examples Of Fisharebest\Webtrees\Functions\FunctionsPrintLists::surnameTable