I
I
Ivan Lykov2018-06-26 14:09:38
Yii
Ivan Lykov, 2018-06-26 14:09:38

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
5b321e5ea8b5e387503774.png
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>";
    }

I see that I am requesting data twice, but how can I do the check correctly and hide what is no longer available ...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Lykov, 2018-06-26
@Jhon_Light

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>";
    }

Model
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 [];
    }

M
Mykola, 2018-06-26
@iSensetivity

And here YII?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question