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
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>';
             }
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Generate the HTML content of this block.
  *
  * @param int      $block_id
  * @param bool     $template
  * @param string[] $cfg
  *
  * @return string
  */
 public function getBlock($block_id, $template = true, $cfg = array())
 {
     global $WT_TREE, $ctype;
     $COMMON_NAMES_REMOVE = $WT_TREE->getPreference('COMMON_NAMES_REMOVE');
     $COMMON_NAMES_THRESHOLD = $WT_TREE->getPreference('COMMON_NAMES_THRESHOLD');
     $num = $this->getBlockSetting($block_id, 'num', '10');
     $infoStyle = $this->getBlockSetting($block_id, 'infoStyle', 'table');
     $block = $this->getBlockSetting($block_id, 'block', '0');
     foreach (array('num', 'infoStyle', 'block') as $name) {
         if (array_key_exists($name, $cfg)) {
             ${$name} = $cfg[$name];
         }
     }
     // This next function is a bit out of date, and doesn't cope well with surname variants
     $top_surnames = FunctionsDb::getTopSurnames($WT_TREE->getTreeId(), $COMMON_NAMES_THRESHOLD, $num);
     // Remove names found in the "Remove Names" list
     if ($COMMON_NAMES_REMOVE) {
         foreach (preg_split("/[,; ]+/", $COMMON_NAMES_REMOVE) as $delname) {
             unset($top_surnames[$delname]);
             unset($top_surnames[I18N::strtoupper($delname)]);
         }
     }
     $all_surnames = array();
     $i = 0;
     foreach (array_keys($top_surnames) as $top_surname) {
         $all_surnames = array_merge($all_surnames, QueryName::surnames($WT_TREE, $top_surname, '', false, false));
         if (++$i == $num) {
             break;
         }
     }
     if ($i < $num) {
         $num = $i;
     }
     $id = $this->getName() . $block_id;
     $class = $this->getName() . '_block';
     if ($ctype === 'gedcom' && Auth::isManager($WT_TREE) || $ctype === 'user' && Auth::check()) {
         $title = '<a class="icon-admin" title="' . I18N::translate('Configure') . '" href="block_edit.php?block_id=' . $block_id . '&amp;ged=' . $WT_TREE->getNameHtml() . '&amp;ctype=' . $ctype . '"></a>';
     } else {
         $title = '';
     }
     if ($num == 1) {
         // I18N: i.e. most popular surname.
         $title .= I18N::translate('Top surname');
     } else {
         // I18N: Title for a list of the most common surnames, %s is a number. Note that a separate translation exists when %s is 1
         $title .= I18N::plural('Top %s surname', 'Top %s surnames', $num, I18N::number($num));
     }
     switch ($infoStyle) {
         case 'tagcloud':
             uksort($all_surnames, '\\Fisharebest\\Webtrees\\I18N::strcasecmp');
             $content = FunctionsPrintLists::surnameTagCloud($all_surnames, 'indilist.php', true, $WT_TREE);
             break;
         case 'list':
             uasort($all_surnames, '\\Fisharebest\\Webtrees\\Module\\TopSurnamesModule::surnameCountSort');
             $content = FunctionsPrintLists::surnameList($all_surnames, '1', true, 'indilist.php', $WT_TREE);
             break;
         case 'array':
             uasort($all_surnames, '\\Fisharebest\\Webtrees\\Module\\TopSurnamesModule::surnameCountSort');
             $content = FunctionsPrintLists::surnameList($all_surnames, '2', true, 'indilist.php', $WT_TREE);
             break;
         case 'table':
         default:
             uasort($all_surnames, '\\Fisharebest\\Webtrees\\Module\\TopSurnamesModule::surnameCountSort');
             $content = FunctionsPrintLists::surnameTable($all_surnames, 'indilist.php', $WT_TREE);
             break;
     }
     if ($template) {
         if ($block) {
             $class .= ' small_inner_block';
         }
         return Theme::theme()->formatBlock($id, $title, $class, $content);
     } else {
         return $content;
     }
 }
