Skip to content

Commit 021047c

Browse files
committed
gets api import working with regular elements
1 parent 0a988e1 commit 021047c

5 files changed

Lines changed: 34 additions & 29 deletions

File tree

UserProfilesPlugin.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public function filterSearchRecordTypes($recordTypes)
170170
return $recordTypes;
171171
}
172172

173-
public function filterApiResources($resources, $arg)
173+
public function filterApiResources($resources)
174174
{
175175
$resources['user_profiles_types'] = array(
176176
'record_type' => 'UserProfilesType',
@@ -198,11 +198,9 @@ 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-
202201
$elementAdapter = new ApiImport_ResponseAdapter_Omeka_GenericAdapter(null, $args['endpointUri'], 'UserProfilesMultiElement)');
203202
$elementAdapter->setResourceProperties(array('element_set' => 'ElementSet'));
204203
$adapters['user_profiles_multielements'] = $elementAdapter;
205-
206204
$profileAdapter = new ApiImport_ResponseAdapter_Omeka_UserProfilesProfile(null, $args['endpointUri'], 'UserProfilesProfile');
207205
$adapters['user_profiles'] = $profileAdapter;
208206

@@ -213,7 +211,6 @@ public function filterApiImportOmekaAdapters($adapters, $args)
213211
'profile' => 'UserProfilesProfile'
214212
));
215213
$adapters['user_profiles_multivalues'] = $valueAdapter;
216-
217214
return $adapters;
218215
}
219216

controllers/ProfilesController.php

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,27 @@ public function init()
1111
protected function _redirectAfterDelete($record)
1212
{
1313
$this->_helper->redirector('user');
14-
}
15-
14+
}
15+
1616
public function editAction()
1717
{
1818
$this->view->addHelperPath(USER_PROFILES_DIR . '/helpers', 'UserProfiles_View_Helper_');
1919
$allTypes = $this->_helper->db->getTable('UserProfilesType')->findAll();
2020
$typeId = $this->getParam('type');
21-
21+
2222
//if no typeId
2323
if(!$typeId) {
2424
$typeId = $allTypes['0']->id;
2525
}
2626
$profileType = $this->_helper->db->getTable('UserProfilesType')->find($typeId);
27-
27+
2828
$userId = $this->_getParam('id');
2929
if($userId) {
3030
$user = $this->_helper->db->getTable('User')->find($userId);
3131
} else {
3232
$user = current_user();
33-
$userId = $user->id;
34-
}
33+
$userId = $user->id;
34+
}
3535
$this->view->user = $user;
3636
$userProfile = $this->_helper->db->getTable()->findByUserIdAndTypeId($userId, $typeId);
3737
if(!$userProfile) {
@@ -40,7 +40,7 @@ public function editAction()
4040
$userProfile->type_id = $typeId;
4141
$userProfile->setRelationData(array('subject_id'=>$userId));
4242
}
43-
43+
4444
if(!is_allowed($userProfile, 'edit')) {
4545
throw new Omeka_Controller_Exception_403;
4646
}
@@ -52,7 +52,6 @@ public function editAction()
5252
} else {
5353
$this->_helper->flashMessenger($userProfile->getErrors());
5454
}
55-
5655
}
5756
$this->view->userprofilesprofile = $userProfile;
5857
$this->view->userprofilestype = $profileType;
@@ -63,9 +62,9 @@ public function userAction()
6362
{
6463
$allTypes = $this->_helper->db->getTable('UserProfilesType')->findAll();
6564
$userId = $this->_getParam('id');
66-
65+
6766
$typeId = $this->getParam('type');
68-
67+
6968
//if no typeId, as happens on the public side, give the first profile typeId
7069
if(!$typeId) {
7170
$typeId = $allTypes['0']->id;
@@ -84,26 +83,24 @@ public function userAction()
8483
$this->view->userprofilestype = $profileType;
8584
$this->view->profile_types = apply_filters('user_profiles_type', $allTypes);
8685
}
87-
86+
8887
public function elementFormAction()
8988
{
9089
$elementId = (int)$_POST['element_id'];
9190
$recordType = $_POST['record_type'];
9291
$recordId = (int)$_POST['record_id'];
93-
92+
9493
// Re-index the element form posts so that they are displayed in the correct order
9594
// when one is removed.
9695
if(isset($_POST['Elements'])) {
9796
$_POST['Elements'][$elementId] = array_merge($_POST['Elements'][$elementId]);
9897
}
9998
$element = $this->_helper->db->getTable('Element')->find($elementId);
10099
$record = $this->_helper->db->getTable($recordType)->find($recordId);
101-
100+
102101
if (!$record) {
103102
$record = new $recordType;
104103
}
105-
106104
$this->view->assign(compact('element', 'record'));
107-
}
108-
105+
}
109106
}

