Answer the question
In order to leave comments, you need to log in
How to form an option in selecte to work with time?
Good afternoon, I ran into a problem.
There is a drop down list which is made by select - volume. It has something like marks - the time is from 8 to 22.
The user selects the time from to and his data is written to the database.
Next, I want to check and close the time that the user has chosen and which is registered in the database.
That's what is.
Form
I can't figure out how to avoid double data. There, what is selected, one is closed (disabled) and the second is not.
Here is the code
$timeStart = $formatter -> asTime( $this->model->working_time_start, 'php:G');
$timeEnd = $formatter -> asTime( $this->model->working_time_end, 'php:G');
$checkTimeStart = $this -> getAllTimeMyOrderInConferenceRoom();
$options = '';
for( $i = $timeStart; $i <= $timeEnd; $i++ )
{
foreach( $checkTimeStart as $time )
{
if( in_array( $i,$time ) )
{
$checkOrderTime = $formatter -> asTime( $time[ 'time_start' ], 'php:G');
if( $i == $checkOrderTime )
{
$options .= "<option disabled value='".$checkOrderTime."'>".$checkOrderTime.":00</option>";
}
}
}
$options .= "<option value='".$i."'>".$i.":00</option>";
}
Answer the question
In order to leave comments, you need to log in
View
$timeStart = $formatter -> asTime( $this->model->working_time_start, 'php:G');
$timeEnd = $formatter -> asTime( $this->model->working_time_end, 'php:G');
$checkTimeStart = $this -> getAllTimeMyOrderInConferenceRoom();
$options = '';
for( $i = $timeStart; $i <= $timeEnd; $i++ )
{
$disabled = ( in_array( $i,$checkTimeStart)) ? 'disabled' : '';
$options .= "<option ". $disabled ." value='".$i."'>".$i.":00</option>";
}
public function getAllTimeMyOrderInConferenceRoom( $id_conf_rom )
{
$rows = BookingConferenceRoom ::find()
-> select( 'time_start' )
-> where( [ 'conf_room_id' => $id_conf_rom ] )
-> orderBy( [ 'time_start' => SORT_ASC ] )
-> column();
if( $rows )
{
$dates = [];
foreach( $rows as $row )
{
$dates[] = Yii ::$app -> formatter -> asTime( $row, 'php:G' );
}
return $dates;
}
return [];
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question