00001 <?php 00002 /*************************************************************************** 00003 * Copyright (C) 2007 by Konstantin V. Arkhipov * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU Lesser General Public License as * 00007 * published by the Free Software Foundation; either version 3 of the * 00008 * License, or (at your option) any later version. * 00009 * * 00010 ***************************************************************************/ 00011 /* $Id: ExtractPart.class.php 4687 2007-12-09 18:57:18Z voxus $ */ 00012 00016 final class ExtractPart implements DialectString, MappableObject 00017 { 00018 private $what = null; 00019 private $from = null; 00020 00021 public static function create( 00022 /* DatePart */ $what, 00023 /* DialectString */ $from 00024 ) 00025 { 00026 return new self($what, $from); 00027 } 00028 00029 public function __construct( 00030 /* DatePart */ $what, 00031 /* DialectString */ $from 00032 ) 00033 { 00034 if ($from instanceof DialectString) 00035 Assert::isTrue( 00036 ($from instanceof DBValue) 00037 || ($from instanceof DBField) 00038 ); 00039 else 00040 $from = new DBField($from); 00041 00042 if (!$what instanceof DatePart) 00043 $what = new DatePart($what); 00044 00045 $this->what = $what; 00046 $this->from = $from; 00047 } 00048 00052 public function toMapped(StorableDAO $dao, JoinCapableQuery $query) 00053 { 00054 return self::create( 00055 $this->what, 00056 $dao->guessAtom($this->from, $query) 00057 ); 00058 } 00059 00060 public function toDialectString(Dialect $dialect) 00061 { 00062 return 00063 'EXTRACT(' 00064 .$this->what->toString() 00065 .' FROM ' 00066 .$this->from->toDialectString($dialect) 00067 .')'; 00068 } 00069 } 00070 ?>