Commit 7f2cbdf3 authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review
Browse files

Merge "(Bug1364691) Add artefact_instances_from_ids function."

parents c81e2fea ccd5e53d
......@@ -1585,6 +1585,34 @@ function artefact_can_render_to($type, $format) {
return in_array($format, call_static_method(generate_artefact_class_name($type), 'get_render_list'));
}
/**
* Get artefact instances from ids
* @param array of int $ids of the artefacts
*
* @result mixed Either the artefact object or false if plugin has gone.
*/
function artefact_instances_from_ids($ids) {
$result = array();
if (empty($ids)) {
return $result;
}
$sql = 'SELECT a.*, i.plugin
FROM {artefact} a
JOIN {artefact_installed_type} i ON a.artefacttype = i.name
WHERE a.id IN (' . join(',', $ids) . ')';
if (!$data = get_records_sql_array($sql, NULL)) {
throw new ArtefactNotFoundException(get_string('artefactsnotfound', 'mahara', implode(', ', $ids)));
}
foreach ($data as $item) {
$classname = generate_artefact_class_name($item->artefacttype);
safe_require('artefact', $item->plugin);
$result[$item->id] = new $classname($item->id, $item);
}
return $result;
}
/**
* Get artefact instance from id
* @param int $id of the artefact
......
......@@ -281,16 +281,29 @@ abstract class PluginExport extends Plugin implements IPluginExport {
}
}
$typestoplugins = get_records_assoc('artefact_installed_type');
$ids_to_get = array();
foreach ($tmpartefacts as $a) {
if ($a instanceof ArtefactType) {
continue;
}
else if (is_object($a) && isset($a->id)) {
$ids_to_get[] = $a->id;
}
else if (is_numeric($a)) {
$ids_to_get[] = $a;
}
}
$artefacts = artefact_instances_from_ids($ids_to_get);
foreach ($tmpartefacts as $a) {
$artefact = null;
if ($a instanceof ArtefactType) {
$artefact = $a;
}
else if (is_object($a) && isset($a->id)) {
$artefact = artefact_instance_from_id($a->id);
$artefact = $artefacts[$a->id];
}
else if (is_numeric($a)) {
$artefact = artefact_instance_from_id($a);
$artefact = $artefacts[$a];
}
if (is_null($artefact)) {
throw new ParamOutOfRangeException("Invalid artefact $a");
......
......@@ -100,6 +100,7 @@ $string['previewimagegenerationfailed'] = 'Sorry, there was a problem generating
$string['artefactnotfoundmaybedeleted'] = "Artefact with id %s not found (maybe it has been deleted already?)";
$string['artefactnotfound'] = 'Artefact with id %s not found';
$string['artefactsnotfound'] = 'No artefact(s) found with the id(s): %s';
$string['artefactnotinview'] = 'Artefact %s not in page %s';
$string['artefactonlyviewableinview'] = 'Artefacts of this type are only viewable within a page.';
$string['notartefactowner'] = 'You do not own this artefact.';
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment