Search:

# CWIS Developers Documentation

- Main Page
- Classes
- Files

- Search for |

- File List
- File Members

# Vocabulary.php

Go to the documentation of this file.

    00001 <?PHP
    00002
    00003 #
    00004 #   FILE:  SPT--Vocabulary.php
    00005 #
    00006 #   METHODS PROVIDED:
    00007 #       Vocabulary()
    00008 #           - constructor
    00009 #       SomeMethod($SomeParameter, $AnotherParameter)
    00010 #           - short description of method
    00011 #
    00012 #   AUTHOR:  Edward Almasy
    00013 #
    00014 #   Part of the Collection Workflow Integration System
    00015 #   Copyright 2007 Edward Almasy and Internet Scout
    00016 #   http://scout.wisc.edu
    00017 #
    00018
    00022 class Vocabulary {
    00023
    00024     # ---- PUBLIC INTERFACE --------------------------------------------------
    00025
    00031     function Vocabulary($FileName)
    00032     {
    00033         # save file name
    00034         $this->FileName = $FileName;
    00035
    00036         # attempt to load vocabulary from file
    00037         $this->Xml = simplexml_load_file($FileName);
    00038
    00039         # set error code if load failed
    00040         $this->StatusString = ($this->Xml === FALSE) ? "XML Load Failed" : "OK";
    00041         $this->Xml = isset($this->Xml->vocabulary) ? $this->Xml->vocabulary : $this->Xml;
    00042     }
    00043
    00047     function Status() {  return $this->StatusString;  }
    00048
    00053     function Hash()
    00054     {
    00055         return self::HashForFile($this->FileName);
    00056     }
    00057
    00063     static function HashForFile($FileName = NULL)
    00064     {
    00065         return strtoupper(md5($FileName));
    00066     }
    00067
    00071     function Name() {  return $this->XmlVal("name");  }
    00072
    00076     function Description() {  return $this->XmlVal("description");  }
    00077
    00081     function Url() {  return $this->XmlVal("url");  }
    00082
    00086     function Version() {  return $this->XmlVal("version");  }
    00087
    00091     function HasQualifier()
    00092     {
    00093         return strlen($this->QualifierName())
    00094                 && (strlen($this->QualifierNamespace())
    00095                         || strlen($this->QualifierUrl()));
    00096     }
    00097
    00101     function QualifierName()
    00102     {
    00103         return isset($this->Xml->qualifier->name)
    00104                 ? (string)$this->Xml->qualifier->name : "";
    00105     }
    00106
    00110     function QualifierNamespace()
    00111     {
    00112         return isset($this->Xml->qualifier->namespace)
    00113                 ? (string)$this->Xml->qualifier->namespace : "";
    00114     }
    00115
    00119     function QualifierUrl()
    00120     {
    00121         return isset($this->Xml->qualifier->url)
    00122                 ? (string)$this->Xml->qualifier->url : "";
    00123     }
    00124
    00129     function OwnerName()
    00130     {
    00131         return isset($this->Xml->owner->name)
    00132                 ? (string)$this->Xml->owner->name : "";
    00133     }
    00134
    00139     function OwnerUrl()
    00140     {
    00141         return isset($this->Xml->owner->url)
    00142                 ? (string)$this->Xml->owner->url : "";
    00143     }
    00144
    00148     function TermArray()
    00149     {
    00150         $Terms = $this->ExtractTermSet($this->Xml);
    00151
    00152         # return array of terms to caller
    00153         return $Terms;
    00154     }
    00155
    00159     function TermList()
    00160     {
    00161         $TermTree = $this->TermArray();
    00162         $Terms = $this->BuildTermList("", $TermTree);
    00163         return $Terms;
    00164     }
    00165
    00166     # ---- PRIVATE INTERFACE -------------------------------------------------
    00167
    00168     var $FileName;
    00169     var $StatusString;
    00170     var $Xml;
    00171
    00172     function XmlVal($ValueName)
    00173     {
    00174         return isset($this->Xml->{$ValueName})
    00175                 ? (string)$this->Xml->{$ValueName} : "";
    00176     }
    00177
    00178     function ExtractTermSet($Tree)
    00179     {
    00180         $Terms = array();
    00181         foreach ($Tree->term as $Term)
    00182         {
    00183             if (isset($Term->value))
    00184             {
    00185                 $Terms[(string)$Term->value] = $this->ExtractTermSet($Term);
    00186             }
    00187             else
    00188             {
    00189                 $Terms[(string)$Term] = array();
    00190             }
    00191         }
    00192         return $Terms;
    00193     }
    00194
    00195     # build double-dash separated term list from hierarchical array
    00196     function BuildTermList($Prefix, $TermTree)
    00197     {
    00198         $Terms = array();
    00199         foreach ($TermTree as $Term => $Children)
    00200         {
    00201             $Term = trim($Term);
    00202             $NewTerm = strlen($Prefix) ? $Prefix." -- ".$Term : $Term;
    00203             $Terms[] = $NewTerm;
    00204             $Terms = array_merge($Terms, $this->BuildTermList($NewTerm, $Children));
    00205         }
    00206         return $Terms;
    00207     }
    00208 }
    00209
    00210
    00211 ?>