memories/lib/Controller/PageController.php

116 lines
2.7 KiB
PHP
Raw Normal View History

2022-08-13 01:58:37 +00:00
<?php
namespace OCA\Memories\Controller;
2022-08-13 01:58:37 +00:00
use OCP\IRequest;
2022-08-20 00:18:04 +00:00
use OCP\AppFramework\Services\IInitialState;
2022-08-13 01:58:37 +00:00
use OCP\AppFramework\Http\TemplateResponse;
2022-08-15 21:41:05 +00:00
use OCA\Viewer\Event\LoadViewer;
2022-08-20 00:18:04 +00:00
use OCA\Files\Event\LoadSidebar;
2022-08-13 01:58:37 +00:00
use OCP\AppFramework\Controller;
2022-08-15 21:41:05 +00:00
use OCP\EventDispatcher\IEventDispatcher;
2022-08-20 00:18:04 +00:00
use OCP\IConfig;
use OCP\IUserSession;
2022-08-14 20:54:18 +00:00
use OCP\Util;
2022-08-13 01:58:37 +00:00
2022-09-16 22:42:29 +00:00
use OCA\Memories\AppInfo\Application;
2022-08-13 01:58:37 +00:00
class PageController extends Controller {
2022-09-14 18:19:51 +00:00
protected $userId;
2022-09-09 07:31:42 +00:00
protected $appName;
protected IEventDispatcher $eventDispatcher;
private IInitialState $initialState;
private IUserSession $userSession;
private IConfig $config;
2022-08-13 01:58:37 +00:00
2022-09-09 07:31:42 +00:00
public function __construct(
string $AppName,
IRequest $request,
2022-09-14 18:19:51 +00:00
$UserId,
2022-09-09 07:31:42 +00:00
IEventDispatcher $eventDispatcher,
IInitialState $initialState,
IUserSession $userSession,
IConfig $config) {
2022-08-22 18:48:35 +00:00
2022-09-09 07:31:42 +00:00
parent::__construct($AppName, $request);
$this->userId = $UserId;
$this->appName = $AppName;
$this->eventDispatcher = $eventDispatcher;
$this->initialState = $initialState;
$this->userSession = $userSession;
$this->config = $config;
}
2022-08-13 01:58:37 +00:00
2022-09-09 07:31:42 +00:00
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function main() {
$user = $this->userSession->getUser();
if (is_null($user)) {
return null;
}
2022-08-20 00:18:04 +00:00
2022-09-09 07:31:42 +00:00
Util::addScript($this->appName, 'memories-main');
2022-08-14 20:54:18 +00:00
2022-09-09 07:31:42 +00:00
$this->eventDispatcher->dispatchTyped(new LoadSidebar());
$this->eventDispatcher->dispatchTyped(new LoadViewer());
2022-08-15 21:41:05 +00:00
2022-09-16 22:42:29 +00:00
$uid = $user->getUid();
$timelinePath = \OCA\Memories\Util::getPhotosPath($this->config, $uid);
2022-09-09 07:31:42 +00:00
$this->initialState->provideInitialState('timelinePath', $timelinePath);
2022-09-16 22:42:29 +00:00
$this->initialState->provideInitialState('showHidden', $this->config->getUserValue(
$uid, Application::APPNAME, 'showHidden', false));
2022-08-20 00:18:04 +00:00
2022-09-09 07:31:42 +00:00
$response = new TemplateResponse($this->appName, 'main');
return $response;
}
2022-08-13 01:58:37 +00:00
2022-09-09 07:31:42 +00:00
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function folder() {
return $this->main();
}
2022-09-12 03:06:28 +00:00
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function favorites() {
return $this->main();
}
2022-09-13 07:55:32 +00:00
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function videos() {
return $this->main();
}
2022-09-25 23:02:26 +00:00
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function archive() {
return $this->main();
}
2022-10-06 20:20:29 +00:00
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function thisday() {
return $this->main();
}
2022-10-06 23:28:35 +00:00
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function tags() {
return $this->main();
}
2022-08-13 01:58:37 +00:00
}