Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/polls.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRené Gieling <github@dartcafe.de>2020-08-25 08:45:20 +0300
committerGitHub <noreply@github.com>2020-08-25 08:45:20 +0300
commit6f103d9fdbba724b4f1c2430b566657a28fa21a7 (patch)
treeb449a892319cfd8682d804c58b69090122ed8c82 /lib/Controller
parentb0b220ef34e65a3f4e4fb12603142c376e5573f5 (diff)
parentf57504ff7cfc8b060efa8feeaad1d43d0d43a034 (diff)
Merge branch 'dev-1.5' into backend-sequence
Diffstat (limited to 'lib/Controller')
-rw-r--r--lib/Controller/OptionController.php51
1 files changed, 50 insertions, 1 deletions
diff --git a/lib/Controller/OptionController.php b/lib/Controller/OptionController.php
index f7a36ce6..545beb79 100644
--- a/lib/Controller/OptionController.php
+++ b/lib/Controller/OptionController.php
@@ -23,6 +23,8 @@
namespace OCA\Polls\Controller;
+use DateTime;
+use DateInterval;
use Exception;
use OCA\Polls\Exceptions\DuplicateEntryException;
@@ -32,12 +34,17 @@ use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCA\Polls\Service\OptionService;
+use OCA\Polls\Service\CalendarService;
+
class OptionController extends Controller {
/** @var OptionService */
private $optionService;
+ /** @var CalendarService */
+ private $calendarService;
+
/**
* OptionController constructor.
* @param string $appName
@@ -48,10 +55,12 @@ class OptionController extends Controller {
public function __construct(
string $appName,
IRequest $request,
- OptionService $optionService
+ OptionService $optionService,
+ CalendarService $calendarService
) {
parent::__construct($appName, $request);
$this->optionService = $optionService;
+ $this->calendarService = $calendarService;
}
/**
@@ -131,4 +140,44 @@ class OptionController extends Controller {
public function sequence($optionId, $step, $unit, $amount) {
return new DataResponse(['options' => $this->optionService->sequence($optionId, $step, $unit, $amount)], Http::STATUS_OK);
}
+
+ * findCalendarEvents
+ * @NoAdminRequired
+ * @param integer $from
+ * @param integer $to
+ * @return DataResponse
+ */
+ public function findCalendarEvents($optionId) {
+
+ $searchFrom = new DateTime();
+ $searchFrom = $searchFrom->setTimestamp($this->optionService->get($optionId)->getTimestamp())->sub(new DateInterval('PT1H'));
+ $searchTo = clone $searchFrom;
+ $searchTo = $searchTo->add(new DateInterval('PT3H'));
+
+ return new DataResponse(['events' => array_values($this->calendarService->getEvents($searchFrom, $searchTo))], Http::STATUS_OK);
+
+
+ if (is_int($from)) {
+ $searchFrom = new DateTime();
+ $searchFrom = $searchFrom->setTimestamp($from);
+ } else {
+ $searchFrom = new DateTime($from);
+ }
+
+
+ if (!$to) {
+ $searchTo = clone $searchFrom;
+ $searchTo = $searchTo->add(new DateInterval('PT1H'));
+
+ } else if (is_int($to)) {
+ $searchTo = new DateTime();
+ $searchTo = $searchTo->setTimestamp($to);
+ } else {
+ $searchTo = new DateTime($to);
+ }
+
+ $events = array_values($this->calendarService->getEvents($searchFrom, $searchTo));
+ return $events;
+
+ }
}