View difference between Paste ID: YApCSH1K and rh4eHc38
SHOW: | | - or go back to the newest paste.
1
def matches_this_week(client)
2-
    matches.find_by_sql("SELECT * FROM matches m INNER JOIN participations p ON p.match_id = m.id INNER JOIN players pl ON p.player_id = pl.id INNER JOIN timeslots t ON t.match_id = m.id INNER JOIN courts c ON t.court_id = c.id INNER JOIN clients cl ON c.client_id = cl.id WHERE cl.id = :client AND pl.id = :player AND t.begin_datetime > :start AND t.end_datetime < :end", {:client => client.id, :player => id, :start => DateTime.now.beginning_of_week, :end => DateTime.now.end_of_week}).count
2+
    query = "SELECT * FROM matches m INNER JOIN participations p ON p.match_id = m.id INNER JOIN players pl ON p.player_id = pl.id INNER JOIN timeslots t ON t.match_id = m.id INNER JOIN courts c ON t.court_id = c.id INNER JOIN clients cl ON c.client_id = cl.id WHERE cl.id = " + client.id + " AND pl.id = " + id + " AND t.begin_datetime > '" + DateTime.now.beginning_of_week.strftime("%Y-%m-%d %H:%M:%S") + "' AND t.end_datetime < '" + DateTime.now.end_of_week.strftime("%Y-%m-%d %H:%M:%S") + "'"
3
    matches.find_by_sql(query).count
4
  end