CWIS Developer Documentation

- Home
- Main Page
- Classes
- Files

- File List
- File Members

MetadataSchema.php
Go to the documentation of this file.
1 <?PHP
2 #
3 # FILE: MetadataSchema.php
4 #
5 # Part of the Collection Workflow Integration System (CWIS)
6 # Copyright 2012-2013 Edward Almasy and Internet Scout Research Group
7 # http://scout.wisc.edu/cwis
8 #
9
13 class MetadataSchema extends ItemFactory {
14
15 # ---- PUBLIC INTERFACE --------------------------------------------------
16
17 # metadata field base types
18 # (must parallel MetadataFields.FieldType declaration in install/CreateTables.sql
19 # and MetadataField::$FieldTypeDBEnums declaration below)
20 const MDFTYPE_TEXT = 1;
21 const MDFTYPE_PARAGRAPH = 2;
22 const MDFTYPE_NUMBER = 4;
23 const MDFTYPE_DATE = 8;
24 const MDFTYPE_TIMESTAMP = 16;
25 const MDFTYPE_FLAG = 32;
26 const MDFTYPE_TREE = 64;
27 const MDFTYPE_CONTROLLEDNAME = 128;
28 const MDFTYPE_OPTION = 256;
29 const MDFTYPE_USER = 512;
30 const MDFTYPE_IMAGE = 1024;
31 const MDFTYPE_FILE = 2048;
32 const MDFTYPE_URL = 4096;
33 const MDFTYPE_POINT = 8192;
34 const MDFTYPE_REFERENCE = 16384;
35
36 # types of field ordering
37 const MDFORDER_DISPLAY = 1;
38 const MDFORDER_EDITING = 2;
39 const MDFORDER_ALPHABETICAL = 3;
40
41 # error status codes
42 const MDFSTAT_OK = 1;
43 const MDFSTAT_ERROR = 2;
44 const MDFSTAT_DUPLICATENAME = 4;
45 const MDFSTAT_DUPLICATEDBCOLUMN = 8;
46 const MDFSTAT_FIELDDOESNOTEXIST = 16;
47 const MDFSTAT_ILLEGALNAME = 32;
48 const MDFSTAT_DUPLICATELABEL = 64;
49 const MDFSTAT_ILLEGALLABEL = 128;
50
51 # special schema IDs
52 const SCHEMAID_DEFAULT = 0;
53 const SCHEMAID_USER = 1;
54
55 # resource names
56 const RESOURCENAME_DEFAULT = "Resource";
57 const RESOURCENAME_USER = "User";
58
59 # names used for display and edit orders
60 const ORDER_DISPLAY_NAME = "Display";
61 const ORDER_EDIT_NAME = "Edit";
62
71 function __construct($SchemaId = self::SCHEMAID_DEFAULT)
72 {
73 # set schema ID
74 $this->Id = $SchemaId;
75
76 # set up item factory base class
77 $this->ItemFactory(
78 "MetadataField", "MetadataFields", "FieldId", "FieldName", FALSE,
79 "SchemaId = ".intval($this->Id()));
80
81 # load schema info from database
82 $this->DB->Query("SELECT * FROM MetadataSchemas"
83 ." WHERE SchemaId = ".intval($SchemaId));
84 if ($this->DB->NumRowsSelected() < 1)
85 {
86 throw new Exception("Attempt to load metadata schema with "
87 ." invalid ID (".$SchemaId.").");
88 }
89 $Info = $this->DB->FetchRow();
90 $this->Name = $Info["Name"];
91 $this->AuthoringPrivileges = new PrivilegeSet($Info["AuthoringPrivileges"]);
92 $this->EditingPrivileges = new PrivilegeSet($Info["EditingPrivileges"]);
93 $this->ViewingPrivileges = new PrivilegeSet($Info["ViewingPrivileges"]);
94 $this->ViewPage = $Info["ViewPage"];
95
96 # start with field info caching enabled
97 $this->CachingOn = TRUE;
98 }
99
109 static function GetConstantName($Value, $Prefix = NULL)
110 {
111 # retrieve all constants for class
112 $Reflect = new ReflectionClass(get_class());
113 $Constants = $Reflect->getConstants();
114
115 # for each constant
116 foreach ($Constants as $CName => $CValue)
117 {
118 # if value matches and prefix (if supplied) matches
119 if (($CValue == $Value)
120 && (($Prefix === NULL) || (strpos($CName, $Prefix) === 0)))
121 {
122 # return name to caller
123 return $CName;
124 }
125 }
126
127 # report to caller that no matching constant was found
128 return NULL;
129 }
130
145 static function Create($Name,
146 PrivilegeSet $AuthorPrivs = NULL,
147 PrivilegeSet $EditPrivs = NULL,
148 PrivilegeSet $ViewPrivs = NULL,
149 $ViewPage = "",
150 $ResourceName = NULL)
151 {
152 # supply privilege settings if none provided
153 if ($AuthorPrivs === NULL) { $AuthorPrivs = new PrivilegeSet(); }
154 if ($EditPrivs === NULL) { $EditPrivs = new PrivilegeSet(); }
155 if ($ViewPrivs === NULL) { $ViewPrivs = new PrivilegeSet(); }
156
157 # add schema to database
158 $DB = new Database;
159 if (strtoupper($Name) == "DEFAULT")
160 {
161 $Id = self::SCHEMAID_DEFAULT;
162 }
163 elseif (strtoupper($Name) == "USER")
164 {
165 $Id = self::SCHEMAID_USER;
166 }
167 else
168 {
169 $Id = $DB->Query("SELECT SchemaId FROM MetadataSchemas"
170 ." ORDER BY SchemaId DESC LIMIT 1", "SchemaId") + 1;
171 }
172 $DB->Query("INSERT INTO MetadataSchemas"
173 ." (SchemaId, Name, ViewPage,"
174 ." AuthoringPrivileges, EditingPrivileges, ViewingPrivileges)"
175 ." VALUES (".intval($Id).","
176 ."'".addslashes($Name)."',"
177 ."'".mysql_escape_string($ViewPage)."',"
178 ."'".mysql_escape_string($AuthorPrivs->Data())."',"
179 ."'".mysql_escape_string($EditPrivs->Data())."',"
180 ."'".mysql_escape_string($ViewPrivs->Data())."')");
181
182 # construct the new schema
183 $Schema = new MetadataSchema($Id);
184
185 # set schema name if none supplied
186 if (!strlen($Name))
187 {
188 $Schema->Name("Metadata Schema ".$Id);
189 }
190
191 # set the resource name if one is supplied
192 if (!is_null($ResourceName))
193 {
194 $Schema->ResourceName($ResourceName);
195 }
196
197 # create display and edit orders
198 MetadataFieldOrder::Create($Schema, MetadataSchema::ORDER_DISPLAY_NAME, array() );
199 MetadataFieldOrder::Create($Schema, MetadataSchema::ORDER_EDIT_NAME, array() );
200
201 # return the new schema
202 return $Schema;
203 }
204
210 static function SchemaExistsWithId($SchemaId)
211 {
212 $DB = new Database();
213 $DB->Query("SELECT * FROM MetadataSchemas"
214 ." WHERE SchemaId = ".intval($SchemaId));
215 return ($DB->NumRowsSelected() > 0) ? TRUE : FALSE;
216 }
217
223 function Id()
224 {
225 # return value to caller
226 return $this->Id;
227 }
228
234 function Name($NewValue = NULL)
235 {
236 # set new name if one supplied
237 if ($NewValue !== NULL)
238 {
239 $this->DB->Query("UPDATE MetadataSchemas"
240 ." SET Name = '".addslashes($NewValue)."'"
241 ." WHERE SchemaId = '".intval($this->Id)."'");
242 $this->Name = $NewValue;
243 }
244
245 # get the name if it hasn't been cached yet
246 if (!isset($this->Name))
247 {
248 $this->Name = $this->DB->Query("SELECT * FROM MetadataSchemas"
249 ." WHERE SchemaId = '".intval($this->Id)."'", "Name");
250 }
251
252 # return current value to caller
253 return $this->Name;
254 }
255
261 function ResourceName($NewValue = NULL)
262 {
263 # set new resource name if one supplied
264 if ($NewValue !== NULL)
265 {
266 $this->DB->Query("
267 UPDATE MetadataSchemas
268 SET ResourceName = '".addslashes($NewValue)."'
269 WHERE SchemaId = '".intval($this->Id)."'");
270 $this->ResourceName = $NewValue;
271 }
272
273 # get the name if it hasn't been cached yet
274 if (!isset($this->ResourceName))
275 {
276 $this->ResourceName = $this->DB->Query("
277 SELECT * FROM MetadataSchemas
278 WHERE SchemaId = '".intval($this->Id)."'",
279 "ResourceName");
280
281 # use the default resource name if one isn't set
282 if (!strlen(trim($this->ResourceName)))
283 {
284 $this->ResourceName = self::RESOURCENAME_DEFAULT;
285 }
286 }
287
288 # return current value to caller
289 return $this->ResourceName;
290 }
291
297 function ViewPage($NewValue = NULL)
298 {
299 # set new viewing page if one supplied
300 if ($NewValue !== NULL)
301 {
302 $this->DB->Query("UPDATE MetadataSchemas"
303 ." SET ViewPage = '".addslashes($NewValue)."'"
304 ." WHERE SchemaId = '".intval($this->Id)."'");
305 $this->ViewPage = $NewValue;
306 }
307
308 # get the view page if it hasn't been cached yet
309 if (!isset($this->ViewPage))
310 {
311 $this->ViewPage = $this->DB->Query("SELECT * FROM MetadataSchemas"
312 ." WHERE SchemaId = '".intval($this->Id)."'", "ViewPage");
313 }
314
315 # return current value to caller
316 return $this->ViewPage;
317 }
318
324 function AuthoringPrivileges(PrivilegeSet $NewValue = NULL)
325 {
326 # if new privileges supplied
327 if ($NewValue !== NULL)
328 {
329 # store new privileges in database
330 $this->DB->Query("UPDATE MetadataSchemas"
331 ." SET AuthoringPrivileges = '"
332 .mysql_escape_string($NewValue->Data())."'"
333 ." WHERE SchemaId = ".intval($this->Id));
334 $this->AuthoringPrivileges = $NewValue;
335 }
336
337 # return current value to caller
338 return $this->AuthoringPrivileges;
339 }
340
346 function EditingPrivileges(PrivilegeSet $NewValue = NULL)
347 {
348 # if new privileges supplied
349 if ($NewValue !== NULL)
350 {
351 # store new privileges in database
352 $this->DB->Query("UPDATE MetadataSchemas"
353 ." SET EditingPrivileges = '"
354 .mysql_escape_string($NewValue->Data())."'"
355 ." WHERE SchemaId = ".intval($this->Id));
356 $this->EditingPrivileges = $NewValue;
357 }
358
359 # return current value to caller
360 return $this->EditingPrivileges;
361 }
362
368 function ViewingPrivileges(PrivilegeSet $NewValue = NULL)
369 {
370 # if new privileges supplied
371 if ($NewValue !== NULL)
372 {
373 # store new privileges in database
374 $this->DB->Query("UPDATE MetadataSchemas"
375 ." SET ViewingPrivileges = '"
376 .mysql_escape_string($NewValue->Data())."'"
377 ." WHERE SchemaId = ".intval($this->Id));
378 $this->ViewingPrivileges = $NewValue;
379 }
380
381 # return current value to caller
382 return $this->ViewingPrivileges;
383 }
384
392 function UserCanAuthor($User)
393 {
394 # get authoring privilege set for schema
395 $AuthorPrivs = $this->AuthoringPrivileges();
396
397 # user can author if privileges are greater than resource set
398 $CanAuthor = $AuthorPrivs->MeetsRequirements($User);
399
400 # allow plugins to modify result of permission check
401 $SignalResult = $GLOBALS["AF"]->SignalEvent(
402 "EVENT_RESOURCE_AUTHOR_PERMISSION_CHECK", array(
403 "Schema" => $this,
404 "User" => $User,
405 "CanAuthor" => $CanAuthor));
406 $CanAuthor = $SignalResult["CanAuthor"];
407
408 # report back to caller whether user can author field
409 return $CanAuthor;
410 }
411
417 function GetViewPageIdParameter()
418 {
419 # get the query/GET parameters for the view page
420 $Query = parse_url($this->ViewPage(), PHP_URL_QUERY);
421
422 # the URL couldn't be parsed
423 if (!is_string($Query))
424 {
425 return NULL;
426 }
427
428 # parse the GET parameters out of the query string
429 $GetVars = ParseQueryString($Query);
430
431 # search for the ID parameter
432 $Result = array_search("\$ID", $GetVars);
433
434 return $Result !== FALSE ? $Result : NULL;
435 }
436
449 function PathMatchesViewPage($Path)
450 {
451 # get the query/GET parameters for the view page
452 $Query = parse_url($this->ViewPage(), PHP_URL_QUERY);
453
454 # can't perform matching if the URL couldn't be parsed
455 if (!is_string($Query))
456 {
457 return FALSE;
458 }
459
460 # parse the GET parameters out of the query string
461 $GetVars = ParseQueryString($Query);
462
463 # now, get the query/GET parameters from the path given
464 $PathQuery = parse_url($Path, PHP_URL_QUERY);
465
466 # can't perform matching if the URL couldn't be parsed
467 if (!is_string($PathQuery))
468 {
469 return FALSE;
470 }
471
472 # parse the GET parameters out of the path's query string
473 $PathGetVars = ParseQueryString($PathQuery);
474
475 # make sure the given path GET parameters contain at least the GET
476 # parameters from the view page and that all non-variable parameters are
477 # equal. the path GET parameters may contain more, which is okay
478 foreach ($GetVars as $GetVarName => $GetVarValue)
479 {
480 # there's a required parameter that is not included in the path GET
481 # parameters
482 if (!array_key_exists($GetVarName, $PathGetVars))
483 {
484 return FALSE;
485 }
486
487 # require the path's value to be equal to the view page's value if
488 # the view page's value is not a variable,
489 if ($PathGetVars[$GetVarName] != $GetVarValue
490 && (!strlen($GetVarValue) || $GetVarValue{0} != "$"))
491 {
492 return FALSE;
493 }
494 }
495
496 # the path matches the view page path
497 return TRUE;
498 }
499
504 function CacheData($NewValue)
505 {
506 $this->CachingOn = $NewValue;
507 }
508
518 function AddField($FieldName, $FieldType, $Optional = TRUE, $DefaultValue = NULL)
519 {
520 # clear any existing error messages
521 if (array_key_exists(__METHOD__, $this->ErrorMsgs))
522 { unset($this->ErrorMsgs[__METHOD__]); }
523
524 # create new field
525 try
526 {
527 $Field = MetadataField::Create($this->Id(), $FieldType,
528 $FieldName, $Optional, $DefaultValue);
529 }
530 catch (Exception $Exception)
531 {
532 $this->ErrorMsgs[__METHOD__][] = $Exception->getMessage();
533 $Field = NULL;
534 }
535
536 # return new field to caller
537 return $Field;
538 }
539
552 function AddFieldsFromXmlFile($FileName, $TestRun = FALSE)
553 {
554 # clear loading status
555 $this->NewFields = array();
556 if (array_key_exists(__METHOD__, $this->ErrorMsgs))
557 { unset($this->ErrorMsgs[__METHOD__]); }
558
559 # check that file exists and is readable
560 if (!file_exists($FileName))
561 {
562 $this->ErrorMsgs[__METHOD__][] = "Could not find XML file '"
563 .$FileName."'.";
564 return FALSE;
565 }
566 elseif (!is_readable($FileName))
567 {
568 $this->ErrorMsgs[__METHOD__][] = "Could not read from XML file '"
569 .$FileName."'.";
570 return FALSE;
571 }
572
573 # load XML from file
574 libxml_use_internal_errors(TRUE);
575 $XmlData = simplexml_load_file($FileName);
576 $Errors = libxml_get_errors();
577 libxml_use_internal_errors(FALSE);
578
579 # if XML load failed
580 if ($XmlData === FALSE)
581 {
582 # retrieve XML error messages
583 foreach ($Errors as $Err)
584 {
585 $ErrType = ($Err->level == LIBXML_ERR_WARNING) ? "Warning"
586 : (($Err->level == LIBXML_ERR_WARNING) ? "Error"
587 : "Fatal Error");
588 $this->ErrorMsgs[__METHOD__][] = "XML ".$ErrType.": ".$Err->message
589 ." (".$Err->file.":".$Err->line.",".$Err->column.")";
590 }
591 }
592 # else if no metadata fields found record error message
593 elseif (!count($XmlData->MetadataField))
594 {
595 $this->ErrorMsgs[__METHOD__][] = "No metadata fields found.";
596 }
597 # else process metadata fields
598 else
599 {
600 # for each metadata field entry found
601 $FieldsAdded = 0;
602 $FieldIndex = 0;
603 foreach ($XmlData->MetadataField as $FieldXml)
604 {
605 $FieldIndex++;
606
607 # pull out field type if present
608 if (isset($FieldXml->Type))
609 {
610 $FieldType = "MetadataSchema::".$FieldXml->Type;
611 if (!defined($FieldType))
612 {
613 $FieldType = "MetadataSchema::MDFTYPE_"
614 .strtoupper(preg_replace("/\\s+/", "",
615 $FieldXml->Type));
616 }
617 }
618
619 # if required values are missing
620 if (!isset($FieldXml->Name) || !isset($FieldXml->Type)
621 || !defined($FieldType))
622 {
623 # add error message about required value missing
624 if (!isset($FieldXml->Name))
625 {
626 $this->ErrorMsgs[__METHOD__][] =
627 "Field name not found (MetadataField #"
628 .$FieldIndex.").";
629 }
630 else
631 {
632 $this->ErrorMsgs[__METHOD__][] =
633 "Valid type not found for field '"
634 .$FieldXml->Name."' (MetadataField #"
635 .$FieldIndex.").";
636 }
637 }
638 # else if there is not already a field with this name
639 elseif (!$this->NameIsInUse(trim($FieldXml->Name)))
640 {
641 # create new field
642 $Field = $this->AddField($FieldXml->Name, constant($FieldType));
643
644 # if field creation failed
645 if ($Field === NULL)
646 {
647 # add any error message to our error list
648 $ErrorMsgs = $this->ErrorMessages("AddField");
649 foreach ($ErrorMsgs as $Msg)
650 {
651 $this->ErrorMsgs[__METHOD__][] =
652 $Msg." (AddField)";
653 }
654 }
655 else
656 {
657 # add field to list of created fields
658 $this->NewFields[$Field->Id()] = $Field;
659
660 # for other field attributes
661 foreach ($FieldXml as $MethodName => $Value)
662 {
663 # if tags look valid and have not already been set
664 if (method_exists($Field, $MethodName)
665 && ($MethodName != "Name")
666 && ($MethodName != "Type"))
667 {
668 # if tag indicates privilege set
669 if (preg_match("/^[a-z]+Privileges\$/i",
670 $MethodName))
671 {
672 # save element for later processing
673 $PrivilegesToSet[$Field->Id()][$MethodName] = $Value;
674 }
675 else
676 {
677 # condense down any extraneous whitespace
678 $Value = preg_replace("/\s+/", " ", trim($Value));
679
680 # set value for field
681 $Field->$MethodName($Value);
682 }
683 }
684 }
685
686 # save the temp ID so that any privileges to set can be
687 # mapped to the actual ID when the field is made
688 # permanent
689 $TempId = $Field->Id();
690
691 # make new field permanent
692 $Field->IsTempItem(FALSE);
693
694 # map privileges to set to the permanent field ID
695 if (isset($PrivilegesToSet) &&
696 isset($PrivilegesToSet[$TempId]) )
697 {
698 # copy the privileges over
699 $PrivilegesToSet[$Field->Id()] =
700 $PrivilegesToSet[$TempId];
701
702 # remove the values for the temp ID
703 unset($PrivilegesToSet[$TempId]);
704 }
705 }
706 }
707 }
708
709 # if we have privileges to set
710 if (isset($PrivilegesToSet))
711 {
712 # for each field with privileges
713 foreach ($PrivilegesToSet as $FieldId => $Privileges)
714 {
715 # load the field for which to set the privileges
716 $Field = new MetadataField($FieldId);
717
718 # for each set of privileges for field
719 foreach ($Privileges as $MethodName => $Value)
720 {
721 # convert privilege value
722 $Value = $this->ConvertXmlToPrivilegeSet($Value);
723
724 # if conversion failed
725 if ($Value === NULL)
726 {
727 # add resulting error messages to our list
728 $ErrorMsgs = $this->ErrorMessages(
729 "ConvertXmlToPrivilegeSet");
730 foreach ($ErrorMsgs as $Msg)
731 {
732 $this->ErrorMsgs[__METHOD__][] =
733 $Msg." (ConvertXmlToPrivilegeSet)";
734 }
735 }
736 else
737 {
738 # set value for field
739 $Field->$MethodName($Value);
740 }
741 }
742 }
743 }
744
745 # if errors were found during creation
746 if (array_key_exists(__METHOD__, $this->ErrorMsgs) || $TestRun)
747 {
748 # remove any fields that were created
749 foreach ($this->NewFields as $Field)
750 {
751 $Field->Drop();
752 }
753 $this->NewFields = array();
754 }
755 }
756
757 # report success or failure based on whether errors were recorded
758 return (array_key_exists(__METHOD__, $this->ErrorMsgs)) ? FALSE : TRUE;
759 }
760
766 function NewFields()
767 {
768 return $this->NewFields;
769 }
770
780 function ErrorMessages($Method = NULL)
781 {
782 if ($Method === NULL)
783 {
784 return $this->ErrorMsgs;
785 }
786 else
787 {
788 if (!method_exists($this, $Method))
789 {
790 throw new Exception("Error messages requested for non-existent"
791 ." method (".$Method.").");
792 }
793 return array_key_exists(__CLASS__."::".$Method, $this->ErrorMsgs)
794 ? $this->ErrorMsgs[__CLASS__."::".$Method] : array();
795 }
796 }
797
807 function AddFieldFromXml($Xml)
808 {
809 # assume field addition will fail
810 $Field = self::MDFSTAT_ERROR;
811
812 # add XML prefixes if needed
813 $Xml = trim($Xml);
814 if (!preg_match("/^<\?xml/i", $Xml))
815 {
816 if (!preg_match("/^<document>/i", $Xml))
817 {
818 $Xml = "<document>".$Xml."</document>";
819 }
820 $Xml = "<?xml version='1.0'?".">".$Xml;
821 }
822
823 # parse XML
824 $XmlData = simplexml_load_string($Xml);
825
826 # if required values are present
827 if (is_object($XmlData)
828 && isset($XmlData->Name)
829 && isset($XmlData->Type)
830 && constant("MetadataSchema::".$XmlData->Type))
831 {
832 # create the metadata field
833 $Field = $this->AddField(
834 $XmlData->Name,
835 constant("MetadataSchema::".$XmlData->Type));
836
837 # if field creation succeeded
838 if ($Field != NULL)
839 {
840 # for other field attributes
841 foreach ($XmlData as $MethodName => $Value)
842 {
843 # if they look valid and have not already been set
844 if (method_exists($Field, $MethodName)
845 && ($MethodName != "Name")
846 && ($MethodName != "Type"))
847 {
848 # if tag indicates privilege set
849 if (preg_match("/^[a-z]+Privileges\$/i",
850 $MethodName))
851 {
852 # save element for later processing
853 $PrivilegesToSet[$MethodName] = $Value;
854 }
855 else
856 {
857 # condense down any extraneous whitespace
858 $Value = preg_replace("/\s+/", " ", trim($Value));
859
860 # set value for field
861 $Field->$MethodName($Value);
862 }
863 }
864 }
865
866 # make new field permanent
867 $Field->IsTempItem(FALSE);
868
869 # if we have privileges to set
870 if (isset($PrivilegesToSet))
871 {
872 # for each set of privileges for field
873 foreach ($PrivilegesToSet as $MethodName => $Value)
874 {
875 # convert privilege value
876 $Value = $this->ConvertXmlToPrivilegeSet($Value);
877
878 # if conversion failed
879 if ($Value === NULL)
880 {
881 # add resulting error messages to our list
882 $ErrorMsgs = $this->ErrorMessages(
883 "ConvertXmlToPrivilegeSet");
884 foreach ($ErrorMsgs as $Msg)
885 {
886 $this->ErrorMsgs[__METHOD__][] =
887 $Msg." (ConvertXmlToPrivilegeSet)";
888 }
889 }
890 else
891 {
892 # set value for field
893 $Field->$MethodName($Value);
894 }
895 }
896 }
897 }
898 }
899
900 # return new field (if any) to caller
901 return $Field;
902 }
903
909 function DropField($FieldId)
910 {
911 $Field = $this->GetField($FieldId);
912 if ($Field !== NULL)
913 {
914 global $AF;
915 $AF->SignalEvent("EVENT_PRE_FIELD_DELETE",
916 array("FieldId" => $FieldId) );
917
918 $Field->Drop();
919 return TRUE;
920 }
921 else
922 {
923 return FALSE;
924 }
925 }
926
932 function GetField($FieldId)
933 {
934 static $Fields;
935
936 # if caching is off or field is not already loaded
937 if (($this->CachingOn != TRUE) || !isset($Fields[$FieldId]))
938 {
939 # retrieve field
940 try
941 {
942 $Fields[$FieldId] = new MetadataField($FieldId);
943 }
944 catch (Exception $Exception)
945 {
946 $Fields[$FieldId] = NULL;
947 }
948 }
949
950 # return field to caller
951 return $Fields[$FieldId];
952 }
953
960 function GetFieldByName($FieldName, $IgnoreCase = FALSE)
961 {
962 $FieldId = $this->GetFieldIdByName($FieldName, $IgnoreCase);
963 return ($FieldId === NULL) ? NULL : $this->GetField($FieldId);
964 }
965
972 function GetFieldByLabel($FieldLabel, $IgnoreCase = FALSE)
973 {
974 $FieldId = $this->GetFieldIdByLabel($FieldLabel, $IgnoreCase);
975 return ($FieldId === NULL) ? NULL : $this->GetField($FieldId);
976 }
977
985 function GetFieldIdByName($FieldName, $IgnoreCase = FALSE)
986 {
987 static $FieldIdsByName;
988
989 # if caching is off or field ID is already loaded
990 if (($this->CachingOn != TRUE) || !isset($FieldIdsByName[$this->Id][$FieldName]))
991 {
992 # retrieve field ID from DB
993 $Condition = $IgnoreCase
994 ? "WHERE LOWER(FieldName) = '".addslashes(strtolower($FieldName))."'"
995 : "WHERE FieldName = '".addslashes($FieldName)."'";
996 $Condition .= " AND SchemaId = ".intval($this->Id);
997 $FieldIdsByName[$this->Id][$FieldName] = $this->DB->Query(
998 "SELECT FieldId FROM MetadataFields ".$Condition, "FieldId");
999 }
1000
1001 return $FieldIdsByName[$this->Id][$FieldName];
1002 }
1003
1011 function GetFieldIdByLabel($FieldLabel, $IgnoreCase = FALSE)
1012 {
1013 static $FieldIdsByLabel;
1014
1015 # if caching is off or field ID is already loaded
1016 if (($this->CachingOn != TRUE) || !isset($FieldIdsByLabel[$FieldLabel]))
1017 {
1018 # retrieve field ID from DB
1019 $Condition = $IgnoreCase
1020 ? "WHERE LOWER(Label) = '".addslashes(strtolower($FieldLabel))."'"
1021 : "WHERE Label = '".addslashes($FieldLabel)."'";
1022 $Condition .= " AND SchemaId = ".intval($this->Id);
1023 $FieldIdsByLabel[$FieldLabel] = $this->DB->Query(
1024 "SELECT FieldId FROM MetadataFields ".$Condition, "FieldId");
1025 }
1026
1027 return $FieldIdsByLabel[$FieldLabel];
1028 }
1029
1035 function FieldExists($FieldName) { return $this->NameIsInUse($FieldName); }
1036
1050 function GetFields($FieldTypes = NULL, $OrderType = NULL,
1051 $IncludeDisabledFields = FALSE, $IncludeTempFields = FALSE)
1052 {
1053 # create empty array to pass back
1054 $Fields = array();
1055
1056 # for each field type in database
1057 $this->DB->Query("SELECT FieldId, FieldType FROM MetadataFields"
1058 ." WHERE SchemaId = ".intval($this->Id)
1059 .(!$IncludeDisabledFields ? " AND Enabled != 0" : "")
1060 .(!$IncludeTempFields ? " AND FieldId >= 0" : ""));
1061 while ($Record = $this->DB->FetchRow())
1062 {
1063 # if field type is known
1064 if (array_key_exists($Record["FieldType"], MetadataField::$FieldTypePHPEnums))
1065 {
1066 # if no specific type requested or if field is of requested type
1067 if (($FieldTypes == NULL)
1068 || (MetadataField::$FieldTypePHPEnums[$Record["FieldType"]]
1069 & $FieldTypes))
1070 {
1071 # create field object and add to array to be passed back
1072 $Fields[$Record["FieldId"]] = $this->GetField($Record["FieldId"]);
1073 }
1074 }
1075 }
1076
1077 # if field sorting requested
1078 if ($OrderType !== NULL)
1079 {
1080 # update field comparison ordering if not set yet
1081 if (!$this->FieldCompareOrdersSet())
1082 {
1083 $this->UpdateFieldCompareOrders();
1084 }
1085
1086 $this->FieldCompareType = $OrderType;
1087
1088 # sort field array by requested order type
1089 uasort($Fields, array($this, "CompareFieldOrder"));
1090 }
1091
1092 # return array of field objects to caller
1093 return $Fields;
1094 }
1095
1110 function GetFieldNames($FieldTypes = NULL, $OrderType = NULL,
1111 $IncludeDisabledFields = FALSE, $IncludeTempFields = FALSE)
1112 {
1113 $Fields = $this->GetFields($FieldTypes, $OrderType,
1114 $IncludeDisabledFields, $IncludeTempFields);
1115
1116 $FieldNames = array();
1117 foreach($Fields as $Field)
1118 {
1119 $FieldNames[$Field->Id()] = $Field->Name();
1120 }
1121
1122 return $FieldNames;
1123 }
1124
1141 function GetFieldsAsOptionList($OptionListName, $FieldTypes = NULL,
1142 $SelectedFieldId = NULL, $IncludeNullOption = TRUE,
1143 $AddEntries = NULL, $AllowMultiple = FALSE)
1144 {
1145 # retrieve requested fields
1146 $FieldNames = $this->GetFieldNames($FieldTypes);
1147
1148 # transform field names to labels
1149 foreach ($FieldNames as $FieldId => $FieldName)
1150 {
1151 $FieldNames[$FieldId] = $this->GetField($FieldId)->GetDisplayName();
1152 }
1153
1154 # begin HTML option list
1155 $Html = "<select id=\"".$OptionListName."\" name=\"".$OptionListName."\"";
1156
1157 # if multiple selections should be allowed
1158 if ($AllowMultiple)
1159 {
1160 $Html .= " multiple=\"multiple\"";
1161 }
1162
1163 $Html .= ">\n";
1164
1165 if ($IncludeNullOption)
1166 {
1167 $Html .= "<option value=\"\">--</option>\n";
1168 }
1169
1170 # make checking for IDs simpler
1171 if (!is_array($SelectedFieldId))
1172 {
1173 $SelectedFieldId = array($SelectedFieldId);
1174 }
1175
1176 # for each metadata field
1177 foreach ($FieldNames as $Id => $Name)
1178 {
1179 # add entry for field to option list
1180 $Html .= "<option value=\"".$Id."\"";
1181 if (in_array($Id, $SelectedFieldId)) { $Html .= " selected"; }
1182 $Html .= ">".htmlspecialchars($Name)."</option>\n";
1183 }
1184
1185 # if additional entries were requested
1186 if ($AddEntries)
1187 {
1188 foreach ($AddEntries as $Value => $Label)
1189 {
1190 $Html .= "<option value=\"".$Value."\"";
1191 if (in_array($Value, $SelectedFieldId))
1192 {
1193 $Html .= " selected";
1194 }
1195 $Html .= ">".htmlspecialchars($Label)."</option>\n";
1196 }
1197 }
1198
1199 # end HTML option list
1200 $Html .= "</select>\n";
1201
1202 # return constructed HTML to caller
1203 return $Html;
1204 }
1205
1211 function GetFieldTypes()
1212 {
1213 return MetadataField::$FieldTypeDBEnums;
1214 }
1215
1221 function GetAllowedFieldTypes()
1222 {
1223 return MetadataField::$FieldTypeDBAllowedEnums;
1224 }
1225
1230 function RemoveQualifierAssociations($QualifierIdOrObject)
1231 {
1232 # sanitize qualifier ID or grab it from object
1233 $QualifierIdOrObject = is_object($QualifierIdOrObject)
1234 ? $QualifierIdOrObject->Id() : intval($QualifierIdOrObject);
1235
1236 # delete intersection records from database
1237 $this->DB->Query("DELETE FROM FieldQualifierInts"
1238 ." WHERE QualifierId = ".$QualifierIdOrObject);
1239 }
1240
1246 function QualifierIsInUse($QualifierIdOrObject)
1247 {
1248 # sanitize qualifier ID or grab it from object
1249 $QualifierIdOrObject = is_object($QualifierIdOrObject)
1250 ? $QualifierIdOrObject->Id() : intval($QualifierIdOrObject);
1251
1252 # determine whether any fields use qualifier as default
1253 $DefaultCount = $this->DB->Query("SELECT COUNT(*) AS RecordCount"
1254 ." FROM MetadataFields"
1255 ." WHERE DefaultQualifier = ".$QualifierIdOrObject,
1256 "RecordCount");
1257
1258 # determine whether any fields are associated with qualifier
1259 $AssociationCount = $this->DB->Query("SELECT COUNT(*) AS RecordCount"
1260 ." FROM FieldQualifierInts"
1261 ." WHERE QualifierId = ".$QualifierIdOrObject,
1262 "RecordCount");
1263
1264 # report whether qualifier is in use based on defaults and associations
1265 return (($DefaultCount + $AssociationCount) > 0) ? TRUE : FALSE;
1266 }
1267
1272 function GetHighestFieldId() { return $this->GetHighestItemId(); }
1273
1281 static function StdNameToFieldMapping($MappedName, $FieldId = NULL)
1282 {
1283 if ($FieldId !== NULL)
1284 {
1285 self::$FieldMappings[$MappedName] = $FieldId;
1286 }
1287 return isset(self::$FieldMappings[$MappedName])
1288 ? self::$FieldMappings[$MappedName] : NULL;
1289 }
1290
1297 static function FieldToStdNameMapping($FieldId)
1298 {
1299 if ($FieldId != -1)
1300 {
1301 foreach (self::$FieldMappings as $MappedName => $MappedFieldId)
1302 {
1303 if ($MappedFieldId == $FieldId)
1304 {
1305 return $MappedName;
1306 }
1307 }
1308 }
1309 return NULL;
1310 }
1311
1319 function GetFieldByMappedName($MappedName)
1320 {
1321 return (self::StdNameToFieldMapping($MappedName) == NULL) ? NULL
1322 : $this->GetField($this->StdNameToFieldMapping($MappedName));
1323 }
1324
1332 function GetFieldIdByMappedName($MappedName)
1333 {
1334 return self::StdNameToFieldMapping($MappedName);
1335 }
1336
1341 function GetOwnedFields()
1342 {
1343 $Fields = array();
1344
1345 $this->DB->Query("SELECT * FROM MetadataFields"
1346 ." WHERE Owner IS NOT NULL AND LENGTH(Owner) > 0"
1347 ." AND SchemaId = ".intval($this->Id));
1348
1349 while (FALSE !== ($Row = $this->DB->FetchRow()))
1350 {
1351 $FieldId = $Row["FieldId"];
1352 $Fields[$FieldId] = $this->GetField($FieldId);
1353 }
1354
1355 return $Fields;
1356 }
1357
1363 static function GetAllSchemas()
1364 {
1365 $Database = new Database();
1366 $Schemas = array();
1367
1368 # fetch the IDs all of the metadata schemas
1369 $Database->Query("SELECT * FROM MetadataSchemas");
1370 $SchemaIds = $Database->FetchColumn("SchemaId");
1371
1372 # construct objects from the IDs
1373 foreach ($SchemaIds as $SchemaId)
1374 {
1375 $Schemas[$SchemaId] = new MetadataSchema($SchemaId);
1376 }
1377
1378 return $Schemas;
1379 }
1380
1386 static function SetOwnerListRetrievalFunction($Callback)
1387 {
1388 if (is_callable($Callback))
1389 {
1390 self::$OwnerListRetrievalFunction = $Callback;
1391 }
1392 }
1393
1399 static function NormalizeOwnedFields()
1400 {
1401 # if an owner list retrieval function and default schema exists
1402 if (self::$OwnerListRetrievalFunction
1403 && self::SchemaExistsWithId(self::SCHEMAID_DEFAULT))
1404 {
1405 # retrieve the list of owners that currently exist
1406 $OwnerList = call_user_func(self::$OwnerListRetrievalFunction);
1407
1408 # an array is expected
1409 if (is_array($OwnerList))
1410 {
1411 $Schema = new MetadataSchema(self::SCHEMAID_DEFAULT);
1412
1413 # get each metadata field that is owned by a plugin
1414 $OwnedFields = $Schema->GetOwnedFields();
1415
1416 # loop through each owned field
1417 foreach ($OwnedFields as $OwnedField)
1418 {
1419 # the owner of the current field
1420 $Owner = $OwnedField->Owner();
1421
1422 # if the owner of the field is in the list of owners that
1423 # currently exist, i.e., available plugins
1424 if (in_array($Owner, $OwnerList))
1425 {
1426 # enable the field and reset its "enable on owner return"
1427 # flag if the "enable on owner return" flag is currently
1428 # set to true. in other words, re-enable the field since
1429 # the owner has returned to the list of existing owners
1430 if ($OwnedField->EnableOnOwnerReturn())
1431 {
1432 $OwnedField->Enabled(TRUE);
1433 $OwnedField->EnableOnOwnerReturn(FALSE);
1434 }
1435 }
1436
1437 # if the owner of the field is *not* in the list of owners
1438 # that currently exist, i.e., available plugins
1439 else
1440 {
1441 # first, see if the field is currently enabled since it
1442 # will determine whether the field is re-enabled when
1443 # the owner becomes available again
1444 $Enabled = $OwnedField->Enabled();
1445
1446 # if the field is enabled, set its "enable on owner
1447 # return" flag to true and disable the field. nothing
1448 # needs to be done if the field is already disabled
1449 if ($Enabled)
1450 {
1451 $OwnedField->EnableOnOwnerReturn($Enabled);
1452 $OwnedField->Enabled(FALSE);
1453 }
1454 }
1455 }
1456 }
1457 }
1458 }
1459
1464 protected function UpdateFieldCompareOrders()
1465 {
1466 $Index = 0;
1467
1468 foreach ($this->GetDisplayOrder()->GetFields() as $Field)
1469 {
1470 $this->FieldCompareDisplayOrder[$Field->Id()] = $Index++;
1471 }
1472
1473 $Index = 0;
1474
1475 foreach ($this->GetEditOrder()->GetFields() as $Field)
1476 {
1477 $this->FieldCompareEditOrder[$Field->Id()] = $Index++;
1478 }
1479 }
1480
1485 function GetDisplayOrder()
1486 {
1487 return MetadataFieldOrder::GetOrderForSchema($this, self::ORDER_DISPLAY_NAME);
1488 }
1489
1494 function GetEditOrder()
1495 {
1496 return MetadataFieldOrder::GetOrderForSchema($this, self::ORDER_EDIT_NAME);
1497 }
1498
1503 protected function FieldCompareOrdersSet()
1504 {
1505 return $this->FieldCompareDisplayOrder && $this->FieldCompareEditOrder;
1506 }
1507
1515 protected function CompareFieldOrder($FieldA, $FieldB)
1516 {
1517 if ($this->FieldCompareType == MetadataSchema::MDFORDER_ALPHABETICAL)
1518 {
1519 return ($FieldA->GetDisplayName() < $FieldB->GetDisplayName()) ? -1 : 1;
1520 }
1521
1522 if ($this->FieldCompareType == MetadataSchema::MDFORDER_EDITING)
1523 {
1524 $Order = $this->FieldCompareEditOrder;
1525 }
1526
1527 else
1528 {
1529 $Order = $this->FieldCompareDisplayOrder;
1530 }
1531
1532 $PositionA = GetArrayValue($Order, $FieldA->Id(), 0);
1533 $PositionB = GetArrayValue($Order, $FieldB->Id(), 0);
1534
1535 return $PositionA < $PositionB ? -1 : 1;
1536 }
1537
1538 # ---- PRIVATE INTERFACE -------------------------------------------------
1539
1540 private $Id;
1541 private $Name;
1542 private $ResourceName;
1543 private $AuthoringPrivileges;
1544 private $EditingPrivileges;
1545 private $ViewingPrivileges;
1546 private $ViewPage;
1547 private $FieldCompareType;
1548 private $CachingOn;
1549 private $NewFields = array();
1550 private $ErrorMsgs = array();
1551 private static $FieldMappings;
1552 protected static $OwnerListRetrievalFunction;
1553
1557 protected $FieldCompareDisplayOrder = array();
1558
1562 protected $FieldCompareEditOrder = array();
1563
1571 private function ConvertXmlToPrivilegeSet($Xml)
1572 {
1573 # clear any existing errors
1574 if (array_key_exists(__METHOD__, $this->ErrorMsgs))
1575 { unset($this->ErrorMsgs[__METHOD__]); }
1576
1577 # create new privilege set
1578 $PrivSet = new PrivilegeSet();
1579
1580 # for each XML child
1581 foreach ($Xml as $Tag => $Value)
1582 {
1583 # take action based on element name
1584 switch ($Tag)
1585 {
1586 case "PrivilegeSet":
1587 # convert child data to new set
1588 $NewSet = $this->ConvertXmlToPrivilegeSet($Value);
1589
1590 # add new set to our privilege set
1591 $PrivSet->AddSet($NewSet);
1592 break;
1593
1594 case "AddCondition":
1595 # start with default values for optional parameters
1596 unset($ConditionField);
1597 $ConditionValue = NULL;
1598 $ConditionOperator = "==";
1599
1600 # pull out parameters
1601 foreach ($Value as $ParamName => $ParamValue)
1602 {
1603 $ParamValue = trim($ParamValue);
1604 switch ($ParamName)
1605 {
1606 case "Field":
1607 $ConditionField = $this->GetFieldByName(
1608 (string)$ParamValue, TRUE);
1609 if ($ConditionField === NULL)
1610 {
1611 # record error about unknown field
1612 $this->ErrorMsgs[__METHOD__][] =
1613 "Unknown metadata field name found"
1614 ." in AddCondition (".$ParamValue.").";
1615
1616 # bail out
1617 return NULL;
1618 }
1619 break;
1620
1621 case "Value":
1622 $ConditionValue = ($ParamValue == "NULL")
1623 ? NULL : (string)$ParamValue;
1624 break;
1625
1626 case "Operator":
1627 $ConditionOperator = (string)$ParamValue;
1628 break;
1629
1630 default:
1631 # record error about unknown parameter name
1632 $this->ErrorMsgs[__METHOD__][] =
1633 "Unknown tag found in AddCondition ("
1634 .$ParamName.").";
1635
1636 # bail out
1637 return NULL;
1638 break;
1639 }
1640 }
1641
1642 # if no field value
1643 if (!isset($ConditionField))
1644 {
1645 # record error about no field value
1646 $this->ErrorMsgs[__METHOD__][] =
1647 "No metadata field specified in AddCondition.";
1648
1649 # bail out
1650 return NULL;
1651 }
1652
1653 # add conditional to privilege set
1654 $PrivSet->AddCondition($ConditionField,
1655 $ConditionValue, $ConditionOperator);
1656 break;
1657
1658 default:
1659 # strip any excess whitespace off of value
1660 $Value = trim($Value);
1661
1662 # if child looks like valid method name
1663 if (method_exists("PrivilegeSet", $Tag))
1664 {
1665 # convert constants if needed
1666 if (defined($Value)) { $Value = constant($Value); }
1667
1668 # convert booleans if needed
1669 if (strtoupper($Value) == "TRUE") { $Value = TRUE; }
1670 elseif (strtoupper($Value) == "FALSE") { $Value = FALSE; }
1671
1672 # set value using child data
1673 $PrivSet->$Tag((string)$Value);
1674 }
1675 else
1676 {
1677 # record error about bad tag
1678 $this->ErrorMsgs[__METHOD__][] =
1679 "Unknown tag encountered (".$Tag.").";
1680
1681 # bail out
1682 return NULL;
1683 }
1684 break;
1685 }
1686 }
1687
1688 # return new privilege set to caller
1689 return $PrivSet;
1690 }
1691 }
MetadataSchema\MDFSTAT_ILLEGALLABEL
const MDFSTAT_ILLEGALLABEL
Definition: MetadataSchema.php:49
MetadataSchema\ORDER_DISPLAY_NAME
const ORDER_DISPLAY_NAME
Definition: MetadataSchema.php:60
ItemFactory\GetHighestItemId
GetHighestItemId($IgnoreSqlCondition=FALSE)
Retrieve highest item ID in use.
Definition: ItemFactory.php:248
MetadataSchema\MDFTYPE_IMAGE
const MDFTYPE_IMAGE
Definition: MetadataSchema.php:30
MetadataField\$FieldTypeDBEnums
static $FieldTypeDBEnums
Definition: MetadataField.php:1242
MetadataSchema\RESOURCENAME_DEFAULT
const RESOURCENAME_DEFAULT
Definition: MetadataSchema.php:56
MetadataField\$FieldTypeDBAllowedEnums
static $FieldTypeDBAllowedEnums
Definition: MetadataField.php:1259
MetadataSchema\GetFieldIdByName
GetFieldIdByName($FieldName, $IgnoreCase=FALSE)
Retrieve metadata field ID by name.
Definition: MetadataSchema.php:985
MetadataSchema\MDFTYPE_TIMESTAMP
const MDFTYPE_TIMESTAMP
Definition: MetadataSchema.php:24
MetadataSchema\GetHighestFieldId
GetHighestFieldId()
Get highest field ID currently in use.
Definition: MetadataSchema.php:1272
MetadataSchema\$FieldCompareEditOrder
$FieldCompareEditOrder
The cache for metadata field edit ordering.
Definition: MetadataSchema.php:1562
MetadataSchema\GetViewPageIdParameter
GetViewPageIdParameter()
Get the resource ID GET parameter for the view page for the schema.
Definition: MetadataSchema.php:417
MetadataSchema\GetAllowedFieldTypes
GetAllowedFieldTypes()
Retrieve array of field types that user can create.
Definition: MetadataSchema.php:1221
MetadataSchema\ViewingPrivileges
ViewingPrivileges(PrivilegeSet $NewValue=NULL)
Get/set privileges that allowing viewing resources with this schema.
Definition: MetadataSchema.php:368
MetadataSchema\MDFTYPE_FILE
const MDFTYPE_FILE
Definition: MetadataSchema.php:31
MetadataSchema
Metadata schema (in effect a Factory class for MetadataField).
Definition: MetadataSchema.php:13
MetadataSchema\ErrorMessages
ErrorMessages($Method=NULL)
Get error messages (if any) from recent calls.
Definition: MetadataSchema.php:780
MetadataSchema\ResourceName
ResourceName($NewValue=NULL)
Get/set name of resources using this schema.
Definition: MetadataSchema.php:261
MetadataField\$FieldTypePHPEnums
static $FieldTypePHPEnums
Definition: MetadataField.php:1276
MetadataSchema\MDFORDER_ALPHABETICAL
const MDFORDER_ALPHABETICAL
Definition: MetadataSchema.php:39
MetadataField\Create
static Create($SchemaId, $FieldType, $FieldName, $Optional=NULL, $DefaultValue=NULL)
Create a new metadata field.
Definition: MetadataField.php:1315
MetadataSchema\NormalizeOwnedFields
static NormalizeOwnedFields()
Disable owned fields that have an owner that is unavailable and re-enable fields if an owner has retu...
Definition: MetadataSchema.php:1399
Database
SQL database abstraction object with smart query caching.
Definition: Axis--Database.php:22
MetadataSchema\UserCanAuthor
UserCanAuthor($User)
Determine if the given user can author resources using this schema.
Definition: MetadataSchema.php:392
MetadataSchema\EditingPrivileges
EditingPrivileges(PrivilegeSet $NewValue=NULL)
Get/set privileges that allowing editing resources with this schema.
Definition: MetadataSchema.php:346
MetadataSchema\MDFTYPE_REFERENCE
const MDFTYPE_REFERENCE
Definition: MetadataSchema.php:34
MetadataSchema\GetFieldByName
GetFieldByName($FieldName, $IgnoreCase=FALSE)
Retrieve metadata field by name.
Definition: MetadataSchema.php:960
MetadataSchema\GetFieldIdByLabel
GetFieldIdByLabel($FieldLabel, $IgnoreCase=FALSE)
Retrieve metadata field ID by label.
Definition: MetadataSchema.php:1011
MetadataSchema\GetFieldsAsOptionList
GetFieldsAsOptionList($OptionListName, $FieldTypes=NULL, $SelectedFieldId=NULL, $IncludeNullOption=TRUE, $AddEntries=NULL, $AllowMultiple=FALSE)
Retrieve fields of specified type as HTML option list with field names as labels and field IDs as val...
Definition: MetadataSchema.php:1141
MetadataSchema\SchemaExistsWithId
static SchemaExistsWithId($SchemaId)
Check with schema exists with specified ID.
Definition: MetadataSchema.php:210
MetadataSchema\FieldToStdNameMapping
static FieldToStdNameMapping($FieldId)
Get mapping of field ID to standard field name.
Definition: MetadataSchema.php:1297
MetadataSchema\MDFSTAT_FIELDDOESNOTEXIST
const MDFSTAT_FIELDDOESNOTEXIST
Definition: MetadataSchema.php:46
MetadataSchema\MDFSTAT_OK
const MDFSTAT_OK
Definition: MetadataSchema.php:42
MetadataSchema\MDFTYPE_NUMBER
const MDFTYPE_NUMBER
Definition: MetadataSchema.php:22
MetadataSchema\FieldExists
FieldExists($FieldName)
Check whether field with specified name exists.
Definition: MetadataSchema.php:1035
MetadataSchema\CompareFieldOrder
CompareFieldOrder($FieldA, $FieldB)
Field sorting callback.
Definition: MetadataSchema.php:1515
MetadataSchema\SCHEMAID_USER
const SCHEMAID_USER
Definition: MetadataSchema.php:53
MetadataSchema\GetFieldIdByMappedName
GetFieldIdByMappedName($MappedName)
Get field ID by standard field name.
Definition: MetadataSchema.php:1332
PrivilegeSet
Set of privileges used to access resource information or other parts of the system.
Definition: PrivilegeSet.php:16
MetadataSchema\GetFieldNames
GetFieldNames($FieldTypes=NULL, $OrderType=NULL, $IncludeDisabledFields=FALSE, $IncludeTempFields=FALSE)
Retrieve field names.
Definition: MetadataSchema.php:1110
MetadataSchema\AddFieldFromXml
AddFieldFromXml($Xml)
Add new metadata field based on supplied XML.
Definition: MetadataSchema.php:807
MetadataSchema\CacheData
CacheData($NewValue)
Enable/disable caching of metadata field info.
Definition: MetadataSchema.php:504
MetadataSchema\MDFTYPE_TREE
const MDFTYPE_TREE
Definition: MetadataSchema.php:26
MetadataSchema\SetOwnerListRetrievalFunction
static SetOwnerListRetrievalFunction($Callback)
Allow external dependencies, i.e., the current list of owners that are available, to be injected...
Definition: MetadataSchema.php:1386
MetadataSchema\MDFTYPE_OPTION
const MDFTYPE_OPTION
Definition: MetadataSchema.php:28
MetadataSchema\Name
Name($NewValue=NULL)
Get/set name of schema.
Definition: MetadataSchema.php:234
MetadataSchema\MDFTYPE_FLAG
const MDFTYPE_FLAG
Definition: MetadataSchema.php:25
MetadataSchema\ViewPage
ViewPage($NewValue=NULL)
Get/set name of page to go to for viewing resources using this schema.
Definition: MetadataSchema.php:297
MetadataSchema\MDFTYPE_CONTROLLEDNAME
const MDFTYPE_CONTROLLEDNAME
Definition: MetadataSchema.php:27
MetadataSchema\MDFSTAT_ERROR
const MDFSTAT_ERROR
Definition: MetadataSchema.php:43
MetadataSchema\GetOwnedFields
GetOwnedFields()
Get fields that have an owner associated with them.
Definition: MetadataSchema.php:1341
MetadataSchema\PathMatchesViewPage
PathMatchesViewPage($Path)
Determine if a path matches the view page path for the schema.
Definition: MetadataSchema.php:449
PHP
PHP
Definition: OAIClient.php:39
ItemFactory\$DB
$DB
Definition: ItemFactory.php:1053
MetadataSchema\MDFSTAT_DUPLICATEDBCOLUMN
const MDFSTAT_DUPLICATEDBCOLUMN
Definition: MetadataSchema.php:45
MetadataSchema\SCHEMAID_DEFAULT
const SCHEMAID_DEFAULT
Definition: MetadataSchema.php:52
MetadataSchema\ORDER_EDIT_NAME
const ORDER_EDIT_NAME
Definition: MetadataSchema.php:61
MetadataSchema\GetEditOrder
GetEditOrder()
Get the editing order for the schema.
Definition: MetadataSchema.php:1494
MetadataSchema\$OwnerListRetrievalFunction
static $OwnerListRetrievalFunction
Definition: MetadataSchema.php:1552
MetadataSchema\MDFSTAT_DUPLICATELABEL
const MDFSTAT_DUPLICATELABEL
Definition: MetadataSchema.php:48
MetadataSchema\MDFORDER_EDITING
const MDFORDER_EDITING
Definition: MetadataSchema.php:38
MetadataFieldOrder\Create
static Create(MetadataSchema $Schema, $Name, array $FieldOrder=array())
Create a new metadata field order, optionally specifying the order of the fields. ...
Definition: MetadataFieldOrder.php:542
MetadataSchema\NewFields
NewFields()
Get new fields recently added (if any) via XML file.
Definition: MetadataSchema.php:766
MetadataSchema\AddField
AddField($FieldName, $FieldType, $Optional=TRUE, $DefaultValue=NULL)
Add new metadata field.
Definition: MetadataSchema.php:518
MetadataSchema\GetFields
GetFields($FieldTypes=NULL, $OrderType=NULL, $IncludeDisabledFields=FALSE, $IncludeTempFields=FALSE)
Retrieve array of fields.
Definition: MetadataSchema.php:1050
MetadataSchema\GetDisplayOrder
GetDisplayOrder()
Get the display order for the schema.
Definition: MetadataSchema.php:1485
MetadataSchema\FieldCompareOrdersSet
FieldCompareOrdersSet()
Determine whether the field comparison ordering caches are set.
Definition: MetadataSchema.php:1503
MetadataSchema\Create
static Create($Name, PrivilegeSet $AuthorPrivs=NULL, PrivilegeSet $EditPrivs=NULL, PrivilegeSet $ViewPrivs=NULL, $ViewPage="", $ResourceName=NULL)
Create new metadata schema.
Definition: MetadataSchema.php:145
MetadataField
Object representing a locally-defined type of metadata field.
Definition: MetadataField.php:13
MetadataSchema\MDFTYPE_PARAGRAPH
const MDFTYPE_PARAGRAPH
Definition: MetadataSchema.php:21
MetadataSchema\AuthoringPrivileges
AuthoringPrivileges(PrivilegeSet $NewValue=NULL)
Get/set privileges that allowing authoring resources with this schema.
Definition: MetadataSchema.php:324
MetadataSchema\__construct
__construct($SchemaId=self::SCHEMAID_DEFAULT)
Object constructor, used to load an existing schema.
Definition: MetadataSchema.php:71
MetadataSchema\MDFTYPE_DATE
const MDFTYPE_DATE
Definition: MetadataSchema.php:23
MetadataSchema\DropField
DropField($FieldId)
Delete metadata field and all associated data.
Definition: MetadataSchema.php:909
MetadataSchema\MDFTYPE_URL
const MDFTYPE_URL
Definition: MetadataSchema.php:32
MetadataSchema\MDFTYPE_TEXT
const MDFTYPE_TEXT
Definition: MetadataSchema.php:20
MetadataSchema\RemoveQualifierAssociations
RemoveQualifierAssociations($QualifierIdOrObject)
Remove all metadata field associations for a given qualifier.
Definition: MetadataSchema.php:1230
MetadataSchema\UpdateFieldCompareOrders
UpdateFieldCompareOrders()
Update the field comparison ordering cache that is used for sorting fields.
Definition: MetadataSchema.php:1464
MetadataFieldOrder\GetOrderForSchema
static GetOrderForSchema(MetadataSchema $Schema, $Name)
Get a metadata field order with a specific name for a given metadata schema.
Definition: MetadataFieldOrder.php:607
MetadataSchema\MDFSTAT_ILLEGALNAME
const MDFSTAT_ILLEGALNAME
Definition: MetadataSchema.php:47
MetadataSchema\RESOURCENAME_USER
const RESOURCENAME_USER
Definition: MetadataSchema.php:57
MetadataSchema\GetField
GetField($FieldId)
Retrieve metadata field by ID.
Definition: MetadataSchema.php:932
MetadataSchema\GetFieldByMappedName
GetFieldByMappedName($MappedName)
Get field by standard field name.
Definition: MetadataSchema.php:1319
MetadataSchema\Id
Id()
Get schema ID.
Definition: MetadataSchema.php:223
MetadataSchema\GetConstantName
static GetConstantName($Value, $Prefix=NULL)
Get name (string) for constant.
Definition: MetadataSchema.php:109
MetadataSchema\MDFTYPE_USER
const MDFTYPE_USER
Definition: MetadataSchema.php:29
MetadataSchema\AddFieldsFromXmlFile
AddFieldsFromXmlFile($FileName, $TestRun=FALSE)
Add new metadata fields from XML file.
Definition: MetadataSchema.php:552
ItemFactory
Common factory class for item manipulation.
Definition: ItemFactory.php:17
MetadataSchema\MDFSTAT_DUPLICATENAME
const MDFSTAT_DUPLICATENAME
Definition: MetadataSchema.php:44
MetadataSchema\$FieldCompareDisplayOrder
$FieldCompareDisplayOrder
The cache for metadata field display ordering.
Definition: MetadataSchema.php:1557
MetadataSchema\MDFTYPE_POINT
const MDFTYPE_POINT
Definition: MetadataSchema.php:33
ItemFactory\NameIsInUse
NameIsInUse($Name, $IgnoreCase=FALSE)
Check whether item name is currently in use.
Definition: ItemFactory.php:640
MetadataSchema\StdNameToFieldMapping
static StdNameToFieldMapping($MappedName, $FieldId=NULL)
Get/set mapping of standard field name to specific field.
Definition: MetadataSchema.php:1281
MetadataSchema\GetFieldTypes
GetFieldTypes()
Retrieve array of field types.
Definition: MetadataSchema.php:1211
ItemFactory\ItemFactory
ItemFactory($ItemClassName, $ItemTableName, $ItemIdFieldName, $ItemNameFieldName=NULL, $OrderOpsAllowed=FALSE, $SqlCondition=NULL)
Class constructor.
Definition: ItemFactory.php:36
MetadataSchema\GetAllSchemas
static GetAllSchemas()
Get all existing metadata schemas.
Definition: MetadataSchema.php:1363
MetadataSchema\MDFORDER_DISPLAY
const MDFORDER_DISPLAY
Definition: MetadataSchema.php:37
MetadataSchema\GetFieldByLabel
GetFieldByLabel($FieldLabel, $IgnoreCase=FALSE)
Retrieve metadata field by label.
Definition: MetadataSchema.php:972
MetadataSchema\QualifierIsInUse
QualifierIsInUse($QualifierIdOrObject)
Check whether qualifier is in use by any metadata field (in any schema).
Definition: MetadataSchema.php:1246