Skip to content

Commit

Permalink
Merge pull request #178 from FriendsOfREDAXO/Media
Browse files Browse the repository at this point in the history
Media as own class
  • Loading branch information
skerbis authored Jun 4, 2024
2 parents 542afaf + aeb0ae8 commit 4a453c4
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 112 deletions.
3 changes: 2 additions & 1 deletion boot.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use FriendsOfRedaxo\QuickNavigation\Button\FavoriteButton;
use FriendsOfRedaxo\QuickNavigation\Button\WatsonButton;
use FriendsOfRedaxo\QuickNavigation\Button\YformButton;
use FriendsOfRedaxo\QuickNavigation\Media\QuickNavigationMedia;
use FriendsOfRedaxo\QuickNavigation\Minibar\ArticleHistoryElement;
use rex;
use rex_addon;
Expand Down Expand Up @@ -75,7 +76,7 @@
return '<div id="quick-navigation-structure" data-url="' . rex_url::currentBackendPage($params + MenuRender::getUrlParams()) . '"></div>' . $ep->getSubject();
});
rex_extension::register('PAGE_TITLE_SHOWN', QuickNavigation::LinkMapQuickNavigation(...));
rex_extension::register('MEDIA_LIST_TOOLBAR', QuickNavigation::MediaHistory(...));
rex_extension::register('MEDIA_LIST_TOOLBAR', QuickNavigationMedia::MediaHistory(...));
}
}

Expand Down
8 changes: 4 additions & 4 deletions lib/QuickNavigation/Button/CategoryButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

