eliminate private classes (OC)
Signed-off-by: dartcafe <github@dartcafe.de>
This commit is contained in:
Родитель
052200f28c
Коммит
f11cd9d4a3
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
|
||||
*
|
||||
|
@ -25,7 +26,6 @@
|
|||
namespace OCA\Polls\AppInfo;
|
||||
|
||||
use Closure;
|
||||
// use OC\EventDispatcher\SymfonyAdapter;
|
||||
use OCP\AppFramework\App;
|
||||
use OCP\AppFramework\Bootstrap\IBootContext;
|
||||
use OCP\AppFramework\Bootstrap\IBootstrap;
|
||||
|
@ -34,6 +34,7 @@ use OCP\Collaboration\Resources\IProviderManager;
|
|||
use OCP\Notification\IManager as NotificationManager;
|
||||
use OCP\Group\Events\GroupDeletedEvent;
|
||||
use OCP\User\Events\UserDeletedEvent;
|
||||
use OCP\EventDispatcher\IEventDispatcher;
|
||||
use OCP\Util;
|
||||
use OCA\Polls\Event\CommentAddEvent;
|
||||
use OCA\Polls\Event\CommentDeleteEvent;
|
||||
|
@ -70,21 +71,25 @@ use OCA\Polls\Listener\VoteListener;
|
|||
use OCA\Polls\Provider\ResourceProvider;
|
||||
use OCA\Polls\Provider\SearchProvider;
|
||||
|
||||
class Application extends App implements IBootstrap {
|
||||
class Application extends App implements IBootstrap
|
||||
{
|
||||
|
||||
/** @var string */
|
||||
public const APP_ID = 'polls';
|
||||
|
||||
public function __construct(array $urlParams = []) {
|
||||
public function __construct(array $urlParams = [])
|
||||
{
|
||||
parent::__construct(self::APP_ID, $urlParams);
|
||||
}
|
||||
|
||||
public function boot(IBootContext $context): void {
|
||||
public function boot(IBootContext $context): void
|
||||
{
|
||||
$context->injectFn(Closure::fromCallable([$this, 'registerNotifications']));
|
||||
$context->injectFn(Closure::fromCallable([$this, 'registerCollaborationResources']));
|
||||
}
|
||||
|
||||
public function register(IRegistrationContext $context): void {
|
||||
public function register(IRegistrationContext $context): void
|
||||
{
|
||||
include_once __DIR__ . '/../../vendor/autoload.php';
|
||||
|
||||
$context->registerEventListener(CommentAddEvent::class, CommentListener::class);
|
||||
|
@ -116,13 +121,14 @@ class Application extends App implements IBootstrap {
|
|||
$context->registerSearchProvider(SearchProvider::class);
|
||||
}
|
||||
|
||||
public function registerNotifications(NotificationManager $notificationManager): void {
|
||||
public function registerNotifications(NotificationManager $notificationManager): void
|
||||
{
|
||||
$notificationManager->registerNotifierService(Notifier::class);
|
||||
}
|
||||
protected function registerCollaborationResources(IProviderManager $resourceManager): void {
|
||||
protected function registerCollaborationResources(IProviderManager $resourceManager, IEventDispatcher $eventDispatcher): void
|
||||
{
|
||||
$resourceManager->registerResourceProvider(ResourceProvider::class);
|
||||
|
||||
\OC::$server->getEventDispatcher()->addListener('\OCP\Collaboration\Resources::loadAdditionalScripts', static function () {
|
||||
$eventDispatcher->addListener('\OCP\Collaboration\Resources::loadAdditionalScripts', static function () {
|
||||
Util::addScript(self::APP_ID, 'polls-collections');
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2021 René Gieling <github@dartcafe.de>
|
||||
*
|
||||
|
@ -23,7 +24,7 @@
|
|||
|
||||
namespace OCA\Polls\Helper;
|
||||
|
||||
use OCA\Polls\AppInfo\Application;
|
||||
use OCP\AppFramework\App;
|
||||
use OCA\Polls\Db\Poll;
|
||||
use OCA\Polls\Db\PollMapper;
|
||||
use OCA\Polls\Db\Share;
|
||||
|
@ -32,29 +33,36 @@ use OCP\App\IAppManager;
|
|||
use OCP\L10N\IFactory;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
abstract class Container {
|
||||
public static function getContainer() : ContainerInterface {
|
||||
$app = \OC::$server->query(Application::class);
|
||||
abstract class Container
|
||||
{
|
||||
public static function getContainer(): ContainerInterface
|
||||
{
|
||||
$app = new App('polls');
|
||||
return $app->getContainer();
|
||||
}
|
||||
|
||||
public static function queryClass(string $class) {
|
||||
public static function queryClass(string $class)
|
||||
{
|
||||
return self::getContainer()->get($class);
|
||||
}
|
||||
|
||||
public static function queryPoll(int $pollId) : Poll {
|
||||
public static function queryPoll(int $pollId): Poll
|
||||
{
|
||||
return self::queryClass(PollMapper::class)->find($pollId);
|
||||
}
|
||||
|
||||
public static function findShare(int $pollId, string $userId) : Share {
|
||||
public static function findShare(int $pollId, string $userId): Share
|
||||
{
|
||||
return self::queryClass(ShareMapper::class)
|
||||
->findByPollAndUser($pollId, $userId);
|
||||
}
|
||||
|
||||
public static function getL10N(string $lang = null) {
|
||||
public static function getL10N(string $lang = null)
|
||||
{
|
||||
return self::queryClass(IFactory::class)->get('polls', $lang);
|
||||
}
|
||||
public static function isAppEnabled(string $app) : bool {
|
||||
public static function isAppEnabled(string $app): bool
|
||||
{
|
||||
return self::queryClass(IAppManager::class)->isEnabledForUser($app);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @copyright Copyright (c) 2017 Vinzenz Rosenkranz <vinzenz.rosenkranz@gmail.com>
|
||||
*
|
||||
|
@ -36,9 +37,10 @@ use OCA\Polls\Db\OptionMapper;
|
|||
use OCA\Polls\Db\Preferences;
|
||||
use OCA\Polls\Model\UserGroup\CurrentUser;
|
||||
|
||||
class CalendarService {
|
||||
class CalendarService
|
||||
{
|
||||
/** @var CurrentUser */
|
||||
private $currentUser ;
|
||||
private $currentUser;
|
||||
|
||||
/** @var CalendarManager */
|
||||
private $calendarManager;
|
||||
|
@ -79,7 +81,8 @@ class CalendarService {
|
|||
*
|
||||
* @psalm-return list<ICalendar>
|
||||
*/
|
||||
public function getCalendarsForPrincipal(string $userId = ''): array {
|
||||
public function getCalendarsForPrincipal(string $userId = ''): array
|
||||
{
|
||||
if (Util::getVersion()[0] < 24) {
|
||||
// deprecated since NC23
|
||||
$this->calendars = $this->calendarManager->getCalendars();
|
||||
|
@ -106,7 +109,8 @@ class CalendarService {
|
|||
*
|
||||
* @psalm-return array{from: DateTimeImmutable, to: DateTimeImmutable}
|
||||
*/
|
||||
private function getTimerange(int $optionId, DateTimeZone $timezone) : array {
|
||||
private function getTimerange(int $optionId, DateTimeZone $timezone): array
|
||||
{
|
||||
$option = $this->optionMapper->find($optionId);
|
||||
$searchIntervalBefore = new DateInterval('PT' . $this->preferences->getCheckCalendarsBefore() . 'H');
|
||||
$searchIntervalAfter = new DateInterval('PT' . $this->preferences->getCheckCalendarsAfter() . 'H');
|
||||
|
@ -126,7 +130,8 @@ class CalendarService {
|
|||
];
|
||||
}
|
||||
|
||||
private function searchEventsByTimeRange(DateTimeImmutable $from, DateTimeImmutable $to) : ?array {
|
||||
private function searchEventsByTimeRange(DateTimeImmutable $from, DateTimeImmutable $to): ?array
|
||||
{
|
||||
$query = $this->calendarManager->newQuery($this->currentUser->getPrincipalUri());
|
||||
$query->setTimerangeStart($from);
|
||||
$query->setTimerangeEnd($to);
|
||||
|
@ -146,7 +151,8 @@ class CalendarService {
|
|||
*
|
||||
* @psalm-return list<CalendarEvent>
|
||||
*/
|
||||
public function getEvents(int $optionId, string $tz): array {
|
||||
public function getEvents(int $optionId, string $tz): array
|
||||
{
|
||||
$timezone = new DateTimeZone($tz);
|
||||
$timerange = $this->getTimerange($optionId, $timezone);
|
||||
|
||||
|
@ -154,7 +160,7 @@ class CalendarService {
|
|||
// deprecated since NC24
|
||||
return $this->getEventsLegcy($timerange['from'], $timerange['to']);
|
||||
}
|
||||
|
||||
|
||||
// use from NC24 on
|
||||
$events = [];
|
||||
$foundEvents = $this->searchEventsByTimeRange($timerange['from'], $timerange['to']);
|
||||
|
@ -178,7 +184,8 @@ class CalendarService {
|
|||
return $events;
|
||||
}
|
||||
|
||||
private function getCalendarFromEvent(array $event): ?ICalendar {
|
||||
private function getCalendarFromEvent(array $event): ?ICalendar
|
||||
{
|
||||
foreach ($this->calendars as $calendar) {
|
||||
if ($calendar->getKey() === $event['calendar-key']) {
|
||||
return $calendar;
|
||||
|
@ -195,7 +202,8 @@ class CalendarService {
|
|||
*
|
||||
* @psalm-return list<CalendarEvent>
|
||||
*/
|
||||
private function getEventsLegcy(DateTimeImmutable $from, DateTimeImmutable $to): array {
|
||||
private function getEventsLegcy(DateTimeImmutable $from, DateTimeImmutable $to): array
|
||||
{
|
||||
$events = [];
|
||||
foreach ($this->calendars as $calendar) {
|
||||
|
||||
|
@ -208,14 +216,15 @@ class CalendarService {
|
|||
// - start before the end of the requested timespan ($to) and
|
||||
// - end after the start of the requested timespan ($from)
|
||||
$foundEvents = $calendar->search('', ['SUMMARY'], ['timerange' => ['start' => $from, 'end' => $to]]);
|
||||
// \OC::$server->getLogger()->error('foundEvents: ' . json_encode($foundEvents));
|
||||
|
||||
foreach ($foundEvents as $event) {
|
||||
$calendarEvent = new CalendarEvent($event, $calendar, $from, $to);
|
||||
// since we get back recurring events of other days, just make sure this event
|
||||
// matches the search pattern
|
||||
// TODO: identify possible time zone issues, when handling all day events
|
||||
if (($from->getTimestamp() < $calendarEvent->getEnd())
|
||||
&& ($to->getTimestamp() > $calendarEvent->getStart())) {
|
||||
&& ($to->getTimestamp() > $calendarEvent->getStart())
|
||||
) {
|
||||
}
|
||||
array_push($events, $calendarEvent);
|
||||
// array_push($events, $calendarEvent);
|
||||
|
@ -231,7 +240,8 @@ class CalendarService {
|
|||
*
|
||||
* @psalm-return list<array{name: mixed, key: mixed, displayColor: mixed, permissions: mixed}>
|
||||
*/
|
||||
public function getCalendars(): array {
|
||||
public function getCalendars(): array
|
||||
{
|
||||
$calendars = [];
|
||||
foreach ($this->calendars as $calendar) {
|
||||
if (Util::getVersion()[0] < 24) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче