2020-04-26 11:36:41 +02:00
|
|
|
<?php
|
2020-06-19 09:28:58 +02:00
|
|
|
|
2020-04-26 11:36:41 +02:00
|
|
|
namespace OCA\BigBlueButton\Service;
|
|
|
|
|
|
|
|
use Exception;
|
|
|
|
|
|
|
|
use OCP\AppFramework\Db\DoesNotExistException;
|
|
|
|
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
|
|
|
|
|
|
|
|
use OCA\BigBlueButton\Db\Room;
|
|
|
|
use OCA\BigBlueButton\Db\RoomMapper;
|
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
class RoomService {
|
2020-04-26 11:36:41 +02:00
|
|
|
|
|
|
|
/** @var RoomMapper */
|
|
|
|
private $mapper;
|
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
public function __construct(RoomMapper $mapper) {
|
2020-04-26 11:36:41 +02:00
|
|
|
$this->mapper = $mapper;
|
|
|
|
}
|
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
public function findAll(string $userId, array $groupIds): array {
|
2020-06-17 10:56:28 +02:00
|
|
|
return $this->mapper->findAll($userId, $groupIds);
|
2020-04-26 11:36:41 +02:00
|
|
|
}
|
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
private function handleException(Exception $e): void {
|
2020-04-26 11:36:41 +02:00
|
|
|
if ($e instanceof DoesNotExistException ||
|
|
|
|
$e instanceof MultipleObjectsReturnedException) {
|
|
|
|
throw new RoomNotFound($e->getMessage());
|
|
|
|
} else {
|
|
|
|
throw $e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
public function find($id): Room {
|
2020-04-26 11:36:41 +02:00
|
|
|
try {
|
2020-06-17 10:56:28 +02:00
|
|
|
return $this->mapper->find($id);
|
2020-04-26 11:36:41 +02:00
|
|
|
|
|
|
|
// in order to be able to plug in different storage backends like files
|
|
|
|
// for instance it is a good idea to turn storage related exceptions
|
|
|
|
// into service related exceptions so controllers and service users
|
|
|
|
// have to deal with only one type of exception
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$this->handleException($e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
public function findByUid($uid) {
|
2020-04-26 11:36:41 +02:00
|
|
|
try {
|
|
|
|
return $this->mapper->findByUid($uid);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
// $this->handleException($e);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
public function create($name, $welcome, $maxParticipants, $record, $userId) {
|
2020-04-26 11:36:41 +02:00
|
|
|
$room = new Room();
|
|
|
|
|
|
|
|
$room->setUid(\OC::$server->getSecureRandom()->generate(16, \OCP\Security\ISecureRandom::CHAR_HUMAN_READABLE));
|
|
|
|
$room->setName($name);
|
|
|
|
$room->setWelcome($welcome);
|
|
|
|
$room->setMaxParticipants($maxParticipants);
|
|
|
|
$room->setAttendeePassword(\OC::$server->getSecureRandom()->generate(32, \OCP\Security\ISecureRandom::CHAR_HUMAN_READABLE));
|
|
|
|
$room->setModeratorPassword(\OC::$server->getSecureRandom()->generate(32, \OCP\Security\ISecureRandom::CHAR_HUMAN_READABLE));
|
|
|
|
$room->setRecord($record);
|
|
|
|
$room->setUserId($userId);
|
|
|
|
|
|
|
|
return $this->mapper->insert($room);
|
|
|
|
}
|
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
public function update($id, $name, $welcome, $maxParticipants, $record, $access, $everyoneIsModerator) {
|
2020-04-26 11:36:41 +02:00
|
|
|
try {
|
2020-06-17 10:56:28 +02:00
|
|
|
$room = $this->mapper->find($id);
|
2020-04-26 11:36:41 +02:00
|
|
|
|
2020-06-04 18:56:55 +02:00
|
|
|
if ($room->access !== $access) {
|
|
|
|
$room->setPassword($access === Room::ACCESS_PASSWORD ? $this->humanReadableRandom(8) : null);
|
|
|
|
}
|
|
|
|
|
2020-04-26 11:36:41 +02:00
|
|
|
$room->setName($name);
|
|
|
|
$room->setWelcome($welcome);
|
|
|
|
$room->setMaxParticipants($maxParticipants);
|
|
|
|
$room->setRecord($record);
|
2020-06-04 18:56:55 +02:00
|
|
|
$room->setAccess($access);
|
2020-06-17 08:19:54 +02:00
|
|
|
$room->setEveryoneIsModerator($everyoneIsModerator);
|
2020-04-26 11:36:41 +02:00
|
|
|
|
|
|
|
return $this->mapper->update($room);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$this->handleException($e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
public function delete($id) {
|
2020-04-26 11:36:41 +02:00
|
|
|
try {
|
2020-06-17 10:56:28 +02:00
|
|
|
$room = $this->mapper->find($id);
|
2020-04-26 11:36:41 +02:00
|
|
|
$this->mapper->delete($room);
|
|
|
|
return $room;
|
|
|
|
} catch (Exception $e) {
|
|
|
|
$this->handleException($e);
|
|
|
|
}
|
|
|
|
}
|
2020-06-04 18:56:55 +02:00
|
|
|
|
2020-06-19 09:28:58 +02:00
|
|
|
private function humanReadableRandom($length) {
|
2020-06-04 18:56:55 +02:00
|
|
|
return \OC::$server->getSecureRandom()->generate($length, \OCP\Security\ISecureRandom::CHAR_HUMAN_READABLE);
|
|
|
|
}
|
2020-04-26 11:36:41 +02:00
|
|
|
}
|