Skip to content

Commit

Permalink
Only query Public templates. Functioning getRecord and listRecords
Browse files Browse the repository at this point in the history
  • Loading branch information
janreijnders committed Oct 20, 2021
1 parent 47fd580 commit 1285959
Showing 1 changed file with 41 additions and 10 deletions.
51 changes: 41 additions & 10 deletions oai-pmh/oai.php
Expand Up @@ -94,11 +94,12 @@ function($metadataPrefix, $from = '', $until = '', $set = '', $count = false, $d
},

'GetRecord' =>
function($identifier, $metadataPrefix) use ($example_record) {
if ($identifier != 'a.b.c') {
throw new OAIException('idDoesNotExist');
}
return $example_record;
function($identifier, $metadataPrefix){

//TODO: Test whether identifier is in the right format and parse identifier to template_id

$response_record = call_user_func(getSingleTemplate, $identifier);
return $response_record;
},
)
);
Expand All @@ -117,6 +118,35 @@ function($identifier, $metadataPrefix) use ($example_record) {
}


function getSingleTemplate($template_id) {
global $xerte_toolkits_site;
$prefix = $xerte_toolkits_site->database_table_prefix;

$q = "select td.template_id,
otd.template_framework,
otd.template_name as template_type,
otd.display_name as type_display_name,
td.template_name,
td.creator_id as owner_userid,
ld.username as owner_username,
td.date_created,
td.date_modified,
td.date_accessed,
td.number_of_uses,
td.access_to_whom,
td.extra_flags,
td.tsugi_published as lti_enabled,
td.tsugi_xapi_enabled as xapi_enabled
from {$prefix}templatedetails as td,
{$prefix}originaltemplatesdetails as otd,
{$prefix}logindetails as ld
where td.template_type_id=otd.template_type_id and td.creator_id=ld.login_id and td.access_to_whom = 'Public' and td.template_id = {$template_id}";

$response_template = db_query($q);
$response_record = call_user_func(makeRecordFromTemplate,$response_template[0]);
return $response_record;
}

function getTemplates() {
$prefix = $xerte_toolkits_site->database_table_prefix;

Expand All @@ -136,9 +166,9 @@ function getTemplates() {
td.tsugi_published as lti_enabled,
td.tsugi_xapi_enabled as xapi_enabled
from {$prefix}templatedetails as td,
{$prefix}originaltemplatesdetails otd,
{$prefix}logindetails ld
where td.template_type_id=otd.template_type_id and td.creator_id=ld.login_id";
{$prefix}originaltemplatesdetails as otd,
{$prefix}logindetails as ld
where td.template_type_id=otd.template_type_id and td.creator_id=ld.login_id and td.access_to_whom = 'Public'";

$templates = db_query($q);
$response = new stdClass();
Expand All @@ -159,8 +189,9 @@ function getTemplates() {
};

function makeRecordFromTemplate($template){
$record = array('identifier' => 'a.b.c',
'datestamp' => date('Y-m-d-H:s'),
global $xerte_toolkits_site;
$record = array('identifier' => ($xerte_toolkits_site->site_url . $template['template_id']),
'datestamp' => date($template['date_modified']),
'set' => 'class:activity',
'metadata' => array(
'container_name' => 'oai_dc:dc',
Expand Down

0 comments on commit 1285959

Please sign in to comment.