58 lines
1.6 KiB
PHP
Executable File
58 lines
1.6 KiB
PHP
Executable File
<?php
|
|
|
|
|
|
class DefaultModel
|
|
{
|
|
public function redirectToStart($string)
|
|
{
|
|
header( "Location: ?c=default&a=index&rsn=$string" );
|
|
exit();
|
|
}
|
|
|
|
public function checkCode($room_code)
|
|
{
|
|
$stmnt = Database::getConnection()->prepare( 'SELECT id FROM rooms WHERE code = :code' );
|
|
$stmnt->execute( array( 'code' => $room_code ) );
|
|
|
|
$result = $stmnt->fetch( PDO::FETCH_ASSOC );
|
|
if( $result === false || empty( $result ) )
|
|
{
|
|
return false;
|
|
}
|
|
return $result['id'];
|
|
}
|
|
|
|
public function joinRoom($room_id)
|
|
{
|
|
$_SESSION['room'] = $room_id;
|
|
header( 'Location: ?c=faq' );
|
|
return true;
|
|
}
|
|
|
|
public function createRoom(string $room_name)
|
|
{
|
|
$room_owner = session_id();
|
|
$stmnt = Database::getConnection()->prepare( 'INSERT INTO rooms ( name, owner_sid, code ) VALUES ( :name, :owner, :code )' );
|
|
$stmnt->execute( array( 'name' => $room_name, 'owner' => $room_owner, 'code' => $this->generateRandomStr( CODE_LENGTH ) ) );
|
|
|
|
$id = Database::getConnection()->lastInsertId( );
|
|
if( empty( $id ) )
|
|
{
|
|
return false;
|
|
}
|
|
return $id;
|
|
}
|
|
|
|
public function generateRandomStr( $length = 4 )
|
|
{
|
|
$characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
$charactersLength = strlen($characters);
|
|
$randomString = '';
|
|
for ($i = 0; $i < $length; $i++) {
|
|
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
|
}
|
|
return $randomString;
|
|
}
|
|
|
|
|
|
} |