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
    00055     function Hash($FileName = NULL)
    00056     {
    00057         return strtoupper(md5(($FileName === NULL)
    00058                 ? $this->FileName : $FileName));
    00059     }
    00060
    00064     function Name() {  return $this->XmlVal("name");  }
    00065
    00069     function Description() {  return $this->XmlVal("description");  }
    00070
    00074     function Url() {  return $this->XmlVal("url");  }
    00075
    00079     function Version() {  return $this->XmlVal("version");  }
    00080
    00084     function HasQualifier()
    00085     {
    00086         return strlen($this->QualifierName())
    00087                 && (strlen($this->QualifierNamespace())
    00088                         || strlen($this->QualifierUrl()));
    00089     }
    00090
    00094     function QualifierName()
    00095     {
    00096         return isset($this->Xml->qualifier->name)
    00097                 ? (string)$this->Xml->qualifier->name : "";
    00098     }
    00099
    00103     function QualifierNamespace()
    00104     {
    00105         return isset($this->Xml->qualifier->namespace)
    00106                 ? (string)$this->Xml->qualifier->namespace : "";
    00107     }
    00108
    00112     function QualifierUrl()
    00113     {
    00114         return isset($this->Xml->qualifier->url)
    00115                 ? (string)$this->Xml->qualifier->url : "";
    00116     }
    00117
    00121     function TermArray()
    00122     {
    00123         $Terms = $this->ExtractTermSet($this->Xml);
    00124
    00125         # return array of terms to caller
    00126         return $Terms;
    00127     }
    00128
    00132     function TermList()
    00133     {
    00134         $TermTree = $this->TermArray();
    00135         $Terms = $this->BuildTermList("", $TermTree);
    00136         return $Terms;
    00137     }
    00138
    00139     # ---- PRIVATE INTERFACE -------------------------------------------------
    00140
    00141     var $FileName;
    00142     var $StatusString;
    00143     var $Xml;
    00144
    00145     function XmlVal($ValueName)
    00146     {
    00147         return isset($this->Xml->{$ValueName})
    00148                 ? (string)$this->Xml->{$ValueName} : "";
    00149     }
    00150
    00151     function ExtractTermSet($Tree)
    00152     {
    00153         $Terms = array();
    00154         foreach ($Tree->term as $Term)
    00155         {
    00156             if (isset($Term->value))
    00157             {
    00158                 $Terms[(string)$Term->value] = $this->ExtractTermSet($Term);
    00159             }
    00160             else
    00161             {
    00162                 $Terms[(string)$Term] = array();
    00163             }
    00164         }
    00165         return $Terms;
    00166     }
    00167
    00168     # build double-dash separated term list from hierarchical array
    00169     function BuildTermList($Prefix, $TermTree)
    00170     {
    00171         $Terms = array();
    00172         foreach ($TermTree as $Term => $Children)
    00173         {
    00174             $Term = trim($Term);
    00175             $NewTerm = strlen($Prefix) ? $Prefix." -- ".$Term : $Term;
    00176             $Terms[] = $NewTerm;
    00177             $Terms = array_merge($Terms, $this->BuildTermList($NewTerm, $Children));
    00178         }
    00179         return $Terms;
    00180     }
    00181 }
    00182
    00183
    00184 ?>