Forums | Mahara Community
Developers
/
get_artefact_metadata
21 February 2017, 11:01
Was trying to get our groupviewimage plugin to work in 16.10.2 today however I noticed that the method get_artefact_metadata() from lib/view.php has been removed. What was the reasoning for this and what would be an alternative to use instead of that method?
24 February 2017, 8:10
Hi Jawyei,
It was removed in this commit https://reviews.mahara.org/#/c/6742/7/htdocs/lib/view.php
By the looks of the code you should be able to use get_artefact_instances() as it does the task that get_artefact_metadata() did plus some extra stuff.
Cheers
Robert
24 February 2017, 11:53
Hi Robert
The returned $artefact_instances object's fields are all private. There are no methods I can find to get the field data without modifying lib/view.php. Is there another way to get the properties of each artefact in a view?
Jawyei
24 February 2017, 12:45
Hi Jawyei,
I note the get_artefact_instances() function also sets the $this->artefact_metadata as well
So with a View object $view one could try something like:
$view->get_artefact_instances(); // populate the artefact_metadata
foreach ($view->get('artefact_metadata') as $metadata) {
... do something with $metadata ...
}
Let me know if that helps
Cheers
Robert
24 February 2017, 15:48
Hi Robert
That method gives me an error of
PHP Fatal error: Call to a member function get() on a non-object...
I noticed that the get_artefact_instances() array already contains the metadata information and using the get() method I can immediate get the information I want.
$theView = new View($aViewProperty['id']);
$artefactInView = $theView->get_artefact_instances();
foreach($artefactInView as $anArtefact){ //for each artefact
if($anArtefact->get('artefacttype') == 'image'){
$artefactID = $anArtefact->get('id'); //if it is an image artefact assign the id and break the loop
echo "artefactID=".$artefactID;
break;
}
...
}
I will see if it can be done for folders (image gallery) later on.
Jawyei
24 February 2017, 16:20
No changes was needed to handle folders. Thanks for your help Robert.
Jawyei