forked from jarves/jarves
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathObjects.php
1258 lines (1092 loc) · 33.8 KB
/
Objects.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* This file is part of Jarves.
*
* (c) Marc J. Schmidt <[email protected]>
*
* J.A.R.V.E.S - Just A Rather Very Easy [content management] System.
*
* http://jarves.io
*
* To get the full copyright and license information, please view the
* LICENSE file, that was distributed with this source code.
*/
namespace Jarves;
use Jarves\Admin\ObjectCrud;
use Jarves\Exceptions\ObjectNotFoundException;
use Jarves\Propel\WorkspaceManager;
use Jarves\Storage\AbstractStorage;
use Symfony\Component\DependencyInjection\ContainerInterface;
class Objects
{
/**
* Array of instances of the object classes
*
* @var array
*/
public $instances = array();
/**
* @var Jarves
*/
protected $jarves;
/**
* @var ContainerInterface
*/
private $container;
/**
* @param Jarves $jarves
* @param ContainerInterface $container
*/
function __construct(Jarves $jarves, ContainerInterface $container)
{
$this->jarves = $jarves;
$this->container = $container;
}
/**
* Translates the internal url to the real path.
*
* Example: getUrl('file://45') => '/myImageFolder/Picture1.png'
* getUrl('news://4') => '/newspage/detail/my-news-title'
* getUrl('user://1') => '/userdetail/admini-strator'
*
* @link http://docu.jarves.io/developer/extensions/internal-url
*
* Can return additionally 'http(s)://myDomain/' at the beginning if the target
* is on a different domain.
*
* @static
*
* @param string $internalUrl
*
* @return string|bool
*/
public function getUrl($internalUrl)
{
$pos = strpos($internalUrl, '://');
$objectIds = substr($internalUrl, 0, $pos);
$params = explode('/', substr($internalUrl, $pos + 2));
$objectDefinition = $this->getDefinition($objectIds);
if (!$objectDefinition) {
return false;
}
if (method_exists($objectDefinition['_extension'], $objectDefinition['urlGetter'])) {
return call_user_func(array($objectDefinition['_extension'], $objectDefinition['urlGetter']), $params);
} else {
return false;
}
}
/**
* Clears the instances cache.
*
*/
public function cleanup()
{
$this->instances = array();
}
/**
* Parse the internal object url scheme and return the information as array.
*
* Pattern:
* object://<object_key>[/<primay_values_url_encoded-1>][/<primay_values_url_encoded-n>][/?<options_as_querystring>]
*
* Examples:
*
* 1. object://news/1
* => returns the object news with primary value equal 1
*
* 2. object://news/id=1
* => equal as 1.
*
* 3. object://news/1/2
* => returns a list of the objects with primary value equal 1 or 2
*
* 4. object://news/id=1/id=2
* => equal as 3.
*
* 5. object://object_with_multiple_primary/2,54
* => returns the object with the first primary field equal 2 and second primary field equal 54
*
* 6. object://object_with_multiple_primary/2,54/34,55
* => returns a list of the objects
*
* 7. object://object_with_multiple_primary/id=2,parent_id=54/id=34,parent_id=55
* => equal as 6 if the first defined primary is 'id' and the second 'parent_id'
*
* 8. object://news/1?fields=title
* => equal as 1. but returns only the field title
*
* 9. object://news/1?fields=title,category_id
* => equal as 1. but returns only the field title and category_id
*
* 10. object://news?fields=title
* => returns all objects from type news
*
* 11. object://news?fields=title&limit=5
* => returns first 5 objects from type news
*
*
* @static
*
* @param string $internalUrl
*
* @return array [object_key, object_id/s, queryParams]
*/
public function parseUrl($internalUrl)
{
$internalUrl = trim($internalUrl);
$list = false;
$catch = 'object://';
if (substr(strtolower($internalUrl), 0, strlen($catch)) == $catch) {
$internalUrl = substr($internalUrl, strlen($catch));
}
$catch = 'objects://';
if (substr(strtolower($internalUrl), 0, strlen($catch)) == $catch) {
$list = true;
$internalUrl = substr($internalUrl, strlen($catch));
}
$firstSlashPos = strpos($internalUrl, '/');
$questionPos = strpos($internalUrl, '?');
if ($firstSlashPos === false && $questionPos === false) {
return array(
$internalUrl,
false,
array(),
$list
);
}
if ($firstSlashPos === false && $questionPos != false) {
$objectKey = substr($internalUrl, 0, $questionPos);
} else {
$objectKey = $this->getObjectKey($internalUrl);
}
if (strpos($objectKey, '%')) {
$objectKey = Tools::urlDecode($objectKey);
}
if (!$objectKey) {
throw new \LogicException(sprintf('The url `%s` does not contain a object key.', $internalUrl));
}
$params = array();
$objectIds = null;
if ($questionPos !== false) {
parse_str(substr($internalUrl, $questionPos + 1), $params);
if ($firstSlashPos !== false) {
$objectIds = substr($internalUrl, $firstSlashPos + 1, $questionPos - ($firstSlashPos + 1));
}
} else {
$objectIds = substr($internalUrl, strlen($objectKey) + 1);
}
$objectIds = $this->parsePk($objectKey, $objectIds);
if ($params && isset($params['condition'])) {
$params['condition'] = json_decode($params['condition'], true);
}
return array(
$objectKey,
(!$objectIds) ? false : $objectIds,
$params,
$list
);
}
/**
* Get object's definition.
*
* @param string $objectKey `Core\Language` or `Core.Language`.
*
* @return Configuration\Object|null
*/
public function getDefinition($objectKey)
{
$objectKey = Objects::normalizeObjectKey($objectKey);
$temp = explode('/', $objectKey);
if (2 !== count($temp)) {
return null;
}
$bundleName = $temp[0];
$name = $temp[1];
$config = $this->jarves->getConfig($bundleName);
return $config ? $config->getObject($name) : null;
}
/**
* Cuts of the namespace/module name of a object key.
*
* jarves/node => Node.
*
* @param string $objectKey
*
* @return string|null
*/
public function getName($objectKey)
{
$objectKey = Objects::normalizeObjectKey($objectKey);
$temp = explode('/', $objectKey);
$config = $this->jarves->getConfig($temp[0]);
if ($config && ($object = $config->getObject($temp[1]))) {
return $object->getId();
}
return null;
}
/**
* Cuts of the object name of the object key.
*
* jarves/node => JarvesBundle.
*
* @param $objectKey
* @return null|string
*/
public function getBundleName($objectKey) {
$objectKey = Objects::normalizeObjectKey($objectKey);
$temp = explode('/', $objectKey);
$config = $this->jarves->getConfig($temp[0]);
return $config ? $config->getBundleName() : null;
}
/**
* Returns the namespace of the bundle of the object key.
*
* JarvesBundle/node => JarvesBundle.
* bundleWithNameSpace/myObject => Bundle\With\Namespace.
*
* @param string $objectKey
*
* @return string
*/
public function getNamespace($objectKey)
{
$objectKey = Objects::normalizeObjectKey($objectKey);
$temp = explode('/', $objectKey);
$config = $this->jarves->getConfig($temp[0]);
return $config ? $config->getBundleClass()->getNamespace() : null;
}
/**
* Returns true of the object is nested.
*
* @param string $objectKey
* @throws Exceptions\ObjectNotFoundException when object is not found
*
* @return boolean
*/
public function isNested($objectKey)
{
$definition = $this->getDefinition($objectKey);
if (!$definition) {
throw new ObjectNotFoundException(sprintf('Object %s not found', $objectKey));
}
return $definition->isNested();
}
/**
* Returns the table name behind a object.
* Not all objects has a table. If the object is based on propel's orm, then it has one.
*
* @param string $objectKey
*
* @return string
*/
public function getTable($objectKey)
{
static $tableName;
if ($tableName && $tableName[$objectKey]) {
return $tableName[$objectKey];
}
$def = $this->getDefinition($objectKey);
$tableName[$objectKey] = $def['table'];
return $tableName[$objectKey];
}
/**
* Converts the primary key statement of a url to normalized structure.
* Generates a array for the usage of Core\Object:get()
*
* 1,2,3 => array( array(id =>1),array(id =>2),array(id =>3) )
* 1 => array(array(id => 1))
* idFooBar => array( id => "idFooBar")
* idFoo-Bar => array(array(id => idFoo, id2 => "Bar"))
* 1-45, 2-45 => array(array(id => 1, pid = 45), array(id => 2, pid=>45))
*
*
* @static
*
* @param string $objectKey
* @param string $primaryKey
*
* @return array
*/
public function parsePk($objectKey, $primaryKey)
{
$obj = $this->getStorageController($objectKey);
$objectIds = $obj->primaryStringToArray($primaryKey);
return $objectIds;
}
/**
* Returns the object key (not id) from an object url.
*
* @param string $url
*
* @return string
*/
public function getObjectKey($url)
{
if (0 === strpos($url, 'object://')){
$url = substr($url, strlen('object://'));
}
$idx = strpos($url, '/');
if (false === $idx) {
return false;
}
$idx = $idx + strpos(substr($url, $idx + 1), '/');
return static::normalizeObjectKey(substr($url, 0, $idx + 1));
}
/**
* Return only the primary keys of pItem as object.
*
* @param string $objectKey
* @param array $item
*
* @return string
*/
public function getObjectPk($objectKey, $item)
{
$definition = $this->getDefinition($objectKey);
$result = [];
foreach ($definition->getPrimaryKeyNames() as $primaryKey) {
if (isset($item[$primaryKey]) && null !== $item[$primaryKey]) {
$result[$primaryKey] = $item[$primaryKey];
}
}
if ($result && $definition->getWorkspace()) {
$result['workspaceId'] = isset($item['workspaceId']) ? $item['workspaceId'] : WorkspaceManager::getCurrent();
}
return $result;
}
/**
* This just cut off object://<objectName>/ and returns the primary key part as plain text.
*
* @param string $url
*
* @return string
*/
public function getCroppedObjectId($url)
{
if (strpos($url, 'object://') === 0) {
$url = substr($url, 9);
}
$idx = strpos($url, '/'); //cut of bundleName
$url = -1 === $idx ? $url : substr($url, $idx +1 );
$idx = strpos($url, '/'); //cut of objectName
$url = -1 === $idx ? $url : substr($url, $idx +1 );
return $url;
}
/**
* Returns the id of an object item for the usage in urls (internal url's) - urlencoded.
*
* @param string $objectKey
* @param array $pk
*
* @return string
* @throws \InvalidArgumentException
*/
public function getObjectUrlId($objectKey, array $pk)
{
$pk = $this->normalizePk($objectKey, $pk);
$pks = $this->getPrimaryList($objectKey);
if (count($pks) == 0) {
throw new \InvalidArgumentException($objectKey . ' does not have primary keys.');
}
$withFieldNames = !is_numeric(key($pk));
if (count($pks) == 1 && is_array($pk)) {
return Tools::urlEncode($pk[$withFieldNames ? $pks[0] : 0]);
} else {
$c = 0;
$urlId = array();
foreach ($pks as $pk2) {
$urlId[] = Tools::urlEncode($pk[$withFieldNames ? $pk2 : $c]);
$c++;
}
return implode(',', $urlId);
}
}
/**
* Checks if a field in a object exists.
*
* @param string $objectKey
* @param string $field
*
* @return bool
*/
public function checkField($objectKey, $field)
{
$definition = $this->getDefinition($objectKey);
if (!$definition->getField($field)) {
return false;
}
return true;
}
/**
* Converts given object key and the object item to the internal url.
*
* @static
*
* @param string $objectKey
* @param mixed $primaryValues
*
* @return string
*/
public function toUrl($objectKey, $primaryValues)
{
$url = 'object://' . $objectKey . '/';
if (is_array($primaryValues)) {
foreach ($primaryValues as $key => $val) {
$url .= Tools::urlEncode($val) . ',';
}
} else {
return $url . Tools::urlEncode($primaryValues);
}
return substr($url, 0, -1);
}
/**
* Returns the object for the given url. Same arguments as in jarvesObjects::get() but given by a string.
*
* Take a look at the jarvesObjects::parseUrl() method for more information.
*
* @static
*
* @param $internalUrl
*
* @return array
*/
public function getFromUrl($internalUrl)
{
list($objectKey, $objectIds, $params, $asList) = $this->parseUrl($internalUrl);
return $asList ? $this->getList($objectKey, $objectIds, $params) : $this->get($objectKey, $objectIds, $params);
}
/**
* Returns the single row of a object.
* $options is a array which can contain following options. All options are optional.
*
* 'fields' Limit the columns selection. Use a array or a comma separated list (like in SQL SELECT)
* If empty all columns will be selected.
* 'offset' Offset of the result set (in SQL OFFSET)
* 'limit' Limits the result set (in SQL LIMIT)
* 'order' The column to order. Example:
* array(
* array('field' => 'category', 'direction' => 'asc'),
* array('field' => 'title', 'direction' => 'asc')
* )
*
* 'foreignKeys' Define which column should be resolved. If empty all columns will be resolved.
* Use a array or a comma separated list (like in SQL SELECT)
*
* 'permissionCheck' Defines whether we check against the ACL or not. true or false. default false
*
* @static
*
* @param string $objectKey
* @param mixed $pk
* @param array $options
*
* @return array|null
*/
public function get($objectKey, $pk, $options = array())
{
$repository = $this->getRepository($objectKey, $options);
return $repository->getItem($pk);
}
/**
* Returns the list of objects.
*
*
* $options is a array which can contain following options. All options are optional.
*
* 'fields' Limit the columns selection. Use a array or a comma separated list (like in SQL SELECT)
* If empty all columns will be selected.
* 'offset' Offset of the result set (in SQL OFFSET)
* 'limit' Limits the result set (in SQL LIMIT)
* 'order' The column to order. Example:
* array(
* array('category' => 'asc'),
* array(title' => 'asc')
* )
*
* 'permissionCheck' Defines whether we check against the ACL or not. true or false. default false
*
* @static
*
* @param string $objectKey
* @param array $filter
* @param array $options
*
* @return array|bool
*/
public function getList($objectKey, $filter = null, $options = array())
{
$repository = $this->getRepository($objectKey, $options);
return $repository->getItems($filter, null, null, null, @$options['fields']);
}
/**
* Counts the items of $internalUrl
*
* @param $internalUrl
*
* @return array
*/
public function getCountFromUrl($internalUrl)
{
list($objectKey, , $params) = $this->parseUrl($internalUrl);
return $this->getCount($objectKey, $params['condition']);
}
/**
* Removes all items.
*
* @param string $objectKey
*
* @return bool
*/
public function clear($objectKey)
{
$obj = $this->getStorageController($objectKey);
return $obj->clear();
}
/**
* Counts the items of $objectKey filtered by $condition
*
* @param string $objectKey
* @param array $condition
* @param array $options
*
* @return array
*/
public function getCount($objectKey, $condition = null, array $options = array())
{
$repository = $this->getRepository($objectKey);
if (isset($options['permissionCheck'])) {
$repository->setPermissionCheck($options['permissionCheck']);
}
return $repository->getCount($condition, @$options['query']);
}
/**
* Counts the items of $objectKey filtered by $condition
*
* @param string $objectKey
* @param mixed $pk
* @param array $condition
* @param mixed $scope
* @param array $options
*
* @return array
*/
public function getBranchChildrenCount(
$objectKey,
$pk = null,
$condition = null,
$scope = null,
array $options = array()
) {
$repository = $this->getRepository($objectKey);
if (isset($options['permissionCheck'])) {
$repository->setPermissionCheck($options['permissionCheck']);
}
return $repository->getBranchChildrenCount($pk, $scope, $condition);
}
/**
* Adds a item.
*
* @param string $objectKey
* @param array $values
* @param mixed $targetPk Full PK as array or as primary key string (url).
* @param string $position If nested set. `first` (child), `last` (last child), `prev` (sibling), `next` (sibling)
* @param bool $targetObjectKey If this object key differs from $objectKey then we'll use $pk as `scope`. Also
* it is then only possible to have position `first` and `last`.
* @param array $options
*
* @return mixed
*
* @throws \Jarves\Exceptions\InvalidArgumentException
*/
public function add(
$objectKey,
$values,
$targetPk = null,
$position = 'first',
$targetObjectKey = null,
array $options = array()
) {
$targetPk = $this->normalizePk($objectKey, $targetPk);
$objectKey = Objects::normalizeObjectKey($objectKey);
if ($targetObjectKey) {
$targetObjectKey = Objects::normalizeObjectKey($targetObjectKey);
}
$repository = $this->getRepository($objectKey, $options);
return $repository->add($values, $targetPk, $position, $targetObjectKey);
}
/**
* Returns the controller to be used to call each update and query at. This controller handles a bit more than
* the pure storageController. For example: ACL, automatic filtering (per language) and event dispatcher.
* It needs to extend ObjectCrud.
*
* @param string $objectKey
* @param array $options
* @return ObjectCrud
*/
public function getRepository($objectKey, array $options = null)
{
if (!$options) {
$options = [];
}
$definition = $this->getDefinition($objectKey);
$crud = $this->container->get($definition->getCrudService());
$crud->setPermissionCheck(false);
if (isset($options['permissionCheck'])) {
$crud->setPermissionCheck($options['permissionCheck']);
}
$crud->setWithNewsFeed(false);
if (isset($options['newsFeed'])) {
$crud->setWithNewsFeed($options['newsFeed']);
}
if (isset($options['domain'])) {
$crud->setDomain($options['domain']);
}
if (isset($options['lang'])) {
$crud->setLanguage($options['lang']);
}
if ($definition->getMultiLanguage()) {
$crud->setMultiLanguage(true);
}
if ($definition->getDomainDepended()) {
$crud->setDomainDepended(true);
}
$crud->setObject($objectKey);
$crud->initialize();
return $crud;
}
/**
* Returns the storage controller, which directly accesses the actual object.
*
* @param string $objectKey
*
* @return AbstractStorage
*
* @throws ObjectNotFoundException
* @throws \Exception
*/
public function getStorageController($objectKey)
{
if (!isset($this->instances[$objectKey])) {
$definition = $this->getDefinition($objectKey);
if (!$definition) {
throw new ObjectNotFoundException(sprintf('Object `%s` not found.', $objectKey));
}
$storageService = $definition->getStorageService();
/** @var $instance */
$instance = $this->container->get($storageService);
$instance->configure($objectKey, $definition);
$this->instances[$objectKey] = $instance;
}
return $this->instances[$objectKey];
}
/**
* Updates a item per url.
*
* @param string $objectUrl
* @param array $values
*
* @return bool
*/
public function updateFromUrl($objectUrl, $values)
{
list($objectKey, $objectIds, $params) = $this->parseUrl($objectUrl);
return $this->update($objectKey, $objectIds[0], $values, $params);
}
/**
* Updates a object entry. This means, all fields which are not defined will be saved as NULL.
*
* @param string $objectKey
* @param mixed $pk
* @param array $values
* @param array $options
*
* @return bool
*/
public function update($objectKey, $pk, $values, array $options = array())
{
$repository = $this->getRepository($objectKey, $options);
return $repository->update($pk, $values);
}
/**
* Patches a object entry. This means, only defined fields will be saved. Fields which are not defined will
* not be overwritten.
*
* @param string $objectKey
* @param mixed $pk
* @param array $values
* @param array $options
*
* @return bool
*/
public function patch($objectKey, $pk, $values, array $options = array())
{
$repository = $this->getRepository($objectKey, $options);
return $repository->patch($pk, $values);
}
/**
* Removes a object item per url.
*
* @param string $objectUrl
* @param array $options
*
* @return bool
*/
public function removeFromUrl($objectUrl, array $options = array())
{
list($objectKey, $objectIds, ) = $this->parseUrl($objectUrl);
return $this->remove($objectKey, $objectIds[0], $options);
}
/**
* Removes a object item.
*
* @param string $objectKey
* @param mixed $pk
* @param array $options
*
* @return boolean
*/
public function remove($objectKey, $pk, array $options = array())
{
$repository = $this->getRepository($objectKey, $options);
return $repository->remove($pk);
}
/*
public function removeUsages($pObjectUrl)
{
}
public function removeUsage($pObjectUrl, $pUseObjectId)
{
}
public function addUsage($pObjectUrl, $pUseObjectId)
{
}
*/
/**
* Returns a single root item. Only for nested objects.
*
* @param string $objectKey
* @param mixed $scope
* @param array $options
*
* @return array
* @throws \Exception
*/
public function getRoot($objectKey, $scope, array $options = array())
{
$repository = $this->getRepository($objectKey, $options);
return $repository->getRoot($scope);
}
/**
* Returns all roots. Only for nested objects.
*
* @param string $objectKey
* @param array $condition
* @param array $options
*
* @return array
* @throws \Exception
*/
public function getRoots($objectKey, $condition = null, array $options = array())
{
$repository = $this->getRepository($objectKey, $options);
return $repository->getRoots($condition);
}
/**
* @static
*
* @param $objectKey
* @param mixed $pk
* @param array $condition
* @param int $depth
* @param mixed $scope
* @param array $options
*
* @return mixed
* @throws \Exception
*/
public function getBranch(
$objectKey,
$pk = null,
$condition = null,
$depth = 1,
$scope = null,
array $options = array()
) {
$repository = $this->getRepository($objectKey, $options);
return $repository->getBranchItems($pk, $condition, null, $scope, $depth);
}
/**
* Returns a hash of all primary fields.
*
* Returns array('<keyOne>' => <arrayDefinition>, '<keyTwo>' => <arrayDefinition>, ...)
*
* @static
*
* @param $objectId
*
* @return array
*/
public function getPrimaries($objectId)
{
$objectDefinition = $this->getDefinition($objectId);
$primaryFields = array();
foreach ($objectDefinition->getFields() as $field) {
if ($field->isPrimaryKey()) {
$primaryFields[$field->getId()] = $field;
}
}
return $primaryFields;
}
/**
* Return a list of all primary keys.
*
* Returns array('<keyOne>', '<keyTwo>', ...);
*
* @static
*
* @param $objectId
*
* @return array
*/
public function getPrimaryList($objectId)
{
$objectDefinition = $this->getDefinition($objectId);
$primaryFields = array();
foreach ($objectDefinition->getFields() as $fieldKey => $field) {
if ($field->getPrimaryKey()) {
$primaryFields[] = $fieldKey;
}
}
return $primaryFields;
}
/**
* Returns the parent pk.
*
* @param string $objectKey
* @param mixed $pk