/** * @return array */ public static function loadAll() { $dbWrapper = new DatabaseWrapper(); $connection = $dbWrapper->getConnection(); $query = "SELECT * FROM temos;"; $temos = []; foreach ($connection->query($query) as $row) { $tema = new Tema($connection); $tema->setId($row['id']); $tema->setDate($row['subject_date']); $tema->setName($row['name']); $query = 'SELECT * FROM comments INNER JOIN temos ON comments.subjectId = ' . $row['id'] . " AND temos.id = " . $row['id'] . ";"; $comments = []; foreach ($connection->query($query) as $i) { $comment = new Comment($connection); $comment->setId($i['id']); $comment->setsubjectId($i['subjectId']); $comment->setText($i['text']); $comment->setDate($i['date']); $comment->setAuthor($i['author']); $comments[] = $comment; } foreach ($comments as $comment) { $tema->setComments($comment); } $temos[] = $tema; } return $temos; }