Пример #1
0
 /**
  * @param $lesson_id
  * @return array
  */
 public static function getAllByLessonId($lesson_id)
 {
     $lesson_id = abs(intval($lesson_id));
     /** @var PDO $db */
     $db = Registry::get('db');
     $result = array();
     $sth = $db->query("\r\n            SELECT t1.* FROM " . RoomModel::TABLE . " as t1\r\n                JOIN " . RoomModel::RELATION_TABLE . " as t2 USING(" . RoomModel::PRIMARY_KEY . ")\r\n                    JOIN " . LessonModel::TABLE . " as t3 USING(" . LessonModel::PRIMARY_KEY . ")\r\n                        WHERE t3." . LessonModel::PRIMARY_KEY . " = '{$lesson_id}'\r\n        ");
     while ($data = $sth->fetch(PDO::FETCH_ASSOC)) {
         $room = new RoomModel();
         $room->unpack($data);
         $result[] = $room->toArray();
     }
     return $result;
 }