Permalink
Browse files

Merge pull request #80 from simukti/master

adding mysql DAY, MONTH, and WEEK function
  • Loading branch information...
2 parents b00cde2 + c55d3c8 commit d38b081dbf826960bd9aad9d7dabed5164d3e7d3 @beberlei committed May 16, 2012
@@ -0,0 +1,53 @@
+<?php
+
+/*
+ * DoctrineExtensions Mysql Function Pack
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to kontakt@beberlei.de so I can send you a copy immediately.
+ */
+
+namespace DoctrineExtensions\Query\Mysql;
+
+use Doctrine\ORM\Query\Lexer;
+use Doctrine\ORM\Query\AST\Functions\FunctionNode;
+
+/**
+ * "DAY" "(" SimpleArithmeticExpression ")". Modified from DoctrineExtensions\Query\Mysql\Year
+ *
+ * @category DoctrineExtensions
+ * @package DoctrineExtensions\Query\Mysql
+ * @author Rafael Kassner <kassner@gmail.com>
+ * @author Sarjono Mukti Aji <me@simukti.net>
+ * @license MIT License
+ */
+class Day extends FunctionNode
+{
+ public $date;
+
+ /**
+ * @override
+ */
+ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
+ {
+ return "DAY(" . $sqlWalker->walkArithmeticPrimary($this->date) . ")";
+ }
+
+ /**
+ * @override
+ */
+ public function parse(\Doctrine\ORM\Query\Parser $parser)
+ {
+ $parser->match(Lexer::T_IDENTIFIER);
+ $parser->match(Lexer::T_OPEN_PARENTHESIS);
+
+ $this->date = $parser->ArithmeticPrimary();
+
+ $parser->match(Lexer::T_CLOSE_PARENTHESIS);
+ }
+}
@@ -0,0 +1,53 @@
+<?php
+
+/*
+ * DoctrineExtensions Mysql Function Pack
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to kontakt@beberlei.de so I can send you a copy immediately.
+ */
+
+namespace DoctrineExtensions\Query\Mysql;
+
+use Doctrine\ORM\Query\Lexer;
+use Doctrine\ORM\Query\AST\Functions\FunctionNode;
+
+/**
+ * "MONTH" "(" SimpleArithmeticExpression ")". Modified from DoctrineExtensions\Query\Mysql\Year
+ *
+ * @category DoctrineExtensions
+ * @package DoctrineExtensions\Query\Mysql
+ * @author Rafael Kassner <kassner@gmail.com>
+ * @author Sarjono Mukti Aji <me@simukti.net>
+ * @license MIT License
+ */
+class Month extends FunctionNode
+{
+ public $date;
+
+ /**
+ * @override
+ */
+ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
+ {
+ return "MONTH(" . $sqlWalker->walkArithmeticPrimary($this->date) . ")";
+ }
+
+ /**
+ * @override
+ */
+ public function parse(\Doctrine\ORM\Query\Parser $parser)
+ {
+ $parser->match(Lexer::T_IDENTIFIER);
+ $parser->match(Lexer::T_OPEN_PARENTHESIS);
+
+ $this->date = $parser->ArithmeticPrimary();
+
+ $parser->match(Lexer::T_CLOSE_PARENTHESIS);
+ }
+}
@@ -0,0 +1,54 @@
+<?php
+
+/*
+ * DoctrineExtensions Mysql Function Pack
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to kontakt@beberlei.de so I can send you a copy immediately.
+ */
+
+namespace DoctrineExtensions\Query\Mysql;
+
+use Doctrine\ORM\Query\Lexer;
+use Doctrine\ORM\Query\AST\Functions\FunctionNode;
+
+/**
+ * "WEEK" "(" SimpleArithmeticExpression ")". Modified from DoctrineExtensions\Query\Mysql\Year
+ *
+ * @category DoctrineExtensions
+ * @package DoctrineExtensions\Query\Mysql
+ * @author Rafael Kassner <kassner@gmail.com>
+ * @author Sarjono Mukti Aji <me@simukti.net>
+ * @author Łukasz Nowicki <lukasz.mnowicki@gmail.com>
+ * @license MIT License
+ */
+class Week extends FunctionNode
+{
+ public $date;
+
+ /**
+ * @override
+ */
+ public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
+ {
+ return "WEEK(" . $sqlWalker->walkArithmeticPrimary($this->date) . ")";
+ }
+
+ /**
+ * @override
+ */
+ public function parse(\Doctrine\ORM\Query\Parser $parser)
+ {
+ $parser->match(Lexer::T_IDENTIFIER);
+ $parser->match(Lexer::T_OPEN_PARENTHESIS);
+
+ $this->date = $parser->ArithmeticPrimary();
+
+ $parser->match(Lexer::T_CLOSE_PARENTHESIS);
+ }
+}

0 comments on commit d38b081

Please sign in to comment.