Skip to content

Commit 088489e

Browse files
committed
#796 Remove hard coded set type name in the SetsManager.
1 parent f5ec39c commit 088489e

File tree

6 files changed

+53
-12
lines changed

6 files changed

+53
-12
lines changed

application/configs/application.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,10 @@ oai.format.xmetadissplus.class = Oai_Model_Prefix_XMetaDissPlus_XMetaDissPlusSer
133133
oai.format.marc21.class = Oai_Model_Prefix_MarcXml_MarcXmlServer
134134

135135
; OAI supported set types
136-
oai.set.collection.class = Oai_Model_Set_CollectionSets
136+
; The order is important, the collection set type must come last.
137137
oai.set.bibliography.class = Oai_Model_Set_BibliographySets
138138
oai.set.doc-type.class = Oai_Model_Set_DocumentTypeSets
139+
oai.set.collection.class = Oai_Model_Set_CollectionSets
139140

140141
; ERROR CONTROLLER SETTINGS
141142
errorController.showException = 0

modules/oai/models/Set/BibliographySets.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,15 @@ public function configureFinder($finder, $setName)
8080

8181
$finder->setBelongsToBibliography((int) filter_var($setValue, FILTER_VALIDATE_BOOLEAN));
8282
}
83+
84+
/**
85+
* Returns if the set type class supports the handling of given set name.
86+
*
87+
* @param Oai_Model_Set_SetName $setName
88+
* @return bool
89+
*/
90+
public function supports($setName)
91+
{
92+
return $setName->getSetName() === 'bibliography';
93+
}
8394
}

modules/oai/models/Set/CollectionSets.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,22 +94,21 @@ public function getSets($document = null)
9494
*/
9595
public function configureFinder($finder, $setName)
9696
{
97-
$setTypeName = $setName->getSetName();
98-
$subsetName = $setName->getSubsetName();
99-
10097
if ($setName->getSetPartsCount() < 1 || $setName->getSetPartsCount() > 2) {
10198
$msg = "Invalid SetSpec: Must be in format 'set:subset'.";
10299
throw new Oai_Model_Exception($msg);
103100
}
104101

105102
// Trying to locate collection role and filter documents.
106-
$role = CollectionRole::fetchByOaiName($setTypeName);
103+
$role = CollectionRole::fetchByOaiName($setName->getSetName());
107104
if ($role === null) {
108105
$msg = "Invalid SetSpec: Top level set does not exist.";
109106
throw new Oai_Model_Exception($msg);
110107
}
111108
$finder->setCollectionRoleId($role->getId());
112109

110+
$subsetName = $setName->getSubsetName();
111+
113112
// Trying to locate given collection and filter documents.
114113
if ($subsetName !== null) {
115114
$foundSubsets = array_filter(
@@ -217,4 +216,16 @@ private function getSetsFromCollections($collections)
217216

218217
return $sets;
219218
}
219+
220+
/**
221+
* Returns if the set type class supports the handling of given set name.
222+
*
223+
* @param Oai_Model_Set_SetName $setName
224+
* @return bool
225+
*/
226+
public function supports($setName)
227+
{
228+
// TODO Assumes collection set type was configured last in the order.
229+
return true;
230+
}
220231
}

modules/oai/models/Set/DocumentTypeSets.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,15 @@ public function configureFinder($finder, $setName)
9696

9797
$finder->setDocumentType($subsetName);
9898
}
99+
100+
/**
101+
* Returns if the set type class supports the handling of given set name.
102+
*
103+
* @param Oai_Model_Set_SetName $setName
104+
* @return bool
105+
*/
106+
public function supports($setName)
107+
{
108+
return $setName->getSetName() === 'doc-type';
109+
}
99110
}

modules/oai/models/Set/SetTypeInterface.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,11 @@ public function getSets($document = null);
5353
*/
5454
public function configureFinder($finder, $setName);
5555

56-
//public function supports($setName);
56+
/**
57+
* Returns if the set type class supports the handling of given set name.
58+
*
59+
* @param Oai_Model_Set_SetName $setName
60+
* @return bool
61+
*/
62+
public function supports($setName);
5763
}

modules/oai/models/Set/SetsManager.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,19 @@ public function getSets($document = null)
5454
}
5555

5656
/**
57+
* Returns the matching set type class for the given set name.
58+
*
5759
* @param Oai_Model_Set_SetName $setName
5860
* @return Oai_Model_Set_SetTypeInterface|null
5961
*/
6062
public function getSetType($setName)
6163
{
62-
$setTypes = $this->getSetTypeObjects();
63-
$setTypeName = $setName->getSetName();
64+
$setTypes = $this->getSetTypeObjects();
6465

65-
if (array_key_exists($setTypeName, $setTypes) && $setTypeName !== 'collection') {
66-
return $setTypes[$setTypeName];
67-
} elseif (array_key_exists('collection', $setTypes)) {
68-
return $setTypes['collection'];
66+
foreach ($setTypes as $setType) {
67+
if ($setType->supports($setName)) {
68+
return $setType;
69+
}
6970
}
7071

7172
return null;

0 commit comments

Comments
 (0)