Last active
March 12, 2016 03:06
-
-
Save infernoboy/abab12a091e6da6f609b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
public function days_request($room_id, $first_day, $last_day, $dst) | |
{ | |
global $console; | |
if(!$this->allowed_in_room($room_id)) return false; | |
$days = array(); | |
$offset = 0; | |
list($dst_start, $dst_offset, $dst_end, $dst_end_offset) = explode(',', $dst); | |
if($first_day == '0') { | |
$first_message = $this->database->query('SELECT `created` FROM `db_messages` WHERE `recipient_id` = "%s" AND `message_type` NOT IN ("temp", "action") ORDER BY `created` ASC LIMIT 0,1', $room_id); | |
$first_day = $first_message[0]['created']; | |
$last_day = $first_message[0]['created'] + 2678400; | |
} | |
$result = $this->database->query('SELECT `created` FROM `db_messages` WHERE `recipient_id` = "%s" AND `created` >= "%s" AND `created` <= "%s" AND `message_type` NOT IN ("temp", "action") ORDER BY `created` ASC', $room_id, $first_day, $last_day); | |
if(!$result) return array('no_messages' => true); | |
$first_offset = ($result[0]['created'] >= $dst_start && $result[0]['created'] < $dst_end) ? $dst_offset : $dst_end_offset; | |
foreach($result as $value) { | |
$offset = ($value['created'] >= $dst_start && $value['created'] < $dst_end) ? $dst_offset : $dst_end_offset; | |
if(!in_array($day = (int)date('j', $value['created'] + $offset), $days)) { | |
if(isset($last_date) && $day < $last_date) break; | |
$last_date = $day; | |
array_push($days, $day); | |
} | |
} | |
$days = array('year' => (int)date('Y', $first_day + $first_offset), 'month' => date('n', $first_day + $first_offset) - 1, 'days' => $days); | |
return $days; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment