db->get_results($sql,ARRAY_A);if($this->db->last_error)throw new \ABeCe\Booking\Domain\CatalogException('abece_booking_statistics_database_error',__('The statistics could not be loaded. Please try again.','abece-booking'),503);return $rows;} public function resources(StatisticsFilter $f):array{$where='';foreach(['resource_id'=>'r.id','sport_id'=>'r.sport_id']as $key=>$column)if($f->values[$key])$where.=$this->db->prepare(' AND '.$column.'=%d',$f->values[$key]);return $this->rows($this->db->prepare("SELECT r.*,COALESCE(s.name,'') sport_name FROM %i r LEFT JOIN %i s ON s.id=r.sport_id WHERE 1=1",\ABeCe\Booking\Infrastructure\Database\Tables::name( $this->db, 'resources' ),\ABeCe\Booking\Infrastructure\Database\Tables::name( $this->db, 'sports' )).$where.' ORDER BY r.sort_order,r.name,r.id');} public function bookings(StatisticsFilter $f):array{$where='';foreach(['resource_id'=>'b.resource_id','sport_id'=>'r.sport_id']as $key=>$column)if($f->values[$key])$where.=$this->db->prepare(' AND '.$column.'=%d',$f->values[$key]);return $this->rows($this->db->prepare("SELECT b.id,b.resource_id,b.booking_reference AS reference,b.starts_at,b.ends_at,b.status FROM %i b JOIN %i r ON r.id=b.resource_id WHERE b.starts_at<%s AND (b.ends_at>%s OR b.starts_at>=%s)",\ABeCe\Booking\Infrastructure\Database\Tables::name( $this->db, 'bookings' ),\ABeCe\Booking\Infrastructure\Database\Tables::name( $this->db, 'resources' ),$f->sqlTo(),$f->sqlFrom(),$f->sqlFrom()).$where.' ORDER BY b.starts_at,b.id');} public function options():array{return ['resources'=>$this->resources(new StatisticsFilter([])),'sports'=>$this->rows($this->db->prepare('SELECT id,name FROM %i ORDER BY sort_order,name',\ABeCe\Booking\Infrastructure\Database\Tables::name( $this->db, 'sports' ))),'membership_types'=>[],'defaults'=>(new StatisticsFilter([]))->values];} public function schedule(StatisticsFilter $f):array{return ['hours'=>$this->rows($this->db->prepare('SELECT * FROM %i',\ABeCe\Booking\Infrastructure\Database\Tables::name( $this->db, 'opening_hours' ))),'exceptions'=>$this->rows($this->db->prepare('SELECT * FROM %i WHERE exception_date BETWEEN %s AND %s',\ABeCe\Booking\Infrastructure\Database\Tables::name( $this->db, 'schedule_exceptions' ),$f->values['date_from'],$f->values['date_to'])),'blocks'=>$this->rows($this->db->prepare('SELECT resource_id,starts_at,ends_at FROM %i WHERE starts_at<%s AND ends_at>%s',\ABeCe\Booking\Infrastructure\Database\Tables::name( $this->db, 'resource_blocks' ),$f->sqlTo(),$f->sqlFrom()))];} }