diff --git a/admin.php b/admin.php deleted file mode 100644 index aac0984b..00000000 --- a/admin.php +++ /dev/null @@ -1,47 +0,0 @@ - - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License, version 3, - * along with this program. If not, see - * - */ - -use OCP\Template; - -\OCP\Util::addScript('survey_client', 'admin'); -\OCP\Util::addStyle('survey_client', 'admin'); - -$application = new \OCA\Survey_Client\AppInfo\Application(); -$collector = $application->getContainer()->query('OCA\Survey_Client\Collector'); - -$lastSentReportTime = (int) \OC::$server->getConfig()->getAppValue('survey_client', 'last_sent', 0); -if ($lastSentReportTime === 0) { - $lastSentReportDate = \OC::$server->getL10NFactory()->get('survey_client')->t('Never'); -} else { - $lastSentReportDate = \OC::$server->getDateTimeFormatter()->formatDate($lastSentReportTime); -} - -$lastReport = \OC::$server->getConfig()->getAppValue('survey_client', 'last_report', ''); -if ($lastReport !== '') { - $lastReport = json_encode(json_decode($lastReport, true), JSON_PRETTY_PRINT); -} - -$template = new Template('survey_client', 'admin'); -$template->assign('is_enabled', \OC::$server->getJobList()->has('OCA\Survey_Client\BackgroundJobs\MonthlyReport', null)); -$template->assign('last_sent', $lastSentReportDate); -$template->assign('last_report', $lastReport); -$template->assign('categories', $collector->getCategories()); -return $template->fetchPage(); diff --git a/appinfo/app.php b/appinfo/app.php index 0f4801b1..807cac9b 100644 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -19,8 +19,6 @@ * */ -\OCP\App::registerAdmin('survey_client', 'admin'); - $l = \OC::$server->getL10N('survey_client'); $notificationManager = \OC::$server->getNotificationManager(); diff --git a/appinfo/info.xml b/appinfo/info.xml index 6d0ce269..4cb5441e 100644 --- a/appinfo/info.xml +++ b/appinfo/info.xml @@ -17,4 +17,8 @@ + + \OCA\Survey_Client\Settings\AdminSettings + \OCA\Survey_Client\Settings\AdminSection + diff --git a/lib/BackgroundJobs/AdminNotification.php b/lib/BackgroundJobs/AdminNotification.php index 5aeeb518..25f39580 100644 --- a/lib/BackgroundJobs/AdminNotification.php +++ b/lib/BackgroundJobs/AdminNotification.php @@ -29,11 +29,13 @@ protected function run($argument) { $urlGenerator = \OC::$server->getURLGenerator(); $notification = $manager->createNotification(); + $url = $urlGenerator->linkToRoute('settings.AdminSettings.index', ['section' => 'survey_client']); + $notification->setApp('survey_client') ->setDateTime(new \DateTime()) ->setSubject('updated') ->setObject('dummy', 23) - ->setLink($urlGenerator->getAbsoluteURL('index.php/settings/admin#usage-report')); + ->setLink($url); $enableAction = $notification->createAction(); $enableAction->setLabel('enable') diff --git a/lib/Settings/AdminSection.php b/lib/Settings/AdminSection.php new file mode 100644 index 00000000..d3ec789e --- /dev/null +++ b/lib/Settings/AdminSection.php @@ -0,0 +1,66 @@ + + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Survey_Client\Settings; + + +use OCP\IL10N; +use OCP\Settings\ISection; + +class AdminSection implements ISection { + + /** @var IL10N */ + private $l; + + public function __construct(IL10N $l) { + $this->l = $l; + } + + /** + * returns the ID of the section. It is supposed to be a lower case string + * + * @returns string + */ + public function getID() { + return 'survey_client'; + } + + /** + * returns the translated name as it should be displayed, e.g. 'LDAP / AD + * integration'. Use the L10N service to translate it. + * + * @return string + */ + public function getName() { + return $this->l->t('Usage report'); + } + + /** + * @return int whether the form should be rather on the top or bottom of + * the settings navigation. The sections are arranged in ascending order of + * the priority values. It is required to return a value between 0 and 99. + */ + public function getPriority() { + return 80; + } + +} diff --git a/lib/Settings/AdminSettings.php b/lib/Settings/AdminSettings.php new file mode 100644 index 00000000..917dde09 --- /dev/null +++ b/lib/Settings/AdminSettings.php @@ -0,0 +1,116 @@ + + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + + +namespace OCA\Survey_Client\Settings; + + +use OCA\Survey_Client\Collector; +use OCP\AppFramework\Http\TemplateResponse; +use OCP\BackgroundJob\IJobList; +use OCP\IConfig; +use OCP\IDateTimeFormatter; +use OCP\IL10N; +use OCP\Settings\ISettings; + +class AdminSettings implements ISettings { + + /** @var Collector */ + private $collector; + + /** @var IConfig */ + private $config; + + /** @var IL10N */ + private $l; + + /** @var IDateTimeFormatter */ + private $dateTimeFormatter; + + /** @var IJobList */ + private $jobList; + + /** + * Admin constructor. + * + * @param Collector $collector + * @param IConfig $config + * @param IL10N $l + * @param IDateTimeFormatter $dateTimeFormatter + * @param IJobList $jobList + */ + public function __construct(Collector $collector, + IConfig $config, + IL10N $l, + IDateTimeFormatter $dateTimeFormatter, + IJobList $jobList + ) { + $this->collector = $collector; + $this->config = $config; + $this->l = $l; + $this->dateTimeFormatter = $dateTimeFormatter; + $this->jobList = $jobList; + } + + /** + * @return TemplateResponse + */ + public function getForm() { + + $lastSentReportTime = (int) $this->config->getAppValue('survey_client', 'last_sent', 0); + if ($lastSentReportTime === 0) { + $lastSentReportDate = $this->l->t('Never'); + } else { + $lastSentReportDate = $this->dateTimeFormatter->formatDate($lastSentReportTime); + } + + $lastReport = $this->config->getAppValue('survey_client', 'last_report', ''); + if ($lastReport !== '') { + $lastReport = json_encode(json_decode($lastReport, true), JSON_PRETTY_PRINT); + } + + $parameters = [ + 'is_enabled' => $this->jobList->has('OCA\Survey_Client\BackgroundJobs\MonthlyReport', null), + 'last_sent' => $lastSentReportDate, + 'last_report' => $lastReport, + 'categories' => $this->collector->getCategories() + ]; + + return new TemplateResponse('survey_client', 'admin', $parameters); + } + + /** + * @return string the section ID, e.g. 'sharing' + */ + public function getSection() { + return 'survey_client'; + } + + /** + * @return int whether the form should be rather on the top or bottom of + * the admin section. The forms are arranged in ascending order of the + * priority values. It is required to return a value between 0 and 100. + */ + public function getPriority() { + return 50; + } + +} diff --git a/templates/admin.php b/templates/admin.php index 9e909ad3..6148966b 100644 --- a/templates/admin.php +++ b/templates/admin.php @@ -21,7 +21,11 @@ /** @var $l \OCP\IL10N */ /** @var $_ array */ + +script('survey_client', 'admin'); +style('survey_client', 'admin'); ?> +

t('Usage report')); ?>