Gdn_SQLDriver::selectCase PHP Method

selectCase() public method

Allows the specification of a case statement in the select list.
public selectCase ( string $Field, array $Options, string $Alias ) : Gdn_SQLDriver
$Field string The field being examined in the case statement.
$Options array The options and results in an associative array. A blank key will be the final "else" option of the case statement. eg. array('null' => 1, '' => 0) results in "when null then 1 else 0".
$Alias string The alias to give a column name.
return Gdn_SQLDriver $this
    public function selectCase($Field, $Options, $Alias)
    {
        $CaseOptions = '';
        foreach ($Options as $Key => $Val) {
            if ($Key == '') {
                $CaseOptions .= ' else ' . $Val;
            } else {
                $CaseOptions .= ' when ' . $Key . ' then ' . $Val;
            }
        }
        $Expr = array('Field' => $Field, 'Function' => '', 'Alias' => $Alias, 'CaseOptions' => $CaseOptions);
        if ($Alias == '') {
            $this->_Selects[] = $Expr;
        } else {
            $this->_Selects[$Alias] = $Expr;
        }
        return $this;
    }