CWIS Developer Documentation

- Home
- Main Page
- Classes
- Files

- File List
- File Members

VocabularyFactory.php
Go to the documentation of this file.
1 <?PHP
2 #
3 # FILE: VocabularyFactory.php
4 #
5 # Part of the Collection Workflow Integration System (CWIS)
6 # Copyright 2007-2013 Edward Almasy and Internet Scout Research Group
7 # http://scout.wisc.edu/cwis/
8 #
9
13 class VocabularyFactory {
14
15 # ---- PUBLIC INTERFACE --------------------------------------------------
16
21 function VocabularyFactory($Path)
22 {
23 $this->Path = $Path;
24 }
25
31 function GetVocabularies()
32 {
33 # load vocabularies (if any)
34 $Vocabularies = array();
35 $VocFileNames = $this->GetFileList();
36 foreach ($VocFileNames as $FileName)
37 {
38 $Vocabularies[] = new Vocabulary($FileName);
39 }
40
41 # sort vocabularies by name
42 $SortFunction = create_function('$VocA, $VocB','
43 $NameA = $VocA->Name();
44 $NameB = $VocB->Name();
45 return ($NameA == $NameB) ? 0 : (($NameA < $NameB) ? -1 : 1);
46 ');
47 usort($Vocabularies, $SortFunction);
48
49 # return array of vocabularies to caller
50 return $Vocabularies;
51 }
52
59 function GetVocabularyByHash($Hash)
60 {
61 # for each available vocabulary file
62 $Vocab = NULL;
63 $VocFileNames = $this->GetFileList();
64 foreach ($VocFileNames as $FileName)
65 {
66 # if hash for vocabulary file matches specified hash
67 if (Vocabulary::HashForFile($FileName) == $Hash)
68 {
69 # load vocabulary and stop searching file list
70 $Vocab = new Vocabulary($FileName);
71 break;
72 }
73 }
74
75 # return matching vocabulary (if any) to caller
76 return $Vocab;
77 }
78
79
80 # ---- PRIVATE INTERFACE -------------------------------------------------
81
83 private $Path;
84
89 private function GetFileList()
90 {
91 $VocFiles = array();
92 if (is_dir($this->Path))
93 {
94 $AllFiles = scandir($this->Path);
95 foreach ($AllFiles as $FileName)
96 {
97 if (preg_match("/\\.voc\$/i", $FileName))
98 {
99 $VocFiles[] = realpath($this->Path."/".$FileName);
100 }
101 }
102 }
103 return $VocFiles;
104 }
105 }
106
Vocabulary\HashForFile
static HashForFile($FileName=NULL)
Get hash string for specified vocabulary file name.
Definition: Vocabulary.php:54
VocabularyFactory\GetVocabularies
GetVocabularies()
load vocabulary objects from files
Definition: VocabularyFactory.php:31
VocabularyFactory\VocabularyFactory
VocabularyFactory($Path)
object constructor
Definition: VocabularyFactory.php:21
PHP
PHP
Definition: OAIClient.php:39
Vocabulary
Controlled vocabulary.
Definition: Vocabulary.php:13
VocabularyFactory\GetVocabularyByHash
GetVocabularyByHash($Hash)
retrieve vocabulary object based on hash string
Definition: VocabularyFactory.php:59
VocabularyFactory
Factory for manipulating Vocabulary objects.
Definition: VocabularyFactory.php:13