fisharebest/webtrees

View on GitHub
resources/views/modules/gedcom_news/list.phtml

Summary

Maintainability
Test Coverage
<?php

declare(strict_types=1);

use Fisharebest\Webtrees\Auth;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Tree;
use Illuminate\Support\Collection;

/**
 * @var Collection<int,object> $articles
 * @var int                    $block_id
 * @var int                    $limit
 * @var Tree                   $tree
 */

?>

<?php if ($articles->isEmpty()) : ?>
    <?= I18N::translate('No news articles have been submitted.') ?>
<?php endif ?>

<?php foreach ($articles as $n => $article) : ?>
    <?php if ($n === $limit && count($articles) > $limit) : ?>
    <p>
        <button class="btn btn-sm btn-secondary" data-bs-toggle="collapse" data-bs-target="#more-news-<?= e($block_id) ?>" role="button" aria-expanded="false" aria-controls="more-news-<?= e($block_id) ?>">
            <?= view('icons/add') ?>
            <?= I18N::translate('show more') ?>
        </button>
    </p>
<div class="collapse" id="more-news-<?= e($block_id) ?>">
    <?php endif ?>

    <div class="news_box">
        <div class="news_title" dir="auto"><?= $article->subject ?></div>
        <div class="news_date"><?= view('components/datetime', ['timestamp' => $article->updated]) ?></div>
        <div dir="auto"><?= $article->body ?></div>

        <?php if (Auth::isManager($tree)) : ?>
            <hr>
            <form method="post" action="<?= e(route('module', ['module' => 'gedcom_news', 'action' => 'DeleteNews', 'news_id' => $article->news_id, 'tree' => $tree->name()])) ?>">
                <a class="btn btn-link" href="<?= e(route('module', ['module' => 'gedcom_news', 'action' => 'EditNews', 'news_id' => $article->news_id, 'tree' => $tree->name()])) ?>">
                    <?= I18N::translate('Edit') ?>
                </a>
                |
                <button class="btn btn-link" type="submit" data-wt-confirm="<?= I18N::translate('Are you sure you want to delete ā€œ%sā€?', e($article->subject)) ?>" onclick="return confirm(this.dataset.confirm);">
                    <?= I18N::translate('Delete') ?>
                </button>

                <?= csrf_field() ?>
            </form>
        <?php endif ?>
    </div>
<?php endforeach ?>

    <?php if (count($articles) > $limit) : ?>
</div>
    <?php endif ?>

<?php if (Auth::isManager($tree)) : ?>
    <p>
        <a class="btn btn-link" href="<?= e(route('module', ['module' => 'gedcom_news', 'action' => 'EditNews', 'tree' => $tree->name()])) ?>">
            <?= I18N::translate('Add a news article') ?>
        </a>
    </p>
<?php endif ?>