ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
ResourceARRepository.php
Go to the documentation of this file.
1 <?php
2 
4 
9 
16 {
17 
21  public function __construct()
22  {
23 // ARResource::installDB();
24  }
25 
26 
30  public function blank(ResourceIdentification $identification) : StorableResource
31  {
32  return new StorableFileResource($identification);
33  }
34 
35 
39  public function get(ResourceIdentification $identification) : StorableResource
40  {
41  $ar = $this->getAR($identification);
42  $r = $this->blank($identification);
43  $r->setStorageId($ar->getStorageId());
44 
45  return $r;
46  }
47 
48 
52  public function has(ResourceIdentification $identification) : bool
53  {
54  return ARResource::find($identification->serialize()) instanceof ARResource;
55  }
56 
57 
61  public function store(StorableResource $resource) : void
62  {
63  $ar = $this->getAR($resource->getIdentification(), true);
64  $ar->setStorageId($resource->getStorageID());
65  $ar->update();
66  }
67 
68 
76  public function getAR(ResourceIdentification $identification, bool $create_if_not_existing = false) : ARResource
77  {
78  $ar = ARResource::find($identification->serialize());
79  if ($ar === null) {
80  if (!$create_if_not_existing) {
81  throw new ResourceNotFoundException("Resource not found: " . $identification->serialize());
82  }
83  $ar = new ARResource();
84  $ar->setIdentification($identification->serialize());
85  $ar->create();
86  }
87 
88  return $ar;
89  }
90 
91 
95  public function delete(StorableResource $resource) : void
96  {
97  $ar = ARResource::find($resource->getIdentification()->serialize());
98  if ($ar instanceof ARResource) {
99  $ar->delete();
100  }
101  }
102 
103 
107  public function getAll() : \Generator
108  {
112  foreach (ARResource::get() as $item) {
113  yield $this->getResourceFromAR($item);
114  }
115  }
116 
117 
118  public function getResourceFromAR(ARResource $AR_resource) : StorableResource
119  {
120  $id = new ResourceIdentification($AR_resource->getIdentification());
121  $r = new StorableFileResource($id);
122  $r->setStorageId($AR_resource->getStorageId());
123 
124  return $r;
125  }
126 }
getAR(ResourceIdentification $identification, bool $create_if_not_existing=false)