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"];
76 switch ($this->
Type())
94 return $this->DBFields[
"SchemaId"];
115 # if new name specified 117 && trim($NewName) != $this->DBFields[
"FieldName"])
119 $NewName = trim($NewName);
120 $NormalizedName = $this->NormalizeFieldNameForDB(strtolower($NewName));
122 # if field name is invalid 123 if (!preg_match(
"/^[[:alnum:] \(\)]+$/", $NewName))
125 # set error status to indicate illegal name 129 # if the new name is a reserved word 130 else if ($NormalizedName ==
"resourceid" || $NormalizedName ==
"schemaid")
132 # set error status to indicate illegal name 136 # the name is okay but might be a duplicate 139 # check for duplicate name 140 $DuplicateCount = $this->DB->Query(
141 "SELECT COUNT(*) AS RecordCount FROM MetadataFields" 142 .
" WHERE FieldName = '".addslashes($NewName).
"'" 143 .
" AND SchemaId = ".intval($this->DBFields[
"SchemaId"]),
146 # if field name is duplicate 147 if ($DuplicateCount > 0)
149 # set error status to indicate duplicate name 154 # modify database declaration to reflect new field name 156 $this->ModifyField($NewName);
161 # return value to caller 162 return $this->DBFields[
"FieldName"];
172 $ValidValueExp =
'/^[[:alnum:] ]*$/';
173 $Value = $this->DBFields[
"Label"];
175 # if a new label was specified 176 if ($NewLabel !==
DB_NOVALUE && trim($NewLabel) != $Value)
178 $NewLabel = trim($NewLabel);
180 # if field label is valid 181 if (preg_match($ValidValueExp, $NewLabel))
183 $this->UpdateValue(
"Label", $NewLabel);
186 # the field label is invalid 203 # determine type list based on our type 204 switch ($this->
Type())
211 $AllowedTypes = array(
222 $AllowedTypes = array(
229 $AllowedTypes = array(
236 $AllowedTypes = array(
248 $AllowedTypes = array();
252 # return type list to caller 253 return $AllowedTypes;
266 $ItemTableName =
"MetadataFields";
267 $ItemIdFieldName =
"FieldId";
268 $ItemFactoryObjectName =
"MetadataSchema";
269 $ItemAssociationTables = array(
270 "FieldQualifierInts",
272 $ItemAssociationFieldName =
"MetadataFieldId";
274 # if new temp item setting supplied 275 if (!is_null($NewSetting))
277 # if caller requested to switch 278 if (($this->
Id() < 0 && $NewSetting == FALSE)
279 || ($this->
Id() >= 0 && $NewSetting == TRUE))
281 # if field name is invalid 282 if (strlen($this->NormalizeFieldNameForDB($this->
Name())) < 1)
284 # set error status to indicate illegal name 289 # lock DB tables to prevent next ID from being grabbed 292 LOCK TABLES ".$ItemTableName.
" WRITE, 293 APSessions WRITE, APSessionData WRITE, 294 MetadataSchemas WRITE");
296 # nuke stale field cache 297 self::$FieldCache = NULL;
299 # get next temp item ID 300 $OldItemId = $this->
Id();
301 $Factory =
new $ItemFactoryObjectName();
302 if ($NewSetting == TRUE)
304 $NewId = $Factory->GetNextTempItemId();
308 $NewId = $Factory->GetNextItemId();
312 $DB->Query(
"UPDATE ".$ItemTableName.
" SET ".$ItemIdFieldName.
" = ".
313 $NewId.
" WHERE ".$ItemIdFieldName.
" = ".$OldItemId);
316 $DB->Query(
"UNLOCK TABLES");
318 # change associations 319 foreach ($ItemAssociationTables as $TableName)
321 $DB->Query(
"UPDATE ".$TableName.
" ".
322 "SET ".$ItemAssociationFieldName.
" = ".$NewId.
" ".
323 "WHERE ".$ItemAssociationFieldName.
" = ".$OldItemId);
326 # if changing item from temp to non-temp 327 if ($NewSetting == FALSE)
329 # add any needed database fields and/or entries 330 $this->AddDatabaseFields();
332 # Signal that a new (real) field was added: 336 array(
"FieldId" => $NewId ) );
338 # set field order values for new field 339 $Schema->GetDisplayOrder()->AppendItem($NewId,
"MetadataField");
340 $Schema->GetEditOrder()->AppendItem($NewId,
"MetadataField");
343 # update metadata field id 344 $this->DBFields[
"FieldId"] = $NewId;
349 # clear caches in MetadataSchema 353 # report to caller whether we are a temp item 354 return ($this->
Id() < 0) ? TRUE : FALSE;
364 # if new privileges supplied 365 if ($NewValue !== NULL)
367 # store new privileges in database 368 $this->UpdateValue(
"AuthoringPrivileges", $NewValue->Data());
372 # return current value to caller 373 return $this->AuthoringPrivileges;
383 # if new privileges supplied 384 if ($NewValue !== NULL)
386 # store new privileges in database 387 $this->UpdateValue(
"EditingPrivileges", $NewValue->Data());
391 # return current value to caller 392 return $this->EditingPrivileges;
402 # if new privileges supplied 403 if ($NewValue !== NULL)
405 # store new privileges in database 406 $this->UpdateValue(
"ViewingPrivileges", $NewValue->Data());
410 # return current value to caller 411 return $this->ViewingPrivileges;
421 # if new privileges supplied 422 if ($NewValue !== NULL)
424 # store new privileges in database 425 $this->UpdateValue(
"PreviewingPrivileges", $NewValue->Data());
429 # return current value to caller 430 return $this->PreviewingPrivileges;
449 return $this->DBFields[
"DBFieldName"];
459 return $this->UpdateValue(
"Description", $NewValue);
469 return $this->UpdateValue(
"Instructions", $NewValue);
479 return $this->UpdateValue(
"Owner", $NewValue);
490 return $this->UpdateBoolValue(
"Enabled", $NewValue);
501 return $this->UpdateBoolValue(
"Optional", $NewValue);
512 return $this->UpdateBoolValue(
"Editable", $NewValue);
523 return $this->UpdateBoolValue(
"AllowMultiple", $NewValue);
534 return $this->UpdateBoolValue(
"IncludeInKeywordSearch", $NewValue);
545 return $this->UpdateBoolValue(
"IncludeInAdvancedSearch", $NewValue);
556 return $this->UpdateBoolValue(
"IncludeInFacetedSearch", $NewValue);
570 # if a new value was passed, verify that it's a legal value 575 "Invalid NewValue for SearchGroupLogic(). " 576 .
"Must be a SearchEngine::LOGIC_* constant.");
580 return $this->UpdateIntValue(
"SearchGroupLogic", $NewValue);
591 return $this->UpdateBoolValue(
"IncludeInSortOptions", $NewValue);
602 return $this->UpdateBoolValue(
"IncludeInRecommender", $NewValue);
612 return $this->UpdateBoolValue(
"CopyOnResourceDuplication", $NewValue);
622 return $this->UpdateIntValue(
"TextFieldSize", $NewValue);
632 return $this->UpdateIntValue(
"MaxLength", $NewValue);
642 return $this->UpdateIntValue(
"ParagraphRows", $NewValue);
652 return $this->UpdateIntValue(
"ParagraphCols", $NewValue);
662 return $this->UpdateFloatValue(
"MinValue", $NewValue);
672 return $this->UpdateFloatValue(
"MaxValue", $NewValue);
682 return $this->UpdateValue(
"FlagOnLabel", $NewValue);
692 return $this->UpdateValue(
"FlagOffLabel", $NewValue);
702 return $this->UpdateValue(
"DateFormat", $NewValue);
713 return $this->UpdateIntValue(
"SearchWeight", $NewValue);
724 return $this->UpdateIntValue(
"RecommenderWeight", $NewValue);
734 return $this->UpdateIntValue(
"MaxHeight", $NewValue);
744 return $this->UpdateIntValue(
"MaxWidth", $NewValue);
754 return $this->UpdateIntValue(
"MaxPreviewHeight", $NewValue);
764 return $this->UpdateIntValue(
"MaxPreviewWidth", $NewValue);
774 return $this->UpdateIntValue(
"MaxThumbnailHeight", $NewValue);
784 return $this->UpdateIntValue(
"MaxThumbnailWidth", $NewValue);
794 return $this->UpdateValue(
"DefaultAltText", $NewValue);
804 return $this->UpdateBoolValue(
"UsesQualifiers", $NewValue);
814 return $this->UpdateBoolValue(
"ShowQualifiers", $NewValue);
824 return $this->UpdateValue(
"DefaultQualifier", $NewValue);
834 return $this->UpdateBoolValue(
"AllowHTML", $NewValue);
844 return $this->UpdateBoolValue(
"UseWysiwygEditor", $NewValue);
854 return $this->UpdateBoolValue(
"UseForOaiSets", $NewValue);
865 return $this->UpdateBoolValue(
"DisplayAsListForAdvancedSearch", $NewValue);
876 return $this->UpdateIntValue(
"MaxDepthForAdvancedSearch", $NewValue);
886 return $this->UpdateIntValue(
"OptionListThreshold", $NewValue);
896 return $this->UpdateIntValue(
"AjaxThreshold", $NewValue);
907 return $this->UpdateIntValue(
"NumAjaxResults", $NewValue);
919 return $this->UpdateBoolValue(
"RequiredBySPT", $NewValue);
932 $OldValue = $this->UpdateValue(
"PointPrecision",
DB_NOVALUE);
934 if ($NewValue != $OldValue)
936 $Decimals = $this->UpdateValue(
"PointDecimalDigits",
DB_NOVALUE);
937 $TotalDigits = $NewValue + $Decimals;
939 $this->DB->Query(
"ALTER TABLE Resources MODIFY COLUMN " 940 .
"`".$this->DBFields[
"DBFieldName"].
"X` " 941 .
"DECIMAL(".$TotalDigits.
",".$Decimals.
")");
942 $this->DB->Query(
"ALTER TABLE Resources MODIFY COLUMN " 943 .
"`".$this->DBFields[
"DBFieldName"].
"Y` " 944 .
"DECIMAL(".$TotalDigits.
",".$Decimals.
")");
948 return $this->UpdateValue(
"PointPrecision", $NewValue);
961 $OldValue = $this->UpdateValue(
"PointDecimalDigits",
DB_NOVALUE);
963 if ($NewValue != $OldValue)
965 $Precision = $this->UpdateValue(
"PointPrecision",
DB_NOVALUE);
967 $TotalDigits = $NewValue + $Precision;
969 $this->DB->Query(
"ALTER TABLE Resources MODIFY COLUMN " 970 .
"`".$this->DBFields[
"DBFieldName"].
"X` " 971 .
"DECIMAL(".$TotalDigits.
",".$NewValue.
")");
972 $this->DB->Query(
"ALTER TABLE Resources MODIFY COLUMN " 973 .
"`".$this->DBFields[
"DBFieldName"].
"Y` " 974 .
"DECIMAL(".$TotalDigits.
",".$NewValue.
")");
978 return $this->UpdateValue(
"PointDecimalDigits", $NewValue);
992 isset($NewValue[
"X"]) && isset($NewValue[
"Y"]))
994 $NewValue = $NewValue[
"X"].
",".$NewValue[
"Y"];
997 # invalid value given 1003 $Value = $this->UpdateValue(
"DefaultValue", $NewValue);
1005 if (is_array($Value))
1007 $tmp = explode(
",", $Value);
1011 return array(
"X" => $tmp[0],
"Y" => $tmp[1]);
1015 return array(
"X" => NULL,
"Y" => NULL);
1020 # multiple default values to set 1021 if (is_array($NewValue))
1024 if (count($NewValue) == 0)
1029 # multiple defaults are allowed 1032 $NewValue = serialize($NewValue);
1035 # only one default is allowed so get the first one 1038 $NewValue = array_shift($NewValue);
1042 $Result = $this->UpdateValue(
"DefaultValue", $NewValue);
1044 return empty($Result) || is_numeric($Result) ?
1045 $Result : unserialize($Result);
1048 return $this->UpdateValue(
"DefaultValue", $NewValue);
1058 return $this->UpdateValue(
"UpdateMethod", $NewValue);
1070 # retrieve values based on field type 1071 switch ($this->
Type())
1074 $QueryString =
"SELECT ClassificationId, ClassificationName" 1075 .
" FROM Classifications WHERE FieldId = ".$this->
Id()
1076 .
" ORDER BY ClassificationName";
1077 if ($MaxNumberOfValues)
1079 $QueryString .=
" LIMIT ".intval($MaxNumberOfValues).
" OFFSET " 1082 $this->DB->Query($QueryString);
1083 $PossibleValues = $this->DB->FetchColumn(
1084 "ClassificationName",
"ClassificationId");
1089 $QueryString =
"SELECT ControlledNameId, ControlledName" 1090 .
" FROM ControlledNames WHERE FieldId = ".$this->
Id()
1091 .
" ORDER BY ControlledName";
1092 if ($MaxNumberOfValues)
1094 $QueryString .=
" LIMIT ".intval($MaxNumberOfValues).
" OFFSET " 1097 $this->DB->Query($QueryString);
1098 $PossibleValues = $this->DB->FetchColumn(
1099 "ControlledName",
"ControlledNameId");
1110 $PossibleValues = array();
1112 if (count($Restrictions))
1114 $PossibleValues = call_user_func_array(
1115 array($UserFactory,
"GetUsersWithPrivileges"),
1121 $Users = $UserFactory->GetMatchingUsers(
".*.");
1123 foreach ($Users as $Id => $Data)
1125 $PossibleValues[$Id] = $Data[
"UserName"];
1132 # for everything else return an empty array 1133 $PossibleValues = array();
1137 # return array of possible values to caller 1138 return $PossibleValues;
1148 # retrieve values based on field type 1149 switch ($this->
Type())
1152 $Count = $this->DB->Query(
"SELECT count(*) AS ValueCount" 1153 .
" FROM Classifications WHERE FieldId = ".$this->
Id(),
1159 $Count = $this->DB->Query(
"SELECT count(*) AS ValueCount" 1160 .
" FROM ControlledNames WHERE FieldId = ".$this->
Id(),
1173 # for everything else return an empty array 1178 # return count of possible values to caller 1190 $ValidTypes = array(
1196 if (!in_array($this->
Type(), $ValidTypes))
1198 throw new Exception(
1199 "Attempt to add a vocabulary to a type of field that does not " 1200 .
"support vocabularies.");
1203 if ($this->
Id() < 0)
1205 throw new Exception(
1206 "Attempt to load a vocabulary into a temporary field");
1211 $Vocab =
new Vocabulary($Vocab);
1214 $Terms = $Vocab->TermList();
1216 # if new vocabulary has a qualifier 1217 if ($Vocab->HasQualifier())
1219 # if we already have a qualifier with the same name 1221 if ($QualFact->NameIsInUse($Vocab->QualifierName()))
1223 # if details for existing and new qualifier do not match 1224 $Qualifier = $QualFact->GetItemByName(
1225 $Vocab->QualifierName());
1226 if ($Vocab->QualifierNamespace() != $Qualifier->NSpace()
1227 || ($Vocab->QualifierUrl() != $Qualifier->Url()))
1230 throw new Exception(
1231 "The vocabulary <i>".$Vocab->Name()
1232 .
"</i> specifies a qualifier <i>" 1233 .$Vocab->QualifierName().
"</i> that conflicts" 1234 .
" with an existing qualifier (has the same name but" 1235 .
" a different namespace or URL or both).");
1239 # add new vocabulary with qualifier 1240 $AddedItemCount = $this->AddTerms($Terms, $Qualifier);
1245 # add new vocabulary with qualifier 1247 $Qualifier->Name($Vocab->QualifierName());
1248 $Qualifier->NSpace($Vocab->QualifierNamespace());
1249 $Qualifier->Url($Vocab->QualifierUrl());
1250 $AddedItemCount = $this->AddTerms($Terms, $Qualifier);
1256 # add new vocabulary 1257 $AddedItemCount = $this->AddTerms($Terms);
1260 return $AddedItemCount;
1270 # retrieve ID based on field type 1271 switch ($this->
Type())
1274 $Id = $this->DB->Query(
"SELECT ClassificationId FROM Classifications" 1275 .
" WHERE ClassificationName = '".addslashes($Value).
"'" 1276 .
" AND FieldId = ".$this->
Id(),
1277 "ClassificationId");
1282 $Id = $this->DB->Query(
"SELECT ControlledNameId FROM ControlledNames" 1283 .
" WHERE ControlledName = '".addslashes($Value).
"'" 1284 .
" AND FieldId = ".$this->
Id(),
1285 "ControlledNameId");
1289 # for everything else return NULL 1294 # return ID for value to caller 1305 # retrieve ID based on field type 1306 switch ($this->
Type())
1309 $Value = $this->DB->Query(
"SELECT ClassificationName FROM Classifications" 1310 .
" WHERE ClassificationId = '".intval($Id).
"'" 1311 .
" AND FieldId = ".$this->
Id(),
1312 "ClassificationName");
1317 $Value = $this->DB->Query(
"SELECT ControlledName FROM ControlledNames" 1318 .
" WHERE ControlledNameId = '".intval($Id).
"'" 1319 .
" AND FieldId = ".$this->
Id(),
1324 # for everything else return NULL 1329 # return ID for value to caller 1345 # retrieve ID if object passed in 1346 if (is_object($Value) && method_exists($Value,
"Id"))
1348 $Value = $Value->Id();
1351 # check value based on field type 1352 $DBFieldName = $this->DBFields[
"DBFieldName"];
1353 switch ($this->
Type())
1364 $UseCount = $this->DB->Query(
"SELECT COUNT(*) AS UseCount" 1366 .
" WHERE `".$DBFieldName.
"` = '".addslashes($Value).
"'" 1367 .
" AND SchemaId = ".intval($this->DBFields[
"SchemaId"]),
1372 $UseCount = $this->DB->Query(
"SELECT COUNT(*) AS UseCount" 1373 .
" FROM ResourceClassInts" 1374 .
" WHERE ClassificationId = ".intval($Value),
1380 $UseCount = $this->DB->Query(
"SELECT COUNT(*) AS UseCount" 1381 .
" FROM ResourceNameInts" 1382 .
" WHERE ControlledNameId = ".intval($Value),
1387 $UseCount = $this->DB->Query(
"SELECT COUNT(*) AS UseCount" 1389 .
" WHERE `".$DBFieldName.
"X` = '".$Value[
"X"].
"'" 1390 .
" AND `".$DBFieldName.
"Y` = '".$Value[
"Y"].
"'" 1391 .
" AND SchemaId = ".intval($this->DBFields[
"SchemaId"]),
1396 throw new Exception(__CLASS__.
"::".__METHOD__.
"() called for" 1397 .
" unsupported field type (".$this->Type().
").");
1401 # report use count to caller 1413 # if value provided different from present value 1415 && ($NewValue != $this->DBFields[
"HasItemLevelQualifiers"]))
1417 # check if qualifier column currently exists 1419 $QualColExists = $this->DB->FieldExists(
"Resources", $QualColName);
1421 # if new value indicates qualifiers should now be used 1422 if ($NewValue == TRUE)
1424 # if qualifier column does not exist in DB for this field 1425 if ($QualColExists == FALSE)
1427 # add qualifier column in DB for this field 1428 $this->DB->Query(
"ALTER TABLE Resources ADD COLUMN `" 1429 .$QualColName.
"` INT");
1434 # if qualifier column exists in DB for this field 1435 if ($QualColExists == TRUE)
1437 # remove qualifier column from DB for this field 1438 $this->DB->Query(
"ALTER TABLE Resources DROP COLUMN `" 1444 return $this->UpdateValue(
"HasItemLevelQualifiers", $NewValue);
1453 # start with empty list 1456 # for each associated qualifier 1457 $this->DB->Query(
"SELECT QualifierId FROM FieldQualifierInts" 1458 .
" WHERE MetadataFieldId = ".$this->DBFields[
"FieldId"]);
1459 while ($Record = $this->DB->FetchRow())
1461 # load qualifier object 1462 $Qual =
new Qualifier($Record[
"QualifierId"]);
1464 # add qualifier ID and name to list 1465 $List[$Qual->Id()] = $Qual->Name();
1468 # return list to caller 1478 # grab list of associated qualifiers 1481 # get list of all qualifiers 1483 $AllQualifiers = $QFactory->GetItemNames();
1485 # return list of unassociated qualifiers 1486 return array_diff($AllQualifiers, $AssociatedQualifiers);
1496 # if qualifier object passed in 1497 if (is_object($Qualifier))
1499 # grab qualifier ID from object 1500 $Qualifier = $Qualifier->Id();
1502 # else if string passed in does not look like ID 1503 elseif (!is_numeric($Qualifier))
1505 # assume string passed in is name and use it to retrieve ID 1507 $Qualifier = $QFact->GetItemIdByName($Qualifier);
1508 if ($Qualifier === FALSE)
1510 throw new InvalidArgumentException(
"Unknown qualifier name (\"" 1511 .$Qualifier.
"\").");
1515 # if not already associated 1516 $RecordCount = $this->DB->Query(
1517 "SELECT COUNT(*) AS RecordCount FROM FieldQualifierInts" 1518 .
" WHERE QualifierId = ".$Qualifier
1519 .
" AND MetadataFieldId = ".$this->
Id(),
"RecordCount");
1520 if ($RecordCount < 1)
1522 # associate field with qualifier 1523 $this->DB->Query(
"INSERT INTO FieldQualifierInts SET" 1524 .
" QualifierId = ".$Qualifier.
"," 1525 .
" MetadataFieldId = ".$this->Id());
1537 # if qualifier object passed in 1538 if (is_object($QualifierIdOrObject))
1540 # grab qualifier ID from object 1541 $QualifierIdOrObject = $QualifierIdOrObject->Id();
1544 # delete intersection record from database 1545 $this->DB->Query(
"DELETE FROM FieldQualifierInts WHERE QualifierId = " 1546 .$QualifierIdOrObject.
" AND MetadataFieldId = ".
1556 switch ($this->
Type())
1585 $CacheKey =
"View".$User->Id() .
"-".
1586 ($AllowHooksToModify ?
"1" :
"0");
1588 # see if we have a cached permission for this field and user 1589 if (!isset($this->PermissionCache[$CacheKey]))
1593 # the field should not be viewed if it is disabled 1594 $this->PermissionCache[$CacheKey] = FALSE;
1601 # otherwise, evaluate the perms 1603 $Schema->ViewingPrivileges()->MeetsRequirements($User) &&
1607 if ($AllowHooksToModify)
1609 $SignalResult = $GLOBALS[
"AF"]->SignalEvent(
1610 "EVENT_FIELD_VIEW_PERMISSION_CHECK", array(
1614 "CanView" => $CheckResult));
1615 $CheckResult = $SignalResult[
"CanView"];
1618 $this->PermissionCache[$CacheKey] = $CheckResult;
1622 return $this->PermissionCache[$CacheKey];
1633 # if a new value was provided, convert it to a string 1638 $Ids = implode(
",", $Ids);
1642 # update/retrieve the value 1643 $Value = $this->UpdateValue(
1644 "ReferenceableSchemaIds", $Ids);
1646 # and convert stored string to an array 1647 return explode(
",", $Value);
1650 # ---- PRIVATE INTERFACE ------------------------------------------------- 1655 private $ErrorStatus;
1656 private $AuthoringPrivileges;
1657 private $EditingPrivileges;
1658 private $ViewingPrivileges;
1659 private $PreviewingPrivileges;
1660 private $PermissionCache;
1683 # field type DB/PHP enum translations 1737 self::UPDATEMETHOD_NOAUTOUPDATE =>
"Do not update automatically",
1738 self::UPDATEMETHOD_ONRECORDCREATE =>
"Update on record creation",
1739 self::UPDATEMETHOD_BUTTON =>
"Provide an update button",
1740 self::UPDATEMETHOD_ONRECORDEDIT =>
"Update when record is edited",
1741 self::UPDATEMETHOD_ONRECORDCHANGE =>
"Update when record is changed" 1757 public static function Create($SchemaId, $FieldType, $FieldName,
1758 $Optional = NULL, $DefaultValue = NULL)
1760 # error out if field type is bad 1761 if (empty(self::$FieldTypeDBEnums[$FieldType]))
1763 throw new InvalidArgumentException(
"Bad field type (".$FieldType.
").");
1766 # error out if field name is duplicate 1768 $FieldName = trim($FieldName);
1769 $DuplicateCount = $DB->Query(
1770 "SELECT COUNT(*) AS RecordCount FROM MetadataFields" 1771 .
" WHERE FieldName = '".addslashes($FieldName).
"'" 1772 .
" AND SchemaId = ".intval($SchemaId),
1774 if ($DuplicateCount > 0)
1776 throw new InvalidArgumentException(
"Duplicate field name (".$FieldName.
").");
1779 # grab current user ID 1780 $UserId = $GLOBALS[
"G_User"]->Get(
"UserId");
1782 # normalize schema ID 1784 $SchemaId = $Schema->Id();
1786 # use schema privileges as starting privilege values 1787 $AuthorPrivs = $Schema->AuthoringPrivileges();
1788 $EditPrivs = $Schema->EditingPrivileges();
1789 $ViewPrivs = $Schema->ViewingPrivileges();
1790 $PreviewPrivs = $Schema->ViewingPrivileges();
1792 # lock DB tables and get next temporary field ID 1793 $DB->Query(
"LOCK TABLES MetadataFields WRITE");
1794 $FieldId = $Schema->GetNextTempItemId();
1796 # add field to MDF table in database 1797 $DB->Query(
"INSERT INTO MetadataFields" 1798 .
" (FieldId, SchemaId, FieldName, FieldType, LastModifiedById," 1799 .
" Optional, AuthoringPrivileges, EditingPrivileges," 1800 .
" ViewingPrivileges, PreviewingPrivileges)" 1802 .intval($FieldId).
", " 1803 .intval($SchemaId).
"," 1804 .
" '".addslashes($FieldName).
"'," 1805 .
" '".self::$FieldTypeDBEnums[$FieldType].
"', " 1806 .intval($UserId).
", " 1807 .($Optional ?
"1" :
"0").
"," 1808 .
"'".$DB->EscapeString($AuthorPrivs->Data()).
"'," 1809 .
"'".$DB->EscapeString($EditPrivs->Data()).
"'," 1810 .
"'".$DB->EscapeString($ViewPrivs->Data()).
"'," 1811 .
"'".$DB->EscapeString($PreviewPrivs->Data()).
"')");
1814 $DB->Query(
"UNLOCK TABLES");
1816 # nuke potentially stale cache information 1817 self::$FieldCache = NULL;
1822 # set field defaults 1823 $Field->SetDefaults();
1825 # set the default value if specified 1826 if ($DefaultValue !== NULL)
1828 $Field->DefaultValue($DefaultValue);
1831 # clear caches in MetadataSchema 1834 # return newly-constructed field to caller 1849 $NewName = $this->
Name().
" (duplicate ".date(
"ymd-His").
")";
1850 $NewField = self::Create($this->
SchemaId(), $this->
Type(), $NewName);
1852 # copy all attributes to database record for new field 1853 $TableName =
"MetadataFields";
1854 $IdColumn =
"FieldId";
1855 $SrcId = $this->
Id();
1856 $DstId = $NewField->Id();
1857 $ColumnsToExclude = array(
"FieldName");
1858 $this->DB->CopyValues(
1859 $TableName, $IdColumn, $SrcId, $DstId, $ColumnsToExclude);
1861 # clear caches in MetadataSchema 1864 # reload new field and return to caller 1876 # assume everything will be okay 1879 # check if we have cached field info 1881 if (self::$FieldCache === NULL)
1883 # if not, retrieve field info from database 1884 $this->DB->Query(
"SELECT * FROM MetadataFields");
1885 while ($Row = $this->DB->FetchRow())
1887 self::$FieldCache[$Row[
"FieldId"]] = $Row;
1891 # error if requested field did not exist 1892 if (!array_key_exists($FieldId, self::$FieldCache) )
1894 throw new InvalidArgumentException(
"Invalid metadata field ID (" 1896 .StdLib::GetMyCaller().
".");
1898 $Row = self::$FieldCache[$FieldId];
1899 $this->DBFields = $Row;
1900 $this->
Id = $FieldId;
1902 # if privileges have not yet been initialized 1903 if (!strlen($this->DBFields[
"AuthoringPrivileges"]))
1905 # set default values for privileges from metadata schema 1914 # set privileges from stored values 1916 $Row[
"AuthoringPrivileges"]);
1918 $Row[
"EditingPrivileges"]);
1920 $Row[
"ViewingPrivileges"]);
1922 $Row[
"PreviewingPrivileges"]);
1925 # set database column name 1926 $this->DBFields[
"DBFieldName"] =
1927 $this->NormalizeFieldNameForDB($this->DBFields[
"FieldName"]);
1936 "Description" => NULL,
1937 "Instructions" => NULL,
1941 "CopyOnResourceDuplication" => TRUE,
1942 "AllowMultiple" => FALSE,
1943 "IncludeInKeywordSearch" => FALSE,
1944 "IncludeInAdvancedSearch" => FALSE,
1945 "IncludeInFacetedSearch" => FALSE,
1947 "IncludeInSortOptions" => TRUE,
1948 "IncludeInRecommender" => FALSE,
1949 "ParagraphRows" => 4,
1950 "ParagraphCols" => 50,
1952 "FlagOnLabel" =>
"On",
1953 "FlagOffLabel" =>
"Off",
1954 "DateFormat" => NULL,
1955 "RecommenderWeight" => 1,
1958 "MaxPreviewHeight" => 100,
1959 "MaxPreviewWidth" => 100,
1960 "MaxThumbnailHeight" => 50,
1961 "MaxThumbnailWidth" => 50,
1962 "DefaultAltText" => NULL,
1963 "UsesQualifiers" => FALSE,
1964 "HasItemLevelQualifiers" => FALSE,
1965 "ShowQualifiers" => FALSE,
1966 "DefaultQualifier" => NULL,
1967 "AllowHTML" => FALSE,
1968 "UseWysiwygEditor" => FALSE,
1969 "UseForOaiSets" => FALSE,
1970 "DisplayAsListForAdvancedSearch" => FALSE,
1971 "MaxDepthForAdvancedSearch" => 1,
1972 "OptionListThreshold" => 25,
1973 "AjaxThreshold" => 50,
1974 "NumAjaxResults" => 50,
1975 "PointPrecision" => 8,
1976 "PointDecimalDigits" => 5,
1977 "UserPrivilegeRestrictions" => array(),
1978 "UpdateMethod" =>
"NoAutoUpdate",
1979 # 9999 is the
default max value because
default number field length is 4
1980 "MaxValue" => 9999);
1988 "DefaultValue" => NULL,
1989 "SearchWeight" => 1,
1990 "TextFieldSize" => 50,
1991 "MaxLength" => 100),
1993 "DefaultValue" => NULL,
1994 "SearchWeight" => 1,
1995 "TextFieldSize" => 50,
1996 "MaxLength" => 100),
1998 "DefaultValue" => NULL,
1999 "SearchWeight" => 1,
2000 "TextFieldSize" => 4,
2001 "MaxLength" => 100),
2003 "DefaultValue" => NULL,
2004 "SearchWeight" => 1,
2005 "TextFieldSize" => 10,
2006 "MaxLength" => 100),
2008 "DefaultValue" => NULL,
2009 "SearchWeight" => 1,
2010 "TextFieldSize" => 50,
2011 "MaxLength" => 100),
2013 "DefaultValue" => NULL,
2014 "SearchWeight" => 1,
2015 "TextFieldSize" => 50,
2016 "MaxLength" => 100),
2018 "DefaultValue" => NULL,
2019 "SearchWeight" => 1,
2020 "AllowMultiple" => TRUE,
2021 "TextFieldSize" => 50,
2022 "MaxLength" => 100),
2024 "DefaultValue" => NULL,
2025 "SearchWeight" => 3,
2026 "AllowMultiple" => TRUE,
2027 "TextFieldSize" => 50,
2028 "MaxLength" => 100),
2030 "DefaultValue" => NULL,
2031 "SearchWeight" => 3,
2032 "TextFieldSize" => 50,
2033 "MaxLength" => 100),
2035 "DefaultValue" => NULL,
2036 "SearchWeight" => 1,
2037 "TextFieldSize" => 50,
2038 "MaxLength" => 100),
2040 "DefaultValue" => NULL,
2041 "CopyOnResourceDuplication" => FALSE,
2042 "SearchWeight" => 1,
2043 "TextFieldSize" => 50,
2044 "MaxLength" => 100),
2046 "DefaultValue" => NULL,
2047 "CopyOnResourceDuplication" => FALSE,
2048 "AllowMultiple" => TRUE,
2049 "SearchWeight" => 1,
2050 "TextFieldSize" => 50,
2051 "MaxLength" => 100),
2053 "DefaultValue" => NULL,
2054 "SearchWeight" => 1,
2055 "TextFieldSize" => 50,
2056 "MaxLength" => 255),
2058 "DefaultValue" => array(
"X" => NULL,
"Y" => NULL),
2059 "SearchWeight" => 1,
2060 "TextFieldSize" => 10,
2061 "MaxLength" => 100),
2063 "DefaultValue" => NULL,
2064 "SearchWeight" => 1,
2065 "TextFieldSize" => 50,
2067 "ReferenceableSchemaIds" => array(
2075 # set defaults that are the same for every field 2076 foreach (self::$FixedDefaults as $Key => $Value)
2078 $this->$Key($Value);
2081 # set defaults that depend on the type of the field 2082 foreach (self::$TypeBasedDefaults[$this->
Type()] as $Key => $Value)
2084 $this->$Key($Value);
2087 # tweak the update method if dealing with the date of record creation 2088 if ($this->
Name() ==
"Date Of Record Creation")
2102 "Attempt to update drop Metadata Field at %FILE%:%LINE%." 2103 .
" (Fields may only be dropped by MetadataSchema.)");
2105 # clear other database entries as appropriate for field type 2107 $DBFieldName = $this->DBFields[
"DBFieldName"];
2109 switch (self::$FieldTypePHPEnums[$this->DBFields[
"FieldType"]])
2119 # remove field from resources table 2120 if ($DB->FieldExists(
"Resources", $DBFieldName))
2122 $DB->Query(
"ALTER TABLE Resources DROP COLUMN `".$DBFieldName.
"`");
2127 if ($DB->FieldExists(
"Resources", $DBFieldName.
"X"))
2129 $DB->Query(
"ALTER TABLE Resources DROP COLUMN `".$DBFieldName.
"X`");
2130 $DB->Query(
"ALTER TABLE Resources DROP COLUMN `".$DBFieldName.
"Y`");
2135 # remove fields from resources table 2136 if ($DB->FieldExists(
"Resources", $DBFieldName.
"Begin"))
2138 $DB->Query(
"ALTER TABLE Resources " 2139 .
"DROP COLUMN `".$DBFieldName.
"Begin`");
2140 $DB->Query(
"ALTER TABLE Resources " 2141 .
"DROP COLUMN `".$DBFieldName.
"End`");
2142 $DB->Query(
"ALTER TABLE Resources " 2143 .
"DROP COLUMN `".$DBFieldName.
"Precision`");
2148 $DB->Query(
"SELECT ClassificationId FROM Classifications " 2149 .
"WHERE FieldId = ".$this->
Id());
2151 while ($ClassificationId = $DB->FetchField(
"ClassificationId"))
2153 # remove any resource / name intersections 2154 $TempDB->Query(
"DELETE FROM ResourceClassInts WHERE " 2155 .
"ClassificationId = ".$ClassificationId);
2157 # remove controlled name 2158 $TempDB->Query(
"DELETE FROM Classifications WHERE " 2159 .
"ClassificationId = ".$ClassificationId);
2165 $DB->Query(
"SELECT ControlledNameId FROM ControlledNames " 2166 .
"WHERE FieldId = ".$this->
Id());
2168 while ($ControlledNameId = $DB->FetchField(
"ControlledNameId"))
2170 # remove any resource / name intersections 2171 $TempDB->Query(
"DELETE FROM ResourceNameInts WHERE " 2172 .
"ControlledNameId = ".$ControlledNameId);
2174 # remove any variant names 2175 $TempDB->Query(
"DELETE FROM VariantNames WHERE " 2176 .
"ControlledNameId = ".$ControlledNameId);
2178 # remove controlled name 2179 $TempDB->Query(
"DELETE FROM ControlledNames WHERE " 2180 .
"ControlledNameId = ".$ControlledNameId);
2185 # for each file associated with this field 2186 $DB->Query(
"SELECT FileId FROM Files WHERE FieldId = '".$this->
Id().
"'");
2187 while ($FileId = $DB->FetchRow())
2190 $File =
new File(intval($FileId));
2196 # remove any resource references for the field 2198 DELETE FROM ReferenceInts 2199 WHERE FieldId = '".addslashes($this->
Id()).
"'");
2203 # remove field from database 2204 $DB->Query(
"DELETE FROM MetadataFields " 2205 .
"WHERE FieldId = '".$this->DBFields[
"FieldId"].
"'");
2207 # remove any qualifier associations 2208 $DB->Query(
"DELETE FROM FieldQualifierInts WHERE MetadataFieldId = '" 2209 .$this->DBFields[
"FieldId"].
"'");
2211 # get the order objects the field is part of 2214 # remove it if it's a direct descendant 2215 $Order->RemoveItem($this->
Id(),
"MetadataField");
2217 # also make sure to remove it if it's part of a group 2218 foreach ($Order->GetItemIds() as $Item)
2220 if ($Item[
"Type"] ==
"MetadataFieldGroup")
2223 $Group->RemoveItem($this->
Id(),
"MetadataField");
2228 # nuke stale field cache 2229 self::$FieldCache = NULL;
2231 # clear caches in MetadataSchema 2242 private function ModifyField($NewName = NULL, $NewType = NULL)
2244 # grab old DB field name 2245 $OldDBFieldName = $this->DBFields[
"DBFieldName"];
2246 $OldFieldType = NULL;
2248 # if new field name supplied 2249 if ($NewName != NULL)
2251 # cache the old name for options and controllednames below 2252 $OldName = $this->DBFields[
"FieldName"];
2255 $this->UpdateValue(
"FieldName", $NewName);
2257 # determine new DB field name 2258 $NewDBFieldName = $this->NormalizeFieldNameForDB($NewName);
2260 # store new database field name 2261 $this->DBFields[
"DBFieldName"] = $NewDBFieldName;
2263 # clear caches in MetadataSchema 2268 # set new field name equal to old field name 2269 $NewDBFieldName = $OldDBFieldName;
2272 # if new type supplied 2273 if ($NewType != NULL)
2275 # grab old field type 2276 $OldFieldType = self::$FieldTypePHPEnums[$this->DBFields[
"FieldType"]];
2278 # store new field type 2279 $this->UpdateValue(
"FieldType", self::$FieldTypeDBEnums[$NewType]);
2282 # if this is not a temporary field 2283 if ($this->
Id() >= 0)
2285 # modify field in DB as appropriate for field type 2287 $FieldType = self::$FieldTypePHPEnums[$this->DBFields[
"FieldType"]];
2293 # alter field declaration in Resources table 2294 $DB->Query(
"ALTER TABLE Resources CHANGE COLUMN `" 2295 .$OldDBFieldName.
"` `" 2296 .$NewDBFieldName.
"` TEXT DEFAULT NULL");
2300 # alter field declaration in Resources table 2301 $DB->Query(
"ALTER TABLE Resources CHANGE COLUMN `" 2302 .$OldDBFieldName.
"` `" 2303 .$NewDBFieldName.
"` INT DEFAULT NULL");
2308 $Precision = $this->UpdateValue(
"PointPrecision",
2310 $Digits = $this->UpdateValue(
"PointDecimalDigits",
2312 $DB->Query(
"ALTER TABLE Resources CHANGE COLUMN " 2313 .
"`".$OldDBFieldName.
"X` " 2314 .
"`".$NewDBFieldName.
"X`".
2315 " DECIMAL(".$Precision.
",".$Digits.
")");
2316 $DB->Query(
"ALTER TABLE Resources CHANGE COLUMN " 2317 .
"`".$OldDBFieldName.
"Y` " 2318 .
"`".$NewDBFieldName.
"Y`".
2319 " DECIMAL(".$Precision.
",".$Digits.
")");
2323 # alter field declaration in Resources table 2324 $DB->Query(
"ALTER TABLE Resources CHANGE COLUMN `" 2325 .$OldDBFieldName.
"` `" 2326 .$NewDBFieldName.
"` INT" 2329 # set any unset values to default 2330 $DB->Query(
"UPDATE Resources SET `".$NewDBFieldName
2332 .
" WHERE `".$NewDBFieldName.
"` IS NULL");
2336 # if new type supplied and new type is different from old 2337 if (($NewType != NULL) && ($NewType != $OldFieldType))
2339 # if old type was time stamp 2342 # change time stamp field in resources table to begin date 2343 $DB->Query(
"ALTER TABLE Resources CHANGE COLUMN `" 2344 .$OldDBFieldName.
"` `" 2345 .$NewDBFieldName.
"Begin` DATE " 2348 # add end date and precision fields 2349 $DB->Query(
"ALTER TABLE Resources " 2350 .
"ADD COLUMN `".$NewDBFieldName.
"End` DATE");
2351 $DB->Query(
"ALTER TABLE Resources " 2352 .
"ADD COLUMN `".$NewDBFieldName.
"Precision`" 2353 .
"INT DEFAULT NULL");
2356 # set precision to reflect time stamp content 2357 $DB->Query(
"UPDATE Resources " 2358 .
"SET `".$NewDBFieldName.
"Precision` = " 2364 exit(
"<br>ERROR: Attempt to convert metadata field " 2365 .
"to date from type other than timestamp<br>\n");
2370 # change name of fields 2371 $DB->Query(
"ALTER TABLE Resources CHANGE COLUMN `" 2372 .$OldDBFieldName.
"Begin` `" 2373 .$NewDBFieldName.
"Begin` DATE " 2375 $DB->Query(
"ALTER TABLE Resources CHANGE COLUMN `" 2376 .$OldDBFieldName.
"End` `" 2377 .$NewDBFieldName.
"End` DATE " 2379 $DB->Query(
"ALTER TABLE Resources CHANGE COLUMN `" 2380 .$OldDBFieldName.
"Precision` `" 2381 .$NewDBFieldName.
"Precision` INT " 2387 # if new type supplied and new type is different from old 2388 if (($NewType != NULL) && ($NewType != $OldFieldType))
2390 # if old type was date 2393 # change begin date field in resource table to time stamp 2394 $DB->Query(
"ALTER TABLE Resources CHANGE COLUMN `" 2395 .$OldDBFieldName.
"Begin` `" 2396 .$NewDBFieldName.
"` DATETIME " 2399 # drop end date and precision fields 2400 $DB->Query(
"ALTER TABLE Resources DROP COLUMN `" 2401 .$OldDBFieldName.
"End`");
2402 $DB->Query(
"ALTER TABLE Resources DROP COLUMN `" 2403 .$OldDBFieldName.
"Precision`");
2407 exit(
"<br>ERROR: Attempt to convert metadata field to " 2408 .
"time stamp from type other than date<br>\n");
2413 # change name of field 2414 $DB->Query(
"ALTER TABLE Resources CHANGE COLUMN `" 2415 .$OldDBFieldName.
"` `" 2416 .$NewDBFieldName.
"` DATETIME " 2430 # if qualifier DB field exists 2431 if ($DB->FieldExists(
"Resources", $OldDBFieldName.
"Qualifier"))
2433 # rename qualifier DB field 2434 $DB->Query(
"ALTER TABLE Resources CHANGE COLUMN `" 2435 .$OldDBFieldName.
"Qualifier` `" 2436 .$NewDBFieldName.
"Qualifier` INT ");
2447 private function UpdateValue($FieldName, $NewValue)
2449 # nuke stale field cache 2452 self::$FieldCache = NULL;
2455 return $this->DB->UpdateValue(
"MetadataFields", $FieldName, $NewValue,
2456 "FieldId = ".intval($this->DBFields[
"FieldId"]),
2466 private function UpdateIntValue($FieldName, $NewValue)
2468 # nuke stale field cache 2471 self::$FieldCache = NULL;
2474 return $this->DB->UpdateIntValue(
"MetadataFields", $FieldName, $NewValue,
2475 "FieldId = ".intval($this->DBFields[
"FieldId"]),
2485 private function UpdateFloatValue($FieldName, $NewValue)
2487 # nuke stale field cache 2490 self::$FieldCache = NULL;
2493 return $this->DB->UpdateFloatValue(
"MetadataFields", $FieldName, $NewValue,
2494 "FieldId = ".intval($this->DBFields[
"FieldId"]),
2504 private function UpdateBoolValue($FieldName, $NewValue)
2506 # nuke stale field cache 2509 self::$FieldCache = NULL;
2512 $NewValue = $this->TranslateStringToConstants($NewValue);
2513 return $this->DB->UpdateIntValue(
"MetadataFields", $FieldName, $NewValue,
2514 "FieldId = ".intval($this->DBFields[
"FieldId"]),
2525 private function UpdateConstValue($FieldName, $NewValue, $ClassName=NULL)
2527 # nuke stale field cache 2530 self::$FieldCache = NULL;
2533 $NewValue = $this->TranslateStringToConstants($NewValue, $ClassName);
2534 return $this->DB->UpdateIntValue(
"MetadataFields", $FieldName, $NewValue,
2535 "FieldId = ".intval($this->DBFields[
"FieldId"]),
2544 private function NormalizeFieldNameForDB($Name)
2546 return preg_replace(
"/[^a-z0-9]/i",
"", $Name)
2554 private function AddDatabaseFields()
2556 # grab values for common use 2560 # set up field(s) based on field type 2561 switch ($this->
Type())
2566 # add field to resources table (if not already present) 2567 if (!$DB->FieldExists(
"Resources", $DBFieldName))
2569 $DB->Query(
"ALTER TABLE Resources ADD COLUMN `".$DBFieldName
2570 .
"` TEXT DEFAULT NULL");
2576 # add field to resources table (if not already present) 2577 if (!$DB->FieldExists(
"Resources", $DBFieldName))
2579 $DB->Query(
"ALTER TABLE Resources ADD COLUMN `".$DBFieldName
2580 .
"` INT DEFAULT NULL");
2585 if (!$DB->FieldExists(
"Resources", $DBFieldName.
"X"))
2587 $Precision = $this->UpdateValue(
"PointPrecision",
2589 $Digits = $this->UpdateValue(
"PointDecimalDigits",
2592 $DB->Query(
"ALTER TABLE Resources ADD COLUMN `" 2594 " DECIMAL(".$Precision.
",".$Digits.
") DEFAULT NULL");
2595 $DB->Query(
"ALTER TABLE Resources ADD COLUMN `" 2597 " DECIMAL(".$Precision.
",".$Digits.
") DEFAULT NULL");
2602 # if field is not already present in database 2603 if (!$DB->FieldExists(
"Resources", $DBFieldName))
2605 # add field to resources table 2606 $DB->Query(
"ALTER TABLE Resources ADD COLUMN `".$DBFieldName
2607 .
"` INT DEFAULT NULL");
2612 # add fields to resources table (if not already present) 2613 if (!$DB->FieldExists(
"Resources", $DBFieldName.
"Begin"))
2615 $DB->Query(
"ALTER TABLE Resources ADD COLUMN `".$DBFieldName.
"Begin`" 2616 .
" DATE DEFAULT NULL");
2618 if (!$DB->FieldExists(
"Resources", $DBFieldName.
"End"))
2620 $DB->Query(
"ALTER TABLE Resources ADD COLUMN `".$DBFieldName.
"End`" 2621 .
" DATE DEFAULT NULL");
2623 if (!$DB->FieldExists(
"Resources", $DBFieldName.
"Precision"))
2625 $DB->Query(
"ALTER TABLE Resources " 2626 .
"ADD COLUMN `".$DBFieldName.
"Precision`" 2627 .
" INT DEFAULT NULL");
2632 # add fields to resources table (if not already present) 2633 if (!$DB->FieldExists(
"Resources", $DBFieldName))
2635 $DB->Query(
"ALTER TABLE Resources ADD COLUMN `".$DBFieldName
2636 .
"` DATETIME DEFAULT NULL");
2650 exit(
"<br>ERROR: Attempt to add database fields " 2651 .
"for illegal metadata field type<br>\n");
2663 private function AddTerms($TermNames, $Qualifier=NULL)
2667 if ($Factory === NULL)
2669 throw new Exception(
2670 "Attempt to add terms to a field that does not " 2674 # for each supplied term name 2675 $ItemClassName = $Factory->GetItemClassName();
2678 foreach ($TermNames as $Name)
2680 # if term does not exist with this name 2681 $Name = trim($Name);
2682 if ($Factory->GetItemByName($Name) === NULL)
2685 $NewTerm = ($ItemClassName ==
"ControlledName") ?
2691 # assign qualifier to term if supplied 2692 if ($Qualifier !== NULL)
2694 $NewTerm->Qualifier($Qualifier);
2699 # return count of terms added to caller 2710 private function TranslateStringToConstants($CString, $ClassName = NULL)
2712 # if not a string return value unchanged to caller 2713 if (!is_string($CString) || ($CString ===
DB_NOVALUE))
2715 $ReturnValue = $CString;
2717 # handle booleans as a special case 2718 elseif (strtoupper(trim($CString)) ==
"TRUE")
2720 $ReturnValue = TRUE;
2722 elseif (strtoupper(trim($CString)) ==
"FALSE")
2724 $ReturnValue = FALSE;
2728 # assume no values will be found 2729 $ReturnValue = NULL;
2731 # split apart any ORed-together values 2732 $Values = explode(
"|", $CString);
2734 # for each value found 2735 foreach ($Values as $Value)
2737 # trim off any extraneous whitespace 2738 $Value = trim($Value);
2740 # add class name prefix to constant name if requested 2741 if ($ClassName) { $Value = $ClassName.
"::".$Value; }
2743 # if value corresponds to a constant 2744 if (defined($Value))
2746 # add constant to return value 2747 $ReturnValue = ($ReturnValue === NULL)
2749 : ($ReturnValue | constant($Value));
2753 # if no corresponding constants were found 2754 if ($ReturnValue === NULL)
2756 # return original value to caller 2757 $ReturnValue = $CString;
2761 # return result to caller 2762 return $ReturnValue;
2768 private static $FieldCache = NULL;
2771 # ---- DEPRECATED METHODS ------------------------------------------------ 2773 # These are maintained only for backward compatibility with older 2774 # code. Newer code should not use them. 2796 $NewValue = serialize((array) $NewValue);
2799 $Value = $this->UpdateValue(
"UserPrivilegeRestrictions", $NewValue);
2804 $Value = (array) unserialize($Value);
2807 # no value set, set it to an empty array 2818 return $this->UpdateConstValue(
2819 "AuthoringUserIsValue", $NewValue,
"MetadataField");
2824 return $this->UpdateConstValue(
"EditingUserIsValue", $NewValue,
"MetadataField");
2829 return $this->UpdateIntValue(
"ViewingUserValue", $NewValue);
2834 return $this->UpdateIntValue(
"AuthoringUserValue", $NewValue);
2839 return $this->UpdateIntValue(
"EditingUserValue", $NewValue);
2844 return $this->UpdateConstValue(
"ViewingUserIsValue", $NewValue,
"MetadataField");
2849 return $this->UpdateBoolValue(
"EnableOnOwnerReturn", $NewValue);
2860 throw new Exception(
"Deprecated ".__METHOD__.
"() called -- ".
2861 __METHOD__.
"s() should be used instead.");
2873 throw new Exception(
"Deprecated ".__METHOD__.
"() called -- ".
2874 __METHOD__.
"s() should be used instead.");
2886 throw new Exception(
"Deprecated ".__METHOD__.
"() called -- ".
2887 __METHOD__.
"s() should be used instead.");
2899 throw new Exception(
"Deprecated ".__METHOD__.
"() called -- ".
2900 "ViewingPrivileges() should be used instead.");
2912 throw new Exception(
"Deprecated ".__METHOD__.
"() called -- ".
2913 "this should probably be using ViewingPrivileges() instead.");
static CheckMyCaller($DesiredCaller, $ExceptionMsg=NULL)
Check the caller of the current function.
static Create($Term, $FieldId)
Create a new empty ControlledName if it's not already present.
SQL database abstraction object with smart query caching.
static Create($Name, $FieldId, $ParentId=NULL)
Add new classification to the hierarchy.
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.
static Create()
Initialize a new qualifier.
Factory for producing and manipulating Classification objects.
Class representing a stored (usually uploaded) file.