Traq\Models\Status::selectOptions PHP Method

selectOptions() public static method

Returns an array formatted for the Form::select() method.
public static selectOptions ( $valueField = 'id' ) : array
return array
    public static function selectOptions($valueField = 'id')
    {
        $open = Language::translate('open');
        $closed = Language::translate('closed');
        $options = [$open => [], $closed => []];
        foreach (static::all() as $status) {
            $option = ['label' => $status['name'], 'value' => $status[$valueField]];
            if ($status->status) {
                $options[$open][] = $option;
            } else {
                $options[$closed][] = $option;
            }
        }
        return $options;
    }

Usage Example

Example #1
0
 /**
  * Returns options for the specific ticket filter.
  *
  * @param string $filter
  *
  * @return array
  */
 public static function selectOptionsFor($filter, Project $project)
 {
     switch ($filter) {
         // Milestone options
         case 'milestone':
             $options = $project->milestoneSelectOptions('slug');
             break;
             // Version options
         // Version options
         case 'version':
             $options = $project->milestoneSelectOptions('slug');
             break;
             // Type options
         // Type options
         case 'type':
             $options = Type::selectOptions('name');
             break;
             // Status options
         // Status options
         case 'status':
             $options = Status::selectOptions('name');
             break;
             // Component options
         // Component options
         case 'component':
             $options = Component::selectOptions($project->id, 'name');
             break;
             // Priority options
         // Priority options
         case 'priority':
             $options = Priority::selectOptions('name');
             break;
             // Severity options
         // Severity options
         case 'severity':
             $options = Severity::selectOptions('name');
             break;
     }
     return $options;
 }