Move "Notify::getTab()" to notification module since it's presentation layer logic

This commit is contained in:
Philipp Holzer 2020-01-19 23:17:52 +01:00
parent 4f29e4c4a7
commit 26d6afd27f
No known key found for this signature in database
GPG key ID: D8365C3D36B77D90
2 changed files with 54 additions and 53 deletions

View file

@ -13,8 +13,36 @@ use Friendica\Core\Renderer;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Notify;
use Friendica\Module\Security\Login;
/** @var array Array of URL parameters */
const URL_TYPES = [
Notify::NETWORK => 'network',
Notify::SYSTEM => 'system',
Notify::HOME => 'home',
Notify::PERSONAL => 'personal',
Notify::INTRO => 'intros',
];
/** @var array Array of the allowed notifies and their printable name */
const PRINT_TYPES = [
Notify::NETWORK => 'Network',
Notify::SYSTEM => 'System',
Notify::HOME => 'Home',
Notify::PERSONAL => 'Personal',
Notify::INTRO => 'Introductions',
];
/** @var array The array of access keys for notify pages */
const ACCESS_KEYS = [
Notify::NETWORK => 'w',
Notify::SYSTEM => 'y',
Notify::HOME => 'h',
Notify::PERSONAL => 'r',
Notify::INTRO => 'i',
];
function notifications_post(App $a)
{
if (!local_user()) {
@ -61,7 +89,7 @@ function notifications_content(App $a)
$o = '';
// Get the nav tabs for the notification pages
$tabs = $nm->getTabs();
$tabs = getTabs($this->args->get(1, ''));
$notif_content = [];
$notif_nocontent = '';
@ -320,3 +348,28 @@ function notifications_content(App $a)
return $o;
}
/**
* List of pages for the Notifications TabBar
*
* @param string $selected The selected notification tab
*
* @return array with with notifications TabBar data
* @throws Exception
*/
function getTabs(string $selected = '')
{
$tabs = [];
foreach (URL_TYPES as $type => $url) {
$tabs[] = [
'label' => $this->l10n->t(PRINT_TYPES[$type]),
'url' => 'notifications/' . $url,
'sel' => (($selected == $url) ? 'active' : ''),
'id' => $type . '-tab',
'accesskey' => ACCESS_KEYS[$type],
];
}
return $tabs;
}

View file

@ -36,33 +36,6 @@ final class Notify
const HOME = 'home';
const INTRO = 'intro';
/** @var array Array of URL parameters */
const URL_TYPES = [
self::NETWORK => 'network',
self::SYSTEM => 'system',
self::HOME => 'home',
self::PERSONAL => 'personal',
self::INTRO => 'intros',
];
/** @var array Array of the allowed notifies and their printable name */
const PRINT_TYPES = [
self::NETWORK => 'Network',
self::SYSTEM => 'System',
self::HOME => 'Home',
self::PERSONAL => 'Personal',
self::INTRO => 'Introductions',
];
/** @var array The array of access keys for notify pages */
const ACCESS_KEYS = [
self::NETWORK => 'w',
self::SYSTEM => 'y',
self::HOME => 'h',
self::PERSONAL => 'r',
self::INTRO => 'i',
];
/** @var Database */
private $dba;
/** @var L10n */
@ -196,31 +169,6 @@ final class Notify
return $this->dba->update('notify', ['seen' => $seen], ['uid' => local_user()]);
}
/**
* List of pages for the Notifications TabBar
*
* @return array with with notifications TabBar data
* @throws Exception
*/
public function getTabs()
{
$selected = $this->args->get(1, '');
$tabs = [];
foreach (self::URL_TYPES as $type => $url) {
$tabs[] = [
'label' => $this->l10n->t(self::PRINT_TYPES[$type]),
'url' => 'notifications/' . $url,
'sel' => (($selected == $url) ? 'active' : ''),
'id' => $type . '-tab',
'accesskey' => self::ACCESS_KEYS[$type],
];
}
return $tabs;
}
/**
* Format the notification query in an usable array
*