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

eventsTable() public static method

Print a table of events
public static eventsTable ( integer $startjd, integer $endjd, string $events = 'BIRT MARR DEAT', boolean $only_living = false, string $sort_by = 'anniv' ) : string
$startjd integer
$endjd integer
$events string
$only_living boolean
$sort_by string
return string
    public static function eventsTable($startjd, $endjd, $events = 'BIRT MARR DEAT', $only_living = false, $sort_by = 'anniv')
    {
        global $controller, $WT_TREE;
        $html = '';
        $table_id = 'table-even-' . Uuid::uuid4();
        // lists requires a unique ID in case there are multiple lists per page
        $controller->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL)->addInlineJavascript('
				jQuery.fn.dataTableExt.oSort["text-asc"] = textCompareAsc;
				jQuery.fn.dataTableExt.oSort["text-desc"] = textCompareDesc;
				jQuery("#' . $table_id . '").dataTable({
					dom: "t",
					' . I18N::datatablesI18N() . ',
					autoWidth: false,
					paging: false,
					lengthChange: false,
					filter: false,
					info: true,
					jQueryUI: true,
					sorting: [[ ' . ($sort_by == 'alpha' ? 0 : 1) . ', "asc"]],
					columns: [
						/* Name        */ { type: "text" },
						/* Date        */ { type: "num" },
						/* Anniversary */ { type: "num" },
						/* Event       */ { type: "text" }
					]
				});
			');
        // Did we have any output? Did we skip anything?
        $filter = 0;
        $filtered_events = array();
        foreach (FunctionsDb::getEventsList($startjd, $endjd, $events, $WT_TREE) as $fact) {
            $record = $fact->getParent();
            // Only living people ?
            if ($only_living) {
                if ($record instanceof Individual && $record->isDead()) {
                    $filter++;
                    continue;
                }
                if ($record instanceof Family) {
                    $husb = $record->getHusband();
                    if (is_null($husb) || $husb->isDead()) {
                        $filter++;
                        continue;
                    }
                    $wife = $record->getWife();
                    if (is_null($wife) || $wife->isDead()) {
                        $filter++;
                        continue;
                    }
                }
            }
            $filtered_events[] = $fact;
        }
        if (!empty($filtered_events)) {
            $html .= '<table id="' . $table_id . '" class="width100">';
            $html .= '<thead><tr>';
            $html .= '<th>' . I18N::translate('Record') . '</th>';
            $html .= '<th>' . GedcomTag::getLabel('DATE') . '</th>';
            $html .= '<th><i class="icon-reminder" title="' . I18N::translate('Anniversary') . '"></i></th>';
            $html .= '<th>' . GedcomTag::getLabel('EVEN') . '</th>';
            $html .= '</tr></thead><tbody>';
            foreach ($filtered_events as $n => $fact) {
                $record = $fact->getParent();
                $html .= '<tr>';
                $html .= '<td data-sort="' . Filter::escapeHtml($record->getSortName()) . '">';
                $html .= '<a href="' . $record->getHtmlUrl() . '">' . $record->getFullName() . '</a>';
                if ($record instanceof Individual) {
                    $html .= $record->getSexImage();
                }
                $html .= '</td>';
                $html .= '<td data-sort="' . $fact->getDate()->minimumJulianDay() . '">';
                $html .= $fact->getDate()->display();
                $html .= '</td>';
                $html .= '<td class="center" data-sort="' . $fact->anniv . '">';
                $html .= $fact->anniv ? I18N::number($fact->anniv) : '';
                $html .= '</td>';
                $html .= '<td class="center">' . $fact->getLabel() . '</td>';
                $html .= '</tr>';
            }
            $html .= '</tbody></table>';
        } else {
            if ($endjd === WT_CLIENT_JD) {
                // We're dealing with the Today’s Events block
                if ($filter === 0) {
                    $html .= I18N::translate('No events exist for today.');
                } else {
                    $html .= I18N::translate('No events for living individuals exist for today.');
                }
            } else {
                // We're dealing with the Upcoming Events block
                if ($filter === 0) {
                    if ($endjd === $startjd) {
                        $html .= I18N::translate('No events exist for tomorrow.');
                    } else {
                        $html .= I18N::plural('No events exist for the next %s day.', 'No events exist for the next %s days.', $endjd - $startjd + 1, I18N::number($endjd - $startjd + 1));
                    }
                } else {
                    if ($endjd === $startjd) {
                        $html .= I18N::translate('No events for living individuals exist for tomorrow.');
                    } else {
                        // I18N: translation for %s==1 is unused; it is translated separately as “tomorrow”
                        $html .= I18N::plural('No events for living people exist for the next %s day.', 'No events for living people exist for the next %s days.', $endjd - $startjd + 1, I18N::number($endjd - $startjd + 1));
                    }
                }
            }
        }
        return $html;
    }

Usage Example

Beispiel #1
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 $ctype, $WT_TREE;
     $filter = $this->getBlockSetting($block_id, 'filter', '1');
     $infoStyle = $this->getBlockSetting($block_id, 'infoStyle', 'table');
     $sortStyle = $this->getBlockSetting($block_id, 'sortStyle', 'alpha');
     $block = $this->getBlockSetting($block_id, 'block', '1');
     foreach (array('filter', 'infoStyle', 'sortStyle', 'block') as $name) {
         if (array_key_exists($name, $cfg)) {
             ${$name} = $cfg[$name];
         }
     }
     $todayjd = WT_CLIENT_JD;
     $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('Preferences') . '" href="block_edit.php?block_id=' . $block_id . '&amp;ged=' . $WT_TREE->getNameHtml() . '&amp;ctype=' . $ctype . '"></a>';
     } else {
         $title = '';
     }
     $title .= $this->getTitle();
     $content = '';
     // If we are only showing living individuals, then we don't need to search for DEAT events.
     $tags = $filter ? 'BIRT MARR' : 'BIRT MARR DEAT';
     switch ($infoStyle) {
         case 'list':
             // Output style 1:  Old format, no visible tables, much smaller text. Better suited to right side of page.
             $content .= FunctionsPrintLists::eventsList($todayjd, $todayjd, $tags, $filter, $sortStyle);
             break;
         case 'table':
             // Style 2: New format, tables, big text, etc. Not too good on right side of page
             ob_start();
             $content .= FunctionsPrintLists::eventsTable($todayjd, $todayjd, $tags, $filter, $sortStyle);
             $content .= ob_get_clean();
             break;
     }
     if ($template) {
         if ($block) {
             $class .= ' small_inner_block';
         }
         return Theme::theme()->formatBlock($id, $title, $class, $content);
     } else {
         return $content;
     }
 }