2 require_once("AOOSException.php");
3 require_once("AOOSModule.php");
7 * Provides an interface for handling data on database or file basis.
8 * @author Sebastian Skejø
10 class AOOSStorageDevice
extends AOOSModule
12 private $_storageObject = null;
13 private $_table = null;
16 * Sets the table in which data should be added, updated or deleted from
17 * @param string $table Table name
20 public function setTable($table)
22 if (!is_string($table))
24 throw new AOOSException($this->_core
, $this->tr("not_string"));
28 $this->_table
= $table;
33 * Sets type of storage device
34 * @param string $type Type of storage device
37 public function setStorageType($type)
39 if (!is_string($type))
41 throw new AOOSException($this->_core
, $this->tr("not_string"));
45 $type = strtolower($type);
49 require_once("lib/AOOSStorageDeviceMySQL.php");
50 $this->_storageObject
= new AOOSStorageDeviceMySQL($this->_core
);
53 throw new AOOSException($this->_core
, $this->tr("storage_type_not_supported"));
59 * Inserts a model to $this->_table
60 * @param AOOSModel $model Model
63 public function insertModel($model)
65 if (!$model instanceof AOOSModel
)
67 throw new AOOSException($this->_core
, $this->tr("not_instance_of_aoos_model"));
73 * Inserts an array to $this->_table
74 * @param array $a Array
77 public function insertArray($a)
81 throw new AOOSException($this->_core
, $this->tr("not_array"));
87 * Inserts a single value to the field of name $key in $this->_table
88 * @param !(array|object) $key Fieldname
89 * @param !(array|object) $value Value
92 public function insertValue($key, $value)
94 if (is_array($key) ||
is_array($value) ||
is_object($key) ||
is_object($value))
96 throw new AOOSException($this->_core
, $this->tr("not_single_value"));
102 * Removes a number of rows from $this->_table
103 * @param int $count Number of rows to delete
106 public function removeRows($count = 1)
110 throw new AOOSException($this->_core
, $this->tr("not_integer"));
116 * Updates $this->_table with values from $model
117 * @param AOOSModel $model Model
120 public function updateModel($model)
122 if (!$model instanceof AOOSModel
)
124 throw new AOOSException($this->_core
, $this->tr("not_instance_of_aoos_model"));
130 * Updates $this->_table with values from $a
131 * @param array $model Array
134 public function updateArray($a)
138 throw new AOOSException($this->_core
, $this->tr("not_array"));
144 * Updates a single field of $this->_table
145 * @param !(array|object) $key Fieldname
146 * @param !(array|object) $value New value of $key
149 public function updateValue($key, $value)
151 if (is_array($key) ||
is_array($value) ||
is_object($key) ||
is_object($value))
153 throw new AOOSException($this->_core
, $this->tr("not_single_value"));