Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/treetrek.git
<?php
require_once __DIR__ . '/BasePage.php';
require_once __DIR__ . '/../model/Tag.php';
require_once __DIR__ . '/../render/HtmlTagRenderer.php';

class TagsPage extends BasePage {
  private $currentRepo;
  private $git;

  public function __construct(
    array $repositories,
    array $currentRepo,
    Git $git
  ) {
    parent::__construct(
      $repositories,
      $currentRepo['name'] . ' - Tags'
    );

    $this->currentRepo = $currentRepo;
    $this->git         = $git;
  }

  public function render() {
    $this->renderLayout( function() {
      $this->renderBreadcrumbs( $this->currentRepo, ['Tags'] );
      echo '<h2>Tags</h2>';

      $tags = [];
      $this->git->eachTag( function( Tag $tag ) use ( &$tags ) {
        $tags[] = $tag;
      } );

      usort( $tags, function( Tag $a, Tag $b ) {
        return $a->compare( $b );
      } );

      if( empty( $tags ) ) {
        echo '<p>No tags found.</p>';
      } else {
        $renderer = new HtmlTagRenderer(
          $this->currentRepo['safe_name']
        );

        echo '<table class="tag-table">';
        echo '<thead>';
        echo '<tr>';
        echo '<th>Name</th><th>Message</th><th>Author</th>';
        echo '<th class="tag-age-header">Age</th>';
        echo '<th class="tag-commit-header">Commit</th>';
        echo '</tr>';
        echo '</thead>';
        echo '<tbody>';

        $count = count( $tags );
        for( $i = 0; $i < $count; $i++ ) {
          $tag     = $tags[$i];
          $prevTag = $tags[$i + 1] ?? null;
          $tag->render( $renderer, $prevTag );
        }

        echo '</tbody>';
        echo '</table>';
      }
    }, $this->currentRepo );
  }
}