CWIS Developer Documentation

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