00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
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, $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 ?>