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

surnameList() public static method

Print a list of surnames.
public static surnameList ( string[][] $surnames, integer $style, boolean $totals, string $script, Fisharebest\Webtrees\Tree $tree ) : string
$surnames string[][] array (of SURN, of array of SPFX_SURN, of array of PID)
$style integer 1=bullet list, 2=semicolon-separated list, 3=tabulated list with up to 4 columns
$totals boolean show totals after each name
$script string indilist or famlist
$tree Fisharebest\Webtrees\Tree Link back to the individual list in this tree
return string
    public static function surnameList($surnames, $style, $totals, $script, Tree $tree)
    {
        $html = array();
        foreach ($surnames as $surn => $surns) {
            // Each surname links back to the indilist
            if ($surn) {
                $url = $script . '?surname=' . urlencode($surn) . '&ged=' . $tree->getNameUrl();
            } else {
                $url = $script . '?alpha=,&ged=' . $tree->getNameUrl();
            }
            // If all the surnames are just case variants, then merge them into one
            // Comment out this block if you want SMITH listed separately from Smith
            $first_spfxsurn = null;
            foreach ($surns as $spfxsurn => $indis) {
                if ($first_spfxsurn) {
                    if (I18N::strtoupper($spfxsurn) == I18N::strtoupper($first_spfxsurn)) {
                        $surns[$first_spfxsurn] = array_merge($surns[$first_spfxsurn], $surns[$spfxsurn]);
                        unset($surns[$spfxsurn]);
                    }
                } else {
                    $first_spfxsurn = $spfxsurn;
                }
            }
            $subhtml = '<a href="' . $url . '" dir="auto">' . Filter::escapeHtml(implode(I18N::$list_separator, array_keys($surns))) . '</a>';
            if ($totals) {
                $subtotal = 0;
                foreach ($surns as $indis) {
                    $subtotal += count($indis);
                }
                $subhtml .= '&nbsp;(' . I18N::number($subtotal) . ')';
            }
            $html[] = $subhtml;
        }
        switch ($style) {
            case 1:
                return '<ul><li>' . implode('</li><li>', $html) . '</li></ul>';
            case 2:
                return implode(I18N::$list_separator, $html);
            case 3:
                $i = 0;
                $count = count($html);
                if ($count > 36) {
                    $col = 4;
                } elseif ($count > 18) {
                    $col = 3;
                } elseif ($count > 6) {
                    $col = 2;
                } else {
                    $col = 1;
                }
                $newcol = ceil($count / $col);
                $html2 = '<table class="list_table"><tr>';
                $html2 .= '<td class="list_value" style="padding: 14px;">';
                foreach ($html as $surns) {
                    $html2 .= $surns . '<br>';
                    $i++;
                    if ($i == $newcol && $i < $count) {
                        $html2 .= '</td><td class="list_value" style="padding: 14px;">';
                        $newcol = $i + ceil($count / $col);
                    }
                }
                $html2 .= '</td></tr></table>';
                return $html2;
        }
    }

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::surnameList