I have a little code just to know when a message was sent:
function time_ago ($respuestas) {
$date = $respuestas;
$today_date = getdate();
$months = ['enero', 'febrero', 'marzo', 'abril', 'mayo', 'junio','julio','agosto','septiembre','octubre','noviembre','diciembre'];
$minute = $today_date['minutes'];
$hour = $today_date['hours'];
$day = $today_date['mday'];
$month = $today_date['mon'];
if ($today_date['hours'] <= 9) {
$hour = "0" . $today_date['hours'];
}
if ($today_date['minutes'] <= 9) {
$minute = "0" . $today_date['minutes'];
}
if ($today_date['mon'] <= 9) {
$month = "0" . $today_date['mon'];
}
if ($today_date['mday'] <= 9) {
$day = "0" . $today_date['mday'];
}
$actual_total_date = $today_date['year'] . "-" . $month . "-" . $day . " " . $hour . ":" . $minute;
$actual_total_date = new DateTime($actual_total_date);
//data of the date of the post
$post_date = substr($date,0,16);
$post_date = new DateTime($post_date);
$post_year = substr($date,0,4);
$post_month = substr($date,5,2);
$post_day = substr($date,8,2);
$post_hour = substr($date,11,2);
$post_minute = substr($date,14,2);
$interval = date_diff($post_date, $actual_total_date);
$invertal_days = substr($interval->format('%R%a'),1,strlen($interval->format('%R%a')));
$invertal_hours = $interval->format('%H');
$invertal_minutes = $interval->format('%I');
$result = "";
if ($invertal_days == 0 AND $invertal_hours == 0 AND $invertal_minutes < 1) {
$result = "Now";
} else if ($invertal_days == 0 AND $invertal_hours == 0 AND $invertal_minutes == 1) {
$result = substr($invertal_minutes,1,2) . " minute ago";
} else if ($invertal_days == 0 AND $invertal_hours == 0 AND $invertal_minutes < 10 AND $invertal_minutes > 1) {
$result = substr($invertal_minutes,1,2) . " minutes ago";
} else if ($invertal_days == 0 AND $invertal_hours == 0 AND $invertal_minutes < 60 AND $invertal_minutes >= 10) {
$result = $invertal_minutes . " minutes ago";
} else if ($invertal_days == 0 AND $post_day == $day) {
$result = "Today at " . $post_hour . ":" . $post_minute ;
} else if ($invertal_days == 0 AND $post_day == $day-1) {
$result = "Yesterday at " . $post_hour . ":" . $post_minute;
} else if ($invertal_days == 1 AND $post_day == $day-1) {
$result = "Yesterday at " . $post_hour . ":" . $post_minute;
} else {
$result = $post_day . " " . $months[$post_month-1] . " " . $post_year . " " . $post_hour . ":" . $post_minute;
}
return $result;
The problem I'm having only happens in production, not in local, and after doing some research I don't know what is happening. What happens is that this function gives me two different outputs with the same input. For example with the date: 2017-07-09 20:52:39, at the time I'm sending this post, it should enter the fourth conditional, because the minutes interval is between 10 and 60 minutes.
I could share to the site where I'm having problems if needed. I have already tested the data I am using for the function and it is correct.
Related
I have a script that allows me to automatically generate slots on a calendar according to the different opening hours of my users.
Today, I would like to improve the execution of my script to make it much faster than today (it takes a few seconds to make the calendar appear).
You have to know that I have a table OPENING_TIMES which contains 7 rows (1 per day) for each user.
I tried some improvements but without success (with joins for example).
Do you have any ideas?
Thanks in advance !
$Sch_Link_User = $_GET['psy'];
$Data_query = mysqli_query($_Db_Con, 'SELECT ID_UNIQUE, CONSULTATION_TIME, CONSULTATION_TIME_BEFORE, TIMEZONE FROM USERS WHERE PROFILE_URL LIKE "' . $Sch_Link_User . '"');
$Data = mysqli_fetch_assoc($Data_query);
$Sch_Id_User = $Data['ID_UNIQUE'];
$Difference = '0';
switch ($Data['CONSULTATION_TIME']) {
case 1:
$Sch_Time_Consultation = 30;
break;
case 2:
$Sch_Time_Consultation = 45;
break;
case 3:
$Sch_Time_Consultation = 60;
break;
default:
$Sch_Time_Consultation = 60;
}
$Calendar = array();
$weekslots = array_map(function($dow) {return array('dow' => $dow, 'hour' => 00);}, range(0, 6));
$date = time();
$end_date = $date + (6 * 7 * 24 * 60 * 60);
$open_hours_cache = array();
while($date <= $end_date) {
$date_dow = date('w', $date);
foreach($weekslots as $timeslot) {
if($date_dow == $timeslot['dow']) {
$timeofday = $date + (3600 * $timeslot['hour']);
for($nd = 1; $nd <= 7; $nd++) {
if(date('N', $timeofday) == $nd) {
if (!isset($open_hours_cache[$nd])) {
$Data_Openhours_query = mysqli_query($_Db_Con, 'SELECT START_HOUR_M, END_HOUR_M, START_HOUR_A, END_HOUR_A FROM OPENING_TIMES WHERE ID_USER = "' . $Sch_Id_User . '" AND WEEKDAY = "' . $nd . '" AND CLOSED = 0');
$open_hours_cache[$nd] = mysqli_fetch_assoc($Data_Openhours_query);
}
$Data_Openhours = $open_hours_cache[$nd];
if(isset($Data_Openhours['START_HOUR_M']) && $Data_Openhours['END_HOUR_M'] == NULL && $Data_Openhours['START_HOUR_A'] == NULL && isset($Data_Openhours['END_HOUR_A'])) {
$shm = strtotime($Data_Openhours['START_HOUR_M'] . $Difference . ' hour');
$eha = strtotime($Data_Openhours['END_HOUR_A'] . $Difference . ' hour');
$timeslots = array();
$interval = new DateInterval("PT{$Sch_Time_Consultation}M");
$timeRange = new DatePeriod(new DateTime(date('Y-m-d H:i', $shm)), $interval, new DateTime(date('Y-m-d H:i', $eha)));
foreach ($timeRange as $time) {
$timeslots[] = $time->format("H:i");
}
foreach ($timeslots as $slot) {
$datefinal = date('Y-m-d', $timeofday) . ' ' . $slot . ':00';
$timestamp = strtotime($datefinal . $Difference . ' hour');
$Check_Slot = mysqli_query($_Db_Con, 'SELECT ID, ID_USER, STATUS FROM APPOINTMENTS WHERE ID_USER = "' . $Sch_Id_User . '" AND DATE_START = "' . $timestamp . '" AND (STATUS = 1 OR STATUS = 2 OR STATUS = 9 OR STATUS = 10) AND DATE_START > "' . $Time . '"');
$Data_Slot = mysqli_fetch_assoc($Check_Slot);
$status = isset($Data_Slot['STATUS']) && $Data_Slot['STATUS'] == 9 && $Data_Slot['ID_USER'] == $_SESSION['uid'];
$check_slot = mysqli_num_rows($Check_Slot) == 0;
$time_before = ($Time + (60 * 60 * $Data['CONSULTATION_TIME_BEFORE'])) < $timestamp;
if ($status) {
$class = 'blocked';
} elseif ($check_slot && $time_before) {
$class = 'available';
} else {
$class = 'unavailable';
}
$Calendar[] = array(
'id' => date('Y-m-d', $timeofday) . '/' . $slot,
'title' => $slot,
'class' => $class,
'psy' => $Sch_Id_User,
'start' => $timestamp . '000',
);
}
} else if(isset($Data_Openhours['START_HOUR_M']) && isset($Data_Openhours['END_HOUR_M']) && isset($Data_Openhours['START_HOUR_A']) && isset($Data_Openhours['END_HOUR_A'])) {
$shm = strtotime($Data_Openhours['START_HOUR_M'] . $Difference . ' hour');
$ehm = strtotime($Data_Openhours['END_HOUR_M'] . $Difference . ' hour');
$sha = strtotime($Data_Openhours['START_HOUR_A'] . $Difference . ' hour');
$eha = strtotime($Data_Openhours['END_HOUR_A'] . $Difference . ' hour');
$timeslots = array();
$interval = new DateInterval("PT{$Sch_Time_Consultation}M");
$timeRange = new DatePeriod(new DateTime(date('Y-m-d H:i', $shm)), $interval, new DateTime(date('Y-m-d H:i', $ehm)));
foreach ($timeRange as $time) {
$timeslots[] = $time->format("H:i");
}
$timeRange = new DatePeriod(new DateTime(date('Y-m-d H:i', $sha)), $interval, new DateTime(date('Y-m-d H:i', $eha)));
foreach ($timeRange as $time) {
$timeslots[] = $time->format("H:i");
}
foreach ($timeslots as $slot) {
$datefinal = date('Y-m-d', $timeofday) . ' ' . $slot . ':00';
$Check_Slot = mysqli_query($_Db_Con, 'SELECT ID, ID_USER, STATUS FROM APPOINTMENTS WHERE ID_USER = "' . $Sch_Id_User . '" AND DATE_START = "' . strtotime($datefinal) . '" AND (STATUS = 1 OR STATUS = 2 OR STATUS = 9 OR STATUS = 10) AND DATE_START > "' . $Time . '"');
$Data_Slot = mysqli_fetch_assoc($Check_Slot);
// * 24 le temps avant possibilité de prende rendez-vous
$status = isset($Data_Slot['STATUS']) && $Data_Slot['STATUS'] == 9 && $Data_Slot['ID_USER'] == $_SESSION['uid'];
$check_slot = mysqli_num_rows($Check_Slot) == 0;
$time_before = ($Time + (60 * 60 * $Data['CONSULTATION_TIME_BEFORE'])) < strtotime($datefinal . $Difference . ' hour');
if ($status) {
$class = 'blocked';
} elseif ($check_slot && $time_before) {
$class = 'available';
} else {
$class = 'unavailable';
}
$Calendar[] = array(
'id' => date('Y-m-d', $timeofday) . '/' . $slot,
'title' => $slot,
'class' => $class,
'psy' => $Sch_Id_User,
'start' => strtotime($datefinal . $Difference . ' hour') . '000',
);
}
}
}
}
}
}
$date += 86400;
}
$Calendar_Data = array(
'success' => 1,
'result' => $Calendar);
echo json_encode($Calendar_Data);
So I try to have a much faster loading with joins or a cache system to limit the number of requests.
Moreover, wouldn't it be more efficient if I also put everything in one column of my user table, the schedules?
How to get the total number of monts, days, and minutes from a given minute. Say for example given a value in minutes 93366 should return 2 months ,5 days and 5 hours. This is what I've tried so far.
function convert_minutes($minutes, $output) {
if ($minutes >= 43833) {
$whole_month = 0;
$decimal_month = 0;
$label = "";
$months = $minutes / 43833;
list($whole_month, $decimal_month) = sscanf($months, '%d.%d');
if ($months > 1) {
$label = "months";
} else {
$label = "month";
}
$output .= $months . " " . $label;
$decimal_month = "0." . $decimal_month;
if ($decimal_month != 0) {
return $this->convert_minutes($decimal_month, $output);
} else {
return $output;
}
} elseif ($minutes >= 1440) {
$whole_day = 0;
$decimal_day = 0;
$label = "";
$days = $minutes / 1440;
list($whole_day, $decimal_day) = sscanf($days, '%d.%d');
if ($days > 1) {
$label = "days";
} else {
$label = "day";
}
$output .= $days . " " . $label;
$decimal_day = "0." . $decimal_day;
if ($decimal_day != 0) {
return $this->convert_minutes($decimal_day, $output);
} else {
return $output;
}
} elseif ($minutes >= 60) {
$whole_minutes = 0;
$decimal_minutes = 0;
$label = "";
$min = $minutes / 60;
list($whole_minutes, $decimal_minutes) = sscanf($min, '%d.%d');
if ($min > 1) {
$label = "minutes";
} else {
$label = "minute";
}
$output .= $min . " " . $label;
$decimal_minutes = "0." . $decimal_minutes;
if ($decimal_minutes != 0) {
return $output . " and " . $decimal_minutes . " minutes";
} else {
return $output;
}
}
}
EDIT
I just wanted to get the estimate. Assuming 1 hour is 60 minutes and 1 day is 1440 minutes and 1 month is 43,200. I am developing a document tracking system and would just like to calculate how long a document stayed in a particular office based on the date received and date released.
You can use floor and mod operator.
Floor rounds down a number.
The modulo operator will give you what is left if split evenly.
Example 5%2 = 1
Since 2*2 = 4 and the remaining is 1.
Echo floor(93366/43200) . " months\n";
$rem = 93366%43200;
Echo floor($rem/1440) . " days\n";
$rem = $rem%1440;
Echo floor($rem/60) . " hours\n";
Echo $rem%60 . " minutes";
Output:
2 months
4 days
20 hours
6 minutes
https://3v4l.org/RreDY
I am creating a calendar and I am in a dire need of a solution. There are records of information in the database and the code reads these records. Two columns hold a date from and a date to. I have to output these dates that appear in the database in different colors. I have tried many times. And the problem is that the code outputs either the last record that it can fetch in the database or all the date periods however these periods get duplicated based on how many rows are there in the database.Here is the output I get
<div id="calender_section_top">
<ul>
<li>Mon</li>
<li>Tue</li>
<li>Wed</li>
<li>Thu</li>
<li>Fri</li>
<li>Sat</li>
<li>Sun</li>
</ul>
</div>
<div id="calender_section_bot">
<ul>
<?php
$dateYear = ($year != '') ? $year : date("Y");
$dateMonth = ($month != '') ? $month : date("m");
$date = $dateYear . '-' . $dateMonth . '-01';
$currentMonthFirstDay = date("N", strtotime($date));
$totalDaysOfMonth = cal_days_in_month(CAL_GREGORIAN, $dateMonth, $dateYear);
$totalDaysOfMonthDisplay = ($currentMonthFirstDay == 7) ? ($totalDaysOfMonth) : ($totalDaysOfMonth + $currentMonthFirstDay);
$boxDisplay = ($totalDaysOfMonthDisplay <= 35) ? 35 : 42;
$dayCount = 1;
for ($cb = 1; $cb <= $boxDisplay; $cb++) {
if (($cb >= $currentMonthFirstDay || $currentMonthFirstDay == 7) && $cb <= ($totalDaysOfMonthDisplay - 1)) {
$duh = array();
array_push($duh, $dayCount);
// Current date
$currentDate = $dateYear . '-' . $dateMonth . '-' . $dayCount;
$currentDate = strtotime($currentDate);
$eventNum = 0;
$sql = ("SELECT * FROM booking_2 GROUP BY date_from ORDER BY COUNT(book2_id) DESC");
$result = $this->connect()->query($sql);
$eventNum = $result->num_rows;
if ($eventNum > 0) {
while ($row = $result->fetch_assoc()) {
$date_from = $row['date_from'];
$date_to = $row['date_to'];
$time_from = strtotime($date_from);
$time_fromm = idate('d', $time_from);
$time_to = strtotime($date_to);
$time_too = idate('d', $time_to);
if ($currentDate >= $time_from && $currentDate <= $time_to) {
for ($i = $time_from; $i <= $time_to; $i++) {
$cope = array();
array_push($cope, $dayCount);
}
echo '<li id="' . $row['book2_id'] . '" style="background-color:#FF3232 !important;" date="' . date("Y-m-d H:i:s", $currentDate) . '" class="date_cell"><span>' . implode($cope) . '</span>';
}
}
if (!($currentDate >= $time_from && $currentDate <= $time_to)) {
for ($g = $time_from; $g <= $time_to; $g++) {
$duh = array();
array_push($duh, $dayCount);
}
echo '<li date="' . date("Y-m-d H:i:s", $currentDate) . '" class="date_cell"><span>' . implode($duh) . '</span>';
}
}
else {
echo '<li date="' . date("Y-m-d H:i:s", $currentDate) . '" class="date_cell"><span>' . implode($duh) . '</span>';
}
echo '</li>';
$dayCount++;
?>
<?php
}
else { ?>
<li><span> </span></li>
<?php
}
} ?>
</ul>
</div>
</div>
sorry for TL;DR. But really need help with this. I have tried all the ways I know so if you have a solution can you please be sure that this will work? I believe this is a hard problem to find a solution to.
I am trying to echo a variable number, but I am not sure the best way to go about it. My problem is this:
I have a series of 'IF' conditions and I echo a variable accordingly.
if ($month == "8" || $month == "9" || $month == "10") {
$comingseason = 'winter';
$elementsDue = "Due October 31, " . $year . ", for our " . $comingseason . " issue No. 9";
}
else if ($month == "11" || $month == "12" || $month == "1") {
$comingseason = 'spring';
$elementsDue = "Due January 31, " . ++$year . ", for our " . $comingseason . " issue No. 9";
}
else if ($month == "2" || $month == "3" || $month == "4") {
$comingseason = 'summer';
$elementsDue = "Due April 30, " . $year . ", for our " . $comingseason . " issue No. 9";
}
else if ($month == "5" || $month == "6" || $month == "7") {
$comingseason = 'fall';
$elementsDue = "Due July 31, " . ++$year . ", for our " . $comingseason . " issue No. 9";
}
I am wondering how I would replace the number in 'issue No. 9' with the next increment ++1 to output '10'? I don't want to have to come back into the code each time and type in the next issue number. I would like the number to increase on its own, essentially every quarter like you see below.
I was thinking of a php session, but from what I understand that will not be permanent. I need the number to remain even after a user has ended their session.
How can I accomplish this?
Looks to me like the issue # is a function of year and quarter: you have 1 issue per quarter starting at some base year/quarter. So, something like this should automatically calculate it (you'll have to play with $base_year and $base_qtr to get it to match your issue numbering).
function currentIssue() {
$base_year = 2014;
$base_qtr = 2;
$now_year = intval(date('Y');
$now_qtr = ceil(intval(date'm')/3);
return ($now_year - $base_year)*4 + ($now_qtr - $base_qtr);
}
Ok this seems to be a very simple problem to solve. I would suggest reading a good entry level PHP programming book. Having said that, you need to set a while loop and some nested if else conditions.
$month = 0;
while ($month < 12) {
$month++;
If ($month > 7 && $month < 11)
{
$comingsoon = "winter";
}
elseif
{
some logic
}
elseif
{
some logic
}
else
{
}
} # end of while loop
I am intentionally leaving the remaining code for you to write. It would be a good exercise for you to learn some coding :) Good Luck!
may be you're looking for this,
Explanation: add an integer variable say it is $issuNo, and than add a initial value of that. Then after if/else condition block put the incremental var of that like $issuNo++ and then you better make a program that can continue your if/else statement later.
$issuNo = 9;
if ($month == "8" || $month == "9" || $month == "10") {
$comingseason = 'winter';
$elementsDue = "Due October 31, " . $year . ", for our " . $comingseason . " issue No. ".$issuNo;
}
else if ($month == "11" || $month == "12" || $month == "1") {
$comingseason = 'spring';
$elementsDue = "Due January 31, " . ++$year . ", for our " . $comingseason . " issue No. ".$issuNo;
}
else if ($month == "2" || $month == "3" || $month == "4") {
$comingseason = 'summer';
$elementsDue = "Due April 30, " . $year . ", for our " . $comingseason . " issue No. ".$issuNo;
}
else if ($month == "5" || $month == "6" || $month == "7") {
$comingseason = 'fall';
$elementsDue = "Due July 31, " . ++$year . ", for our " . $comingseason . " issue No. ".$issuNo;
}
$issuNo++;
If this is what you're looking for:
<?php
$month = '3';
$year = '2015';
$issue = 9;
if ($month == "8" || $month == "9" || $month == "10") {
$comingseason = 'winter';
echo $elementsDue = "Due October 31, " . $year . ", for our " . $comingseason . " issue No. $issue";
}
else if ($month == "11" || $month == "12" || $month == "1") {
$comingseason = 'spring';
$issue = $issue + 1;
echo $elementsDue = "Due January 31, " . ++$year . ", for our " . $comingseason . " issue No. $issue";
}
else if ($month == "2" || $month == "3" || $month == "4") {
$comingseason = 'summer';
$issue = $issue + 2;
echo $elementsDue = "Due April 30, " . $year . ", for our " . $comingseason . " issue No. $issue";
}
else if ($month == "5" || $month == "6" || $month == "7") {
$comingseason = 'fall';
$issue = $issue + 3;
echo $elementsDue = "Due July 31, " . ++$year . ", for our " . $comingseason . " issue No. $issue";
}
?>
PHP fiddle
I have the following table:
-------------------------------------------
|id|list_id|start_date|end_date|min_nights|
-------------------------------------------
|17| 55 |1437487200|1437735600|3|
|18| 55 |1438005600|1438167600|2|
I want to display the minimum nights for each range.
PHP:
//Seasonal Price
//1. Store all the dates between checkin and checkout in an array
$checkin_time = get_gmt_time(strtotime($checkin));
$checkout_time = get_gmt_time(strtotime($checkout));
$travel_dates = array();
$seasonal_prices = array();
$total_nights = 1;
$total_price = 0;
$is_seasonal = 0;
$i = $checkin_time;
while ($i < $checkout_time) {
$i = get_gmt_time(strtotime('+1 day', $i));
$checkin_date = date('m/d/Y', $i);
$checkin_date = explode('/', $checkin_date);
$travel_dates[$total_nights] = $checkin_date[1] . $checkin_date[0] . $checkin_date[2];
$total_nights++;
}
for ($i = 1; $i < $total_nights; $i++) {
$seasonal_prices[$travel_dates[$i]] = "";
}
//Store seasonal price of a list in an array
$seasonal_query = $this->Common_model->getTableData('seasonalprice', array('list_id' => $id));
//vaild array checked ilan
$seasonal_result = $seasonal_query->result_array();
if ($seasonal_query->num_rows() > 0) {
foreach ($seasonal_result as $time) {
//Get Seasonal price
$seasonalprice_query = $this->Common_model->getTableData(
'seasonalprice', array(
'list_id' => $id,
'start_date' => $time['start_date'],
'end_date' => $time['end_date']
));
$seasonalprice = $seasonalprice_query->row()->price;
$seasonal_min_nights = $seasonalprice_query->row()->min_nights;
//Days between start date and end date -> seasonal price
$start_time = $time['start_date'];
$end_time = $time['end_date'];
$i = $start_time;
while ($i <= $end_time) {
$start_date = date('m/d/Y', $i);
$s_date = explode('/', $start_date);
$s_date = $s_date[1] . $s_date[0] . $s_date[2];
$seasonal_prices[$s_date] = $seasonalprice;
$i = get_gmt_time(strtotime('+1 day', $i));
}
}
Then there are the following conditions:
//half-day booking functionality
//add time up to 2PM
$checkin_timestamp = get_gmt_time(strtotime($checkin)) + (14 * 60 * 60);
//add time up to 11AM
$checkout_timestamp = get_gmt_time(strtotime($checkout)) + (11 * 60 * 60);
$query = $this->db->query('SELECT id, list_id FROM `calendar` WHERE `list_id` = "' . $id . '" AND (`booked_days` BETWEEN ' . $checkin_timestamp . ' AND ' . $checkout_timestamp . ') GROUP BY `list_id`');
$rows = $query->num_rows();
$daysexist = $this->db->query("SELECT id,list_id,booked_days FROM `calendar` WHERE `list_id` = '" . $id . "' AND (`booked_days` BETWEEN " . $checkin_timestamp . " AND " . $checkout_timestamp . ") GROUP BY `list_id`");
$rowsexist = $daysexist->num_rows();
if ($rowsexist > 0) {
echo '{"available":false,"total_price":' . $data['price'] . ',"reason_message":"Those dates are not available"}';
}
if ($data['guests'] > $capacity) {
echo '{"available":false,"total_price":' . $data['price'] . ',"reason_message":"' . $capacity . ' guest(s) only allowed"}';
}
elseif ($is_seasonal == 1 && $total_nights -1 < $seasonal_min_nights) {
echo '{"available":false,"total_price":"0","reason_message":"Minimum stay is ' . $data['min_nights_seasonal'] . ' nights for the following period: '.date('m/d/Y', $start_time).' - '.date('m/d/Y', $end_time).'"}';
exit;
}
$this->session->set_userdata("total_price_'" . $id . "'_'" . $this->dx_auth->get_user_id() . "'", $data['price']);
$staggered_price = "";
if ($days >= 30) {
$staggered_price = ',"staggered_price":"' . get_currency_symbol($id) . get_currency_value1($id, $data['price']) . '","staggered":false';
}
elseif (isset($extra_guest)) {
if ($extra_guest == 1) {
echo '{"service_fee":"' . get_currency_symbol($id) . get_currency_value_lys($row->currency, get_currency_code(), $data['commission']) . '","extra_guest_price":"' . get_currency_symbol($id) . get_currency_value1($id, $extra_guest_price) . '","extra_guest":1,"reason_message":"","price_per_night":"' . get_currency_symbol($id) . get_currency_value1($id, $per_night) . '","nights":' . $days . ',"available":true,"can_instant_book":false,"total_price":"' . get_currency_symbol($id) . get_currency_value1($id, $data['price']) . '"' . $staggered_price . '}';
}
}
else {
echo '{"service_fee":"' . get_currency_symbol($id) . get_currency_value_lys($row->currency, get_currency_code(), $data['commission']) . '","reason_message":"","price_per_night":"' . get_currency_symbol($id) . get_currency_value1($id, $per_night) . '","nights":' . $days . ',"available":true,"can_instant_book":false,"total_price":"' . get_currency_symbol($id) . get_currency_value1($id, $data['price']).'"}';
}
And the condition i setted up:
elseif ($is_seasonal == 1 && $total_nights -1 < $seasonal_min_nights) {
echo '{"available":false,"total_price":"0","reason_message":"Minimum stay is ' . $data['min_nights_seasonal'] . ' nights for the following period: '.date('m/d/Y', $start_time).' - '.date('m/d/Y', $end_time).'"}';
exit;
}
And it works fine as long as i have only 1 custom range, in the database there are 2 entries. but the condition i have made always show me the last information that was added to the database instead of the information that applies for the specific timestamp range.
How would i modify the condition to meet with the timestamps and retrive the min_nights foreach timestamps range? Thanks!
I have solved it myself, looped the timestamps and in the loop i setted up the variables i need to work with, then the condition applied to each range of the timestamp individually.. If anybody have similar situation:
Getting the min_nights
$seasonal_min_nights = $seasonalprice_query->row()->min_nights;
Looping in a while:
$start_time = $time['start_date'];
$end_time = $time['end_date'];
$i = $start_time;
while ($i <= $end_time) {
$start_date = date('m/d/Y', $i);
$s_date = explode('/', $start_date);
$s_date = $s_date[1] . $s_date[0] . $s_date[2];
$seasonal_nights[$s_date] = $seasonal_min_nights;
$i = get_gmt_time(strtotime('+1 day', $i));
}
And for loop:
//Total Price
for ($i = 1; $i < $total_nights; $i++) {
$min_seasonal_nights = $seasonal_nights[$travel_dates[$i]];
$is_seasonal = 1;
}
Finally the statment:
if ($is_seasonal == 1 && $total_nights - 1 < $min_seasonal_nights) {
echo '{"available":false,"total_price":"0","reason_message":"Minimum stay is ' . $data['min_seasonal_nights'] . ' nights for the following period: ' . date('m/d/Y', $data['s_start_date']) . ' - ' . date('m/d/Y', $data['s_end_date']) . '"}';
exit;
}
I would do other stype of coding for this but had to work with the existing.. so hope it helps anybody :)