Created
August 20, 2012 19:45
-
-
Save MiniCodeMonkey/3407136 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function getOpenStoresCount() | |
{ | |
$textualDateCondition = OpeningHour::getTextualDateQuery(); // Use the helper function from OpeningHour | |
$query = "SELECT | |
COUNT(*) | |
FROM `stores` | |
WHERE id IN ( | |
SELECT store_id FROM opening_hours WHERE date = CURDATE() | |
AND | |
( | |
(open_time < CURTIME() AND close_time > CURTIME()) | |
OR | |
(open_time = MAKETIME(23, 59, 00) AND close_time = MAKETIME(00, 01, 00)) | |
) | |
UNION | |
".''/* ...or todays weekday is an opening hour */." | |
SELECT store_id FROM opening_hours WHERE (". $textualDateCondition .") | |
AND | |
( | |
(open_time < CURTIME() AND close_time > CURTIME()) | |
OR | |
(open_time = MAKETIME(23, 59, 00) AND close_time = MAKETIME(00, 01, 00)) | |
) | |
AND store_id NOT IN ".''/* Select ONLY if we haven't already registered the store as open using date */." | |
( | |
SELECT store_id FROM opening_hours WHERE date = CURDATE() | |
AND | |
( | |
(open_time < CURTIME() AND close_time > CURTIME()) | |
OR | |
(open_time = MAKETIME(23, 59, 00) AND close_time = MAKETIME(00, 01, 00)) | |
) | |
) | |
) | |
AND parser_id IN (SELECT id FROM parsers WHERE active=1) | |
AND country = 'Denmark'"; | |
$sth = Database::getInstance()->prepare($query); | |
$sth->execute(array()); | |
if ($row = $sth->fetch()) | |
{ | |
return $row[0]; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment