コード例 #1
0
ファイル: module.php プロジェクト: brambravo/webtrees
    public function getBlock($block_id, $template = true, $cfg = null)
    {
        global $TEXT_DIRECTION, $ctype, $controller;
        $num = get_block_setting($block_id, 'num', 10);
        $infoStyle = get_block_setting($block_id, 'infoStyle', 'table');
        $block = get_block_setting($block_id, 'block', false);
        if ($cfg) {
            foreach (array('num', 'infoStyle', 'block') as $name) {
                if (array_key_exists($name, $cfg)) {
                    ${$name} = $cfg[$name];
                }
            }
        }
        $stats = new WT_Stats(WT_GEDCOM);
        $id = $this->getName() . $block_id;
        $class = $this->getName() . '_block';
        if ($ctype == 'gedcom' && WT_USER_GEDCOM_ADMIN || $ctype == 'user' && WT_USER_ID) {
            $title = '<i class="icon-admin" title="' . WT_I18N::translate('Configure') . '" onclick="modalDialog(\'block_edit.php?block_id=' . $block_id . '\', \'' . $this->getTitle() . '\');"></i>';
        } else {
            $title = '';
        }
        if ($num == 1) {
            // I18N: i.e. most popular given name.
            $title .= WT_I18N::translate('Top given name');
        } else {
            // I18N: Title for a list of the most common given names, %s is a number.  Note that a separate translation exists when %s is 1
            $title .= WT_I18N::plural('Top %s given name', 'Top %s given names', $num, WT_I18N::number($num));
        }
        $content = '<div class="normal_inner_block">';
        //Select List or Table
        switch ($infoStyle) {
            case "list":
                // Output style 1:  Simple list style.  Better suited to left side of page.
                if ($TEXT_DIRECTION == 'ltr') {
                    $padding = 'padding-left: 15px';
                } else {
                    $padding = 'padding-right: 15px';
                }
                $params = array(1, $num, 'rcount');
                //List Female names
                $totals = $stats->commonGivenFemaleTotals($params);
                if ($totals) {
                    $content .= '<b>' . WT_I18N::translate('Females') . '</b><div class="wrap" style="' . $padding . '">' . $totals . '</div><br>';
                }
                //List Male names
                $totals = $stats->commonGivenMaleTotals($params);
                if ($totals) {
                    $content .= '<b>' . WT_I18N::translate('Males') . '</b><div class="wrap" style="' . $padding . '">' . $totals . '</div><br>';
                }
                break;
            case "table":
                // Style 2: Tabular format.  Narrow, 2 or 3 column table, good on right side of page
                $params = array(1, $num, 'rcount');
                $content .= '<table style="margin:auto;">
						<tr valign="top">
						<td>' . $stats->commonGivenFemaleTable($params) . '</td>
						<td>' . $stats->commonGivenMaleTable($params) . '</td>';
                $content .= '</tr></table>';
                break;
        }
        $content .= "</div>";
        if ($template) {
            if ($block) {
                require WT_THEME_DIR . 'templates/block_small_temp.php';
            } else {
                require WT_THEME_DIR . 'templates/block_main_temp.php';
            }
        } else {
            return $content;
        }
    }