1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Directus – <http://getdirectus.com> |
5
|
|
|
* |
6
|
|
|
* @link The canonical repository – <https://github.com/directus/directus> |
7
|
|
|
* @copyright Copyright 2006-2016 RANGER Studio, LLC – <http://rangerstudio.com> |
8
|
|
|
* @license GNU General Public License (v3) – <http://www.gnu.org/copyleft/gpl.html> |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Directus\SDK; |
12
|
|
|
|
13
|
|
|
use Directus\Database\Connection; |
14
|
|
|
use Directus\Database\TableGateway\BaseTableGateway; |
15
|
|
|
use Directus\Database\TableGateway\DirectusActivityTableGateway; |
16
|
|
|
use Directus\Database\TableGateway\DirectusMessagesTableGateway; |
17
|
|
|
use Directus\Database\TableGateway\DirectusPreferencesTableGateway; |
18
|
|
|
use Directus\Database\TableGateway\DirectusPrivilegesTableGateway; |
19
|
|
|
use Directus\Database\TableGateway\DirectusUiTableGateway; |
20
|
|
|
use Directus\Database\TableGateway\DirectusUsersTableGateway; |
21
|
|
|
use Directus\Database\TableGateway\RelationalTableGateway; |
22
|
|
|
use Directus\Database\TableSchema; |
23
|
|
|
use Directus\Util\ArrayUtils; |
24
|
|
|
use Directus\Util\SchemaUtils; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Client Local |
28
|
|
|
* |
29
|
|
|
* Client to Interact with the database directly using Directus Database Component |
30
|
|
|
* |
31
|
|
|
* @author Welling Guzmán <[email protected]> |
32
|
|
|
*/ |
33
|
|
|
class ClientLocal extends AbstractClient |
34
|
|
|
{ |
35
|
|
|
/** |
36
|
|
|
* @var BaseTableGateway[] |
37
|
|
|
*/ |
38
|
|
|
protected $tableGateways = []; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var Connection |
42
|
|
|
*/ |
43
|
|
|
protected $connection = null; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* ClientLocal constructor. |
47
|
|
|
* |
48
|
|
|
* @param $connection |
49
|
|
|
*/ |
50
|
|
|
public function __construct($connection) |
51
|
|
|
{ |
52
|
|
|
$this->connection = $connection; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @inheritDoc |
57
|
|
|
*/ |
58
|
|
|
public function getTables(array $params = []) |
59
|
|
|
{ |
60
|
|
|
return $this->createResponseFromData(TableSchema::getTablesSchema($params)); |
|
|
|
|
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @inheritDoc |
65
|
|
|
*/ |
66
|
|
|
public function getTable($tableName) |
67
|
|
|
{ |
68
|
|
|
return $this->createResponseFromData(TableSchema::getSchemaArray($tableName)); |
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @inheritDoc |
73
|
|
|
*/ |
74
|
|
|
public function getColumns($tableName, array $params = []) |
75
|
|
|
{ |
76
|
|
|
return $this->createResponseFromData(TableSchema::getColumnSchemaArray($tableName, $params)); |
|
|
|
|
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @inheritDoc |
81
|
|
|
*/ |
82
|
|
|
public function getColumn($tableName, $columnName) |
83
|
|
|
{ |
84
|
|
|
return $this->createResponseFromData(TableSchema::getColumnSchema($tableName, $columnName)->toArray()); |
|
|
|
|
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @inheritDoc |
89
|
|
|
*/ |
90
|
|
|
public function getEntries($tableName, array $params = []) |
91
|
|
|
{ |
92
|
|
|
$tableGateway = $this->getTableGateway($tableName); |
93
|
|
|
|
94
|
|
|
return $this->createResponseFromData($tableGateway->getEntries($params)); |
|
|
|
|
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @inheritDoc |
99
|
|
|
*/ |
100
|
|
|
public function getEntry($tableName, $id, array $params = []) |
101
|
|
|
{ |
102
|
|
|
// @TODO: Dynamic ID |
103
|
|
|
return $this->getEntries($tableName, array_merge($params, [ |
|
|
|
|
104
|
|
|
'id' => $id |
105
|
|
|
])); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @inheritDoc |
110
|
|
|
*/ |
111
|
|
|
public function getUsers(array $params = []) |
112
|
|
|
{ |
113
|
|
|
// @TODO: store the directus tables somewhere (SchemaManager?) |
114
|
|
|
return $this->getEntries('directus_users', $params); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @inheritDoc |
119
|
|
|
*/ |
120
|
|
|
public function getUser($id, array $params = []) |
121
|
|
|
{ |
122
|
|
|
return $this->getEntry('directus_users', $id, $params); |
|
|
|
|
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @inheritDoc |
127
|
|
|
*/ |
128
|
|
|
public function getGroups(array $params = []) |
129
|
|
|
{ |
130
|
|
|
return $this->getEntries('directus_groups', $params); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* @inheritDoc |
135
|
|
|
*/ |
136
|
|
|
public function getGroup($id, array $params = []) |
137
|
|
|
{ |
138
|
|
|
return $this->getEntry('directus_groups', $id, $params); |
|
|
|
|
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* @inheritDoc |
143
|
|
|
*/ |
144
|
|
|
public function getGroupPrivileges($groupID) |
145
|
|
|
{ |
146
|
|
|
$this->getEntries('directus_privileges', [ |
147
|
|
|
'filter' => [ |
148
|
|
|
'group_id' => ['eq' => $groupID] |
149
|
|
|
] |
150
|
|
|
]); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @inheritDoc |
155
|
|
|
*/ |
156
|
|
|
public function getFiles(array $params = []) |
157
|
|
|
{ |
158
|
|
|
return $this->getEntries('directus_files', $params); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
/** |
162
|
|
|
* @inheritDoc |
163
|
|
|
*/ |
164
|
|
|
public function getFile($id, array $params = []) |
165
|
|
|
{ |
166
|
|
|
return $this->getEntry('directus_files', $id, $params); |
|
|
|
|
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @inheritDoc |
171
|
|
|
*/ |
172
|
|
|
public function getSettings() |
173
|
|
|
{ |
174
|
|
|
return $this->getEntries('directus_settings'); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @inheritDoc |
179
|
|
|
*/ |
180
|
|
|
public function getSettingsByCollection($collectionName) |
181
|
|
|
{ |
182
|
|
|
return $this->getEntries('directus_settings', [ |
183
|
|
|
'filter' => [ |
184
|
|
|
'collection' => ['eq' => $collectionName] |
185
|
|
|
] |
186
|
|
|
]); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* @inheritDoc |
191
|
|
|
*/ |
192
|
|
|
public function getMessages($userId) |
193
|
|
|
{ |
194
|
|
|
$messagesTableGateway = new DirectusMessagesTableGateway($this->connection, null); |
|
|
|
|
195
|
|
|
$result = $messagesTableGateway->fetchMessagesInboxWithHeaders($userId); |
196
|
|
|
|
197
|
|
|
return $this->createResponseFromData($result); |
|
|
|
|
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @inheritDoc |
202
|
|
|
*/ |
203
|
|
View Code Duplication |
public function createEntry($tableName, array $data) |
|
|
|
|
204
|
|
|
{ |
205
|
|
|
$tableGateway = $this->getTableGateway($tableName); |
206
|
|
|
$data = $this->processData($tableName, $data); |
207
|
|
|
|
208
|
|
|
foreach($data as $key => $value) { |
209
|
|
|
if ($value instanceof File) { |
210
|
|
|
$data[$key] = $this->processFile($value); |
211
|
|
|
} |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
$newRecord = $tableGateway->manageRecordUpdate($tableName, $data); |
215
|
|
|
|
216
|
|
|
return $this->getEntry($tableName, $newRecord[$tableGateway->primaryKeyFieldName]); |
|
|
|
|
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* @inheritDoc |
221
|
|
|
*/ |
222
|
|
View Code Duplication |
public function updateEntry($tableName, $id, array $data) |
|
|
|
|
223
|
|
|
{ |
224
|
|
|
$tableGateway = $this->getTableGateway($tableName); |
225
|
|
|
$data = $this->processData($tableName, $data); |
226
|
|
|
|
227
|
|
|
foreach($data as $key => $value) { |
228
|
|
|
if ($value instanceof File) { |
229
|
|
|
$data[$key] = $this->processFile($value); |
230
|
|
|
} |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
$updatedRecord = $tableGateway->manageRecordUpdate($tableName, array_merge($data, ['id' => $id])); |
234
|
|
|
|
235
|
|
|
return $this->getEntry($tableName, $updatedRecord[$tableGateway->primaryKeyFieldName]); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* @inheritDoc |
240
|
|
|
*/ |
241
|
|
|
public function deleteEntry($tableName, $ids) |
242
|
|
|
{ |
243
|
|
|
// @TODO: Accept EntryCollection and Entry |
244
|
|
|
$tableGateway = $this->getTableGateway($tableName); |
245
|
|
|
|
246
|
|
|
if (!is_array($ids)) { |
247
|
|
|
$ids = [$ids]; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
return $tableGateway->delete(function($delete) use ($ids) { |
251
|
|
|
return $delete->where->in('id', $ids); |
252
|
|
|
}); |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* @inheritDoc |
257
|
|
|
*/ |
258
|
|
|
public function createUser(array $data) |
259
|
|
|
{ |
260
|
|
|
return $this->createEntry('directus_users', $data); |
|
|
|
|
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* @inheritDoc |
265
|
|
|
*/ |
266
|
|
|
public function updateUser($id, array $data) |
267
|
|
|
{ |
268
|
|
|
return $this->updateEntry('directus_users', $id, $data); |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* @inheritDoc |
273
|
|
|
*/ |
274
|
|
|
public function deleteUser($ids) |
275
|
|
|
{ |
276
|
|
|
return $this->deleteEntry('directus_users', $ids); |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* @inheritDoc |
281
|
|
|
*/ |
282
|
|
|
public function createFile(File $file) |
283
|
|
|
{ |
284
|
|
|
$data = $this->processFile($file); |
285
|
|
|
|
286
|
|
|
return $this->createEntry('directus_files', $data); |
|
|
|
|
287
|
|
|
} |
288
|
|
|
|
289
|
|
|
/** |
290
|
|
|
* @inheritDoc |
291
|
|
|
*/ |
292
|
|
|
public function updateFile($id, array $data) |
293
|
|
|
{ |
294
|
|
|
return $this->updateEntry('directus_files', $id, $data); |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
* @inheritDoc |
299
|
|
|
*/ |
300
|
|
|
public function deleteFile($ids) |
301
|
|
|
{ |
302
|
|
|
return $this->deleteEntry('directus_files', $ids); |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
public function createPreferences($data) |
306
|
|
|
{ |
307
|
|
|
if (!ArrayUtils::contains($data, ['title', 'table_name'])) { |
308
|
|
|
throw new \Exception('title and table_name are required'); |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
$acl = $this->container->get('acl'); |
312
|
|
|
$data['user'] = $acl->getUserId(); |
313
|
|
|
|
314
|
|
|
return $this->createEntry('directus_preferences', $data); |
|
|
|
|
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
/** |
318
|
|
|
* @inheritdoc |
319
|
|
|
*/ |
320
|
|
|
public function createBookmark($data) |
321
|
|
|
{ |
322
|
|
|
$acl = $this->container->get('acl'); |
323
|
|
|
$data['user'] = $acl->getUserId(); |
324
|
|
|
|
325
|
|
|
$preferences = $this->createPreferences(ArrayUtils::pick($data, [ |
326
|
|
|
'title', 'table_name', 'sort', 'status', 'search_string', 'sort_order', 'columns_visible', 'user' |
327
|
|
|
])); |
328
|
|
|
|
329
|
|
|
$title = $preferences->title; |
|
|
|
|
330
|
|
|
$tableName = $preferences->table_name; |
|
|
|
|
331
|
|
|
$bookmarkData = [ |
332
|
|
|
'section' => 'search', |
333
|
|
|
'title' => $title, |
334
|
|
|
'url' => 'tables/' . $tableName . '/pref/' . $title, |
335
|
|
|
'user' => $data['user'] |
336
|
|
|
]; |
337
|
|
|
|
338
|
|
|
return $this->createEntry('directus_bookmarks', $bookmarkData); |
|
|
|
|
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
/** |
342
|
|
|
* @inheritdoc |
343
|
|
|
*/ |
344
|
|
|
public function createColumn($data) |
345
|
|
|
{ |
346
|
|
|
$data = $this->parseColumnData($data); |
347
|
|
|
|
348
|
|
|
$tableGateway = $this->getTableGateway($data['table_name']); |
349
|
|
|
|
350
|
|
|
$tableGateway->addColumn($data['table_name'], ArrayUtils::omit($data, ['table_name'])); |
351
|
|
|
|
352
|
|
|
return $this->getColumn($data['table_name'], $data['column_name']); |
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
/** |
356
|
|
|
* @inheritdoc |
357
|
|
|
*/ |
358
|
|
|
public function createGroup(array $data) |
359
|
|
|
{ |
360
|
|
|
return $this->createEntry('directus_groups', $data); |
|
|
|
|
361
|
|
|
} |
362
|
|
|
|
363
|
|
|
/** |
364
|
|
|
* @inheritdoc |
365
|
|
|
*/ |
366
|
|
|
public function createMessage(array $data) |
367
|
|
|
{ |
368
|
|
|
$this->requiredAttributes(['from', 'message', 'subject'], $data); |
369
|
|
|
$this->requiredOneAttribute(['to', 'toGroup'], $data); |
370
|
|
|
|
371
|
|
|
$recipients = $this->getMessagesTo($data); |
372
|
|
|
$recipients = explode(',', $recipients); |
373
|
|
|
ArrayUtils::remove($data, ['to', 'toGroup']); |
374
|
|
|
|
375
|
|
|
$groupRecipients = []; |
376
|
|
|
$userRecipients = []; |
377
|
|
|
foreach ($recipients as $recipient) { |
378
|
|
|
$typeAndId = explode('_', $recipient); |
379
|
|
|
if ($typeAndId[0] == 0) { |
380
|
|
|
$userRecipients[] = $typeAndId[1]; |
381
|
|
|
} else { |
382
|
|
|
$groupRecipients[] = $typeAndId[1]; |
383
|
|
|
} |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
$ZendDb = $this->container->get('connection'); |
387
|
|
|
$acl = $this->container->get('acl'); |
388
|
|
|
if (count($groupRecipients) > 0) { |
389
|
|
|
$usersTableGateway = new DirectusUsersTableGateway($ZendDb, $acl); |
390
|
|
|
$result = $usersTableGateway->findActiveUserIdsByGroupIds($groupRecipients); |
391
|
|
|
foreach ($result as $item) { |
392
|
|
|
$userRecipients[] = $item['id']; |
393
|
|
|
} |
394
|
|
|
} |
395
|
|
|
|
396
|
|
|
$userRecipients[] = $acl->getUserId(); |
397
|
|
|
|
398
|
|
|
$messagesTableGateway = new DirectusMessagesTableGateway($ZendDb, $acl); |
399
|
|
|
$id = $messagesTableGateway->sendMessage($data, array_unique($userRecipients), $acl->getUserId()); |
400
|
|
|
|
401
|
|
|
if ($id) { |
402
|
|
|
$Activity = new DirectusActivityTableGateway($ZendDb, $acl); |
403
|
|
|
$data['id'] = $id; |
404
|
|
|
$Activity->recordMessage($data, $acl->getUserId()); |
405
|
|
|
} |
406
|
|
|
|
407
|
|
|
$message = $messagesTableGateway->fetchMessageWithRecipients($id, $acl->getUserId()); |
408
|
|
|
$response = [ |
409
|
|
|
'meta' => [ |
410
|
|
|
'type' => 'entry', |
411
|
|
|
'table' => 'directus_messages' |
412
|
|
|
], |
413
|
|
|
'data' => $message |
414
|
|
|
]; |
415
|
|
|
|
416
|
|
|
return $this->createResponseFromData($response); |
|
|
|
|
417
|
|
|
} |
418
|
|
|
|
419
|
|
|
/** |
420
|
|
|
* @inheritdoc |
421
|
|
|
*/ |
422
|
|
|
public function sendMessage(array $data) |
423
|
|
|
{ |
424
|
|
|
return $this->createMessage($data); |
425
|
|
|
} |
426
|
|
|
|
427
|
|
View Code Duplication |
public function createPrivileges(array $data) |
|
|
|
|
428
|
|
|
{ |
429
|
|
|
$connection = $this->container->get('connection'); |
430
|
|
|
$acl = $this->container->get('acl'); |
431
|
|
|
$privileges = new DirectusPrivilegesTableGateway($connection, $acl); |
432
|
|
|
|
433
|
|
|
$response = [ |
434
|
|
|
'meta' => [ |
435
|
|
|
'type' => 'entry', |
436
|
|
|
'table' => 'directus_privileges' |
437
|
|
|
], |
438
|
|
|
'data' => $privileges->insertPrivilege($data) |
439
|
|
|
]; |
440
|
|
|
|
441
|
|
|
return $this->createResponseFromData($response); |
|
|
|
|
442
|
|
|
} |
443
|
|
|
|
444
|
|
|
public function createTable($name, array $data = []) |
445
|
|
|
{ |
446
|
|
|
$isTableNameAlphanumeric = preg_match("/[a-z0-9]+/i", $name); |
447
|
|
|
$zeroOrMoreUnderscoresDashes = preg_match("/[_-]*/i", $name); |
448
|
|
|
|
449
|
|
|
if (!($isTableNameAlphanumeric && $zeroOrMoreUnderscoresDashes)) { |
450
|
|
|
return $this->createResponseFromData(['error' => ['message' => 'invalid_table_name']]); |
|
|
|
|
451
|
|
|
} |
452
|
|
|
|
453
|
|
|
$schema = $this->container->get('schemaManager'); |
454
|
|
|
$emitter = $this->container->get('emitter'); |
455
|
|
|
if (!$schema->tableExists($name)) { |
456
|
|
|
$emitter->run('table.create:before', $name); |
457
|
|
|
// Through API: |
458
|
|
|
// Remove spaces and symbols from table name |
459
|
|
|
// And in lowercase |
460
|
|
|
$name = SchemaUtils::cleanTableName($name); |
461
|
|
|
$schema->createTable($name); |
462
|
|
|
$emitter->run('table.create', $name); |
463
|
|
|
$emitter->run('table.create:after', $name); |
464
|
|
|
} |
465
|
|
|
|
466
|
|
|
$connection = $this->container->get('connection'); |
467
|
|
|
$acl = $this->container->get('acl'); |
468
|
|
|
$privileges = new DirectusPrivilegesTableGateway($connection, $acl); |
469
|
|
|
|
470
|
|
|
return $this->createResponseFromData($privileges->insertPrivilege([ |
|
|
|
|
471
|
|
|
'group_id' => 1, |
472
|
|
|
'table_name' => $name |
473
|
|
|
])); |
474
|
|
|
} |
475
|
|
|
|
476
|
|
|
/** |
477
|
|
|
* @inheritdoc |
478
|
|
|
*/ |
479
|
|
|
public function createColumnUIOptions(array $data) |
480
|
|
|
{ |
481
|
|
|
$this->requiredAttributes(['table', 'column', 'ui', 'options'], $data); |
482
|
|
|
$tableGateway = $this->getTableGateway('directus_ui'); |
483
|
|
|
|
484
|
|
|
$table = $data['table']; |
485
|
|
|
$column = $data['column']; |
486
|
|
|
$ui = $data['ui']; |
487
|
|
|
|
488
|
|
|
$data = $data['options']; |
489
|
|
|
$keys = ['table_name' => $table, 'column_name' => $column, 'ui_name' => $ui]; |
490
|
|
|
$uis = to_name_value($data, $keys); |
491
|
|
|
|
492
|
|
|
$column_settings = []; |
493
|
|
|
foreach ($uis as $col) { |
494
|
|
|
$existing = $tableGateway->select(['table_name' => $table, 'column_name' => $column, 'ui_name' => $ui, 'name' => $col['name']])->toArray(); |
495
|
|
|
if (count($existing) > 0) { |
496
|
|
|
$col['id'] = $existing[0]['id']; |
497
|
|
|
} |
498
|
|
|
array_push($column_settings, $col); |
499
|
|
|
} |
500
|
|
|
$tableGateway->updateCollection($column_settings); |
501
|
|
|
|
502
|
|
|
$connection = $this->container->get('connection'); |
503
|
|
|
$acl = $this->container->get('acl'); |
504
|
|
|
$UiOptions = new DirectusUiTableGateway($connection, $acl); |
505
|
|
|
$response = $UiOptions->fetchOptions($table, $column, $ui); |
506
|
|
|
|
507
|
|
|
if (!$response) { |
|
|
|
|
508
|
|
|
$response = [ |
509
|
|
|
'error' => [ |
510
|
|
|
'message' => sprintf('unable_to_find_column_%s_options_for_%s', ['column' => $column, 'ui' => $ui]) |
511
|
|
|
], |
512
|
|
|
'success' => false |
513
|
|
|
]; |
514
|
|
|
} else { |
515
|
|
|
$response = [ |
516
|
|
|
'meta' => [ |
517
|
|
|
'type' => 'entry', |
518
|
|
|
'table' => 'directus_ui' |
519
|
|
|
], |
520
|
|
|
'data' => $response |
521
|
|
|
]; |
522
|
|
|
} |
523
|
|
|
|
524
|
|
|
return $this->createResponseFromData($response); |
|
|
|
|
525
|
|
|
} |
526
|
|
|
|
527
|
|
View Code Duplication |
public function getPreferences($table, $user) |
|
|
|
|
528
|
|
|
{ |
529
|
|
|
$acl = $this->container->get('acl'); |
530
|
|
|
$connection = $this->container->get('connection'); |
531
|
|
|
$preferencesTableGateway = new DirectusPreferencesTableGateway($connection, $acl); |
532
|
|
|
|
533
|
|
|
$response = [ |
534
|
|
|
'meta' => [ |
535
|
|
|
'type' => 'entry', |
536
|
|
|
'table' => 'directus_preferences' |
537
|
|
|
], |
538
|
|
|
'data' => $preferencesTableGateway->fetchByUserAndTableAndTitle($user, $table) |
539
|
|
|
]; |
540
|
|
|
|
541
|
|
|
return $this->createResponseFromData($response); |
|
|
|
|
542
|
|
|
} |
543
|
|
|
|
544
|
|
|
/** |
545
|
|
|
* Get a table gateway for the given table name |
546
|
|
|
* |
547
|
|
|
* @param $tableName |
548
|
|
|
* |
549
|
|
|
* @return RelationalTableGateway |
550
|
|
|
*/ |
551
|
|
|
protected function getTableGateway($tableName) |
552
|
|
|
{ |
553
|
|
|
if (!array_key_exists($tableName, $this->tableGateways)) { |
554
|
|
|
$acl = TableSchema::getAclInstance(); |
555
|
|
|
$this->tableGateways[$tableName] = new RelationalTableGateway($tableName, $this->connection, $acl); |
556
|
|
|
} |
557
|
|
|
|
558
|
|
|
return $this->tableGateways[$tableName]; |
559
|
|
|
} |
560
|
|
|
} |
561
|
|
|
|