3 # FILE: MetadataSchema.php
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
15 # ---- PUBLIC INTERFACE --------------------------------------------------
17 # metadata field base types
18 # (must parallel MetadataFields.FieldType declaration in install/CreateTables.sql
19 # and MetadataField::$FieldTypeDBEnums declaration below)
36 # types of field ordering
59 # names used for display and edit orders
74 $this->
Id = $SchemaId;
76 # set up item factory base class
78 "MetadataField",
"MetadataFields",
"FieldId",
"FieldName", FALSE,
79 "SchemaId = ".intval($this->
Id()));
81 # load schema info from database
82 $this->DB->Query(
"SELECT * FROM MetadataSchemas"
83 .
" WHERE SchemaId = ".intval($SchemaId));
84 if ($this->DB->NumRowsSelected() < 1)
86 throw new Exception(
"Attempt to load metadata schema with "
87 .
" invalid ID (".$SchemaId.
").");
89 $Info = $this->DB->FetchRow();
90 $this->
Name = $Info[
"Name"];
96 # start with field info caching enabled
97 $this->CachingOn = TRUE;
111 # retrieve all constants for class
112 $Reflect =
new ReflectionClass(get_class());
113 $Constants = $Reflect->getConstants();
116 foreach ($Constants as $CName => $CValue)
118 # if value matches and prefix (if supplied) matches
119 if (($CValue == $Value)
120 && (($Prefix === NULL) || (strpos($CName, $Prefix) === 0)))
122 # return name to caller
127 # report to caller that no matching constant was found
150 $ResourceName = NULL)
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(); }
157 # add schema to database
159 if (strtoupper($Name) ==
"DEFAULT")
161 $Id = self::SCHEMAID_DEFAULT;
163 elseif (strtoupper($Name) ==
"USER")
165 $Id = self::SCHEMAID_USER;
169 $Id =
$DB->Query(
"SELECT SchemaId FROM MetadataSchemas"
170 .
" ORDER BY SchemaId DESC LIMIT 1",
"SchemaId") + 1;
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()).
"')");
182 # construct the new schema
185 # set schema name if none supplied
188 $Schema->Name(
"Metadata Schema ".$Id);
191 # set the resource name if one is supplied
192 if (!is_null($ResourceName))
194 $Schema->ResourceName($ResourceName);
197 # create display and edit orders
201 # return the new schema
213 $DB->Query(
"SELECT * FROM MetadataSchemas"
214 .
" WHERE SchemaId = ".intval($SchemaId));
215 return (
$DB->NumRowsSelected() > 0) ? TRUE : FALSE;
225 # return value to caller
234 function Name($NewValue = NULL)
236 # set new name if one supplied
237 if ($NewValue !== NULL)
239 $this->DB->Query(
"UPDATE MetadataSchemas"
240 .
" SET Name = '".addslashes($NewValue).
"'"
241 .
" WHERE SchemaId = '".intval($this->
Id).
"'");
242 $this->
Name = $NewValue;
245 # get the name if it hasn't been cached yet
246 if (!isset($this->
Name))
248 $this->
Name = $this->DB->Query(
"SELECT * FROM MetadataSchemas"
249 .
" WHERE SchemaId = '".intval($this->
Id).
"'",
"Name");
252 # return current value to caller
263 # set new resource name if one supplied
264 if ($NewValue !== NULL)
267 UPDATE MetadataSchemas
268 SET ResourceName = '".addslashes($NewValue).
"'
269 WHERE SchemaId = '".intval($this->
Id).
"'");
273 # get the name if it hasn't been cached yet
277 SELECT * FROM MetadataSchemas
278 WHERE SchemaId = '".intval($this->
Id).
"'",
281 # use the default resource name if one isn't set
288 # return current value to caller
289 return $this->ResourceName;
299 # set new viewing page if one supplied
300 if ($NewValue !== NULL)
302 $this->DB->Query(
"UPDATE MetadataSchemas"
303 .
" SET ViewPage = '".addslashes($NewValue).
"'"
304 .
" WHERE SchemaId = '".intval($this->
Id).
"'");
308 # get the view page if it hasn't been cached yet
311 $this->
ViewPage = $this->DB->Query(
"SELECT * FROM MetadataSchemas"
312 .
" WHERE SchemaId = '".intval($this->
Id).
"'",
"ViewPage");
315 # return current value to caller
316 return $this->ViewPage;
326 # if new privileges supplied
327 if ($NewValue !== NULL)
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));
337 # return current value to caller
338 return $this->AuthoringPrivileges;
348 # if new privileges supplied
349 if ($NewValue !== NULL)
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));
359 # return current value to caller
360 return $this->EditingPrivileges;
370 # if new privileges supplied
371 if ($NewValue !== NULL)
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));
381 # return current value to caller
382 return $this->ViewingPrivileges;
394 # get authoring privilege set for schema
397 # user can author if privileges are greater than resource set
398 $CanAuthor = $AuthorPrivs->MeetsRequirements($User);
400 # allow plugins to modify result of permission check
401 $SignalResult = $GLOBALS[
"AF"]->SignalEvent(
402 "EVENT_RESOURCE_AUTHOR_PERMISSION_CHECK", array(
405 "CanAuthor" => $CanAuthor));
406 $CanAuthor = $SignalResult[
"CanAuthor"];
408 # report back to caller whether user can author field
419 # get the query/GET parameters for the view page
420 $Query = parse_url($this->
ViewPage(), PHP_URL_QUERY);
422 # the URL couldn't be parsed
423 if (!is_string($Query))
428 # parse the GET parameters out of the query string
429 $GetVars = ParseQueryString($Query);
431 # search for the ID parameter
432 $Result = array_search(
"\$ID", $GetVars);
434 return $Result !== FALSE ? $Result : NULL;
451 # get the query/GET parameters for the view page
452 $Query = parse_url($this->
ViewPage(), PHP_URL_QUERY);
454 # can't perform matching if the URL couldn't be parsed
455 if (!is_string($Query))
460 # parse the GET parameters out of the query string
461 $GetVars = ParseQueryString($Query);
463 # now, get the query/GET parameters from the path given
464 $PathQuery = parse_url($Path, PHP_URL_QUERY);
466 # can't perform matching if the URL couldn't be parsed
467 if (!is_string($PathQuery))
472 # parse the GET parameters out of the path's query string
473 $PathGetVars = ParseQueryString($PathQuery);
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)
480 # there's a required parameter that is not included in the path GET
482 if (!array_key_exists($GetVarName, $PathGetVars))
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} !=
"$"))
496 # the path matches the view page path
506 $this->CachingOn = $NewValue;
518 function AddField($FieldName, $FieldType, $Optional = TRUE, $DefaultValue = NULL)
520 # clear any existing error messages
521 if (array_key_exists(__METHOD__, $this->ErrorMsgs))
522 { unset($this->ErrorMsgs[__METHOD__]); }
528 $FieldName, $Optional, $DefaultValue);
530 catch (Exception $Exception)
532 $this->ErrorMsgs[__METHOD__][] = $Exception->getMessage();
536 # return new field to caller
554 # clear loading status
556 if (array_key_exists(__METHOD__, $this->ErrorMsgs))
557 { unset($this->ErrorMsgs[__METHOD__]); }
559 # check that file exists and is readable
560 if (!file_exists($FileName))
562 $this->ErrorMsgs[__METHOD__][] =
"Could not find XML file '"
566 elseif (!is_readable($FileName))
568 $this->ErrorMsgs[__METHOD__][] =
"Could not read from XML file '"
574 libxml_use_internal_errors(TRUE);
575 $XmlData = simplexml_load_file($FileName);
576 $Errors = libxml_get_errors();
577 libxml_use_internal_errors(FALSE);
580 if ($XmlData === FALSE)
582 # retrieve XML error messages
583 foreach ($Errors as $Err)
585 $ErrType = ($Err->level == LIBXML_ERR_WARNING) ?
"Warning"
586 : (($Err->level == LIBXML_ERR_WARNING) ?
"Error"
588 $this->ErrorMsgs[__METHOD__][] =
"XML ".$ErrType.
": ".$Err->message
589 .
" (".$Err->file.
":".$Err->line.
",".$Err->column.
")";
592 # else if no metadata fields found record error message
593 elseif (!count($XmlData->MetadataField))
595 $this->ErrorMsgs[__METHOD__][] =
"No metadata fields found.";
597 # else process metadata fields
600 # for each metadata field entry found
603 foreach ($XmlData->MetadataField as $FieldXml)
607 # pull out field type if present
608 if (isset($FieldXml->Type))
610 $FieldType =
"MetadataSchema::".$FieldXml->Type;
611 if (!defined($FieldType))
613 $FieldType =
"MetadataSchema::MDFTYPE_"
614 .strtoupper(preg_replace(
"/\\s+/",
"",
619 # if required values are missing
620 if (!isset($FieldXml->Name) || !isset($FieldXml->Type)
621 || !defined($FieldType))
623 # add error message about required value missing
624 if (!isset($FieldXml->Name))
626 $this->ErrorMsgs[__METHOD__][] =
627 "Field name not found (MetadataField #"
632 $this->ErrorMsgs[__METHOD__][] =
633 "Valid type not found for field '"
634 .$FieldXml->Name.
"' (MetadataField #"
638 # else if there is not already a field with this name
639 elseif (!$this->
NameIsInUse(trim($FieldXml->Name)))
642 $Field = $this->
AddField($FieldXml->Name, constant($FieldType));
644 # if field creation failed
647 # add any error message to our error list
649 foreach ($ErrorMsgs as $Msg)
651 $this->ErrorMsgs[__METHOD__][] =
657 # add field to list of created fields
660 # for other field attributes
661 foreach ($FieldXml as $MethodName => $Value)
663 # if tags look valid and have not already been set
664 if (method_exists($Field, $MethodName)
665 && ($MethodName !=
"Name")
666 && ($MethodName !=
"Type"))
668 # if tag indicates privilege set
669 if (preg_match(
"/^[a-z]+Privileges\$/i",
672 # save element for later processing
673 $PrivilegesToSet[$Field->Id()][$MethodName] = $Value;
677 # condense down any extraneous whitespace
678 $Value = preg_replace(
"/\s+/",
" ", trim($Value));
680 # set value for field
681 $Field->$MethodName($Value);
686 # save the temp ID so that any privileges to set can be
687 # mapped to the actual ID when the field is made
689 $TempId = $Field->Id();
691 # make new field permanent
692 $Field->IsTempItem(FALSE);
694 # map privileges to set to the permanent field ID
695 if (isset($PrivilegesToSet) &&
696 isset($PrivilegesToSet[$TempId]) )
698 # copy the privileges over
699 $PrivilegesToSet[$Field->Id()] =
700 $PrivilegesToSet[$TempId];
702 # remove the values for the temp ID
703 unset($PrivilegesToSet[$TempId]);
709 # if we have privileges to set
710 if (isset($PrivilegesToSet))
712 # for each field with privileges
713 foreach ($PrivilegesToSet as $FieldId => $Privileges)
715 # load the field for which to set the privileges
718 # for each set of privileges for field
719 foreach ($Privileges as $MethodName => $Value)
721 # convert privilege value
722 $Value = $this->ConvertXmlToPrivilegeSet($Value);
724 # if conversion failed
727 # add resulting error messages to our list
729 "ConvertXmlToPrivilegeSet");
730 foreach ($ErrorMsgs as $Msg)
732 $this->ErrorMsgs[__METHOD__][] =
733 $Msg.
" (ConvertXmlToPrivilegeSet)";
738 # set value for field
739 $Field->$MethodName($Value);
745 # if errors were found during creation
746 if (array_key_exists(__METHOD__, $this->ErrorMsgs) || $TestRun)
748 # remove any fields that were created
757 # report success or failure based on whether errors were recorded
758 return (array_key_exists(__METHOD__, $this->ErrorMsgs)) ? FALSE : TRUE;
768 return $this->NewFields;
782 if ($Method === NULL)
784 return $this->ErrorMsgs;
788 if (!method_exists($this, $Method))
790 throw new Exception(
"Error messages requested for non-existent"
791 .
" method (".$Method.
").");
793 return array_key_exists(__CLASS__.
"::".$Method, $this->ErrorMsgs)
794 ? $this->ErrorMsgs[__CLASS__.
"::".$Method] : array();
809 # assume field addition will fail
810 $Field = self::MDFSTAT_ERROR;
812 # add XML prefixes if needed
814 if (!preg_match(
"/^<\?xml/i", $Xml))
816 if (!preg_match(
"/^<document>/i", $Xml))
818 $Xml =
"<document>".$Xml.
"</document>";
820 $Xml =
"<?xml version='1.0'?".
">".$Xml;
824 $XmlData = simplexml_load_string($Xml);
826 # if required values are present
827 if (is_object($XmlData)
828 && isset($XmlData->Name)
829 && isset($XmlData->Type)
830 && constant(
"MetadataSchema::".$XmlData->Type))
832 # create the metadata field
835 constant(
"MetadataSchema::".$XmlData->Type));
837 # if field creation succeeded
840 # for other field attributes
841 foreach ($XmlData as $MethodName => $Value)
843 # if they look valid and have not already been set
844 if (method_exists($Field, $MethodName)
845 && ($MethodName !=
"Name")
846 && ($MethodName !=
"Type"))
848 # if tag indicates privilege set
849 if (preg_match(
"/^[a-z]+Privileges\$/i",
852 # save element for later processing
853 $PrivilegesToSet[$MethodName] = $Value;
857 # condense down any extraneous whitespace
858 $Value = preg_replace(
"/\s+/",
" ", trim($Value));
860 # set value for field
861 $Field->$MethodName($Value);
866 # make new field permanent
867 $Field->IsTempItem(FALSE);
869 # if we have privileges to set
870 if (isset($PrivilegesToSet))
872 # for each set of privileges for field
873 foreach ($PrivilegesToSet as $MethodName => $Value)
875 # convert privilege value
876 $Value = $this->ConvertXmlToPrivilegeSet($Value);
878 # if conversion failed
881 # add resulting error messages to our list
883 "ConvertXmlToPrivilegeSet");
884 foreach ($ErrorMsgs as $Msg)
886 $this->ErrorMsgs[__METHOD__][] =
887 $Msg.
" (ConvertXmlToPrivilegeSet)";
892 # set value for field
893 $Field->$MethodName($Value);
900 # return new field (if any) to caller
915 $AF->SignalEvent(
"EVENT_PRE_FIELD_DELETE",
916 array(
"FieldId" => $FieldId) );
936 # if caching is off or field is not already loaded
937 if (($this->CachingOn != TRUE) || !isset($Fields[$FieldId]))
944 catch (Exception $Exception)
946 $Fields[$FieldId] = NULL;
950 # return field to caller
951 return $Fields[$FieldId];
963 return ($FieldId === NULL) ? NULL : $this->
GetField($FieldId);
975 return ($FieldId === NULL) ? NULL : $this->
GetField($FieldId);
987 static $FieldIdsByName;
989 # if caching is off or field ID is already loaded
990 if (($this->CachingOn != TRUE) || !isset($FieldIdsByName[$this->
Id][$FieldName]))
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");
1001 return $FieldIdsByName[$this->Id][$FieldName];
1013 static $FieldIdsByLabel;
1015 # if caching is off or field ID is already loaded
1016 if (($this->CachingOn != TRUE) || !isset($FieldIdsByLabel[$FieldLabel]))
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");
1027 return $FieldIdsByLabel[$FieldLabel];
1051 $IncludeDisabledFields = FALSE, $IncludeTempFields = FALSE)
1053 # create empty array to pass back
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())
1063 # if field type is known
1066 # if no specific type requested or if field is of requested type
1067 if (($FieldTypes == NULL)
1071 # create field object and add to array to be passed back
1072 $Fields[$Record[
"FieldId"]] = $this->
GetField($Record[
"FieldId"]);
1077 # if field sorting requested
1078 if ($OrderType !== NULL)
1080 # update field comparison ordering if not set yet
1086 $this->FieldCompareType = $OrderType;
1088 # sort field array by requested order type
1089 uasort($Fields, array($this,
"CompareFieldOrder"));
1092 # return array of field objects to caller
1111 $IncludeDisabledFields = FALSE, $IncludeTempFields = FALSE)
1113 $Fields = $this->
GetFields($FieldTypes, $OrderType,
1114 $IncludeDisabledFields, $IncludeTempFields);
1116 $FieldNames = array();
1117 foreach($Fields as $Field)
1119 $FieldNames[$Field->Id()] = $Field->Name();
1142 $SelectedFieldId = NULL, $IncludeNullOption = TRUE,
1143 $AddEntries = NULL, $AllowMultiple = FALSE)
1145 # retrieve requested fields
1148 # transform field names to labels
1149 foreach ($FieldNames as $FieldId => $FieldName)
1151 $FieldNames[$FieldId] = $this->
GetField($FieldId)->GetDisplayName();
1154 # begin HTML option list
1155 $Html =
"<select id=\"".$OptionListName.
"\" name=\"".$OptionListName.
"\"";
1157 # if multiple selections should be allowed
1160 $Html .=
" multiple=\"multiple\"";
1165 if ($IncludeNullOption)
1167 $Html .=
"<option value=\"\">--</option>\n";
1170 # make checking for IDs simpler
1171 if (!is_array($SelectedFieldId))
1173 $SelectedFieldId = array($SelectedFieldId);
1176 # for each metadata field
1177 foreach ($FieldNames as $Id => $Name)
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";
1185 # if additional entries were requested
1188 foreach ($AddEntries as $Value => $Label)
1190 $Html .=
"<option value=\"".$Value.
"\"";
1191 if (in_array($Value, $SelectedFieldId))
1193 $Html .=
" selected";
1195 $Html .=
">".htmlspecialchars($Label).
"</option>\n";
1199 # end HTML option list
1200 $Html .=
"</select>\n";
1202 # return constructed HTML to caller
1232 # sanitize qualifier ID or grab it from object
1233 $QualifierIdOrObject = is_object($QualifierIdOrObject)
1234 ? $QualifierIdOrObject->Id() : intval($QualifierIdOrObject);
1236 # delete intersection records from database
1237 $this->DB->Query(
"DELETE FROM FieldQualifierInts"
1238 .
" WHERE QualifierId = ".$QualifierIdOrObject);
1248 # sanitize qualifier ID or grab it from object
1249 $QualifierIdOrObject = is_object($QualifierIdOrObject)
1250 ? $QualifierIdOrObject->Id() : intval($QualifierIdOrObject);
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,
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,
1264 # report whether qualifier is in use based on defaults and associations
1265 return (($DefaultCount + $AssociationCount) > 0) ? TRUE : FALSE;
1283 if ($FieldId !== NULL)
1285 self::$FieldMappings[$MappedName] = $FieldId;
1287 return isset(self::$FieldMappings[$MappedName])
1288 ? self::$FieldMappings[$MappedName] : NULL;
1301 foreach (self::$FieldMappings as $MappedName => $MappedFieldId)
1303 if ($MappedFieldId == $FieldId)
1321 return (self::StdNameToFieldMapping($MappedName) == NULL) ? NULL
1334 return self::StdNameToFieldMapping($MappedName);
1345 $this->DB->Query(
"SELECT * FROM MetadataFields"
1346 .
" WHERE Owner IS NOT NULL AND LENGTH(Owner) > 0"
1347 .
" AND SchemaId = ".intval($this->
Id));
1349 while (FALSE !== ($Row = $this->DB->FetchRow()))
1351 $FieldId = $Row[
"FieldId"];
1352 $Fields[$FieldId] = $this->
GetField($FieldId);
1368 # fetch the IDs all of the metadata schemas
1369 $Database->Query(
"SELECT * FROM MetadataSchemas");
1370 $SchemaIds = $Database->FetchColumn(
"SchemaId");
1372 # construct objects from the IDs
1373 foreach ($SchemaIds as $SchemaId)
1388 if (is_callable($Callback))
1390 self::$OwnerListRetrievalFunction = $Callback;
1401 # if an owner list retrieval function and default schema exists
1402 if (self::$OwnerListRetrievalFunction
1403 && self::SchemaExistsWithId(self::SCHEMAID_DEFAULT))
1405 # retrieve the list of owners that currently exist
1406 $OwnerList = call_user_func(self::$OwnerListRetrievalFunction);
1408 # an array is expected
1409 if (is_array($OwnerList))
1413 # get each metadata field that is owned by a plugin
1414 $OwnedFields = $Schema->GetOwnedFields();
1416 # loop through each owned field
1417 foreach ($OwnedFields as $OwnedField)
1419 # the owner of the current field
1420 $Owner = $OwnedField->Owner();
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))
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())
1432 $OwnedField->Enabled(TRUE);
1433 $OwnedField->EnableOnOwnerReturn(FALSE);
1437 # if the owner of the field is *not* in the list of owners
1438 # that currently exist, i.e., available plugins
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();
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
1451 $OwnedField->EnableOnOwnerReturn($Enabled);
1452 $OwnedField->Enabled(FALSE);
1470 $this->FieldCompareDisplayOrder[$Field->Id()] = $Index++;
1477 $this->FieldCompareEditOrder[$Field->Id()] = $Index++;
1519 return ($FieldA->GetDisplayName() < $FieldB->GetDisplayName()) ? -1 : 1;
1532 $PositionA = GetArrayValue($Order, $FieldA->Id(), 0);
1533 $PositionB = GetArrayValue($Order, $FieldB->Id(), 0);
1535 return $PositionA < $PositionB ? -1 : 1;
1538 # ---- PRIVATE INTERFACE -------------------------------------------------
1542 private $ResourceName;
1543 private $AuthoringPrivileges;
1544 private $EditingPrivileges;
1545 private $ViewingPrivileges;
1547 private $FieldCompareType;
1549 private $NewFields = array();
1550 private $ErrorMsgs = array();
1551 private static $FieldMappings;
1571 private function ConvertXmlToPrivilegeSet($Xml)
1573 # clear any existing errors
1574 if (array_key_exists(__METHOD__, $this->ErrorMsgs))
1575 { unset($this->ErrorMsgs[__METHOD__]); }
1577 # create new privilege set
1580 # for each XML child
1581 foreach ($Xml as $Tag => $Value)
1583 # take action based on element name
1586 case "PrivilegeSet":
1587 # convert child data to new set
1588 $NewSet = $this->ConvertXmlToPrivilegeSet($Value);
1590 # add new set to our privilege set
1591 $PrivSet->AddSet($NewSet);
1594 case "AddCondition":
1595 # start with default values for optional parameters
1596 unset($ConditionField);
1597 $ConditionValue = NULL;
1598 $ConditionOperator =
"==";
1600 # pull out parameters
1601 foreach ($Value as $ParamName => $ParamValue)
1603 $ParamValue = trim($ParamValue);
1608 (
string)$ParamValue, TRUE);
1609 if ($ConditionField === NULL)
1611 # record error about unknown field
1612 $this->ErrorMsgs[__METHOD__][] =
1613 "Unknown metadata field name found"
1614 .
" in AddCondition (".$ParamValue.
").";
1622 $ConditionValue = ($ParamValue ==
"NULL")
1623 ? NULL : (
string)$ParamValue;
1627 $ConditionOperator = (string)$ParamValue;
1631 # record error about unknown parameter name
1632 $this->ErrorMsgs[__METHOD__][] =
1633 "Unknown tag found in AddCondition ("
1643 if (!isset($ConditionField))
1645 # record error about no field value
1646 $this->ErrorMsgs[__METHOD__][] =
1647 "No metadata field specified in AddCondition.";
1653 # add conditional to privilege set
1654 $PrivSet->AddCondition($ConditionField,
1655 $ConditionValue, $ConditionOperator);
1659 # strip any excess whitespace off of value
1660 $Value = trim($Value);
1662 # if child looks like valid method name
1663 if (method_exists(
"PrivilegeSet", $Tag))
1665 # convert constants if needed
1666 if (defined($Value)) { $Value = constant($Value); }
1668 # convert booleans if needed
1669 if (strtoupper($Value) ==
"TRUE") { $Value = TRUE; }
1670 elseif (strtoupper($Value) ==
"FALSE") { $Value = FALSE; }
1672 # set value using child data
1673 $PrivSet->$Tag((
string)$Value);
1677 # record error about bad tag
1678 $this->ErrorMsgs[__METHOD__][] =
1679 "Unknown tag encountered (".$Tag.
").";
1688 # return new privilege set to caller
GetHighestItemId($IgnoreSqlCondition=FALSE)
Retrieve highest item ID in use.
SQL database abstraction object with smart query caching.
Set of privileges used to access resource information or other parts of the system.
Common factory class for item manipulation.
NameIsInUse($Name, $IgnoreCase=FALSE)
Check whether item name is currently in use.
ItemFactory($ItemClassName, $ItemTableName, $ItemIdFieldName, $ItemNameFieldName=NULL, $OrderOpsAllowed=FALSE, $SqlCondition=NULL)
Class constructor.