-
Notifications
You must be signed in to change notification settings - Fork 343
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c70732f
commit 78e50b9
Showing
39 changed files
with
2,200 additions
and
122 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
components/ILIAS/AdvancedMetaData/classes/Record/File/Factory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of ILIAS, a powerful learning management system | ||
* published by ILIAS open source e-Learning e.V. | ||
* | ||
* ILIAS is licensed with the GPL-3.0, | ||
* see https://www.gnu.org/licenses/gpl-3.0.en.html | ||
* You should have received a copy of said license along with the | ||
* source code, too. | ||
* | ||
* If this is not the case or you just want to try ILIAS, you'll find | ||
* us at: | ||
* https://www.ilias.de | ||
* https://github.com/ILIAS-eLearning | ||
* | ||
*********************************************************************/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ILIAS\AdvancedMetaData\Record\File; | ||
|
||
use ilDBInterface; | ||
use ILIAS\Data\Factory as DataFactory; | ||
use ILIAS\AdvancedMetaData\Record\File\Handler as File; | ||
use ILIAS\AdvancedMetaData\Record\File\I\FactoryInterface as FileFactoryInterface; | ||
use ILIAS\AdvancedMetaData\Record\File\I\HandlerInterface as FileInterface; | ||
use ILIAS\AdvancedMetaData\Record\File\I\Repository\FactoryInterface as FileRepositoryFactoryInterface; | ||
use ILIAS\AdvancedMetaData\Record\File\Repository\Factory as FileRepositoryFactory; | ||
use ILIAS\ResourceStorage\Services as IRSS; | ||
|
||
class Factory implements FileFactoryInterface | ||
{ | ||
protected ilDBInterface $db; | ||
protected IRSS $irss; | ||
protected DataFactory $data_factory; | ||
|
||
public function __construct() | ||
{ | ||
global $DIC; | ||
$this->db = $DIC->database(); | ||
$this->irss = $DIC->resourceStorage(); | ||
$this->data_factory = new DataFactory(); | ||
} | ||
|
||
public function handler(): FileInterface | ||
{ | ||
return new File( | ||
$this, | ||
$this->irss, | ||
$this->data_factory | ||
); | ||
} | ||
|
||
public function repository(): FileRepositoryFactoryInterface | ||
{ | ||
return new FileRepositoryFactory( | ||
$this->db, | ||
$this->irss | ||
); | ||
} | ||
} |
176 changes: 176 additions & 0 deletions
176
components/ILIAS/AdvancedMetaData/classes/Record/File/Handler.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of ILIAS, a powerful learning management system | ||
* published by ILIAS open source e-Learning e.V. | ||
* | ||
* ILIAS is licensed with the GPL-3.0, | ||
* see https://www.gnu.org/licenses/gpl-3.0.en.html | ||
* You should have received a copy of said license along with the | ||
* source code, too. | ||
* | ||
* If this is not the case or you just want to try ILIAS, you'll find | ||
* us at: | ||
* https://www.ilias.de | ||
* https://github.com/ILIAS-eLearning | ||
* | ||
*********************************************************************/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ILIAS\AdvancedMetaData\Record\File; | ||
|
||
use ILIAS\AdvancedMetaData\Record\File\I\HandlerInterface as FileInterface; | ||
use ILIAS\AdvancedMetaData\Record\File\I\Repository\Element\CollectionInterface as FileRepositoryElementCollectionInterface; | ||
use ILIAS\AdvancedMetaData\Record\File\I\Repository\Element\HandlerInterface as FileRepositoryElementInterface; | ||
use ILIAS\Data\ObjectId; | ||
use ILIAS\Data\Factory as DataFactory; | ||
use ILIAS\AdvancedMetaData\Record\File\I\FactoryInterface as FileFactoryInterface; | ||
use ILIAS\Filesystem\Stream\FileStream; | ||
use ILIAS\ResourceStorage\Services as IRSS; | ||
|
||
class Handler implements FileInterface | ||
{ | ||
protected FileFactoryInterface $amd_record_file_factory; | ||
protected IRSS $irss; | ||
protected DataFactory $data_factory; | ||
|
||
public function __construct( | ||
FileFactoryInterface $amd_record_file_factory, | ||
IRSS $irss, | ||
DataFactory $data_factory | ||
) { | ||
$this->amd_record_file_factory = $amd_record_file_factory; | ||
$this->irss = $irss; | ||
$this->data_factory = $data_factory; | ||
} | ||
|
||
public function getFilesByObjectId( | ||
ObjectId $object_id | ||
): FileRepositoryElementCollectionInterface { | ||
$key = $this->amd_record_file_factory->repository()->key()->handler() | ||
->withObjectId($object_id); | ||
return $this->amd_record_file_factory->repository()->handler()->getElements($key); | ||
} | ||
|
||
public function getFileByObjectIdAndResourceId( | ||
ObjectId $object_id, | ||
string $resource_id_serialized | ||
): FileRepositoryElementInterface|null { | ||
$key = $this->amd_record_file_factory->repository()->key()->handler() | ||
->withObjectId($object_id) | ||
->withResourceIdSerialized($resource_id_serialized); | ||
$elements = $this->amd_record_file_factory->repository()->handler()->getElements($key); | ||
$elements->rewind(); | ||
return $elements->count() === 0 ? null : $elements->current(); | ||
} | ||
|
||
public function getGlobalFiles(): FileRepositoryElementCollectionInterface | ||
{ | ||
$key = $this->amd_record_file_factory->repository()->key()->handler() | ||
->withIsGlobal(true); | ||
return $this->amd_record_file_factory->repository()->handler()->getElements($key); | ||
} | ||
|
||
public function addFile( | ||
ObjectId $object_id, | ||
int $user_id, | ||
string $file_name, | ||
FileStream $content | ||
): void { | ||
$stakeholder = $this->amd_record_file_factory->repository()->stakeholder()->handler() | ||
->withOwnerId($user_id); | ||
$rid = $this->irss->manage()->stream($content, $stakeholder); | ||
$this->irss->manage()->getResource($rid)->getCurrentRevision()->setTitle($file_name); | ||
$key = $this->amd_record_file_factory->repository()->key()->handler() | ||
->withObjectId($object_id) | ||
->withIsGlobal(false) | ||
->withResourceIdSerialized($rid->serialize()); | ||
$this->amd_record_file_factory->repository()->handler()->store($key); | ||
} | ||
|
||
public function addGlobalFile( | ||
int $user_id, | ||
string $file_name, | ||
FileStream $content | ||
): void { | ||
$stakeholder = $this->amd_record_file_factory->repository()->stakeholder()->handler() | ||
->withOwnerId($user_id); | ||
$rid = $this->irss->manage()->stream($content, $stakeholder); | ||
$this->irss->manage()->getResource($rid)->getCurrentRevision()->setTitle($file_name); | ||
$key = $this->amd_record_file_factory->repository()->key()->handler() | ||
->withObjectId($this->data_factory->objId(0)) | ||
->withIsGlobal(true) | ||
->withResourceIdSerialized($rid->serialize()); | ||
$this->amd_record_file_factory->repository()->handler()->store($key); | ||
} | ||
|
||
public function download( | ||
ObjectId $object_id, | ||
string $resource_id_serialized, | ||
string|null $filename_overwrite | ||
): void { | ||
$key = $this->amd_record_file_factory->repository()->key()->handler() | ||
->withIsGlobal(false) | ||
->withObjectId($object_id) | ||
->withResourceIdSerialized($resource_id_serialized); | ||
$elements = $this->amd_record_file_factory->repository()->handler()->getElements($key); | ||
if ($elements->count() === 0) { | ||
return; | ||
} | ||
$elements->rewind(); | ||
$elements->current()->getIRSS()->download($filename_overwrite); | ||
} | ||
|
||
public function downloadGlobal( | ||
string $resource_id_serialized, | ||
string|null $filename_overwrite | ||
): void { | ||
$key = $this->amd_record_file_factory->repository()->key()->handler() | ||
->withIsGlobal(true) | ||
->withObjectId($this->data_factory->objId(0)) | ||
->withResourceIdSerialized($resource_id_serialized); | ||
$elements = $this->amd_record_file_factory->repository()->handler()->getElements($key); | ||
if ($elements->count() === 0) { | ||
return; | ||
} | ||
$elements->rewind(); | ||
$elements->current()->getIRSS()->download($filename_overwrite); | ||
} | ||
|
||
public function delete( | ||
ObjectId $object_id, | ||
int $user_id, | ||
string $resource_id_serialized | ||
): void { | ||
$key = $this->amd_record_file_factory->repository()->key()->handler() | ||
->withIsGlobal(false) | ||
->withObjectId($object_id) | ||
->withResourceIdSerialized($resource_id_serialized); | ||
$elements = $this->amd_record_file_factory->repository()->handler()->getElements($key); | ||
if ($elements->count() === 0) { | ||
return; | ||
} | ||
$elements->rewind(); | ||
$element = $elements->current(); | ||
$this->amd_record_file_factory->repository()->handler()->delete($key); | ||
} | ||
|
||
public function deleteGlobal( | ||
int $user_id, | ||
string $resource_id_serialized | ||
): void { | ||
$key = $this->amd_record_file_factory->repository()->key()->handler() | ||
->withIsGlobal(true) | ||
->withObjectId($this->data_factory->objId(0)) | ||
->withResourceIdSerialized($resource_id_serialized); | ||
$elements = $this->amd_record_file_factory->repository()->handler()->getElements($key); | ||
if ($elements->count() === 0) { | ||
return; | ||
} | ||
$elements->rewind(); | ||
$element = $elements->current(); | ||
|
||
$this->amd_record_file_factory->repository()->handler()->delete($key); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
components/ILIAS/AdvancedMetaData/classes/Record/File/I/FactoryInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of ILIAS, a powerful learning management system | ||
* published by ILIAS open source e-Learning e.V. | ||
* | ||
* ILIAS is licensed with the GPL-3.0, | ||
* see https://www.gnu.org/licenses/gpl-3.0.en.html | ||
* You should have received a copy of said license along with the | ||
* source code, too. | ||
* | ||
* If this is not the case or you just want to try ILIAS, you'll find | ||
* us at: | ||
* https://www.ilias.de | ||
* https://github.com/ILIAS-eLearning | ||
* | ||
*********************************************************************/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ILIAS\AdvancedMetaData\Record\File\I; | ||
|
||
use ILIAS\AdvancedMetaData\Record\File\I\HandlerInterface as FileInterface; | ||
use ILIAS\AdvancedMetaData\Record\File\I\Repository\FactoryInterface as FileRepositoryFactoryInterface; | ||
|
||
interface FactoryInterface | ||
{ | ||
public function handler(): FileInterface; | ||
|
||
public function repository(): FileRepositoryFactoryInterface; | ||
} |
75 changes: 75 additions & 0 deletions
75
components/ILIAS/AdvancedMetaData/classes/Record/File/I/HandlerInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of ILIAS, a powerful learning management system | ||
* published by ILIAS open source e-Learning e.V. | ||
* | ||
* ILIAS is licensed with the GPL-3.0, | ||
* see https://www.gnu.org/licenses/gpl-3.0.en.html | ||
* You should have received a copy of said license along with the | ||
* source code, too. | ||
* | ||
* If this is not the case or you just want to try ILIAS, you'll find | ||
* us at: | ||
* https://www.ilias.de | ||
* https://github.com/ILIAS-eLearning | ||
* | ||
*********************************************************************/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ILIAS\AdvancedMetaData\Record\File\I; | ||
|
||
use ILIAS\Data\ObjectId; | ||
use ILIAS\AdvancedMetaData\Record\File\I\Repository\Element\CollectionInterface as FileRepositoryElementCollectionInterface; | ||
use ILIAS\AdvancedMetaData\Record\File\I\Repository\Element\HandlerInterface as FileRepositoryElementInterface; | ||
use ILIAS\Filesystem\Stream\FileStream; | ||
|
||
interface HandlerInterface | ||
{ | ||
public function getFilesByObjectId( | ||
ObjectId $object_id | ||
): FileRepositoryElementCollectionInterface; | ||
|
||
public function getFileByObjectIdAndResourceId( | ||
ObjectId $object_id, | ||
string $resource_id_serialized | ||
): FileRepositoryElementInterface|null; | ||
|
||
public function getGlobalFiles(): FileRepositoryElementCollectionInterface; | ||
|
||
public function addFile( | ||
ObjectId $object_id, | ||
int $user_id, | ||
string $file_name, | ||
FileStream $content | ||
): void; | ||
|
||
public function addGlobalFile( | ||
int $user_id, | ||
string $file_name, | ||
FileStream $content | ||
): void; | ||
|
||
public function download( | ||
ObjectId $object_id, | ||
string $resource_id_serialized, | ||
string|null $filename_overwrite | ||
): void; | ||
|
||
public function downloadGlobal( | ||
string $resource_id_serialized, | ||
string|null $filename_overwrite | ||
): void; | ||
|
||
public function delete( | ||
ObjectId $object_id, | ||
int $user_id, | ||
string $resource_id_serialized | ||
): void; | ||
|
||
public function deleteGlobal( | ||
int $user_id, | ||
string $resource_id_serialized | ||
): void; | ||
} |
45 changes: 45 additions & 0 deletions
45
...s/ILIAS/AdvancedMetaData/classes/Record/File/I/Repository/Element/CollectionInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of ILIAS, a powerful learning management system | ||
* published by ILIAS open source e-Learning e.V. | ||
* | ||
* ILIAS is licensed with the GPL-3.0, | ||
* see https://www.gnu.org/licenses/gpl-3.0.en.html | ||
* You should have received a copy of said license along with the | ||
* source code, too. | ||
* | ||
* If this is not the case or you just want to try ILIAS, you'll find | ||
* us at: | ||
* https://www.ilias.de | ||
* https://github.com/ILIAS-eLearning | ||
* | ||
*********************************************************************/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ILIAS\AdvancedMetaData\Record\File\I\Repository\Element; | ||
|
||
use Countable; | ||
use Iterator; | ||
use ILIAS\AdvancedMetaData\Record\File\I\Repository\Element\HandlerInterface as FileRepositoryElementInterface; | ||
|
||
interface CollectionInterface extends Iterator, Countable | ||
{ | ||
public function withElement( | ||
FileRepositoryElementInterface $element | ||
): CollectionInterface; | ||
|
||
public function current(): FileRepositoryElementInterface; | ||
|
||
public function key(): int; | ||
|
||
public function valid(): bool; | ||
|
||
public function rewind(): void; | ||
|
||
public function next(): void; | ||
|
||
public function count(): int; | ||
|
||
} |
Oops, something went wrong.