12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?php
- class VideoChat
- {
-
- public static function getChatRoomByUsers($user1, $user2)
- {
- $user1 = intval($user1);
- $user2 = intval($user2);
- if (empty($user1) || empty($user2)) {
- return false;
- }
- return Database::select(
- '*',
- Database::get_main_table(TABLE_MAIN_CHAT_VIDEO),
- [
- 'where' => [
- '(from_user = ? AND to_user = ?)' => [$user1, $user2],
- 'OR (from_user = ? AND to_user = ?)' => [$user2, $user1]
- ]
- ],
- 'first'
- );
- }
-
- public static function createRoom($fromUser, $toUser)
- {
- $fromUserInfo = api_get_user_info($fromUser);
- $toUserInfo = api_get_user_info($toUser);
- $chatName = vsprintf(
- get_lang('VideoChatBetweenUserXAndUserY'),
- [$fromUserInfo['firstname'], $toUserInfo['firstname']]
- );
- return Database::insert(
- Database::get_main_table(TABLE_MAIN_CHAT_VIDEO),
- [
- 'from_user' => intval($fromUser),
- 'to_user' => intval($toUser),
- 'room_name' => $chatName,
- 'datetime' => api_get_utc_datetime()
- ]
- );
- }
-
- public static function nameExists($name)
- {
- $resultData = Database::select(
- 'COUNT(1) AS count',
- Database::get_main_table(TABLE_MAIN_CHAT_VIDEO),
- [
- 'where' => ['room_name = ?' => $name]
- ],
- 'first'
- );
- if ($resultData !== false) {
- return $resultData['count'] > 0;
- }
- return false;
- }
- }
|