ILIAS  release_7 Revision v7.30-3-g800a261c036
ResourceARRepository.php
Go to the documentation of this file.
1<?php
2
4
9
17{
18
22 public function blank(ResourceIdentification $identification) : StorableResource
23 {
24 return new StorableFileResource($identification);
25 }
26
30 public function get(ResourceIdentification $identification) : StorableResource
31 {
32 $ar = $this->getAR($identification);
33 $r = $this->blank($identification);
34 $r->setStorageId($ar->getStorageId());
35
36 return $r;
37 }
38
42 public function has(ResourceIdentification $identification) : bool
43 {
44 return ARResource::find($identification->serialize()) instanceof ARResource;
45 }
46
50 public function store(StorableResource $resource) : void
51 {
52 $ar = $this->getAR($resource->getIdentification(), true);
53 $ar->setStorageId($resource->getStorageID());
54 $ar->update();
55 }
56
63 public function getAR(ResourceIdentification $identification, bool $create_if_not_existing = false) : ARResource
64 {
65 $ar = ARResource::find($identification->serialize());
66 if ($ar === null) {
67 if (!$create_if_not_existing) {
68 throw new ResourceNotFoundException("Resource not found: " . $identification->serialize());
69 }
70 $ar = new ARResource();
71 $ar->setIdentification($identification->serialize());
72 $ar->create();
73 }
74
75 return $ar;
76 }
77
81 public function delete(StorableResource $resource) : void
82 {
83 $ar = ARResource::find($resource->getIdentification()->serialize());
84 if ($ar instanceof ARResource) {
85 $ar->delete();
86 }
87 }
88
92 public function getAll() : \Generator
93 {
97 foreach (ARResource::get() as $item) {
98 yield $this->getResourceFromAR($item);
99 }
100 }
101
102 public function getResourceFromAR(ARResource $AR_resource) : StorableResource
103 {
104 $id = new ResourceIdentification($AR_resource->getIdentification());
105 $r = new StorableFileResource($id);
106 $r->setStorageId($AR_resource->getStorageId());
107
108 return $r;
109 }
110
111 public function getNamesForLocking() : array
112 {
113 return [
114 (new ARResource())->getConnectorContainerName()
115 ];
116 }
117
118 public function preload(array $identification_strings) : void
119 {
120 // noting to to
121 }
122
123 public function populateFromArray(array $data) : void
124 {
125 // noting to to
126 }
127}
An exception for terminatinating execution or to throw for unit testing.
has(ResourceIdentification $identification)
@inheritDoc
getAR(ResourceIdentification $identification, bool $create_if_not_existing=false)
blank(ResourceIdentification $identification)
@inheritDoc
$data
Definition: storeScorm.php:23