Exemplo n.º 3
0
    echo '</p>';
}
if ($show === 'indi' || $show === 'surn') {
    $surns = QueryName::surnames($WT_TREE, $surname, $alpha, $show_marnm === 'yes', false);
    if ($show === 'surn') {
        // Show the surname list
        switch ($WT_TREE->getPreference('SURNAME_LIST_STYLE')) {
            case 'style1':
                echo FunctionsPrintLists::surnameList($surns, 3, true, WT_SCRIPT_NAME, $WT_TREE);
                break;
            case 'style3':
                echo FunctionsPrintLists::surnameTagCloud($surns, WT_SCRIPT_NAME, true, $WT_TREE);
                break;
            case 'style2':
            default:
                echo FunctionsPrintLists::surnameTable($surns, WT_SCRIPT_NAME, $WT_TREE);
                break;
        }
    } else {
        // Show the list
        $count = 0;
        foreach ($surns as $surnames) {
            foreach ($surnames as $list) {
                $count += count($list);
            }
        }
        // Don't sublists short lists.
        if ($count < $WT_TREE->getPreference('SUBLIST_TRIGGER_I')) {
            $falpha = '';
            $show_all_firstnames = 'no';
        } else {
Exemplo n.º 4
0
 /**
  * Generate the HTML content of this block.
  *
  * @param int      $block_id
  * @param bool     $template
  * @param string[] $cfg
  *
  * @return string
  */
 public function getBlock($block_id, $template = true, $cfg = array())
 {
     global $WT_TREE, $ctype;
     $COMMON_NAMES_REMOVE = $WT_TREE->getPreference('COMMON_NAMES_REMOVE');
     $COMMON_NAMES_THRESHOLD = $WT_TREE->getPreference('COMMON_NAMES_THRESHOLD');
     $num = $this->getBlockSetting($block_id, 'num', '10');
     // The “Minimum number of occurrences” input field from Control Panel’s Preferences page
     // has to be copied here otherwise user doesn't understand why the result is different
     // than expected (input of add and remove surnames may also be copied to make this module
     // indenpendent from module statistics; it is not copied yet).  The data of original input
     // field is still used in the bottom of the statistics module
     $threshold = $this->getBlockSetting($block_id, 'threshold', '5');
     $infoStyle = $this->getBlockSetting($block_id, 'infoStyle', 'table');
     $block = $this->getBlockSetting($block_id, 'block', '0');
     foreach (array('num', 'infoStyle', 'block') as $name) {
         if (array_key_exists($name, $cfg)) {
             ${$name} = $cfg[$name];
         }
     }
     // This next function is a bit out of date, and doesn't cope well with surname variants
     // First defining the upper limit of surname occurrences to get at least one row in
     // result list if user sets too high number in “Minimum number of occurrences” field.
     // Without this definition a short message “No data available in table” appears by
     // webtrees\packages\datatables-1.10.7\js\jquery.dataTables.min.js JavaScript file
     // without the possibility of translating (and only if presentation style is table;
     // all other styles result no message at all)
     $top_surnames_in_DB = FunctionsDb::getCommonSurnames($WT_TREE->getPreference('COMMON_NAMES_THRESHOLD'), $WT_TREE);
     $max_occurrences = 0;
     foreach ($top_surnames_in_DB as $array) {
         if ($array['match'] > $max_occurrences) {
             $max_occurrences = $array['match'];
         }
     }
     if ($threshold > $max_occurrences) {
         $threshold = $max_occurrences;
     }
     $top_surnames = FunctionsDb::getTopSurnames($WT_TREE->getTreeId(), $threshold, $num);
     // Remove names found in the "Remove Names" list
     if ($COMMON_NAMES_REMOVE) {
         foreach (preg_split("/[,; ]+/", $COMMON_NAMES_REMOVE) as $delname) {
             unset($top_surnames[$delname]);
             unset($top_surnames[I18N::strtoupper($delname)]);
         }
     }
     $all_surnames = array();
     $i = 0;
     foreach (array_keys($top_surnames) as $top_surname) {
         $all_surnames = array_merge($all_surnames, QueryName::surnames($WT_TREE, $top_surname, '', false, false));
         if (++$i == $num) {
             break;
         }
     }
     if ($i < $num) {
         $num = $i;
     }
     $id = $this->getName() . $block_id;
     $class = $this->getName() . '_block';
     if ($ctype === 'gedcom' && Auth::isManager($WT_TREE) || $ctype === 'user' && Auth::check()) {
         $title = '<a class="icon-admin" title="' . I18N::translate('Configure') . '" href="block_edit.php?block_id=' . $block_id . '&amp;ged=' . $WT_TREE->getNameHtml() . '&amp;ctype=' . $ctype . '"></a>';
     } else {
         $title = '';
     }
     if ($num == 1) {
         // I18N: i.e. most popular surname.
         $title .= I18N::translate('Top surname');
     } else {
         // I18N: Title for a list of the most common surnames, %s is a number.  Note that a separate translation exists when %s is 1
         $title .= I18N::plural('Top %s surname', 'Top %s surnames', $num, I18N::number($num));
     }
     switch ($infoStyle) {
         case 'tagcloud':
             uksort($all_surnames, '\\Fisharebest\\Webtrees\\I18N::strcasecmp');
             $content = FunctionsPrintLists::surnameTagCloud($all_surnames, 'indilist.php', true, $WT_TREE);
             break;
         case 'list':
             uasort($all_surnames, '\\Fisharebest\\Webtrees\\Module\\TopSurnamesModule::surnameCountSort');
             $content = FunctionsPrintLists::surnameList($all_surnames, '1', true, 'indilist.php', $WT_TREE);
             break;
         case 'array':
             uasort($all_surnames, '\\Fisharebest\\Webtrees\\Module\\TopSurnamesModule::surnameCountSort');
             $content = FunctionsPrintLists::surnameList($all_surnames, '2', true, 'indilist.php', $WT_TREE);
             break;
         case 'table':
         default:
             uasort($all_surnames, '\\Fisharebest\\Webtrees\\Module\\TopSurnamesModule::surnameCountSort');
             $content = FunctionsPrintLists::surnameTable($all_surnames, 'indilist.php', $WT_TREE);
             break;
     }
     if ($template) {
         if ($block) {
             $class .= ' small_inner_block';
         }
         return Theme::theme()->formatBlock($id, $title, $class, $content);
     } else {
         return $content;
     }
 }