diff options
author | Dan Ungureanu <udan1107@gmail.com> | 2015-07-25 13:30:10 +0300 |
---|---|---|
committer | Dan Ungureanu <udan1107@gmail.com> | 2015-07-25 13:30:10 +0300 |
commit | 0a76734db341f2d0ebd4ea0d1463d2731a59ceda (patch) | |
tree | 168522481e6048256a527469ff992a64c565f934 /src | |
parent | 997d824f8e066a64b121e60f6631e53c44fbb28f (diff) | |
download | sql-parser-0a76734db341f2d0ebd4ea0d1463d2731a59ceda.zip sql-parser-0a76734db341f2d0ebd4ea0d1463d2731a59ceda.tar.gz sql-parser-0a76734db341f2d0ebd4ea0d1463d2731a59ceda.tar.bz2 |
Added builder for ORDER keyword.
Diffstat (limited to 'src')
-rw-r--r-- | src/Components/OrderKeyword.php | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/src/Components/OrderKeyword.php b/src/Components/OrderKeyword.php index 26d0f20..7f1879c 100644 --- a/src/Components/OrderKeyword.php +++ b/src/Components/OrderKeyword.php @@ -37,7 +37,19 @@ class OrderKeyword extends Component * * @var string */ - public $type = 'ASC'; + public $type; + + /** + * Constructor. + * + * @param Expression $field The field that we are sorting by. + * @param string $type The sorting type. + */ + public function __construct($field = null, $type = 'ASC') + { + $this->field = $field; + $this->type = $type; + } /** * @param Parser $parser The parser that serves as context. @@ -110,4 +122,22 @@ class OrderKeyword extends Component --$list->idx; return $ret; } + + /** + * @param OrderKeyword $component The component to be built. + * + * @return string + */ + public static function build($component) + { + if (is_array($component)) { + $ret = array(); + foreach ($component as $c) { + $ret[] = static::build($c); + } + return implode(", ", $ret); + } else { + return Expression::build($component->field) . ' ' . $component->type; + } + } } |