3 # FILE: MetadataField.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 # update methods for timestamp fields
24 # values for the *UserIsValue fields
36 return $this->ErrorStatus;
47 # if new value supplied
48 $FTFieldName = $this->DBFields[
"FieldType"];
50 && ($NewValue != self::$FieldTypePHPEnums[$FTFieldName]))
52 # update database fields and store new type
53 $this->ModifyField(NULL, $NewValue);
56 # return type to caller
57 return self::$FieldTypePHPEnums[$FTFieldName];
66 return $this->DBFields[
"FieldType"];
75 return $this->DBFields[
"SchemaId"];
96 # if new name specified
98 && trim($NewName) != $this->DBFields[
"FieldName"])
100 $NewName = trim($NewName);
101 $NormalizedName = $this->NormalizeFieldNameForDB(strtolower($NewName));
103 # if field name is invalid
104 if (!preg_match(
"/^[[:alnum:] \(\)]+$/", $NewName))
106 # set error status to indicate illegal name
110 # if the new name is a reserved word
111 else if ($NormalizedName ==
"resourceid" || $NormalizedName ==
"schemaid")
113 # set error status to indicate illegal name
117 # the name is okay but might be a duplicate
120 # check for duplicate name
121 $DuplicateCount = $this->DB->Query(
122 "SELECT COUNT(*) AS RecordCount FROM MetadataFields"
123 .
" WHERE FieldName = '".addslashes($NewName).
"'"
124 .
" AND SchemaId = ".intval($this->DBFields[
"SchemaId"]),
127 # if field name is duplicate
128 if ($DuplicateCount > 0)
130 # set error status to indicate duplicate name
135 # modify database declaration to reflect new field name
137 $this->ModifyField($NewName);
142 # return value to caller
143 return $this->DBFields[
"FieldName"];
153 $ValidValueExp =
'/^[[:alnum:] ]*$/';
154 $Value = $this->DBFields[
"Label"];
156 # if a new label was specified
157 if ($NewLabel !==
DB_NOVALUE && trim($NewLabel) != $Value)
159 $NewLabel = trim($NewLabel);
161 # if field label is valid
162 if (preg_match($ValidValueExp, $NewLabel))
164 $this->UpdateValue(
"Label", $NewLabel);
167 # the field label is invalid
184 # determine type list based on our type
185 switch ($this->
Type())
192 $AllowedTypes = array(
203 $AllowedTypes = array(
210 $AllowedTypes = array(
217 $AllowedTypes = array(
229 $AllowedTypes = array();
233 # return type list to caller
234 return $AllowedTypes;
247 $ItemTableName =
"MetadataFields";
248 $ItemIdFieldName =
"FieldId";
249 $ItemFactoryObjectName =
"MetadataSchema";
250 $ItemAssociationTables = array(
251 "FieldQualifierInts",
253 $ItemAssociationFieldName =
"MetadataFieldId";
255 # if new temp item setting supplied
256 if (!is_null($NewSetting))
258 # if caller requested to switch
259 if (($this->
Id() < 0 && $NewSetting == FALSE)
260 || ($this->
Id() >= 0 && $NewSetting == TRUE))
262 # if field name is invalid
263 if (strlen($this->NormalizeFieldNameForDB($this->
Name())) < 1)
265 # set error status to indicate illegal name
270 # lock DB tables to prevent next ID from being grabbed
273 LOCK TABLES ".$ItemTableName.
" WRITE,
274 APSessions WRITE, APSessionData WRITE,
275 MetadataSchemas WRITE");
277 # nuke stale field cache
278 self::$FieldCache = NULL;
280 # get next temp item ID
281 $OldItemId = $this->
Id();
282 $Factory =
new $ItemFactoryObjectName();
283 if ($NewSetting == TRUE)
285 $NewId = $Factory->GetNextTempItemId();
289 $NewId = $Factory->GetNextItemId();
293 $DB->Query(
"UPDATE ".$ItemTableName.
" SET ".$ItemIdFieldName.
" = ".
294 $NewId.
" WHERE ".$ItemIdFieldName.
" = ".$OldItemId);
297 $DB->Query(
"UNLOCK TABLES");
299 # change associations
300 foreach ($ItemAssociationTables as $TableName)
302 $DB->Query(
"UPDATE ".$TableName.
" ".
303 "SET ".$ItemAssociationFieldName.
" = ".$NewId.
" ".
304 "WHERE ".$ItemAssociationFieldName.
" = ".$OldItemId);
307 # if changing item from temp to non-temp
308 if ($NewSetting == FALSE)
310 # add any needed database fields and/or entries
311 $this->AddDatabaseFields();
313 # Signal that a new (real) field was added:
317 array(
"FieldId" => $NewId ) );
319 # set field order values for new field
320 $Schema->GetDisplayOrder()->AppendItem($NewId,
"MetadataField");
321 $Schema->GetEditOrder()->AppendItem($NewId,
"MetadataField");
324 # update metadata field id
325 $this->DBFields[
"FieldId"] = $NewId;
331 # report to caller whether we are a temp item
332 return ($this->
Id() < 0) ? TRUE : FALSE;
342 # if new privileges supplied
343 if ($NewValue !== NULL)
345 # store new privileges in database
346 $this->UpdateValue(
"AuthoringPrivileges", $NewValue->Data());
350 # return current value to caller
351 return $this->AuthoringPrivileges;
361 # if new privileges supplied
362 if ($NewValue !== NULL)
364 # store new privileges in database
365 $this->UpdateValue(
"EditingPrivileges", $NewValue->Data());
369 # return current value to caller
370 return $this->EditingPrivileges;
380 # if new privileges supplied
381 if ($NewValue !== NULL)
383 # store new privileges in database
384 $this->UpdateValue(
"ViewingPrivileges", $NewValue->Data());
388 # return current value to caller
389 return $this->ViewingPrivileges;
399 # if new privileges supplied
400 if ($NewValue !== NULL)
402 # store new privileges in database
403 $this->UpdateValue(
"PreviewingPrivileges", $NewValue->Data());
407 # return current value to caller
408 return $this->PreviewingPrivileges;
427 return $this->DBFields[
"DBFieldName"];
437 return $this->UpdateValue(
"Description", $NewValue);
447 return $this->UpdateValue(
"Instructions", $NewValue);
457 return $this->UpdateValue(
"Owner", $NewValue);
468 return $this->UpdateBoolValue(
"Enabled", $NewValue);
479 return $this->UpdateBoolValue(
"Optional", $NewValue);
490 return $this->UpdateBoolValue(
"Editable", $NewValue);
501 return $this->UpdateBoolValue(
"AllowMultiple", $NewValue);
512 return $this->UpdateBoolValue(
"IncludeInKeywordSearch", $NewValue);
523 return $this->UpdateBoolValue(
"IncludeInAdvancedSearch", $NewValue);
534 return $this->UpdateBoolValue(
"IncludeInFacetedSearch", $NewValue);
545 return $this->UpdateBoolValue(
"IncludeInSortOptions", $NewValue);
556 return $this->UpdateBoolValue(
"IncludeInRecommender", $NewValue);
565 return $this->UpdateBoolValue(
"CopyOnResourceDuplication", $NewValue);
570 return $this->UpdateIntValue(
"TextFieldSize", $NewValue);
575 return $this->UpdateIntValue(
"MaxLength", $NewValue);
580 return $this->UpdateIntValue(
"ParagraphRows", $NewValue);
585 return $this->UpdateIntValue(
"ParagraphCols", $NewValue);
590 return $this->UpdateFloatValue(
"MinValue", $NewValue);
595 return $this->UpdateFloatValue(
"MaxValue", $NewValue);
600 return $this->UpdateValue(
"FlagOnLabel", $NewValue);
605 return $this->UpdateValue(
"FlagOffLabel", $NewValue);
610 return $this->UpdateValue(
"DateFormat", $NewValue);
615 return $this->UpdateIntValue(
"SearchWeight", $NewValue);
620 return $this->UpdateIntValue(
"RecommenderWeight", $NewValue);
625 return $this->UpdateIntValue(
"MaxHeight", $NewValue);
630 return $this->UpdateIntValue(
"MaxWidth", $NewValue);
635 return $this->UpdateIntValue(
"MaxPreviewHeight", $NewValue);
640 return $this->UpdateIntValue(
"MaxPreviewWidth", $NewValue);
645 return $this->UpdateIntValue(
"MaxThumbnailHeight", $NewValue);
650 return $this->UpdateIntValue(
"MaxThumbnailWidth", $NewValue);
655 return $this->UpdateValue(
"DefaultAltText", $NewValue);
660 return $this->UpdateBoolValue(
"UsesQualifiers", $NewValue);
665 return $this->UpdateBoolValue(
"ShowQualifiers", $NewValue);
670 return $this->UpdateValue(
"DefaultQualifier", $NewValue);
675 return $this->UpdateBoolValue(
"AllowHTML", $NewValue);
680 return $this->UpdateBoolValue(
"UseWysiwygEditor", $NewValue);
685 return $this->UpdateBoolValue(
"UseForOaiSets", $NewValue);
690 return $this->UpdateBoolValue(
"DisplayAsListForAdvancedSearch", $NewValue);
695 return $this->UpdateIntValue(
"OptionListThreshold", $NewValue);
700 return $this->UpdateIntValue(
"AjaxThreshold", $NewValue);
705 return $this->UpdateIntValue(
"NumAjaxResults", $NewValue);
716 throw new Exception(
"Deprecated ".__METHOD__.
"() called -- ".
717 __METHOD__.
"s() should be used instead.");
728 throw new Exception(
"Deprecated ".__METHOD__.
"() called -- ".
729 __METHOD__.
"s() should be used instead.");
740 throw new Exception(
"Deprecated ".__METHOD__.
"() called -- ".
741 __METHOD__.
"s() should be used instead.");
752 throw new Exception(
"Deprecated ".__METHOD__.
"() called -- ".
753 "ViewingPrivileges() should be used instead.");
765 throw new Exception(
"Deprecated ".__METHOD__.
"() called -- ".
766 "this should probably be using ViewingPrivileges() instead.");
771 return $this->UpdateBoolValue(
"EnableOnOwnerReturn", $NewValue);
776 return $this->UpdateConstValue(
"ViewingUserIsValue", $NewValue,
"MetadataField");
781 return $this->UpdateConstValue(
782 "AuthoringUserIsValue", $NewValue,
"MetadataField");
787 return $this->UpdateConstValue(
"EditingUserIsValue", $NewValue,
"MetadataField");
792 return $this->UpdateIntValue(
"ViewingUserValue", $NewValue,
"MetadataField");
797 return $this->UpdateIntValue(
"AuthoringUserValue", $NewValue,
"MetadataField");
802 return $this->UpdateIntValue(
"EditingUserValue", $NewValue,
"MetadataField");
807 return $this->UpdateBoolValue(
"RequiredBySPT", $NewValue);
815 $NewValue = serialize((array) $NewValue);
818 $Value = $this->UpdateValue(
"UserPrivilegeRestrictions", $NewValue);
823 $Value = (array) unserialize($Value);
826 # no value set, set it to an empty array
840 $OldValue = $this->UpdateValue(
"PointPrecision",
DB_NOVALUE);
842 if ($NewValue != $OldValue)
844 $Decimals = $this->UpdateValue(
"PointDecimalDigits",
DB_NOVALUE);
845 $TotalDigits = $NewValue + $Decimals;
847 $this->DB->Query(
"ALTER TABLE Resources MODIFY COLUMN "
848 .
"`".$this->DBFields[
"DBFieldName"].
"X` "
849 .
"DECIMAL(".$TotalDigits.
",".$Decimals.
")");
850 $this->DB->Query(
"ALTER TABLE Resources MODIFY COLUMN "
851 .
"`".$this->DBFields[
"DBFieldName"].
"Y` "
852 .
"DECIMAL(".$TotalDigits.
",".$Decimals.
")");
856 return $this->UpdateValue(
"PointPrecision", $NewValue);
864 $OldValue = $this->UpdateValue(
"PointDecimalDigits",
DB_NOVALUE);
866 if ($NewValue != $OldValue)
868 $Precision = $this->UpdateValue(
"PointPrecision",
DB_NOVALUE);
870 $TotalDigits = $NewValue + $Precision;
872 $this->DB->Query(
"ALTER TABLE Resources MODIFY COLUMN "
873 .
"`".$this->DBFields[
"DBFieldName"].
"X` "
874 .
"DECIMAL(".$TotalDigits.
",".$NewValue.
")");
875 $this->DB->Query(
"ALTER TABLE Resources MODIFY COLUMN "
876 .
"`".$this->DBFields[
"DBFieldName"].
"Y` "
877 .
"DECIMAL(".$TotalDigits.
",".$NewValue.
")");
881 return $this->UpdateValue(
"PointDecimalDigits", $NewValue);
890 isset($NewValue[
"X"]) && isset($NewValue[
"Y"]))
892 $NewValue = $NewValue[
"X"].
",".$NewValue[
"Y"];
895 # invalid value given
901 $Value = $this->UpdateValue(
"DefaultValue", $NewValue);
903 if (is_array($Value))
905 $tmp = explode(
",", $Value);
909 return array(
"X" => $tmp[0],
"Y" => $tmp[1]);
913 return array(
"X" => NULL,
"Y" => NULL);
918 # multiple default values to set
919 if (is_array($NewValue))
922 if (count($NewValue) == 0)
927 # multiple defaults are allowed
930 $NewValue = serialize($NewValue);
933 # only one default is allowed so get the first one
936 $NewValue = array_shift($NewValue);
940 $Result = $this->UpdateValue(
"DefaultValue", $NewValue);
942 return empty($Result) || is_numeric($Result) ?
943 $Result : unserialize($Result);
946 return $this->UpdateValue(
"DefaultValue", $NewValue);
956 return $this->UpdateValue(
"UpdateMethod", $NewValue);
959 # get possible values (only meaningful for Trees, Controlled Names, Options,
961 # (index for returned array is IDs for values)
964 # retrieve values based on field type
965 switch ($this->
Type())
968 $QueryString =
"SELECT ClassificationId, ClassificationName"
969 .
" FROM Classifications WHERE FieldId = ".$this->
Id()
970 .
" ORDER BY ClassificationName";
971 if ($MaxNumberOfValues)
973 $QueryString .=
" LIMIT ".intval($MaxNumberOfValues).
" OFFSET "
976 $this->DB->Query($QueryString);
977 $PossibleValues = $this->DB->FetchColumn(
978 "ClassificationName",
"ClassificationId");
983 $QueryString =
"SELECT ControlledNameId, ControlledName"
984 .
" FROM ControlledNames WHERE FieldId = ".$this->
Id()
985 .
" ORDER BY ControlledName";
986 if ($MaxNumberOfValues)
988 $QueryString .=
" LIMIT ".intval($MaxNumberOfValues).
" OFFSET "
991 $this->DB->Query($QueryString);
992 $PossibleValues = $this->DB->FetchColumn(
993 "ControlledName",
"ControlledNameId");
1004 $PossibleValues = array();
1006 if (count($Restrictions))
1008 $PossibleValues = call_user_func_array(
1009 array($UserFactory,
"GetUsersWithPrivileges"),
1015 $Users = $UserFactory->GetMatchingUsers(
".*.");
1017 foreach ($Users as $Id => $Data)
1019 $PossibleValues[$Id] = $Data[
"UserName"];
1026 # for everything else return an empty array
1027 $PossibleValues = array();
1031 # return array of possible values to caller
1032 return $PossibleValues;
1035 # get count of possible values (only meaningful for Trees, Controlled Names,
1036 # Options, and Users)
1039 # retrieve values based on field type
1040 switch ($this->
Type())
1043 $Count = $this->DB->Query(
"SELECT count(*) AS ValueCount"
1044 .
" FROM Classifications WHERE FieldId = ".$this->
Id(),
1050 $Count = $this->DB->Query(
"SELECT count(*) AS ValueCount"
1051 .
" FROM ControlledNames WHERE FieldId = ".$this->
Id(),
1064 # for everything else return an empty array
1069 # return count of possible values to caller
1073 # get ID for specified value (only meaningful for Trees / Controlled Names / Options)
1074 # (returns NULL if value not found)
1077 # retrieve ID based on field type
1078 switch ($this->
Type())
1081 $Id = $this->DB->Query(
"SELECT ClassificationId FROM Classifications"
1082 .
" WHERE ClassificationName = '".addslashes($Value).
"'"
1083 .
" AND FieldId = ".$this->
Id(),
1084 "ClassificationId");
1089 $Id = $this->DB->Query(
"SELECT ControlledNameId FROM ControlledNames"
1090 .
" WHERE ControlledName = '".addslashes($Value).
"'"
1091 .
" AND FieldId = ".$this->
Id(),
1092 "ControlledNameId");
1096 # for everything else return NULL
1101 # return ID for value to caller
1105 # get value for specified ID (only meaningful for Trees / Controlled Names / Options)
1106 # (returns NULL if ID not found)
1109 # retrieve ID based on field type
1110 switch ($this->
Type())
1113 $Value = $this->DB->Query(
"SELECT ClassificationName FROM Classifications"
1114 .
" WHERE ClassificationId = '".intval($Id).
"'"
1115 .
" AND FieldId = ".$this->
Id(),
1116 "ClassificationName");
1121 $Value = $this->DB->Query(
"SELECT ControlledName FROM ControlledNames"
1122 .
" WHERE ControlledNameId = '".intval($Id).
"'"
1123 .
" AND FieldId = ".$this->
Id(),
1128 # for everything else return NULL
1133 # return ID for value to caller
1149 # retrieve ID if object passed in
1150 if (is_object($Value) && method_exists($Value,
"Id"))
1152 $Value = $Value->Id();
1155 # check value based on field type
1156 $DBFieldName = $this->DBFields[
"DBFieldName"];
1157 switch ($this->
Type())
1168 $UseCount = $this->DB->Query(
"SELECT COUNT(*) AS UseCount"
1170 .
" WHERE `".$DBFieldName.
"` = '".addslashes($Value).
"'"
1171 .
" AND SchemaId = ".intval($this->DBFields[
"SchemaId"]),
1176 $UseCount = $this->DB->Query(
"SELECT COUNT(*) AS UseCount"
1177 .
" FROM ResourceClassInts"
1178 .
" WHERE ClassificationId = ".intval($Value),
1184 $UseCount = $this->DB->Query(
"SELECT COUNT(*) AS UseCount"
1185 .
" FROM ResourceNameInts"
1186 .
" WHERE ControlledNameId = ".intval($Value),
1191 $UseCount = $this->DB->Query(
"SELECT COUNT(*) AS UseCount"
1193 .
" WHERE `".$DBFieldName.
"X` = '".$Value[
"X"].
"'"
1194 .
" AND `".$DBFieldName.
"Y` = '".$Value[
"Y"].
"'"
1195 .
" AND SchemaId = ".intval($this->DBFields[
"SchemaId"]),
1200 throw new Exception(__CLASS__.
"::".__METHOD__.
"() called for"
1201 .
" unsupported field type (".$this->Type().
").");
1205 # report use count to caller
1209 # get/set whether field uses item-level qualifiers
1212 # if value provided different from present value
1214 && ($NewValue != $this->DBFields[
"HasItemLevelQualifiers"]))
1216 # check if qualifier column currently exists
1218 $QualColExists = $this->DB->FieldExists(
"Resources", $QualColName);
1220 # if new value indicates qualifiers should now be used
1221 if ($NewValue == TRUE)
1223 # if qualifier column does not exist in DB for this field
1224 if ($QualColExists == FALSE)
1226 # add qualifier column in DB for this field
1227 $this->DB->Query(
"ALTER TABLE Resources ADD COLUMN `"
1228 .$QualColName.
"` INT");
1233 # if qualifier column exists in DB for this field
1234 if ($QualColExists == TRUE)
1236 # remove qualifier column from DB for this field
1237 $this->DB->Query(
"ALTER TABLE Resources DROP COLUMN `"
1243 return $this->UpdateValue(
"HasItemLevelQualifiers", $NewValue);
1246 # get list of qualifiers associated with field
1249 # start with empty list
1252 # for each associated qualifier
1253 $this->DB->Query(
"SELECT QualifierId FROM FieldQualifierInts"
1254 .
" WHERE MetadataFieldId = ".$this->DBFields[
"FieldId"]);
1255 while ($Record = $this->DB->FetchRow())
1257 # load qualifier object
1258 $Qual =
new Qualifier($Record[
"QualifierId"]);
1260 # add qualifier ID and name to list
1261 $List[$Qual->Id()] = $Qual->Name();
1264 # return list to caller
1268 # get list of qualifiers not associated with field
1271 # grab list of associated qualifiers
1274 # get list of all qualifiers
1276 $AllQualifiers = $QFactory->GetItemNames();
1278 # return list of unassociated qualifiers
1279 return array_diff($AllQualifiers, $AssociatedQualifiers);
1288 # if qualifier object passed in
1289 if (is_object($Qualifier))
1291 # grab qualifier ID from object
1292 $Qualifier = $Qualifier->Id();
1294 # else if string passed in does not look like ID
1295 elseif (!preg_match(
'/^[0-9]+$/', $Qualifier))
1297 # assume string passed in is name and use it to retrieve ID
1299 $Qualifier = $QFact->GetItemIdByName($Qualifier);
1302 # if not already associated
1303 $RecordCount = $this->DB->Query(
1304 "SELECT COUNT(*) AS RecordCount FROM FieldQualifierInts"
1305 .
" WHERE QualifierId = ".$Qualifier
1306 .
" AND MetadataFieldId = ".$this->
Id(),
"RecordCount");
1307 if ($RecordCount < 1)
1309 # associate field with qualifier
1310 $this->DB->Query(
"INSERT INTO FieldQualifierInts SET"
1311 .
" QualifierId = ".$Qualifier.
","
1312 .
" MetadataFieldId = ".$this->Id());
1325 # delete qualifier association
1328 # if qualifier object passed in
1329 if (is_object($QualifierIdOrObject))
1331 # grab qualifier ID from object
1332 $QualifierIdOrObject = $QualifierIdOrObject->Id();
1335 # delete intersection record from database
1336 $this->DB->Query(
"DELETE FROM FieldQualifierInts WHERE QualifierId = "
1337 .$QualifierIdOrObject.
" AND MetadataFieldId = ".
1341 # retrieve item factory object for this field
1344 switch ($this->
Type())
1369 # the field should not be viewed if it is disabled
1375 $User = $GLOBALS[
"G_User"];
1377 # the user can view the field if they can edit it
1383 # if the user can view the field
1389 # the user can't view the field
1393 # ---- PRIVATE INTERFACE -------------------------------------------------
1398 private $ErrorStatus;
1399 private $AuthoringPrivileges;
1400 private $EditingPrivileges;
1401 private $ViewingPrivileges;
1402 private $PreviewingPrivileges;
1425 # field type DB/PHP enum translations
1479 self::UPDATEMETHOD_NOAUTOUPDATE =>
"Do not update automatically",
1480 self::UPDATEMETHOD_ONRECORDCREATE =>
"Update on record creation",
1481 self::UPDATEMETHOD_BUTTON =>
"Provide an update button",
1482 self::UPDATEMETHOD_ONRECORDEDIT =>
"Update when record is edited",
1483 self::UPDATEMETHOD_ONRECORDCHANGE =>
"Update when record is changed"
1499 static function Create($SchemaId, $FieldType, $FieldName,
1500 $Optional = NULL, $DefaultValue = NULL)
1502 # error out if field type is bad
1503 if (empty(self::$FieldTypeDBEnums[$FieldType]))
1505 throw new InvalidArgumentException(
"Bad field type (".$FieldType.
").");
1508 # error out if field name is duplicate
1510 $FieldName = trim($FieldName);
1511 $DuplicateCount = $DB->Query(
1512 "SELECT COUNT(*) AS RecordCount FROM MetadataFields"
1513 .
" WHERE FieldName = '".addslashes($FieldName).
"'"
1514 .
" AND SchemaId = ".intval($SchemaId),
1516 if ($DuplicateCount > 0)
1518 throw new InvalidArgumentException(
"Duplicate field name (".$FieldName.
").");
1521 # grab current user ID
1522 $UserId = $GLOBALS[
"G_User"]->Get(
"UserId");
1524 # normalize schema ID
1526 $SchemaId = $Schema->Id();
1528 # use schema privileges as starting privilege values
1529 $AuthorPrivs = $Schema->AuthoringPrivileges();
1530 $EditPrivs = $Schema->EditingPrivileges();
1531 $ViewPrivs = $Schema->ViewingPrivileges();
1532 $PreviewPrivs = $Schema->ViewingPrivileges();
1534 # lock DB tables and get next temporary field ID
1535 $DB->Query(
"LOCK TABLES MetadataFields WRITE");
1536 $FieldId = $Schema->GetNextTempItemId();
1538 # add field to MDF table in database
1539 $DB->Query(
"INSERT INTO MetadataFields"
1540 .
" (FieldId, SchemaId, FieldName, FieldType, LastModifiedById,"
1541 .
" Optional, AuthoringPrivileges, EditingPrivileges,"
1542 .
" ViewingPrivileges, PreviewingPrivileges)"
1544 .intval($FieldId).
", "
1545 .intval($SchemaId).
","
1546 .
" '".addslashes($FieldName).
"',"
1547 .
" '".self::$FieldTypeDBEnums[$FieldType].
"', "
1548 .intval($UserId).
", "
1549 .($Optional ?
"1" :
"0").
","
1550 .
"'".$DB->EscapeString($AuthorPrivs->Data()).
"',"
1551 .
"'".$DB->EscapeString($EditPrivs->Data()).
"',"
1552 .
"'".$DB->EscapeString($ViewPrivs->Data()).
"',"
1553 .
"'".$DB->EscapeString($PreviewPrivs->Data()).
"')");
1556 $DB->Query(
"UNLOCK TABLES");
1558 # nuke potentially stale cache information
1559 self::$FieldCache = NULL;
1564 # set field defaults
1565 $Field->SetDefaults();
1567 # set the default value if specified
1568 if ($DefaultValue !== NULL)
1570 $Field->DefaultValue($DefaultValue);
1573 # return newly-constructed field to caller
1585 # assume everything will be okay
1588 # check if we have cached field info
1590 if (self::$FieldCache === NULL)
1592 # if not, retrieve field info from database
1593 $this->DB->Query(
"SELECT * FROM MetadataFields");
1594 while ($Row = $this->DB->FetchRow())
1596 self::$FieldCache[$Row[
"FieldId"]] = $Row;
1600 # error if requested field did not exist
1601 if (!array_key_exists($FieldId, self::$FieldCache) )
1603 throw new InvalidArgumentException(
"Invalid metadata field ID ("
1606 $Row = self::$FieldCache[$FieldId];
1607 $this->DBFields = $Row;
1608 $this->
Id = $FieldId;
1610 # if privileges have not yet been initialized
1611 if (!strlen($this->DBFields[
"AuthoringPrivileges"]))
1613 # set default values for privileges from metadata schema
1622 # set privileges from stored values
1624 $Row[
"AuthoringPrivileges"]);
1626 $Row[
"EditingPrivileges"]);
1628 $Row[
"ViewingPrivileges"]);
1630 $Row[
"PreviewingPrivileges"]);
1633 # set database column name
1634 $this->DBFields[
"DBFieldName"] =
1635 $this->NormalizeFieldNameForDB($this->DBFields[
"FieldName"]);
1644 "Description" => NULL,
1645 "Instructions" => NULL,
1649 "CopyOnResourceDuplication" => TRUE,
1650 "AllowMultiple" => FALSE,
1651 "IncludeInKeywordSearch" => FALSE,
1652 "IncludeInAdvancedSearch" => FALSE,
1653 "IncludeInFacetedSearch" => FALSE,
1654 "IncludeInSortOptions" => TRUE,
1655 "IncludeInRecommender" => FALSE,
1656 "ParagraphRows" => 4,
1657 "ParagraphCols" => 50,
1659 "FlagOnLabel" =>
"On",
1660 "FlagOffLabel" =>
"Off",
1661 "DateFormat" => NULL,
1662 "RecommenderWeight" => 1,
1665 "MaxPreviewHeight" => 100,
1666 "MaxPreviewWidth" => 100,
1667 "MaxThumbnailHeight" => 50,
1668 "MaxThumbnailWidth" => 50,
1669 "DefaultAltText" => NULL,
1670 "UsesQualifiers" => FALSE,
1671 "HasItemLevelQualifiers" => FALSE,
1672 "ShowQualifiers" => FALSE,
1673 "DefaultQualifier" => NULL,
1674 "AllowHTML" => FALSE,
1675 "UseWysiwygEditor" => FALSE,
1676 "UseForOaiSets" => FALSE,
1677 "DisplayAsListForAdvancedSearch" => FALSE,
1678 "OptionListThreshold" => 25,
1679 "AjaxThreshold" => 50,
1680 "NumAjaxResults" => 50,
1681 "PointPrecision" => 8,
1682 "PointDecimalDigits" => 5,
1683 "UserPrivilegeRestrictions" => array(),
1684 "UpdateMethod" =>
"NoAutoUpdate",
1685 # 9999 is the
default max value because
default number field length is 4
1686 "MaxValue" => 9999);
1694 "DefaultValue" => NULL,
1695 "SearchWeight" => 1,
1696 "TextFieldSize" => 50,
1697 "MaxLength" => 100),
1699 "DefaultValue" => NULL,
1700 "SearchWeight" => 1,
1701 "TextFieldSize" => 50,
1702 "MaxLength" => 100),
1704 "DefaultValue" => NULL,
1705 "SearchWeight" => 1,
1706 "TextFieldSize" => 4,
1707 "MaxLength" => 100),
1709 "DefaultValue" => NULL,
1710 "SearchWeight" => 1,
1711 "TextFieldSize" => 10,
1712 "MaxLength" => 100),
1714 "DefaultValue" => NULL,
1715 "SearchWeight" => 1,
1716 "TextFieldSize" => 50,
1717 "MaxLength" => 100),
1719 "DefaultValue" => NULL,
1720 "SearchWeight" => 1,
1721 "TextFieldSize" => 50,
1722 "MaxLength" => 100),
1724 "DefaultValue" => NULL,
1725 "SearchWeight" => 1,
1726 "TextFieldSize" => 50,
1727 "MaxLength" => 100),
1729 "DefaultValue" => NULL,
1730 "SearchWeight" => 3,
1731 "TextFieldSize" => 50,
1732 "MaxLength" => 100),
1734 "DefaultValue" => NULL,
1735 "SearchWeight" => 3,
1736 "TextFieldSize" => 50,
1737 "MaxLength" => 100),
1739 "DefaultValue" => NULL,
1740 "SearchWeight" => 1,
1741 "TextFieldSize" => 50,
1742 "MaxLength" => 100),
1744 "DefaultValue" => NULL,
1745 "CopyOnResourceDuplication" => FALSE,
1746 "SearchWeight" => 1,
1747 "TextFieldSize" => 50,
1748 "MaxLength" => 100),
1750 "DefaultValue" => NULL,
1751 "CopyOnResourceDuplication" => FALSE,
1752 "SearchWeight" => 1,
1753 "TextFieldSize" => 50,
1754 "MaxLength" => 100),
1756 "DefaultValue" => NULL,
1757 "SearchWeight" => 1,
1758 "TextFieldSize" => 50,
1759 "MaxLength" => 255),
1761 "DefaultValue" => array(
"X" => NULL,
"Y" => NULL),
1762 "SearchWeight" => 1,
1763 "TextFieldSize" => 10,
1764 "MaxLength" => 100),
1766 "DefaultValue" => NULL,
1767 "SearchWeight" => 1,
1768 "TextFieldSize" => 50,
1769 "MaxLength" => 100));
1777 # set defaults that are the same for every field
1778 foreach (self::$FixedDefaults as $Key => $Value)
1780 $this->$Key($Value);
1783 # set defaults that depend on the type of the field
1784 foreach (self::$TypeBasedDefaults[$this->
Type()] as $Key => $Value)
1786 $this->$Key($Value);
1789 # tweak the update method if dealing with the date of record creation
1790 if ($this->
Name() ==
"Date Of Record Creation")
1796 # remove field from database (only for use by MetadataSchema object)
1799 # clear other database entries as appropriate for field type
1801 $DBFieldName = $this->DBFields[
"DBFieldName"];
1803 switch (self::$FieldTypePHPEnums[$this->DBFields[
"FieldType"]])
1813 # remove field from resources table
1814 if ($DB->FieldExists(
"Resources", $DBFieldName))
1816 $DB->Query(
"ALTER TABLE Resources DROP COLUMN `".$DBFieldName.
"`");
1821 if ($DB->FieldExists(
"Resources", $DBFieldName.
"X"))
1823 $DB->Query(
"ALTER TABLE Resources DROP COLUMN `".$DBFieldName.
"X`");
1824 $DB->Query(
"ALTER TABLE Resources DROP COLUMN `".$DBFieldName.
"Y`");
1829 # remove fields from resources table
1830 if ($DB->FieldExists(
"Resources", $DBFieldName.
"Begin"))
1832 $DB->Query(
"ALTER TABLE Resources "
1833 .
"DROP COLUMN `".$DBFieldName.
"Begin`");
1834 $DB->Query(
"ALTER TABLE Resources "
1835 .
"DROP COLUMN `".$DBFieldName.
"End`");
1836 $DB->Query(
"ALTER TABLE Resources "
1837 .
"DROP COLUMN `".$DBFieldName.
"Precision`");
1842 $DB->Query(
"SELECT ClassificationId FROM Classifications "
1843 .
"WHERE FieldId = ".$this->
Id());
1845 while ($ClassificationId = $DB->FetchField(
"ClassificationId"))
1847 # remove any resource / name intersections
1848 $TempDB->Query(
"DELETE FROM ResourceClassInts WHERE "
1849 .
"ClassificationId = ".$ClassificationId);
1851 # remove controlled name
1852 $TempDB->Query(
"DELETE FROM Classifications WHERE "
1853 .
"ClassificationId = ".$ClassificationId);
1859 $DB->Query(
"SELECT ControlledNameId FROM ControlledNames "
1860 .
"WHERE FieldId = ".$this->
Id());
1862 while ($ControlledNameId = $DB->FetchField(
"ControlledNameId"))
1864 # remove any resource / name intersections
1865 $TempDB->Query(
"DELETE FROM ResourceNameInts WHERE "
1866 .
"ControlledNameId = ".$ControlledNameId);
1868 # remove any variant names
1869 $TempDB->Query(
"DELETE FROM VariantNames WHERE "
1870 .
"ControlledNameId = ".$ControlledNameId);
1872 # remove controlled name
1873 $TempDB->Query(
"DELETE FROM ControlledNames WHERE "
1874 .
"ControlledNameId = ".$ControlledNameId);
1879 # for each file associated with this field
1880 $DB->Query(
"SELECT FileId FROM Files WHERE FieldId = '".$this->
Id().
"'");
1881 while ($FileId = $DB->FetchRow())
1884 $File =
new File(intval($FileId));
1890 # remove any resource references for the field
1892 DELETE FROM ReferenceInts
1893 WHERE FieldId = '".addslashes($this->
Id()).
"'");
1897 # remove field from database
1898 $DB->Query(
"DELETE FROM MetadataFields "
1899 .
"WHERE FieldId = '".$this->DBFields[
"FieldId"].
"'");
1901 # remove any qualifier associations
1902 $DB->Query(
"DELETE FROM FieldQualifierInts WHERE MetadataFieldId = '"
1903 .$this->DBFields[
"FieldId"].
"'");
1905 # get the order objects the field is part of
1908 # remove it if it's a direct descendant
1909 $Order->RemoveItem($this->
Id(),
"MetadataField");
1911 # also make sure to remove it if it's part of a group
1912 foreach ($Order->GetItemIds() as $Item)
1914 if ($Item[
"Type"] ==
"MetadataFieldGroup")
1917 $Group->RemoveItem($this->
Id(),
"MetadataField");
1922 # nuke stale field cache
1923 self::$FieldCache = NULL;
1926 # modify any database fields
1927 private function ModifyField($NewName = NULL, $NewType = NULL)
1929 # grab old DB field name
1930 $OldDBFieldName = $this->DBFields[
"DBFieldName"];
1931 $OldFieldType = NULL;
1933 # if new field name supplied
1934 if ($NewName != NULL)
1936 # cache the old name for options and controllednames below
1937 $OldName = $this->DBFields[
"FieldName"];
1940 $this->UpdateValue(
"FieldName", $NewName);
1942 # determine new DB field name
1943 $NewDBFieldName = $this->NormalizeFieldNameForDB($NewName);
1945 # store new database field name
1946 $this->DBFields[
"DBFieldName"] = $NewDBFieldName;
1950 # set new field name equal to old field name
1951 $NewDBFieldName = $OldDBFieldName;
1954 # if new type supplied
1955 if ($NewType != NULL)
1957 # grab old field type
1958 $OldFieldType = self::$FieldTypePHPEnums[$this->DBFields[
"FieldType"]];
1960 # store new field type
1961 $this->UpdateValue(
"FieldType", self::$FieldTypeDBEnums[$NewType]);
1964 # if this is not a temporary field
1965 if ($this->
Id() >= 0)
1967 # modify field in DB as appropriate for field type
1969 $FieldType = self::$FieldTypePHPEnums[$this->DBFields[
"FieldType"]];
1975 # alter field declaration in Resources table
1976 $DB->Query(
"ALTER TABLE Resources CHANGE COLUMN `"
1977 .$OldDBFieldName.
"` `"
1978 .$NewDBFieldName.
"` TEXT "
1979 .($this->DBFields[
"Optional"] ?
"" :
"NOT NULL"));
1984 # alter field declaration in Resources table
1985 $DB->Query(
"ALTER TABLE Resources CHANGE COLUMN `"
1986 .$OldDBFieldName.
"` `"
1987 .$NewDBFieldName.
"` INT "
1988 .($this->DBFields[
"Optional"] ?
"" :
"NOT NULL"));
1992 $Precision = $this->UpdateValue(
"PointPrecision",
1994 $Digits = $this->UpdateValue(
"PointDecimalDigits",
1996 $DB->Query(
"ALTER TABLE Resources CHANGE COLUMN "
1997 .
"`".$OldDBFieldName.
"X` "
1998 .
"`".$NewDBFieldName.
"X`".
1999 " DECIMAL(".$Precision.
",".$Digits.
")");
2000 $DB->Query(
"ALTER TABLE Resources CHANGE COLUMN "
2001 .
"`".$OldDBFieldName.
"Y` "
2002 .
"`".$NewDBFieldName.
"Y`".
2003 " DECIMAL(".$Precision.
",".$Digits.
")");
2007 # if DB field name has changed
2008 if ($NewDBFieldName != $OldDBFieldName)
2010 # alter field declaration in Resources table
2011 $DB->Query(
"ALTER TABLE Resources CHANGE COLUMN `"
2012 .$OldDBFieldName.
"` `"
2013 .$NewDBFieldName.
"` TEXT");
2018 # alter field declaration in Resources table
2019 $DB->Query(
"ALTER TABLE Resources CHANGE COLUMN `"
2020 .$OldDBFieldName.
"` `"
2021 .$NewDBFieldName.
"` INT"
2024 # set any unset values to default
2025 $DB->Query(
"UPDATE Resources SET `".$NewDBFieldName
2027 .
" WHERE `".$NewDBFieldName.
"` IS NULL");
2031 # if new type supplied and new type is different from old
2032 if (($NewType != NULL) && ($NewType != $OldFieldType))
2034 # if old type was time stamp
2037 # change time stamp field in resources table to begin date
2038 $DB->Query(
"ALTER TABLE Resources CHANGE COLUMN `"
2039 .$OldDBFieldName.
"` `"
2040 .$NewDBFieldName.
"Begin` DATE "
2041 .($this->DBFields[
"Optional"] ?
"" :
"NOT NULL"));
2043 # add end date and precision fields
2044 $DB->Query(
"ALTER TABLE Resources "
2045 .
"ADD COLUMN `".$NewDBFieldName.
"End` DATE");
2046 $DB->Query(
"ALTER TABLE Resources "
2047 .
"ADD COLUMN `".$NewDBFieldName.
"Precision`"
2048 .
" INT ".($Optional ?
"" :
"NOT NULL"));
2050 # set precision to reflect time stamp content
2051 $DB->Query(
"UPDATE Resources "
2052 .
"SET `".$NewDBFieldName.
"Precision` = "
2058 exit(
"<br>ERROR: Attempt to convert metadata field "
2059 .
"to date from type other than timestamp<br>\n");
2064 # change name of fields
2065 $DB->Query(
"ALTER TABLE Resources CHANGE COLUMN `"
2066 .$OldDBFieldName.
"Begin` `"
2067 .$NewDBFieldName.
"Begin` DATE "
2068 .($this->DBFields[
"Optional"] ?
"" :
"NOT NULL"));
2069 $DB->Query(
"ALTER TABLE Resources CHANGE COLUMN `"
2070 .$OldDBFieldName.
"End` `"
2071 .$NewDBFieldName.
"End` DATE "
2072 .($this->DBFields[
"Optional"] ?
"" :
"NOT NULL"));
2073 $DB->Query(
"ALTER TABLE Resources CHANGE COLUMN `"
2074 .$OldDBFieldName.
"Precision` `"
2075 .$NewDBFieldName.
"Precision` INT "
2076 .($this->DBFields[
"Optional"] ?
"" :
"NOT NULL"));
2081 # if new type supplied and new type is different from old
2082 if (($NewType != NULL) && ($NewType != $OldFieldType))
2084 # if old type was date
2087 # change begin date field in resource table to time stamp
2088 $DB->Query(
"ALTER TABLE Resources CHANGE COLUMN `"
2089 .$OldDBFieldName.
"Begin` `"
2090 .$NewDBFieldName.
"` DATETIME "
2091 .($this->DBFields[
"Optional"] ?
"" :
"NOT NULL"));
2093 # drop end date and precision fields
2094 $DB->Query(
"ALTER TABLE Resources DROP COLUMN `"
2095 .$OldDBFieldName.
"End`");
2096 $DB->Query(
"ALTER TABLE Resources DROP COLUMN `"
2097 .$OldDBFieldName.
"Precision`");
2101 exit(
"<br>ERROR: Attempt to convert metadata field to "
2102 .
"time stamp from type other than date<br>\n");
2107 # change name of field
2108 $DB->Query(
"ALTER TABLE Resources CHANGE COLUMN `"
2109 .$OldDBFieldName.
"` `"
2110 .$NewDBFieldName.
"` DATETIME "
2111 .($this->DBFields[
"Optional"] ?
"" :
"NOT NULL"));
2123 # if qualifier DB field exists
2124 if ($DB->FieldExists(
"Resources", $OldDBFieldName.
"Qualifier"))
2126 # rename qualifier DB field
2127 $DB->Query(
"ALTER TABLE Resources CHANGE COLUMN `"
2128 .$OldDBFieldName.
"Qualifier` `"
2129 .$NewDBFieldName.
"Qualifier` INT ");
2134 # convenience functions to supply parameters to Database->UpdateValue()
2135 private function UpdateValue($FieldName, $NewValue)
2137 # nuke stale field cache
2138 self::$FieldCache = NULL;
2140 return $this->DB->UpdateValue(
"MetadataFields", $FieldName, $NewValue,
2141 "FieldId = ".intval($this->DBFields[
"FieldId"]),
2144 private function UpdateIntValue($FieldName, $NewValue)
2146 # nuke stale field cache
2147 self::$FieldCache = NULL;
2149 return $this->DB->UpdateIntValue(
"MetadataFields", $FieldName, $NewValue,
2150 "FieldId = ".intval($this->DBFields[
"FieldId"]),
2153 private function UpdateFloatValue($FieldName, $NewValue)
2155 # nuke stale field cache
2156 self::$FieldCache = NULL;
2158 return $this->DB->UpdateFloatValue(
"MetadataFields", $FieldName, $NewValue,
2159 "FieldId = ".intval($this->DBFields[
"FieldId"]),
2162 private function UpdateBoolValue($FieldName, $NewValue)
2164 # nuke stale field cache
2165 self::$FieldCache = NULL;
2167 $NewValue = $this->TranslateStringToConstants($NewValue);
2168 return $this->DB->UpdateIntValue(
"MetadataFields", $FieldName, $NewValue,
2169 "FieldId = ".intval($this->DBFields[
"FieldId"]),
2172 private function UpdateConstValue($FieldName, $NewValue, $ClassName=NULL)
2174 # nuke stale field cache
2175 self::$FieldCache = NULL;
2177 $NewValue = $this->TranslateStringToConstants($NewValue, $ClassName);
2178 return $this->DB->UpdateIntValue(
"MetadataFields", $FieldName, $NewValue,
2179 "FieldId = ".intval($this->DBFields[
"FieldId"]),
2183 # normalize field name for use as database field name
2184 private function NormalizeFieldNameForDB($Name)
2186 return preg_replace(
"/[^a-z0-9]/i",
"", $Name)
2191 # add any needed database fields and/or entries
2192 private function AddDatabaseFields()
2194 # grab values for common use
2196 $FieldName = $this->
Name();
2201 if ($DefaultValue != NULL && !is_array($DefaultValue) )
2206 $DefaultSql =
"DEFAULT ".intval($DefaultValue);
2210 $DefaultSql =
"DEFAULT '".addslashes($DefaultValue).
"'";
2215 $DefaultSql =
"DEFAULT NULL";
2218 # set up field(s) based on field type
2219 switch ($this->
Type())
2224 # add field to resources table (if not already present)
2225 if (!$DB->FieldExists(
"Resources", $DBFieldName))
2227 $DB->Query(
"ALTER TABLE Resources ADD COLUMN `".$DBFieldName
2228 .
"` TEXT ".$DefaultSql);
2234 # add field to resources table (if not already present)
2235 if (!$DB->FieldExists(
"Resources", $DBFieldName))
2237 $DB->Query(
"ALTER TABLE Resources ADD COLUMN `".$DBFieldName
2238 .
"` INT ".$DefaultSql);
2243 if (!$DB->FieldExists(
"Resources", $DBFieldName.
"X"))
2245 $Precision = $this->UpdateValue(
"PointPrecision",
2247 $Digits = $this->UpdateValue(
"PointDecimalDigits",
2250 $DB->Query(
"ALTER TABLE Resources ADD COLUMN `"
2252 " DECIMAL(".$Precision.
",".$Digits.
") DEFAULT NULL");
2253 $DB->Query(
"ALTER TABLE Resources ADD COLUMN `"
2255 " DECIMAL(".$Precision.
",".$Digits.
") DEFAULT NULL");
2260 # if field is not already present in database
2261 if (!$DB->FieldExists(
"Resources", $DBFieldName))
2263 # add field to resources table
2264 $DB->Query(
"ALTER TABLE Resources ADD COLUMN `".$DBFieldName
2265 .
"` INT ".$DefaultSql);
2270 # add field to resources table (if not already present)
2271 if (!$DB->FieldExists(
"Resources", $DBFieldName))
2273 $DB->Query(
"ALTER TABLE Resources ADD COLUMN `".$DBFieldName
2274 .
"` INT DEFAULT NULL");
2279 # add fields to resources table (if not already present)
2280 if (!$DB->FieldExists(
"Resources", $DBFieldName))
2282 $DB->Query(
"ALTER TABLE Resources ADD COLUMN `"
2283 .$DBFieldName.
"` TEXT DEFAULT NULL");
2288 # add fields to resources table (if not already present)
2289 if (!$DB->FieldExists(
"Resources", $DBFieldName))
2291 $DB->Query(
"ALTER TABLE Resources ADD COLUMN `"
2292 .$DBFieldName.
"` INT DEFAULT NULL");
2297 # add fields to resources table (if not already present)
2298 if (!$DB->FieldExists(
"Resources", $DBFieldName.
"Begin"))
2300 $DB->Query(
"ALTER TABLE Resources ADD COLUMN `".$DBFieldName.
"Begin`"
2301 .
" DATE DEFAULT NULL");
2303 if (!$DB->FieldExists(
"Resources", $DBFieldName.
"End"))
2305 $DB->Query(
"ALTER TABLE Resources ADD COLUMN `".$DBFieldName.
"End`"
2306 .
" DATE DEFAULT NULL");
2308 if (!$DB->FieldExists(
"Resources", $DBFieldName.
"Precision"))
2310 $DB->Query(
"ALTER TABLE Resources "
2311 .
"ADD COLUMN `".$DBFieldName.
"Precision`"
2312 .
" INT DEFAULT NULL");
2317 # add fields to resources table (if not already present)
2318 if (!$DB->FieldExists(
"Resources", $DBFieldName))
2320 $DB->Query(
"ALTER TABLE Resources ADD COLUMN `".$DBFieldName
2321 .
"` DATETIME DEFAULT NULL");
2332 exit(
"<br>ERROR: Attempt to add database fields "
2333 .
"for illegal metadata field type<br>\n");
2345 private function TranslateStringToConstants($CString, $ClassName = NULL)
2347 # if not a string return value unchanged to caller
2348 if (!is_string($CString) || ($CString ===
DB_NOVALUE))
2350 $ReturnValue = $CString;
2352 # handle booleans as a special case
2353 elseif (strtoupper(trim($CString)) ==
"TRUE")
2355 $ReturnValue = TRUE;
2357 elseif (strtoupper(trim($CString)) ==
"FALSE")
2359 $ReturnValue = FALSE;
2363 # assume no values will be found
2364 $ReturnValue = NULL;
2366 # split apart any ORed-together values
2367 $Values = explode(
"|", $CString);
2369 # for each value found
2370 foreach ($Values as $Value)
2372 # trim off any extraneous whitespace
2373 $Value = trim($Value);
2375 # add class name prefix to constant name if requested
2376 if ($ClassName) { $Value = $ClassName.
"::".$Value; }
2378 # if value corresponds to a constant
2379 if (defined($Value))
2381 # add constant to return value
2382 $ReturnValue = ($ReturnValue === NULL)
2384 : ($ReturnValue | constant($Value));
2388 # if no corresponding constants were found
2389 if ($ReturnValue === NULL)
2391 # return original value to caller
2392 $ReturnValue = $CString;
2396 # return result to caller
2397 return $ReturnValue;
2403 private static $FieldCache = NULL;
SQL database abstraction object with smart query caching.
Set of privileges used to access resource information or other parts of the system.
Factory class for Qualifier.
CWIS-specific user factory class.
Factory for manipulating ControlledName objects.
Factory for producing and manipulating Classification objects.
Class representing a stored (usually uploaded) file.