controllers/TypesController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ public function addAction()
8585
} else {
8686
$elementSet->delete();
8787
$errors = $profileType->getErrors();
88-
debug($errors);
8988
$this->_helper->flashMessenger($errors, 'error');
9089
}
9190
}

libraries/ApiImport/ResponseAdapter/Omeka/UserProfilesProfile.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
class ApiImport_ResponseAdapter_Omeka_UserProfilesProfile extends ApiImport_ResponseAdapter_GenericAdapter
3+
class ApiImport_ResponseAdapter_Omeka_UserProfilesProfile extends ApiImport_ResponseAdapter_Omeka_GenericAdapter
44
{
55

66
protected $resourceProperties = array('type' => 'UserProfilesType');
@@ -12,13 +12,17 @@ class ApiImport_ResponseAdapter_Omeka_UserProfilesProfile extends ApiImport_Resp
1212
public function import()
1313
{
1414
if(! $this->record) {
15-
$this->record = new $this->recordType;
15+
$this->record = new UserProfilesProfile;
1616
}
1717
$this->setFromResponseData();
1818
$elementTexts = $this->elementTexts();
19+
$this->record->deleteElementTexts();
1920
$this->record->addElementTextsByArray($elementTexts);
2021
try {
22+
$this->record->setRelationData(array('subject_id'=> $this->record->owner_id, 'object_id' => $this->record->id));
23+
$relation = $this->record->getRelation();
2124
$this->record->save(true);
25+
$relation->save(true);
2226
$this->addOmekaApiImportRecordIdMap();
2327
} catch (Exception $e) {
2428
_log($e);

models/UserProfilesProfile.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,20 +99,20 @@ protected function _initializeMixins()
9999
$this->_mixins[] = new Mixin_Owner($this);
100100
$this->_mixins[] = new Mixin_Timestamp($this);
101101
$this->_mixins[] = new Mixin_Search($this);
102-
}
103-
102+
}
103+
104104
public function afterSave($args)
105105
{
106106
if (!$this->public) {
107107
$this->setSearchTextPrivate();
108108
}
109-
110-
$this->saveElementTexts();
109+
110+
$this->saveElementTexts();
111111
$this->saveMultiElementValues();
112112
foreach ($this->getAllElementTexts() as $elementText) {
113113
$this->addSearchText($elementText->text);
114-
}
115-
114+
}
115+
116116
foreach($this->getAllMultiValues() as $multiValueRecord) {
117117
$displayValues = $multiValueRecord->getValuesForDisplay();
118118
foreach($displayValues as $value) {
@@ -121,6 +121,14 @@ public function afterSave($args)
121121
}
122122
$owner = $this->getOwner();
123123
$this->setSearchTextTitle($owner->name);
124+
if(!empty($this->_relation)) {
125+
if($this->_isSubject) {
126+
$this->_relation->subject_id = $this->id;
127+
} else {
128+
$this->_relation->object_id = $this->id;
129+
}
130+
$this->_relation->save();
131+
}
124132
parent::afterSave($args);
125133
}
126134

0 commit comments

Comments
 (0)