Merge pull request #8150 from nupplaphil/task/prepare_enotify

Prepare Model\Notify for include/enotify.php (Part 1)
This commit is contained in:
Hypolite Petovan 2020-01-22 14:18:59 -05:00 committed by GitHub
commit 3c1f174c7f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 78 additions and 68 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(DI::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' => DI::l10n()->t(PRINT_TYPES[$type]),
'url' => 'notifications/' . $url,
'sel' => (($selected == $url) ? 'active' : ''),
'id' => $type . '-tab',
'accesskey' => ACCESS_KEYS[$type],
];
}
return $tabs;
}

View file

@ -3,11 +3,7 @@
namespace Friendica\Collection;
use Friendica\BaseCollection;
use Friendica\Model\Introduction;
/**
* @property Introduction[] $models
*/
class Introductions extends BaseCollection
{

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
*

View file

@ -10,6 +10,12 @@ use Friendica\DI;
/**
* functions for interacting with the permission set of an object (item, photo, event, ...)
*
* @property int uid
* @property string allow_cid
* @property string allow_gid
* @property string deny_cid
* @property string deny_gid
*/
class PermissionSet extends BaseModel
{

View file

@ -2,15 +2,14 @@
namespace Friendica\Repository;
use Friendica\BaseModel;
use Friendica\BaseRepository;
use Friendica\Collection;
use Friendica\Core\L10n;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Database\Database;
use Friendica\Model;
use Friendica\Model\Group;
use Friendica\Network\HTTPException;
use Friendica\Util\ACLFormatter;
use Psr\Log\LoggerInterface;
class PermissionSet extends BaseRepository
{
@ -20,6 +19,16 @@ class PermissionSet extends BaseRepository
protected static $collection_class = Collection\PermissionSets::class;
/** @var ACLFormatter */
private $aclFormatter;
public function __construct(Database $dba, LoggerInterface $logger, ACLFormatter $aclFormatter)
{
parent::__construct($dba, $logger);
$this->aclFormatter = $aclFormatter;
}
/**
* @param array $data
* @return Model\PermissionSet
@ -93,12 +102,10 @@ class PermissionSet extends BaseRepository
string $deny_cid = null,
string $deny_gid = null
) {
$ACLFormatter = DI::aclFormatter();
$allow_cid = $ACLFormatter->sanitize($allow_cid);
$allow_gid = $ACLFormatter->sanitize($allow_gid);
$deny_cid = $ACLFormatter->sanitize($deny_cid);
$deny_gid = $ACLFormatter->sanitize($deny_gid);
$allow_cid = $this->aclFormatter->sanitize($allow_cid);
$allow_gid = $this->aclFormatter->sanitize($allow_gid);
$deny_cid = $this->aclFormatter->sanitize($deny_cid);
$deny_gid = $this->aclFormatter->sanitize($deny_gid);
// Public permission
if (!$allow_cid && !$allow_gid && !$deny_cid && !$deny_gid) {
@ -134,7 +141,7 @@ class PermissionSet extends BaseRepository
public function selectByContactId($contact_id, $uid)
{
$groups = [];
if (DBA::exists('contact', ['id' => $contact_id, 'uid' => $uid, 'blocked' => false])) {
if ($this->dba->exists('contact', ['id' => $contact_id, 'uid' => $uid, 'blocked' => false])) {
$groups = Group::getIdsByContactId($contact_id);
}