Source of file MDMetadata.php
Size: 17,125 Bytes - Last Modified: 2021-12-23T10:31:40+00:00
/var/www/docs.ssmods.com/process/src/code/model/MDMetadata.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461 | <?php /** * @author Rainer Spittel (rainer at silverstripe dot com) * @package geocatalog * @subpackage model * * The MDMetadata class implements the core Metadata dataobject * to store ISO19139 metadata. This dataobject is used to render the search * results onto the CataloguePage (@link CataloguePage) and for processing * a metadata registration (@link RegisterDataPage). * * ISO19139 is a OGC metadata standard and 'replaces/derives' from ISO19115. * Other standards are: * - ISO19119 * - DublinCore * - MCP (derived version of ISO19115) */ class MDMetadata extends MDDataObject { /** * Data Structure for ISO19139 mandatory core data fields * @var array */ public static $db = array( "gnID" => "Varchar", // internal GeoNetwork ID "fileIdentifier" => "Varchar", // mandatory "dateStamp" => "SSDatetime", // mandatory "metadataStandardName" => "Varchar", "metadataStandardVersion" => "Varchar", "MDTitle" => "Varchar", // mandatory "MDAbstract" => "Varchar", // mandatory "MDPurpose" => "Varchar", "MDLanguage" => "Varchar", // mandatory "MDEdition" => "Varchar", "MDPresentationForm" => "Varchar", "MDSpatialRepresentationType" => "Varchar", // enhanced "MDGeographicDiscription" => "Varchar", // mandatory "MDWestBound" => "Double", // mandatory "MDEastBound" => "Double", // mandatory "MDSouthBound" => "Double", // mandatory "MDNorthBound" => "Double", // mandatory "MDParentIdentifier" => "Varchar", // ANZLIC ); public static $summary_fields = array( "fileIdentifier" => "ID", "MDTitle" => "Title", "MDAbstract" => "Abstract", "MDGeographicDiscription" => "GeographicDiscription", ); /** * Relationship to other data-objects. Implement a semi ISO19139 * implementation recommondation. * @var array */ public static $has_many = array( "MDContacts" => "MDContact", "PointOfContacts" => "MDContact", "MDCitationDates" => "MDCitationDate", "MDKeywords" => "MDKeyword", "MDTopicCategory" => "MDTopicCategory", // mandatory "MDResourceConstraints" => "MDResourceConstraint", "MDResourceFormats" => "MDResourceFormat", "CIOnlineResources" => "CIOnlineResource", "MCPMDCreativeCommons" => "MCPMDCreativeCommons", "MDHierarchyLevel" => "MDHierarchyLevel", // ANZLIC "MDHierarchyLevelName" => "MDHierarchyLevelName" // ANZLIC ); /** * Being able to configure what is shown as 'online urls' in templates. */ public static $online_resource_web_url_filter = array( 'WWW:LINK-1.0-http--link' ); /** * Sets the whiltelist array for online web urls protocol. * This array will be used to remove online-resources * from the metadata-detail page. * * @param $value Array of protocol values, such as array('WWW:LINK-1.0-http--downloaddata', 'WWW:LINK-1.0-http--link') */ public static function set_online_resource_web_url_filter($value) { self::$online_resource_web_url_filter = $value; } public static function get_online_resource_web_url_filter() { return self::$online_resource_web_url_filter; } public function CIOnlineResources_WebAddresses() { return $this->getFilteredCIOnlineResources(self::get_online_resource_web_url_filter()); } public function MetadataCIOnlineResources() { return $this->getFilteredCIOnlineResources(array('WWW:LINK-1.0-http--metadata-URL')); } /** * Returns all CIOnlineResources objects of this metadata record which * are web-addresses. * * @param $filter Array of protocol types you like to retrieve. * * @return DataObjectSet The components of the one-to-many relationship. */ public function getFilteredCIOnlineResources($filter = null) { // important: don't pass in the filter into the get-component // method because it would try to get the data from the database // and would not use the memory/cached version. $resources = $this->getComponents('CIOnlineResources'); $result = new ArrayList(); $protocols = $filter; // if $filter is null, then get the default list, stored in // CIOnlineResource. if ($filter == null) { $protocols = CIOnlineResource::get_public_protocols(); } // if filter is an empty array, then return all online resource records. if (is_array($filter) && empty($filter)) { $result = $resources; } elseif ($resources) { foreach ($resources as $resource) { if (in_array($resource->CIOnlineProtocol, $protocols)) { if (isset($resource->CIOnlineLinkage) && $resource->CIOnlineLinkage != '') { $result->add($resource); } } } } return $result; } /** * Returns all CIOnlineResources objects of this metadata record which * are web-addresses. * * @see RecordFull.ss * * @return DataObjectSet The components of the one-to-many relationship. */ public function CIOnlineResources_FirstWebAddress() { $result = $this->CIOnlineResources_WebAddresses(); return $result->First(); } /** * Returns true if a web-address for this metadata exists. It is used by * the RecordFull.ss template to determine if the web-address block need * to be rendered. * * @see CIOnlineResources_FirstWebAddress * @see RecordFull.ss * @return boolean true if the metadata record has a web-address reference. */ public function CIOnlineResources_HasFirstWebAddress() { $result = $this->CIOnlineResources_WebAddresses(); $item = $result->First(); $retValue = true; if ($item == null) { $retValue = false; } return $retValue; } /** * Returns the MDDateTime in RFC3339 string format (incl. timezone). * This is required for the atom feed support. */ public function getDateTimeInRFC3339($dateType = 'creation') { $result = ''; foreach ($this->MDCitationDates() as $date) { if ($date != null) { // strtotime doesn't like british dates so we reverse it first $tempDate=$date->MDDateTime; $dateParts=explode('/', $tempDate); $tempDate = $dateParts[2] . '-' . $dateParts[1] . '-' . $dateParts[0]; $result = date('c', strtotime($tempDate)); if ($date->MDDateType == $dateType) { return $result; } } } return $result; } /** * Returns the MDDateTime in RFC3339 string format (incl. timezone). * This is required for the atom feed support. */ public function getCreatedInRFC3339() { return $this->getDateTimeInRFC3339('creation'); } /** * Returns the MDDateTime in RFC3339 string format (incl. timezone). * This is required for the atom feed support. */ public function getPublicationInRFC3339() { return $this->getDateTimeInRFC3339('publication'); } /** * Returns the nice, human readable string for the codetype (defined by * the OGC ISO standard). * * @return string */ public function getTopicCategoryNice() { $dos = new ArrayList(); foreach ($this->MDTopicCategory() as $item) { $codeTypes = MDCodeTypes::get_categories(); if (isset($codeTypes[$item->Value])) { if ($codeTypes[$item->Value] != "(please select a category)") { $dos->push(new ArrayData(array('Value' => $codeTypes[$item->Value]))); } } } return $dos; } /** * Returns the nice, human readable string for the codetype (defined by * the OGC ISO standard). * * @return string */ public function getSpatialRepresentationTypeNice() { $index = $this->MDSpatialRepresentationType; $codeTypes = MDCodeTypes::get_spatial_representation_type(); return isset($codeTypes[$index]) ? $codeTypes[$index] : MDCodeTypes::$default_for_null_value; } /** * Returns the nice, human readable string for the codetype (defined by * the OGC ISO standard). * * @return string */ public function getPlaceName() { $index = $this->MDWestBound.";".$this->MDEastBound.";".$this->MDSouthBound.";".$this->MDNorthBound; $result = ''; $codeTypes = MDCodeTypes::get_places(); if (isset($codeTypes[$index])) { $result = $codeTypes[$index]; } return $result; } public function getHasBBox() { $value = ($this->MDWestBound & $this->MDEastBound & $this->MDSouthBound & $this->MDNorthBound); return $value; } /** * This method loads a provided array into the data structure. * It also creates dependencies, such as contact data objects * and populate the values into those objects. * * @param $data array of db-values. */ public function loadData($data) { if ($data == null) { return; } if (!is_array($data)) { return; } foreach ($data as $k => $v) { // store data into this object (no ':" in the string) if (strpos($k, ':') === false) { $this->$k = Convert::xml2raw($v); } else { // A ':' is used as a namespace marker. It is used to // create the related data objects, such as MDContacts. $relations = explode(':', $k); $fieldName = array_pop($relations); $relObj = $this; // iterate through the relationships. At the moment, this // loading process just works for 1 level hierarchies. foreach ($relations as $relation) { if ($relation == 'PointOfContacts') { // load the sub-array into the MDContact object $item = new MDContact(); $item->loadData($v); // add the new MDContect to the collection class of this // object. $relObj->PointOfContacts()->add($item); } if ($relation == 'MDContacts') { // load the sub-array into the MDContact object $item = new MDContact(); $item->loadData($v); // add the new MDContect to the collection class of this // object. $relObj->MDContacts()->add($item); } if ($relation == 'MDResourceConstraints') { // load the sub-array into the MDResourceConstraints object if (is_array($v)) { foreach ($v as $vitem) { $item = new MDResourceConstraint(); $item->loadData($vitem); // add the new MDContect to the collection class of this // object. $relObj->MDResourceConstraints()->add($item); } } } if ($relation == 'MDResourceFormats') { if (is_array($v)) { foreach ($v as $vitem) { // load the sub-array into the MDResourceFormats object $item = new MDResourceFormat(); $item->loadData($vitem); // add the new MDContect to the collection class of this // object. $relObj->MDResourceFormats()->add($item); } } } if ($relation == 'MDTopicCategory') { if (is_array($v)) { foreach ($v as $vitem) { // load the sub-array into the MDResourceFormats object $item = new MDTopicCategory(); $item->loadData($vitem); // add the new MDTopicCategory to the collection class of this // object. $relObj->MDTopicCategory()->add($item); } } } if ($relation == 'MDKeywords') { if (is_array($v)) { foreach ($v as $vitem) { // load the sub-array into the MDKeyword object $item = new MDKeyword(); $item->loadData($vitem); // add the new MDKeyword to the collection class of this // object. $relObj->MDKeywords()->add($item); } } } if ($relation == 'MDCitationDates') { if (is_array($v)) { foreach ($v as $vitem) { // load the sub-array into the MDResourceFormats object $item = new MDCitationDate(); $item->loadData($vitem); // add the new MDContect to the collection class of this // object. $relObj->MDCitationDates()->add($item); } } } if ($relation == 'MCPMDCreativeCommons') { if (is_array($v)) { foreach ($v as $vitem) { // load the sub-array into the MDContact object $item = new MCPMDCreativeCommons(); $item->loadData($vitem); // add the new MCPMDCreativeCommons to the collection class of this // object. $relObj->MCPMDCreativeCommons()->add($item); } } } if ($relation == 'CIOnlineResources') { if (is_array($v)) { foreach ($v as $vitem) { // load the sub-array into the MDContact object $item = new CIOnlineResource(); $item->loadData($vitem); // add the new MDContect to the collection class of this // object. $relObj->CIOnlineResources()->add($item); } } } if ($relation == 'MDHierarchyLevel') { if (is_array($v)) { foreach ($v as $vitem) { $codes = MDCodeTypes::get_scope_codes(); if (isset($codes[$vitem['Value']])) { $item = new MDHierarchyLevel(); $item->loadData($vitem); $relObj->MDHierarchyLevel()->add($item); } } } } if ($relation == 'MDHierarchyLevelName') { if (is_array($v)) { foreach ($v as $vitem) { $item = new MDHierarchyLevelName(); $item->loadData($vitem); $relObj->MDHierarchyLevelName()->add($item); } } } } } } } } |