InsertOrUpdateQuery.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2004-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: InsertOrUpdateQuery.class.php 4687 2007-12-09 18:57:18Z voxus $ */
00012 
00018     abstract class InsertOrUpdateQuery
00019         extends QuerySkeleton
00020         implements SQLTableName
00021     {
00022         protected $table    = null;
00023         protected $fields   = array();
00024 
00025         abstract public function setTable($table);
00026 
00027         public function getTable()
00028         {
00029             return $this->table;
00030         }
00031         
00035         public function set($field, $value = null)
00036         {
00037             $this->fields[$field] = $value;
00038 
00039             return $this;
00040         }
00041 
00046         public function drop($field)
00047         {
00048             if (!array_key_exists($field, $this->fields))
00049                 throw new MissingElementException("unknown field '{$field}'");
00050 
00051             unset($this->fields[$field]);
00052 
00053             return $this;
00054         }
00055 
00059         public function lazySet($field, /* Identifiable */ $object = null)
00060         {
00061             if ($object === null)
00062                 $this->set($field, null);
00063             elseif ($object instanceof Identifiable)
00064                 $this->set($field, $object->getId());
00065             elseif ($object instanceof Range)
00066                 $this->
00067                     set($field.'_min', $object->getMin())->
00068                     set($field.'_max', $object->getMax());
00069             elseif ($object instanceof DateRange)
00070                 $this->
00071                     set($field.'_start', $object->getStart())->
00072                     set($field.'_end', $object->getEnd());
00073             elseif ($object instanceof Stringable)
00074                 $this->set($field, $object->toString());
00075             else
00076                 $this->set($field, $object);
00077             
00078             return $this;
00079         }
00080 
00084         public function setBoolean($field, $value = false)
00085         {
00086             try {
00087                 Assert::isTernaryBase($value);
00088                 $this->set($field, $value);
00089             } catch (WrongArgumentException $e) {/*_*/}
00090 
00091             return $this;
00092         }
00093 
00099         public function arraySet($fields)
00100         {
00101             Assert::isArray($fields);
00102 
00103             $this->fields = array_merge($this->fields, $fields);
00104 
00105             return $this;
00106         }
00107     }
00108 ?>

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