class CategoryButton implements ButtonInterface
{
public function renderCategoriesAsList(array $categoriesArray, int $depth = 0): array
public function RenderCategoriesAsList(array $categoriesArray, int $depth = 0): array
{
$listItems = [];
foreach ($categoriesArray as $item) {
Expand All @@ -39,7 +39,7 @@ public function renderCategoriesAsList(array $categoriesArray, int $depth = 0):

if (!empty($item['children'])) {
$fragment = new rex_fragment([
'listItems' => $this->renderCategoriesAsList($item['children'], $depth + 1),
'listItems' => $this->RenderCategoriesAsList($item['children'], $depth + 1),
]);
$listItem .= $fragment->parse('QuickNavigation/List.php');
}
Expand All @@ -59,9 +59,9 @@ public function get(): string
}

$currentClangId = rex_clang::getCurrentId();
$categoriesArray = BuildNavigationArray::generateBackendNavArray($currentClangId, $ignoreOffline, null);
$categoriesArray = BuildNavigationArray::GenerateBackendNavArray($currentClangId, $ignoreOffline, null);

$listItems = $this->renderCategoriesAsList($categoriesArray);
$listItems = $this->RenderCategoriesAsList($categoriesArray);
$placeholder = rex_i18n::msg('quick_navigation_placeholder');
$fragment = new rex_fragment();
$fragment->setVar('id', 'quick-navigation-search');
Expand Down
120 changes: 120 additions & 0 deletions lib/QuickNavigation/Media/QuickNavigationMedia.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?php

namespace FriendsOfRedaxo\QuickNavigation\Media;

use rex;
use rex_be_controller;
use rex_i18n;
use rex_extension;
use rex_extension_point;
use rex_formatter;
use rex_fragment;
use rex_sql;
use rex_string;
use rex_url;

class QuickNavigationMedia
{
/**
* @param rex_extension_point<string> $ep
*/
public static function MediaHistory(rex_extension_point $ep): ?string
{
if (rex_be_controller::getCurrentPagePart(1) == 'mediapool') {
$subject = $ep->getSubject();
$drophistory = self::GenerateMediaHistoryList();
$custom_media_buttons = rex_extension::registerPoint(new rex_extension_point('QUICK_NAVI_CUSTOM_MEDIA', ''));
$button = $custom_media_buttons . '<div class="input-group-btn quickmedia clearfix">' . $drophistory . '</div><select name="rex_file_category"';
return str_replace('<select name="rex_file_category"', $button, $subject);
}

return null;
}

public static function GenerateMediaHistoryList(int $limit = 15): ?string
{
$opener = rex_request('opener_input_field');
if (rex::getUser()->hasPerm('quick_navigation[history]')) {
$file_id = rex_request('file_id', 'int');

// Verwendung der neuen Funktion zur Generierung der quick_file_nav
$quick_file_nav = self::GenerateFileNavigation($file_id, $opener);

$where = '';
if (!rex::getUser()->hasPerm('quick_navigation[all_changes]')) {
$where = 'WHERE updateuser="' . rex::getUser()->getValue('login') . '"';
}

$qry = 'SELECT category_id, id, title, filename, updateuser, updatedate FROM ' . rex::getTable('media') . ' ' . $where . ' ORDER BY updatedate DESC LIMIT ' . $limit;
$datas = rex_sql::factory()->getArray($qry);
$listItems = [];
if (count($datas) === 0) {
$fragment = new rex_fragment();
$listItems[] = $fragment->parse('QuickNavigation/NoResult.php');
}

foreach ($datas as $data) {
$attributes = [
'title' => $data['filename'],
'href' => rex_url::backendPage('mediapool/media', ['opener_input_field' => $opener, 'rex_file_category' => $data['category_id'], 'file_id' => $data['id']]),
];

$date = rex_formatter::intlDateTime(strtotime($data['updatedate']));

$listItems[] = '
<div class="quick-navigation-item-row">
<a' . rex_string::buildAttributes($attributes) . '>
' . ('' !== $data['title'] ? rex_escape($data['title']) : rex_escape($data['filename'])) . '
</a>
</div>
<div class="quick-navigation-item-row">
<div class="quick-navigation-item-info">
<small>
<i class="fa fa-user" aria-hidden="true"></i>
' . rex_escape($data['updateuser']) . ' - ' . $date . '
</small>
</div>
</div>';
}

$fragment = new rex_fragment([
'label' => rex_i18n::msg('quick_navigation_media_history'),
'icon' => 'fa-regular fa-clock',
'listItems' => $listItems,
]);
return $quick_file_nav . $fragment->parse('QuickNavigation/Dropdown.php');
}

return null;
}

protected static function GenerateFileNavigation(int $file_id, string $opener): string
{
$quick_file_nav = '';
if ($file_id !== 0) {
$quick_file = rex_sql::factory();
$quick_file->setQuery('SELECT * FROM ' . rex::getTablePrefix() . 'media WHERE id = ?', [$file_id]);

$quick_file_before = rex_sql::factory();
$quick_file_before->setQuery('SELECT * FROM ' . rex::getTablePrefix() . 'media WHERE category_id = ? AND updatedate > ? ORDER BY updatedate LIMIT 1', [$quick_file->getValue('category_id'), $quick_file->getValue('updatedate')]);

$quick_file_after = rex_sql::factory();
$quick_file_after->setQuery('SELECT * FROM ' . rex::getTablePrefix() . 'media WHERE category_id = ? AND updatedate < ? ORDER BY updatedate DESC LIMIT 1', [$quick_file->getValue('category_id'), $quick_file->getValue('updatedate')]);

// Link für "Zurück" Button, aktiv oder deaktiviert
$backButton = $quick_file_before->getRows() == 1
? '<a class="btn btn-default rex-form-aligned" href="' . rex_url::currentBackendPage(['opener_input_field' => $opener, 'file_id' => $quick_file_before->getValue('id'), 'rex_file_category' => $quick_file->getValue('category_id')]) . '"><span class="fa fa-chevron-left"></span></a>'
: '<a class="btn btn-default rex-form-aligned disabled"><span class="fa fa-chevron-left"></span></a>';

// Link für "Vorwärts" Button, aktiv oder deaktiviert
$forwardButton = $quick_file_after->getRows() == 1
? '<a class="btn btn-default rex-form-aligned" href="' . rex_url::currentBackendPage(['opener_input_field' => $opener, 'file_id' => $quick_file_after->getValue('id'), 'rex_file_category' => $quick_file->getValue('category_id')]) . '"><span class="fa fa-chevron-right"></span></a>'
: '<a class="btn btn-default rex-form-aligned disabled"><span class="fa fa-chevron-right"></span></a>';

// Kombinieren der Buttons mit einem Trennzeichen
$quick_file_nav = '<div class="btn-group">' . $backButton . $forwardButton . '</div>';
}

return $quick_file_nav;
}
}
106 changes: 0 additions & 106 deletions lib/QuickNavigation/QuickNavigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@
use rex_extension_point;
use rex_formatter;
use rex_fragment;
use rex_i18n;
use rex_sql;
use rex_string;
use rex_url;

use function count;

class QuickNavigation
{
/**
Expand Down Expand Up @@ -46,109 +43,6 @@ public static function LinkMapQuickNavigation(rex_extension_point $ep): ?string

return null;
}

/**
* @param rex_extension_point<string> $ep
*/
public static function MediaHistory(rex_extension_point $ep): ?string
{
if (rex_be_controller::getCurrentPagePart(1) == 'mediapool') {
$subject = $ep->getSubject();
$drophistory = self::GenerateMediaHistoryList();
$custom_media_buttons = rex_extension::registerPoint(new rex_extension_point('QUICK_NAVI_CUSTOM_MEDIA', ''));
$button = $custom_media_buttons . '<div class="input-group-btn quickmedia clearfix">' . $drophistory . '</div><select name="rex_file_category"';
return str_replace('<select name="rex_file_category"', $button, $subject);
}

return null;
}

public static function GenerateMediaHistoryList(int $limit = 15): ?string
{
$opener = rex_request('opener_input_field');
if (rex::getUser()->hasPerm('quick_navigation[history]')) {
$file_id = rex_request('file_id', 'int');

// Verwendung der neuen Funktion zur Generierung der quick_file_nav
$quick_file_nav = self::GenerateFileNavigation($file_id, $opener);

$where = '';
if (!rex::getUser()->hasPerm('quick_navigation[all_changes]')) {
$where = 'WHERE updateuser="' . rex::getUser()->getValue('login') . '"';
}

$qry = 'SELECT category_id, id, title, filename, updateuser, updatedate FROM ' . rex::getTable('media') . ' ' . $where . ' ORDER BY updatedate DESC LIMIT ' . $limit;
$datas = rex_sql::factory()->getArray($qry);
$listItems = [];
if (count($datas) === 0) {
$fragment = new rex_fragment();
$listItems[] = $fragment->parse('QuickNavigation/NoResult.php');
}

foreach ($datas as $data) {
$attributes = [
'title' => $data['filename'],
'href' => rex_url::backendPage('mediapool/media', ['opener_input_field' => $opener, 'rex_file_category' => $data['category_id'], 'file_id' => $data['id']]),
];

$date = rex_formatter::intlDateTime(strtotime($data['updatedate']));

$listItems[] = '
<div class="quick-navigation-item-row">
<a' . rex_string::buildAttributes($attributes). '>
' . ('' !== $data['title'] ? rex_escape($data['title']) : rex_escape($data['filename'])) . '
</a>
</div>
<div class="quick-navigation-item-row">
<div class="quick-navigation-item-info">
<small>
<i class="fa fa-user" aria-hidden="true"></i>
' . rex_escape($data['updateuser']) . ' - ' . $date . '
</small>
</div>
</div>';
}

$fragment = new rex_fragment([
'label' => rex_i18n::msg('quick_navigation_media_history'),
'icon' => 'fa-regular fa-clock',
'listItems' => $listItems,
]);
return $quick_file_nav . $fragment->parse('QuickNavigation/Dropdown.php');
}

return null;
}

protected static function GenerateFileNavigation(int $file_id, string $opener): string
{
$quick_file_nav = '';
if ($file_id !== 0) {
$quick_file = rex_sql::factory();
$quick_file->setQuery('SELECT * FROM ' . rex::getTablePrefix() . 'media WHERE id = ?', [$file_id]);

$quick_file_before = rex_sql::factory();
$quick_file_before->setQuery('SELECT * FROM ' . rex::getTablePrefix() . 'media WHERE category_id = ? AND updatedate > ? ORDER BY updatedate LIMIT 1', [$quick_file->getValue('category_id'), $quick_file->getValue('updatedate')]);

$quick_file_after = rex_sql::factory();
$quick_file_after->setQuery('SELECT * FROM ' . rex::getTablePrefix() . 'media WHERE category_id = ? AND updatedate < ? ORDER BY updatedate DESC LIMIT 1', [$quick_file->getValue('category_id'), $quick_file->getValue('updatedate')]);

// Link für "Zurück" Button, aktiv oder deaktiviert
$backButton = $quick_file_before->getRows() == 1
? '<a class="btn btn-default rex-form-aligned" href="' . rex_url::currentBackendPage(['opener_input_field' => $opener, 'file_id' => $quick_file_before->getValue('id'), 'rex_file_category' => $quick_file->getValue('category_id')]) . '"><span class="fa fa-chevron-left"></span></a>'
: '<a class="btn btn-default rex-form-aligned disabled"><span class="fa fa-chevron-left"></span></a>';

// Link für "Vorwärts" Button, aktiv oder deaktiviert
$forwardButton = $quick_file_after->getRows() == 1
? '<a class="btn btn-default rex-form-aligned" href="' . rex_url::currentBackendPage(['opener_input_field' => $opener, 'file_id' => $quick_file_after->getValue('id'), 'rex_file_category' => $quick_file->getValue('category_id')]) . '"><span class="fa fa-chevron-right"></span></a>'
: '<a class="btn btn-default rex-form-aligned disabled"><span class="fa fa-chevron-right"></span></a>';

// Kombinieren der Buttons mit einem Trennzeichen
$quick_file_nav = '<div class="btn-group">' . $backButton . $forwardButton . '</div>';
}

return $quick_file_nav;
}

public static function get(): string
{
Expand Down
2 changes: 1 addition & 1 deletion lib/QuickNavigation/Utiliy/BuildNavigationArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class BuildNavigationArray
/**
* @return array<mixed>
*/
public static function generateBackendNavArray(int $clangId = null, bool $ignoreOffline = true, int $parentId = null, bool $includeHome = true): array
public static function GenerateBackendNavArray(int $clangId = null, bool $ignoreOffline = true, int $parentId = null, bool $includeHome = true): array
{
$user = rex::getUser();
if ($clangId === null) {
Expand Down

0 comments on commit 4a453c4

Please sign in to comment.