OrderChain.class.php

Go to the documentation of this file.
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: OrderChain.class.php 4687 2007-12-09 18:57:18Z voxus $ */
00012 
00016     final class OrderChain implements DialectString, MappableObject
00017     {
00018         private $chain = array();
00019         
00023         public static function create()
00024         {
00025             return new self;
00026         }
00027         
00031         public function add($order)
00032         {
00033             $this->chain[] = $this->makeOrder($order);
00034             
00035             return $this;
00036         }
00037         
00041         public function prepend($order)
00042         {
00043             if ($this->chain)
00044                 array_unshift($this->chain, $this->makeOrder($order));
00045             else
00046                 $this->chain[] = $this->makeOrder($order);
00047             
00048             return $this;
00049         }
00050         
00054         public function getLast()
00055         {
00056             return end($this->chain);
00057         }
00058         
00059         public function getList()
00060         {
00061             return $this->chain;
00062         }
00063         
00064         public function getCount()
00065         {
00066             return count($this->chain);
00067         }
00068         
00072         public function toMapped(StorableDAO $dao, JoinCapableQuery $query)
00073         {
00074             $chain = new self;
00075             
00076             foreach ($this->chain as $order)
00077                 $chain->add($order->toMapped($dao, $query));
00078             
00079             return $chain;
00080         }
00081         
00082         public function toDialectString(Dialect $dialect)
00083         {
00084             if (!$this->chain)
00085                 return null;
00086             
00087             $out = null;
00088             
00089             foreach ($this->chain as $order)
00090                 $out .= $order->toDialectString($dialect).', ';
00091             
00092             return rtrim($out, ', ');
00093         }
00094         
00098         private function makeOrder($object)
00099         {
00100             if ($object instanceof OrderBy)
00101                 return $object;
00102             elseif ($object instanceof DialectString)
00103                 return new OrderBy($object);
00104             
00105             return
00106                 new OrderBy(
00107                     new DBField($object)
00108                 );
00109         }
00110     }
00111 ?>

Generated on Sun Dec 9 21:56:23 2007 for onPHP by  doxygen 1.5.4