VocabularyFactory.php
Go to the documentation of this file.00001 <?PHP
00002
00003 #
00004 # FILE: VocabularyFactory.php
00005 #
00006 # Part of the Collection Workflow Integration System
00007 # Copyright 2007-2009 Edward Almasy and Internet Scout
00008 # http://scout.wisc.edu
00009 #
00010
00014 class VocabularyFactory {
00015
00016 # ---- PUBLIC INTERFACE --------------------------------------------------
00017
00022 function VocabularyFactory($Path)
00023 {
00024 $this->Path = $Path;
00025 }
00026
00032 function GetVocabularies()
00033 {
00034 # load vocabularies (if any)
00035 $Vocabularies = array();
00036 $VocFileNames = $this->GetFileList();
00037 foreach ($VocFileNames as $FileName)
00038 {
00039 $Vocabularies[] = new Vocabulary($FileName);
00040 }
00041
00042 # sort vocabularies by name
00043 function SORT_VocabularyFactory_GetVocabularies($VocA, $VocB)
00044 {
00045 $NameA = $VocA->Name();
00046 $NameB = $VocB->Name();
00047 return ($NameA == $NameB) ? 0 : (($NameA < $NameB) ? -1 : 1);
00048 }
00049 usort($Vocabularies, "SORT_VocabularyFactory_GetVocabularies");
00050
00051 # return array of vocabularies to caller
00052 return $Vocabularies;
00053 }
00054
00060 function GetVocabularyByHash($Hash)
00061 {
00062 # for each available vocabulary file
00063 $Vocab = NULL;
00064 $VocFileNames = $this->GetFileList();
00065 foreach ($VocFileNames as $FileName)
00066 {
00067 # if hash for vocabulary file matches specified hash
00068 if (Vocabulary::HashForFile($FileName) == $Hash)
00069 {
00070 # load vocabulary and stop searching file list
00071 $Vocab = new Vocabulary($FileName);
00072 break;
00073 }
00074 }
00075
00076 # return matching vocabulary (if any) to caller
00077 return $Vocab;
00078 }
00079
00080 # ---- PRIVATE INTERFACE -------------------------------------------------
00081
00082 private $Path;
00083
00084 private function GetFileList()
00085 {
00086 # read in list of vocabulary files
00087 $VocFiles = array();
00088 if (is_dir($this->Path))
00089 {
00090 $AllFiles = scandir($this->Path);
00091 foreach ($AllFiles as $FileName)
00092 {
00093 if (preg_match("/\\.voc\$/i", $FileName))
00094 {
00095 $VocFiles[] = realpath($this->Path."/".$FileName);
00096 }
00097 }
00098 }
00099 return $VocFiles;
00100 }
00101 }
00102
00103
00104 ?>