Skip to content

Commit 1796cdb

Browse files
committed
Get multielements and values working for api import
1 parent 021047c commit 1796cdb

2 files changed

Lines changed: 39 additions & 3 deletions

File tree

UserProfilesPlugin.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,16 +198,16 @@ public function filterApiImportOmekaAdapters($adapters, $args)
198198
$typesAdapter = new ApiImport_ResponseAdapter_Omeka_GenericAdapter(null, $args['endpointUri'], 'UserProfilesType');
199199
$typesAdapter->setResourceProperties(array('element_set' => 'ElementSet'));
200200
$adapters['user_profiles_types'] = $typesAdapter;
201-
$elementAdapter = new ApiImport_ResponseAdapter_Omeka_GenericAdapter(null, $args['endpointUri'], 'UserProfilesMultiElement)');
201+
$elementAdapter = new ApiImport_ResponseAdapter_Omeka_UserProfilesMulti(null, $args['endpointUri'], 'UserProfilesMultiElement');
202202
$elementAdapter->setResourceProperties(array('element_set' => 'ElementSet'));
203203
$adapters['user_profiles_multielements'] = $elementAdapter;
204204
$profileAdapter = new ApiImport_ResponseAdapter_Omeka_UserProfilesProfile(null, $args['endpointUri'], 'UserProfilesProfile');
205205
$adapters['user_profiles'] = $profileAdapter;
206206

207-
$valueAdapter = new ApiImport_ResponseAdapter_Omeka_GenericAdapter(null, $args['endpointUri'], 'UserProfilesMultiValue');
207+
$valueAdapter = new ApiImport_ResponseAdapter_Omeka_UserProfilesMulti(null, $args['endpointUri'], 'UserProfilesMultiValue');
208208
$valueAdapter->setResourceProperties(array(
209209
'profile_type' => 'UserProfilesType',
210-
'multi' => 'UserProfilesMultiValue',
210+
'multi' => 'UserProfilesMultiElement',
211211
'profile' => 'UserProfilesProfile'
212212
));
213213
$adapters['user_profiles_multivalues'] = $valueAdapter;
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/**
4+
* Combines handling for multielements and multivalues for user profile importing
5+
* Both need to json_decode the relevant values from API and serialize them,
6+
* which is a slight difference from the GenericAdapter
7+
*/
8+
9+
class ApiImport_ResponseAdapter_Omeka_UserProfilesMulti extends ApiImport_ResponseAdapter_Omeka_GenericAdapter
10+
{
11+
12+
protected function setFromResponseData()
13+
{
14+
$allSkipProperties = array_merge($this->resourceProperties, $this->userProperties, $this->skipProperties);
15+
foreach($this->responseData as $key=>$value) {
16+
if(!in_array($key, $allSkipProperties)) {
17+
if ($key == 'values' || $key == 'options') {
18+
$value = json_decode($value, true);
19+
}
20+
if(is_array($value)) {
21+
$this->record->$key = serialize($value);
22+
} else {
23+
$this->record->$key = $value;
24+
}
25+
}
26+
if(in_array($key, $this->userProperties)) {
27+
$prop = $key . '_id';
28+
$this->record->$prop = $this->getLocalUserId($value);
29+
}
30+
if(array_key_exists($key, $this->resourceProperties)) {
31+
$prop = $key . '_id';
32+
$this->record->$prop = $this->getLocalResourceId($value, $this->resourceProperties[$key]);
33+
}
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)