2016-10-19 13:00:17 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2016 Lukas Reschke <lukas@statuscode.ch>
|
2016-11-11 18:00:14 +03:00
|
|
|
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
|
2016-10-19 13:00:17 +03:00
|
|
|
*
|
|
|
|
* @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\Spreed;
|
|
|
|
|
2016-11-14 13:54:54 +03:00
|
|
|
use OCP\DB\QueryBuilder\IQueryBuilder;
|
2016-11-11 18:12:45 +03:00
|
|
|
use OCP\IDBConnection;
|
|
|
|
use OCP\IUser;
|
|
|
|
|
2016-10-19 13:00:17 +03:00
|
|
|
class Room {
|
|
|
|
const ONE_TO_ONE_CALL = 1;
|
2016-11-09 16:08:46 +03:00
|
|
|
const GROUP_CALL = 2;
|
2016-11-11 18:00:14 +03:00
|
|
|
|
2016-11-11 18:12:45 +03:00
|
|
|
/** @var IDBConnection */
|
|
|
|
private $db;
|
|
|
|
|
|
|
|
/** @var int */
|
|
|
|
private $id;
|
|
|
|
/** @var int */
|
|
|
|
private $type;
|
|
|
|
/** @var string */
|
|
|
|
private $name;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Room constructor.
|
|
|
|
*
|
|
|
|
* @param IDBConnection $db
|
|
|
|
* @param int $id
|
|
|
|
* @param int $type
|
|
|
|
* @param string $name
|
|
|
|
*/
|
|
|
|
public function __construct(IDBConnection $db, $id, $type, $name) {
|
|
|
|
$this->db = $db;
|
2016-11-11 18:00:14 +03:00
|
|
|
$this->id = $id;
|
|
|
|
$this->type = $type;
|
|
|
|
$this->name = $name;
|
|
|
|
}
|
|
|
|
|
2016-11-11 18:12:45 +03:00
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
2016-11-11 18:00:14 +03:00
|
|
|
public function getId() {
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
|
2016-11-11 18:12:45 +03:00
|
|
|
/**
|
|
|
|
* @return int
|
|
|
|
*/
|
2016-11-11 18:00:14 +03:00
|
|
|
public function getType() {
|
|
|
|
return $this->type;
|
|
|
|
}
|
|
|
|
|
2016-11-11 18:12:45 +03:00
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-11-11 18:00:14 +03:00
|
|
|
public function getName() {
|
|
|
|
return $this->name;
|
|
|
|
}
|
2016-11-11 18:12:45 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param IUser $user
|
|
|
|
*/
|
|
|
|
public function addUser(IUser $user) {
|
|
|
|
$query = $this->db->getQueryBuilder();
|
|
|
|
$query->insert('spreedme_room_participants')
|
|
|
|
->values(
|
|
|
|
[
|
|
|
|
'userId' => $query->createNamedParameter($user),
|
|
|
|
'roomId' => $query->createNamedParameter($this->getId()),
|
2016-11-14 13:54:54 +03:00
|
|
|
'lastPing' => $query->createNamedParameter(0, IQueryBuilder::PARAM_INT),
|
2016-11-11 18:12:45 +03:00
|
|
|
]
|
|
|
|
);
|
|
|
|
$query->execute();
|
|
|
|
}
|
2016-11-14 13:54:54 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param int $lastPing When the last ping is older than the given timestamp, the user is ignored
|
|
|
|
* @return array[] Array of users with [userId, roomId, lastPing]
|
|
|
|
*/
|
|
|
|
public function getParticipants($lastPing = 0) {
|
|
|
|
$query = $this->db->getQueryBuilder();
|
|
|
|
$query->select('*')
|
|
|
|
->from('spreedme_room_participants')
|
|
|
|
->where($query->expr()->eq('roomId', $query->createNamedParameter($this->getId(), IQueryBuilder::PARAM_INT)));
|
|
|
|
|
|
|
|
if ($lastPing > 0) {
|
|
|
|
$query->andWhere($query->expr()->gt('lastPing', $query->createNamedParameter($lastPing, IQueryBuilder::PARAM_INT)));
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = $query->execute();
|
|
|
|
$rows = $result->fetchAll();
|
|
|
|
$result->closeCursor();
|
|
|
|
|
|
|
|
return $rows;
|
|
|
|
}
|
2016-10-19 13:00:17 +03:00
|
|
|
}
|