-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50 from FriendsOfREDAXO/newsmanager
Migrationshilfe - Fragmente und Beispiel
- Loading branch information
Showing
11 changed files
with
335 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/.idea | ||
/composer.lock | ||
/.php-cs-fixer.cache | ||
/vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Beispiel und Fragmente | ||
|
||
Wurde Neues mit dem URL-Addon installiert und entsprechend der [Anleitung](/redaxo/index.php?page=neues/docs&mdfile=06_url) konfiguriert, kannst du dir eine Beispielvorlage für die Ausgabe im Template ausgeben lassen. | ||
|
||
Die Ausgabe erfolgt über Fragment-Dateien. Diese findest du im Ordner `fragments/neues`. Die Fragmente können nach Belieben angepasst werden. Weitere Informationen zu Fragmenten findest du in der [Redaxo-Dokumentation](https://redaxo.org/doku/main/fragmente). | ||
|
||
Im Template, in dem du die Ausgabe von Neues realisieren möchtest, fügst du folgenden Code ein: | ||
|
||
```php | ||
<?php | ||
// Voraussetzung: URL-Addon ist installiert und konfiguriert | ||
$manager = Url\Url::resolveCurrent(); | ||
|
||
if($manager) { | ||
// Ausgabe eines einzelnen Datensatzes | ||
$postId = $manager->getDatasetId(); | ||
echo neues::getEntry($postId); | ||
} else { | ||
// Ausgabe einer Liste | ||
echo neues::getList(); | ||
} | ||
?> | ||
``` | ||
|
||
|
||
## Methoden | ||
|
||
### getEntry(int $postId) | ||
|
||
Gibt einen einzelnen Datensatz aus. Benötigt wird die ID des Datensatzes. | ||
|
||
```php | ||
$entry = neues::getEntry(1); | ||
``` | ||
|
||
### getList(int $rowsPerPage = 10, string $pageCursor = 'page') | ||
|
||
Gibt eine Liste aller Datensätze als HTML aus. | ||
|
||
- rowsPerPage: Anzahl der Datensätze pro Seite. Standard: `10` | ||
- pageCursor: Name des GET-Parameters, der die aktuelle Seite enthält. Standard: `page` | ||
|
||
|
||
```php | ||
$list = neues::getList(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
/** @var rex_fragment $this */ | ||
|
||
/** @var neues_entry $post */ | ||
$post = $this->getVar('post'); | ||
?> | ||
|
||
<div class="container"> | ||
<div class="row justify-content-center"> | ||
<div class="col-md-8"> | ||
<article class="post"> | ||
|
||
<!-- Headline --> | ||
<?php if ('' !== $post->getName()) : ?> | ||
<h1 class="mb-2 fw-bold"><?= htmlspecialchars($post->getName()) ?></h1> | ||
<?php endif ?> | ||
|
||
<!-- Date --> | ||
<?php if ($post->getPublishDate()) : ?> | ||
<p class="blog-post-meta"> | ||
<?= $post->getFormattedPublishDate() ?> | ||
|
||
<!-- Author --> | ||
<?php if ($post->getAuthor()) : ?> | ||
<?php if ($post->getAuthor()->getName()) : ?> | ||
von <span><?= htmlspecialchars($post->getAuthor()->getName()) ?></span> | ||
<?php elseif($post->getAuthor()->getNickname()): ?> | ||
von <span><?= htmlspecialchars($post->getAuthor()->getNickname()) ?></span> | ||
<?php endif ?> | ||
<?php endif ?> | ||
|
||
</p> | ||
<?php endif ?> | ||
|
||
<!-- Post Image --> | ||
<?php if ('' !== $post->getImage()) : ?> | ||
<?php | ||
$media = rex_media::get($post->getImage()); | ||
?> | ||
<?php if ($media) : ?> | ||
<div class="ratio ratio-16x9 mb-3 mt-4"> | ||
<img src="<?= $media->getUrl() ?>" alt="<?= htmlspecialchars($media->getTitle()) ?>" class="h-100 object-fit-cover" width="200"/> | ||
</div> | ||
<?php endif ?> | ||
<?php endif ?> | ||
|
||
|
||
<!-- Post Content --> | ||
<?php if ($post->getDescription()) : ?> | ||
<div class="mt-5"> | ||
<?= $post->getDescription() ?> | ||
</div> | ||
<?php endif ?> | ||
|
||
<!-- Post Images/Gallery --> | ||
<?php if ($post->getImages()) : ?> | ||
<div class="mt-5 row g-3"> | ||
<?php foreach ($post->getImages() as $image) : ?> | ||
<?php | ||
$media = rex_media::get($image); | ||
$mediaUrl = rex_media_manager::getUrl('rex_media_medium', $image); | ||
?> | ||
<?php if ($media) : ?> | ||
<div class="col-md-4"> | ||
<a href="<?= $media->getUrl() ?>" class="d-inline-flex ratio ratio-16x9 h-100"> | ||
<img src="<?= $mediaUrl ?>" alt="<?= htmlspecialchars($media->getTitle()) ?>" class="h-100 object-fit-cover" width="200"/> | ||
</a> | ||
</div> | ||
<?php endif ?> | ||
<?php endforeach ?> | ||
</div> | ||
<?php endif ?> | ||
|
||
</article> | ||
|
||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
/** @var rex_fragment $this */ | ||
|
||
/** @var neues_entry $post */ | ||
$post = $this->getVar('post'); | ||
?> | ||
|
||
<div class="row g-0 border rounded overflow-hidden flex-md-row mb-4 shadow-sm h-md-250 position-relative h-100"> | ||
<div class="col p-4 d-flex flex-column position-static"> | ||
|
||
<!-- Categories --> | ||
<?php if ($post->getCategories()) : ?> | ||
<p class="d-inline-block mb-2 text-primary-emphasis"> | ||
<?= htmlspecialchars(implode(', ', $post->getCategories()->toKeyValue('id', 'name'))) ?> | ||
</p> | ||
<?php endif ?> | ||
|
||
<!-- Title --> | ||
<?php if ('' !== $post->getName()) : ?> | ||
<h3 class="mb-0"> | ||
<a href="<?= rex_getUrl('', '', ['neues-entry-id' => $post->getId()]) ?>" class="stretched-link"><?= $post->getName() ?></a> | ||
</h3> | ||
<?php endif ?> | ||
|
||
<!-- Date --> | ||
<?php if ($post->getPublishDate()) : ?> | ||
<div class="mb-2 text-body-secondary"> | ||
<?= $post->getFormattedPublishDate() ?> | ||
</div> | ||
<?php endif ?> | ||
|
||
<!-- Teaser --> | ||
<?php if ('' !== $post->getTeaser()) : ?> | ||
<p class="card-text mb-0"> | ||
<?= htmlspecialchars($post->getTeaser()) ?> | ||
</p> | ||
<?php endif ?> | ||
</div> | ||
|
||
<!-- Image --> | ||
<?php if ('' !== $post->getImage()) : ?> | ||
<?php | ||
$media = rex_media::get($post->getImage()); | ||
$mediaUrl = rex_media_manager::getUrl('rex_media_medium', $post->getImage()); | ||
?> | ||
<?php if ($media) : ?> | ||
<div class="col-auto d-none d-lg-block"> | ||
<img src="<?= $mediaUrl ?>" alt="<?= htmlspecialchars($media->getTitle()) ?>" class="h-100 object-fit-cover" width="200"/> | ||
</div> | ||
<?php endif ?> | ||
<?php endif ?> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
/** @var rex_fragment $this */ | ||
|
||
/** @var rex_pager $pager */ | ||
$pager = $this->getVar('pager'); | ||
|
||
/** @var rex_yform_manager_collection $posts */ | ||
$posts = $this->getVar('posts'); | ||
?> | ||
|
||
<!-- Entry list --> | ||
<div class="container"> | ||
<div class="row row-cols-1 row-cols-md-2 g-3"> | ||
<?php foreach ($posts as $post) : ?> | ||
<div class="col"> | ||
<?php | ||
$fragment = new rex_fragment(); | ||
$fragment->setVar('post', $post); | ||
echo $fragment->parse('neues/list-entry.php'); | ||
?> | ||
</div> | ||
<?php endforeach ?> | ||
</div> | ||
</div> | ||
|
||
<!-- Pagination --> | ||
<?php | ||
$fragment = new rex_fragment(); | ||
$fragment->setVar('pager', $pager); | ||
echo $fragment->parse('neues/pagination.php'); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?php | ||
/** @var rex_fragment $this */ | ||
|
||
/** @var rex_pager $pager */ | ||
$pager = $this->getVar('pager'); | ||
|
||
$currentPage = $pager->getCurrentPage(); | ||
$prevPage = $pager->getPrevPage(); | ||
$firsPage = $pager->getFirstPage(); | ||
$nextPage = $pager->getNextPage(); | ||
$lastPage = $pager->getLastPage(); | ||
$articleLink = rex_article::getCurrent()->getUrl(); | ||
?> | ||
|
||
<?php | ||
/** | ||
* The pagination snippet is based on the Bootstrap 5 pagination component. | ||
* See https://getbootstrap.com/docs/5.2/components/pagination/. | ||
* | ||
* The pagination will only be displayed if there is more than one page. | ||
*/ | ||
?> | ||
|
||
<?php if ($pager->getPageCount() > 1) : $page = 0 ?> | ||
<nav class="mt-5"> | ||
<ul class="pagination justify-content-center"> | ||
<!-- Previous --> | ||
<li class="page-item <?= $prevPage === $currentPage ? 'disabled' : '' ?>"> | ||
<?php if (0 === $prevPage) : ?> | ||
<a class="page-link d-inline-flex align-items-center h-100" href="<?= $prevPage === $currentPage ? '#' : $articleLink ?>"> | ||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"> | ||
<path fill-rule="evenodd" d="M11.354 1.646a.5.5 0 0 1 0 .708L5.707 8l5.647 5.646a.5.5 0 0 1-.708.708l-6-6a.5.5 0 0 1 0-.708l6-6a.5.5 0 0 1 .708 0z"/> | ||
</svg> | ||
</a> | ||
<?php else: ?> | ||
<a class="page-link d-inline-flex align-items-center h-100" href="<?= $prevPage === $currentPage ? '#' : '?page=' . $prevPage ?>"> | ||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"> | ||
<path fill-rule="evenodd" d="M11.354 1.646a.5.5 0 0 1 0 .708L5.707 8l5.647 5.646a.5.5 0 0 1-.708.708l-6-6a.5.5 0 0 1 0-.708l6-6a.5.5 0 0 1 .708 0z"/> | ||
</svg> | ||
</a> | ||
<?php endif ?> | ||
</li> | ||
|
||
<!-- Pages --> | ||
<?php for($i = 0; $i < $pager->getPageCount(); ++$i): ?> | ||
<li class="page-item"> | ||
<?php if (0 === $page) : ?> | ||
<a class="page-link <?= $currentPage === $i ? 'active' : '' ?>" | ||
href="<?= $articleLink ?>"> | ||
<?= $page + 1 ?> | ||
</a> | ||
<?php else: ?> | ||
<a class="page-link <?= $currentPage === $i ? 'active' : '' ?>" | ||
href="?page=<?= $page ?>"> | ||
<?= $page + 1 ?> | ||
</a> | ||
<?php endif ?> | ||
</li> | ||
<?php $page = $i + 1; endfor ?> | ||
|
||
<!-- Next --> | ||
<li class="page-item <?= $nextPage === $currentPage ? 'disabled' : '' ?>"> | ||
<a class="page-link d-inline-flex align-items-center h-100" | ||
href="<?= $nextPage === $currentPage ? '#' : '?page=' . $nextPage ?>"> | ||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"> | ||
<path fill-rule="evenodd" d="M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708z"/> | ||
</svg> | ||
</a> | ||
</li> | ||
</ul> | ||
</nav> | ||
<?php endif ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,49 @@ | ||
<?php | ||
|
||
class neues {} | ||
class neues | ||
{ | ||
/** | ||
* Gibt eine HTML-Liste mit den Einträgen zurück. | ||
* Diese Liste ist paginiert. | ||
* Die Einträge werden nach dem Veröffentlichungsdatum absteigend sortiert. | ||
* Der Output wird über ein Fragment erzeugt, diese können nach Belieben angepasst werden. | ||
* Die Beispiel-Fragmente bauen auf Bootstrap 5 auf. | ||
* | ||
* @param int $rowsPerPage Anzahl der Einträge pro Seite | ||
* @param string $pageCursor Name des GET-Parameters für die Seitennummer | ||
* @return string HTML-Liste mit den Einträgen | ||
* | ||
* Beispiel / Example: | ||
* echo neues::getList(2); | ||
*/ | ||
public static function getList(int $rowsPerPage = 10, string $pageCursor = 'page'): string | ||
{ | ||
$query = neues_entry::query()->orderBy('publishdate', 'desc'); | ||
$pager = new rex_pager($rowsPerPage, $pageCursor); | ||
$posts = $query->paginate($pager); | ||
|
||
$fragment = new rex_fragment(); | ||
$fragment->setVar('posts', $posts); | ||
$fragment->setVar('pager', $pager); | ||
return $fragment->parse('neues/list.php'); | ||
} | ||
|
||
/** | ||
* Gibt einen einzelnen Eintrag zurück. | ||
* Der Output wird über ein Fragment erzeugt, diese können nach Belieben angepasst werden. | ||
* Die Beispiel-Fragmente bauen auf Bootstrap 5 auf. | ||
* | ||
* @param int $postId ID des Eintrags | ||
* @return string HTML des Eintrags | ||
* | ||
* Beispiel / Example: | ||
* echo neues::getEntry(2); | ||
*/ | ||
public static function getEntry(int $postId): string | ||
{ | ||
$post = neues_entry::get($postId); | ||
$fragment = new rex_fragment(); | ||
$fragment->setVar('post', $post); | ||
return $fragment->parse('neues/entry.php'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters