/**
  * Get all the rooms from the database in the $entityCollection attribute
  *
  * @return     RoomCollection  All the rooms from the database
  */
 public function getAllRooms()
 {
     $rooms = new RoomCollection();
     $sqlMarks = 'SELECT * FROM %s';
     $sql = static::sqlFormat($sqlMarks, (new Room())->getTableName());
     foreach (DB::query($sql)->fetchAll() as $roomAttributes) {
         $rooms->add(new Room($roomAttributes));
     }
     return $rooms;
 }
예제 #2
0
 /**
  * Determine if a room exist in the current collection
  *
  * @param      int   $roomId  The room ID
  *
  * @return     bool  True if room exist, false otherwise.
  */
 public function isRoomExist(int $roomId) : bool
 {
     return $this->roomCollection->isRoomExist($roomId);
 }
예제 #3
0
 /**
  * Insert room data in database
  */
 private function insertRoomData()
 {
     $rooms = new RoomCollection();
     $roomManager = new RoomManager(null, $rooms);
     static::out('Create room data' . PHP_EOL);
     // Create a default chat room
     $default = new Room(['id' => 1, 'name' => 'Default', 'creator' => 1, 'creationDate' => new \DateTime(), 'maxUsers' => 50]);
     $rooms->add($default);
     // Create some rooms some public and some with password 123
     for ($i = 1; $i < 11; $i++) {
         $room = new Room(['id' => $i + 1, 'name' => 'Room ' . $i, 'creator' => 1, 'password' => mt_rand(0, 1) ? null : '123', 'creationDate' => new \DateTime(), 'maxUsers' => 20]);
         $rooms->add($room);
     }
     if ($roomManager->saveRoomCollection()) {
         static::ok(sprintf('The followings chat rooms are inserted %s' . PHP_EOL, $rooms));
     } else {
         static::fail('An error occurred on chat rooms collection save' . PHP_EOL);
     }
 }