CWIS Developer Documentation

- Home
- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

CWPlugin.php
Go to the documentation of this file.
1 <?PHP
2 #
3 # FILE: CWPlugin.php
4 #
5 # Part of the Collection Workflow Integration System (CWIS)
6 # Copyright 2016 Edward Almasy and Internet Scout Research Group
7 # http://scout.wisc.edu/cwis/
8 #
9
13 abstract class CWPlugin extends Plugin
14 {
15 # ---- PUBLIC INTERFACE --------------------------------------------------
16
17
18 # ---- PROTECTED INTERFACE -----------------------------------------------
19
28 protected function AddMetadataFieldsFromXml($Schema)
29 {
30 # load schema
31 if (!is_object($Schema))
32 {
33 $Schema = new MetadataSchema($Schema);
34 }
35
36 # assemble XML file name
37 $PossibleSuffixes = array(
38 StdLib::Singularize($Schema->ResourceName()),
39 StdLib::Pluralize($Schema->ResourceName()));
40 foreach ($PossibleSuffixes as $Suffix)
41 {
42 $FileName = "plugins/".get_class($this)
43 ."/install/MetadataSchema--"
44 .str_replace(" ", "", $Suffix).".xml";
45 if (is_file($FileName))
46 {
47 $XmlFile = $FileName;
48 break;
49 }
50 }
51 if (!isset($XmlFile))
52 {
53 throw new Exception("No XML file found to load metadata fields from"
54 ." for ".$SchemaName." schema.");
55 }
56
57 # load fields from file
58 $Result = $Schema->AddFieldsFromXmlFile($XmlFile);
59
60 # if load failed
61 if ($Result === FALSE)
62 {
63 # return error message(s) to caller
64 return "Error loading User metadata fields from XML: ".implode(
65 " ", $Schema->ErrorMessages("AddFieldsFromXmlFile"));
66 }
67
68 # report success to caller
69 return NULL;
70 }
71
77 protected function DeleteMetadataFields($SchemaId)
78 {
79 # load schema
80 $Schema = new MetadataSchema($SchemaId);
81
82 # for each field in schema
83 foreach ($Schema->GetFields() as $FieldId => $Field)
84 {
85 # drop field if we own it
86 if ($Field->Owner() == get_class($this))
87 {
88 $Schema->DropField($FieldId);
89 }
90 }
91
92 # report success to caller
93 return NULL;
94 }
95
96
97 # ---- PRIVATE INTERFACE -------------------------------------------------
98 }
MetadataSchema
Metadata schema (in effect a Factory class for MetadataField).
Definition: MetadataSchema.php:13
CWPlugin\AddMetadataFieldsFromXml
AddMetadataFieldsFromXml($Schema)
Load fields into metadata schema from XML file.
Definition: CWPlugin.php:28
StdLib\Pluralize
static Pluralize($Word)
Pluralize an English word.
Definition: StdLib.php:105
Plugin
Base class for all plugins.
Definition: Plugin.php:13
PHP
PHP
Definition: RSSClient--Test.php:12
CWPlugin\DeleteMetadataFields
DeleteMetadataFields($SchemaId)
Delete any metadata fields owned by plugin from specified schema.
Definition: CWPlugin.php:77
CWPlugin
This class extends the base Plugin class with CWIS-specific functionality.
Definition: CWPlugin.php:13
StdLib\Singularize
static Singularize($Word)
Singularize an English word.
Definition: StdLib.php:141