Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test/TestQuestionPool: switch to LOM API #7923

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 30 additions & 48 deletions components/ILIAS/Test/classes/class.ilObjTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
use ILIAS\Refinery\Factory as Refinery;
use ILIAS\Filesystem\Filesystem;
use ILIAS\Filesystem\Stream\Streams;
use ILIAS\MetaData\Services\ServicesInterface as LOMetadata;

/**
* Class ilObjTest
Expand Down Expand Up @@ -147,6 +148,8 @@ class ilObjTest extends ilObject

protected ?ilTestParticipantList $access_filtered_participant_list = null;

protected LOMetadata $lo_metadata;

/**
* Constructor
*
Expand All @@ -166,6 +169,7 @@ public function __construct(int $id = 0, bool $a_call_by_reference = true)
$this->component_repository = $DIC['component.repository'];
$this->component_factory = $DIC['component.factory'];
$this->filesystem_web = $DIC->filesystem()->web();
$this->lo_metadata = $DIC->learningObjectMetadata();

$local_dic = $this->getLocalDIC();
$this->participant_access_filter = $local_dic['participant.access_filter.factory'];
Expand Down Expand Up @@ -4333,22 +4337,20 @@ public function marksEditable(): bool
*/
public function saveAuthorToMetadata($author = "")
{
$md = new ilMD($this->getId(), 0, $this->getType());
$md_life = $md->getLifecycle();
if (!$md_life) {
if (strlen($author) == 0) {
$author = $this->user->getFullname();
}
$path_to_lifecycle = $this->lo_metadata->paths()->custom()->withNextStep('lifeCycle')->get();
$path_to_authors = $this->lo_metadata->paths()->authors();

$reader = $this->lo_metadata->read($this->getId(), 0, $this->getType(), $path_to_lifecycle);
if (!is_null($reader->allData($path_to_lifecycle)->current())) {
return;
}

$md_life = $md->addLifecycle();
$md_life->save();
$con = $md_life->addContribute();
$con->setRole("Author");
$con->save();
$ent = $con->addEntity();
$ent->setEntity($author);
$ent->save();
if ($author === '') {
$author = $this->user->getFullname();
}
$this->lo_metadata->manipulate($this->getId(), 0, $this->getType())
->prepareCreateOrUpdate($path_to_authors, $author)
->execute();
}

/**
Expand All @@ -4368,23 +4370,11 @@ protected function doCreateMetaData(): void
*/
public function getAuthor(): string
{
$author = [];
$md = new ilMD($this->getId(), 0, $this->getType());
$md_life = $md->getLifecycle();
if ($md_life) {
$ids = $md_life->getContributeIds();
foreach ($ids as $id) {
$md_cont = $md_life->getContribute($id);
if (strcmp($md_cont->getRole(), "Author") == 0) {
$entids = $md_cont->getEntityIds();
foreach ($entids as $entid) {
$md_ent = $md_cont->getEntity($entid);
array_push($author, $md_ent->getEntity());
}
}
}
}
return join(",", $author);
$path_to_authors = $this->lo_metadata->paths()->authors();
$author_data = $this->lo_metadata->read($this->getId(), 0, $this->getType(), $path_to_authors)
->allData($path_to_authors);

return $this->lo_metadata->dataHelper()->makePresentableAsList(',', ...$author_data);
}

/**
Expand All @@ -4396,23 +4386,15 @@ public function getAuthor(): string
*/
public static function _lookupAuthor($obj_id): string
{
$author = [];
$md = new ilMD($obj_id, 0, "tst");
$md_life = $md->getLifecycle();
if ($md_life) {
$ids = $md_life->getContributeIds();
foreach ($ids as $id) {
$md_cont = $md_life->getContribute($id);
if (strcmp($md_cont->getRole(), "Author") == 0) {
$entids = $md_cont->getEntityIds();
foreach ($entids as $entid) {
$md_ent = $md_cont->getEntity($entid);
array_push($author, $md_ent->getEntity());
}
}
}
}
return join(",", $author);
global $DIC;

$lo_metadata = $DIC->learningObjectMetadata();

$path_to_authors = $lo_metadata->paths()->authors();
$author_data = $lo_metadata->read($obj_id, 0, "tst", $path_to_authors)
->allData($path_to_authors);

return $lo_metadata->dataHelper()->makePresentableAsList(',', ...$author_data);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1057,8 +1057,7 @@ public function cloneObject(int $target_id, int $copy_id = 0, bool $omit_tree =
$questionIdsMap[$question_id] = $newQuestionId;
}

$md = new ilMD($this->getId(), 0, $this->getType());
$md->cloneMD($new_obj->getId(), 0, $new_obj->getType());
$this->cloneMetaData($new_obj);
$new_obj->updateMetaData();

$duplicator = new ilQuestionPoolTaxonomiesDuplicator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,6 @@ private function buildForm(): Form
{
$items = [];

$md_obj = new ilMD($this->poolOBJ->getId(), 0, "qpl");
$md_section = $md_obj->getGeneral();

$title_and_description = $this->poolOBJ->getObjectProperties()->getPropertyTitleAndDescription()->toForm(
$this->lng,
$this->ui_factory->input()->field(),
Expand Down
Loading