[TASK] Move and Namespace classes
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Resource / AbstractRepository.php
1 <?php
2 namespace TYPO3\CMS\Core\Resource;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2011 Andreas Wolf <andreas.wolf@ikt-werk.de>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29 /**
30 * Abstract repository implementing the basic repository methods
31 *
32 * @author Andreas Wolf <andreas.wolf@ikt-werk.de>
33 * @author Ingmar Schlecht <ingmar@typo3.org>
34 * @package TYPO3
35 * @subpackage t3lib
36 */
37 abstract class AbstractRepository implements \TYPO3\CMS\Extbase\Persistence\RepositoryInterface, \TYPO3\CMS\Core\SingletonInterface {
38
39 /**
40 * @var string
41 */
42 protected $table = '';
43
44 /**
45 * @var \TYPO3\CMS\Core\Resource\ResourceFactory
46 */
47 protected $factory;
48
49 /**
50 * @var string
51 */
52 protected $typeField = '';
53
54 /**
55 * @var string
56 */
57 protected $type = '';
58
59 /**
60 * Creates this object.
61 */
62 public function __construct() {
63 $this->factory = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\ResourceFactory');
64 }
65
66 /**
67 * Adds an object to this repository.
68 *
69 * @param object $object The object to add
70 * @return void
71 * @api
72 */
73 public function add($object) {
74
75 }
76
77 /**
78 * Removes an object from this repository.
79 *
80 * @param object $object The object to remove
81 * @return void
82 * @api
83 */
84 public function remove($object) {
85
86 }
87
88 /**
89 * Replaces an object by another.
90 *
91 * @param object $existingObject The existing object
92 * @param object $newObject The new object
93 * @return void
94 * @api
95 */
96 public function replace($existingObject, $newObject) {
97
98 }
99
100 /**
101 * Replaces an existing object with the same identifier by the given object
102 *
103 * @param object $modifiedObject The modified object
104 * @api
105 */
106 public function update($modifiedObject) {
107
108 }
109
110 /**
111 * Returns all objects of this repository add()ed but not yet persisted to
112 * the storage layer.
113 *
114 * @return array An array of objects
115 */
116 public function getAddedObjects() {
117
118 }
119
120 /**
121 * Returns an array with objects remove()d from the repository that
122 * had been persisted to the storage layer before.
123 *
124 * @return array
125 */
126 public function getRemovedObjects() {
127
128 }
129
130 /**
131 * Returns all objects of this repository.
132 *
133 * @return array An array of objects, empty if no objects found
134 * @api
135 */
136 public function findAll() {
137 $itemList = array();
138 $whereClause = 'deleted = 0';
139 if ($this->type != '') {
140 $whereClause .= ((' AND ' . $this->typeField) . ' = ') . $GLOBALS['TYPO3_DB']->fullQuoteStr($this->type, $this->table);
141 }
142 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $this->table, $whereClause);
143 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
144 $itemList[] = $this->createDomainObject($row);
145 }
146 $GLOBALS['TYPO3_DB']->sql_free_result($res);
147 return $itemList;
148 }
149
150 /**
151 * Creates an object managed by this repository.
152 *
153 * @abstract
154 * @param array $databaseRow
155 * @return object
156 */
157 abstract protected function createDomainObject(array $databaseRow);
158
159 /**
160 * Returns the total number objects of this repository.
161 *
162 * @return integer The object count
163 * @api
164 */
165 public function countAll() {
166
167 }
168
169 /**
170 * Removes all objects of this repository as if remove() was called for
171 * all of them.
172 *
173 * @return void
174 * @api
175 */
176 public function removeAll() {
177
178 }
179
180 /**
181 * Finds an object matching the given identifier.
182 *
183 * @param int $uid The identifier of the object to find
184 * @return object The matching object
185 * @api
186 */
187 public function findByUid($uid) {
188 if (!is_numeric($uid)) {
189 throw new \InvalidArgumentException('uid has to be numeric.', 1316779798);
190 }
191 $row = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('*', $this->table, ('uid=' . intval($uid)) . ' AND deleted=0');
192 if (count($row) === 0) {
193 throw new \RuntimeException(('Could not find row with uid "' . $uid) . '" in table $this->table.', 1314354065);
194 }
195 return $this->createDomainObject($row);
196 }
197
198 /**
199 * Sets the property names to order the result by per default.
200 * Expected like this:
201 * array(
202 * 'foo' => Tx_Extbase_Persistence_QueryInterface::ORDER_ASCENDING,
203 * 'bar' => Tx_Extbase_Persistence_QueryInterface::ORDER_DESCENDING
204 * )
205 *
206 * @param array $defaultOrderings The property names to order by
207 * @return void
208 * @api
209 */
210 public function setDefaultOrderings(array $defaultOrderings) {
211 throw new \BadMethodCallException('Repository does not support the setDefaultOrderings() method.', 1313185906);
212 }
213
214 /**
215 * Sets the default query settings to be used in this repository
216 *
217 * @param \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $defaultQuerySettings The query settings to be used by default
218 * @return void
219 * @api
220 */
221 public function setDefaultQuerySettings(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $defaultQuerySettings) {
222 throw new \BadMethodCallException('Repository does not support the setDefaultQuerySettings() method.', 1313185907);
223 }
224
225 /**
226 * Returns a query for objects of this repository
227 *
228 * @return \TYPO3\CMS\Extbase\Persistence\QueryInterface
229 * @api
230 */
231 public function createQuery() {
232 throw new \BadMethodCallException('Repository does not support the createQuery() method.', 1313185908);
233 }
234
235 }
236
237
238 ?>