-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Christoph Wurst <[email protected]>
- Loading branch information
1 parent
422604b
commit ac52bb6
Showing
18 changed files
with
347 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* @copyright 2022 Christoph Wurst <[email protected]> | ||
* | ||
* @author 2022 Christoph Wurst <[email protected]> | ||
* | ||
* @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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
namespace OCA\Calendar\Events; | ||
|
||
use OCA\Calendar\Db\AppointmentConfig; | ||
use OCA\Calendar\Db\Booking; | ||
use OCP\EventDispatcher\Event; | ||
|
||
class AppointmentBookedEvent extends Event { | ||
|
||
/** @var Booking */ | ||
private $booking; | ||
/** @var AppointmentConfig */ | ||
|
||
private $config; | ||
|
||
public function __construct(Booking $booking, AppointmentConfig $config) { | ||
parent::__construct(); | ||
|
||
$this->booking = $booking; | ||
$this->config = $config; | ||
} | ||
|
||
public function getBooking(): Booking { | ||
return $this->booking; | ||
} | ||
|
||
public function getConfig(): AppointmentConfig { | ||
return $this->config; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* @copyright 2022 Christoph Wurst <[email protected]> | ||
* | ||
* @author 2022 Christoph Wurst <[email protected]> | ||
* | ||
* @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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
namespace OCA\Calendar\Listener; | ||
|
||
use OCA\Calendar\Events\AppointmentBookedEvent; | ||
use OCP\EventDispatcher\Event; | ||
use OCP\EventDispatcher\IEventListener; | ||
use OCP\IL10N; | ||
use OCP\IUserManager; | ||
use OCP\Talk\IBroker; | ||
use Psr\Log\LoggerInterface; | ||
|
||
class AppointmentBookedListener implements IEventListener { | ||
|
||
/** @var IBroker */ | ||
private $broker; | ||
|
||
/** @var IUserManager */ | ||
private $userManager; | ||
|
||
private IL10N $l10n; | ||
|
||
/** @var LoggerInterface */ | ||
private $logger; | ||
|
||
public function __construct(IBroker $broker, | ||
IUserManager $userManager, | ||
IL10N $l10n, | ||
LoggerInterface $logger) { | ||
$this->broker = $broker; | ||
$this->userManager = $userManager; | ||
$this->l10n = $l10n; | ||
$this->logger = $logger; | ||
} | ||
|
||
public function handle(Event $event): void { | ||
if (!($event instanceof AppointmentBookedEvent)) { | ||
// Don't care | ||
return; | ||
} | ||
|
||
if (!$event->getConfig()->getCreateTalkRoom()) { | ||
$this->logger->debug('Booked appointment of config {config} does not need a Talk room', [ | ||
'config' => $event->getConfig()->getId(), | ||
]); | ||
return; | ||
} | ||
|
||
if (!$this->broker->hasBackend()) { | ||
$this->logger->warning('Can not create Talk room for config {config} because there is no backend', [ | ||
'config' => $event->getConfig()->getId(), | ||
]); | ||
return; | ||
} | ||
|
||
$organizer = $this->userManager->get($event->getConfig()->getUserId()); | ||
if ($organizer === null) { | ||
$this->logger->error('Could not find appointment owner {uid}', [ | ||
'uid' => $event->getConfig()->getUserId(), | ||
]); | ||
return; | ||
} | ||
$conversationName = $this->l10n->t('%s with %s', [ | ||
$event->getConfig()->getName(), | ||
$event->getBooking()->getDisplayName(), | ||
]); | ||
$conversation = $this->broker->createConversation( | ||
$conversationName, | ||
[$organizer], | ||
$this->broker->newConversationOptions(), | ||
); | ||
$event->getBooking()->setTalkUrl( | ||
$conversation->getAbsoluteUrl(), | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* @copyright 2022 Christoph Wurst <[email protected]> | ||
* | ||
* @author 2022 Christoph Wurst <[email protected]> | ||
* | ||
* @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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
namespace OCA\Calendar\Migration; | ||
|
||
use Closure; | ||
use OCP\DB\ISchemaWrapper; | ||
use OCP\DB\Types; | ||
use OCP\Migration\IOutput; | ||
use OCP\Migration\SimpleMigrationStep; | ||
|
||
class Version4004Date20230414163505 extends SimpleMigrationStep { | ||
|
||
/** | ||
* @param IOutput $output | ||
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` | ||
* @param array $options | ||
* @return null|ISchemaWrapper | ||
*/ | ||
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { | ||
/** @var ISchemaWrapper $schema */ | ||
$schema = $schemaClosure(); | ||
|
||
$table = $schema->getTable('calendar_appt_configs'); | ||
$table->addColumn('create_talk_room', Types::BOOLEAN, [ | ||
'notnull' => false, | ||
'default' => false, | ||
]); | ||
|
||
return $schema; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.