Improved grammar of documentation.
[AOOS.git] / AOOSStorageDevice.php
blobf7e4a1bd2cdce35799cfb1381db31d6bcf3e7e49
1 <?php
2 require_once("AOOSException.php");
3 require_once("AOOSModule.php");
5 /**
6 * AOOSStorageDevice
7 * Provides an interface for handling data on database or file basis.
8 * @author Sebastian Skejø
9 */
10 class AOOSStorageDevice extends AOOSModule
12 private $_storageObject = null;
13 private $_table = null;
15 /**
16 * Sets the table in which data should be added, updated or deleted from
17 * @param string $table Table name
18 * @return bool
20 public function setTable($table)
22 if (!is_string($table))
24 throw new AOOSException($this->_core, $this->tr("not_string"));
25 return false;
28 $this->_table = $table;
29 return true;
32 /**
33 * Sets type of storage device
34 * @param string $type Type of storage device
35 * @return bool
37 public function setStorageType($type)
39 if (!is_string($type))
41 throw new AOOSException($this->_core, $this->tr("not_string"));
42 return false;
45 $type = strtolower($type);
46 switch ($type)
48 case ("mysql"):
49 require_once("lib/AOOSStorageDeviceMySQL.php");
50 $this->_storageObject = new AOOSStorageDeviceMySQL($this->_core);
51 break;
52 default:
53 throw new AOOSException($this->_core, $this->tr("storage_type_not_supported"));
54 return false;
58 /**
59 * Inserts a model to $this->_table
60 * @param AOOSModel $model Model
61 * @return bool
63 public function insertModel($model)
65 if (!$model instanceof AOOSModel)
67 throw new AOOSException($this->_core, $this->tr("not_instance_of_aoos_model"));
68 return false;
72 /**
73 * Inserts an array to $this->_table
74 * @param array $a Array
75 * @return bool
77 public function insertArray($a)
79 if (!is_array($a))
81 throw new AOOSException($this->_core, $this->tr("not_array"));
82 return false;
86 /**
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
90 * @return bool
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"));
97 return false;
102 * Removes a number of rows from $this->_table
103 * @param int $count Number of rows to delete
104 * @return bool
106 public function removeRows($count = 1)
108 if(!is_int($count))
110 throw new AOOSException($this->_core, $this->tr("not_integer"));
111 return false;
116 * Updates $this->_table with values from $model
117 * @param AOOSModel $model Model
118 * @return bool
120 public function updateModel($model)
122 if (!$model instanceof AOOSModel)
124 throw new AOOSException($this->_core, $this->tr("not_instance_of_aoos_model"));
125 return false;
130 * Updates $this->_table with values from $a
131 * @param array $model Array
132 * @return bool
134 public function updateArray($a)
136 if (!is_array($a))
138 throw new AOOSException($this->_core, $this->tr("not_array"));
139 return false;
144 * Updates a single field of $this->_table
145 * @param !(array|object) $key Fieldname
146 * @param !(array|object) $value New value of $key
147 * @return bool
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"));
154 return false;