CWIS Developer Documentation
MetadataField.php
Go to the documentation of this file.
1 <?PHP
2 #
3 # FILE: MetadataField.php
4 #
5 # Part of the Collection Workflow Integration System (CWIS)
6 # Copyright 2012-2013 Edward Almasy and Internet Scout Research Group
7 # http://scout.wisc.edu/cwis/
8 #
9 
14 {
15  # ---- PUBLIC INTERFACE --------------------------------------------------
16 
17  # update methods for timestamp fields
18  const UPDATEMETHOD_NOAUTOUPDATE = "NoAutoUpdate";
19  const UPDATEMETHOD_ONRECORDCREATE = "OnRecordCreate";
20  const UPDATEMETHOD_BUTTON = "Button";
21  const UPDATEMETHOD_ONRECORDEDIT = "OnRecordEdit";
22  const UPDATEMETHOD_ONRECORDCHANGE = "OnRecordChange";
23 
24  # values for the *UserIsValue fields
25  const USERISVALUE_OR = -1;
26  const USERISVALUE_UNSET = 0;
27  const USERISVALUE_AND = 1;
28 
34  public function Status()
35  {
36  return $this->ErrorStatus;
37  }
38 
45  public function Type($NewValue = DB_NOVALUE)
46  {
47  # if new value supplied
48  $FTFieldName = $this->DBFields["FieldType"];
49  if (($NewValue != DB_NOVALUE)
50  && ($NewValue != self::$FieldTypePHPEnums[$FTFieldName]))
51  {
52  # update database fields and store new type
53  $this->ModifyField(NULL, $NewValue);
54  }
55 
56  # return type to caller
57  return self::$FieldTypePHPEnums[$FTFieldName];
58  }
59 
64  public function TypeAsName()
65  {
66  return $this->DBFields["FieldType"];
67  }
68 
74  public function IsControlledVocabularyField()
75  {
76  switch ($this->Type())
77  {
81  return TRUE;
82 
83  default:
84  return FALSE;
85  }
86  }
87 
92  public function SchemaId()
93  {
94  return $this->DBFields["SchemaId"];
95  }
96 
102  public function GetDisplayName()
103  {
104  return strlen($this->Label()) ? $this->Label() : $this->Name();
105  }
106 
113  public function Name($NewName = DB_NOVALUE)
114  {
115  # if new name specified
116  if ($NewName != DB_NOVALUE
117  && trim($NewName) != $this->DBFields["FieldName"])
118  {
119  $NewName = trim($NewName);
120  $NormalizedName = $this->NormalizeFieldNameForDB(strtolower($NewName));
121 
122  # if field name is invalid
123  if (!preg_match("/^[[:alnum:] \(\)]+$/", $NewName))
124  {
125  # set error status to indicate illegal name
126  $this->ErrorStatus = MetadataSchema::MDFSTAT_ILLEGALNAME;
127  }
128 
129  # if the new name is a reserved word
130  else if ($NormalizedName == "resourceid" || $NormalizedName == "schemaid")
131  {
132  # set error status to indicate illegal name
133  $this->ErrorStatus = MetadataSchema::MDFSTAT_ILLEGALNAME;
134  }
135 
136  # the name is okay but might be a duplicate
137  else
138  {
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"]),
144  "RecordCount");
145 
146  # if field name is duplicate
147  if ($DuplicateCount > 0)
148  {
149  # set error status to indicate duplicate name
150  $this->ErrorStatus = MetadataSchema::MDFSTAT_DUPLICATENAME;
151  }
152  else
153  {
154  # modify database declaration to reflect new field name
155  $this->ErrorStatus = MetadataSchema::MDFSTAT_OK;
156  $this->ModifyField($NewName);
157  }
158  }
159  }
160 
161  # return value to caller
162  return $this->DBFields["FieldName"];
163  }
164 
170  public function Label($NewLabel = DB_NOVALUE)
171  {
172  $ValidValueExp = '/^[[:alnum:] ]*$/';
173  $Value = $this->DBFields["Label"];
174 
175  # if a new label was specified
176  if ($NewLabel !== DB_NOVALUE && trim($NewLabel) != $Value)
177  {
178  $NewLabel = trim($NewLabel);
179 
180  # if field label is valid
181  if (preg_match($ValidValueExp, $NewLabel))
182  {
183  $this->UpdateValue("Label", $NewLabel);
184  $Value = $NewLabel;
185  }
186  # the field label is invalid
187  else
188  {
189  $this->ErrorStatus = MetadataSchema::MDFSTAT_ILLEGALLABEL;
190  }
191  }
192 
193  return $Value;
194  }
195 
201  public function GetAllowedConversionTypes()
202  {
203  # determine type list based on our type
204  switch ($this->Type())
205  {
211  $AllowedTypes = array(
213  MetadataSchema::MDFTYPE_PARAGRAPH => "Paragraph",
214  MetadataSchema::MDFTYPE_NUMBER => "Number",
217  );
218  break;
219 
222  $AllowedTypes = array(
223  MetadataSchema::MDFTYPE_CONTROLLEDNAME => "ControlledName",
224  MetadataSchema::MDFTYPE_OPTION => "Option",
225  );
226  break;
227 
229  $AllowedTypes = array(
232  );
233  break;
234 
236  $AllowedTypes = array(
238  MetadataSchema::MDFTYPE_IMAGE => "Still Image",
239  );
240  break;
241 
247  default:
248  $AllowedTypes = array();
249  break;
250  }
251 
252  # return type list to caller
253  return $AllowedTypes;
254  }
255 
263  public function IsTempItem($NewSetting = NULL)
264  {
265  $Schema = new MetadataSchema($this->SchemaId());
266  $ItemTableName = "MetadataFields";
267  $ItemIdFieldName = "FieldId";
268  $ItemFactoryObjectName = "MetadataSchema";
269  $ItemAssociationTables = array(
270  "FieldQualifierInts",
271  );
272  $ItemAssociationFieldName = "MetadataFieldId";
273 
274  # if new temp item setting supplied
275  if (!is_null($NewSetting))
276  {
277  # if caller requested to switch
278  if (($this->Id() < 0 && $NewSetting == FALSE)
279  || ($this->Id() >= 0 && $NewSetting == TRUE))
280  {
281  # if field name is invalid
282  if (strlen($this->NormalizeFieldNameForDB($this->Name())) < 1)
283  {
284  # set error status to indicate illegal name
285  $this->ErrorStatus = MetadataSchema::MDFSTAT_ILLEGALNAME;
286  }
287  else
288  {
289  # lock DB tables to prevent next ID from being grabbed
290  $DB = $this->DB;
291  $DB->Query("
292  LOCK TABLES ".$ItemTableName." WRITE,
293  APSessions WRITE, APSessionData WRITE,
294  MetadataSchemas WRITE");
295 
296  # nuke stale field cache
297  self::$FieldCache = NULL;
298 
299  # get next temp item ID
300  $OldItemId = $this->Id();
301  $Factory = new $ItemFactoryObjectName();
302  if ($NewSetting == TRUE)
303  {
304  $NewId = $Factory->GetNextTempItemId();
305  }
306  else
307  {
308  $NewId = $Factory->GetNextItemId();
309  }
310 
311  # change item ID
312  $DB->Query("UPDATE ".$ItemTableName." SET ".$ItemIdFieldName." = ".
313  $NewId. " WHERE ".$ItemIdFieldName." = ".$OldItemId);
314 
315  # release DB tables
316  $DB->Query("UNLOCK TABLES");
317 
318  # change associations
319  foreach ($ItemAssociationTables as $TableName)
320  {
321  $DB->Query("UPDATE ".$TableName." ".
322  "SET ".$ItemAssociationFieldName." = ".$NewId." ".
323  "WHERE ".$ItemAssociationFieldName." = ".$OldItemId);
324  }
325 
326  # if changing item from temp to non-temp
327  if ($NewSetting == FALSE)
328  {
329  # add any needed database fields and/or entries
330  $this->AddDatabaseFields();
331 
332  # Signal that a new (real) field was added:
333  global $AF;
334  $AF->SignalEvent(
335  "EVENT_FIELD_ADDED",
336  array("FieldId" => $NewId ) );
337 
338  # set field order values for new field
339  $Schema->GetDisplayOrder()->AppendItem($NewId, "MetadataField");
340  $Schema->GetEditOrder()->AppendItem($NewId, "MetadataField");
341  }
342 
343  # update metadata field id
344  $this->DBFields["FieldId"] = $NewId;
345  $this->Id = $NewId;
346  }
347  }
348  }
349 
350  # report to caller whether we are a temp item
351  return ($this->Id() < 0) ? TRUE : FALSE;
352  }
353 
359  public function AuthoringPrivileges($NewValue = NULL)
360  {
361  # if new privileges supplied
362  if ($NewValue !== NULL)
363  {
364  # store new privileges in database
365  $this->UpdateValue("AuthoringPrivileges", $NewValue->Data());
366  $this->AuthoringPrivileges = $NewValue;
367  }
368 
369  # return current value to caller
370  return $this->AuthoringPrivileges;
371  }
372 
378  public function EditingPrivileges($NewValue = NULL)
379  {
380  # if new privileges supplied
381  if ($NewValue !== NULL)
382  {
383  # store new privileges in database
384  $this->UpdateValue("EditingPrivileges", $NewValue->Data());
385  $this->EditingPrivileges = $NewValue;
386  }
387 
388  # return current value to caller
389  return $this->EditingPrivileges;
390  }
391 
397  public function ViewingPrivileges($NewValue = NULL)
398  {
399  # if new privileges supplied
400  if ($NewValue !== NULL)
401  {
402  # store new privileges in database
403  $this->UpdateValue("ViewingPrivileges", $NewValue->Data());
404  $this->ViewingPrivileges = $NewValue;
405  }
406 
407  # return current value to caller
408  return $this->ViewingPrivileges;
409  }
410 
416  public function PreviewingPrivileges($NewValue = NULL)
417  {
418  # if new privileges supplied
419  if ($NewValue !== NULL)
420  {
421  # store new privileges in database
422  $this->UpdateValue("PreviewingPrivileges", $NewValue->Data());
423  $this->PreviewingPrivileges = $NewValue;
424  }
425 
426  # return current value to caller
427  return $this->PreviewingPrivileges;
428  }
429 
434  public function Id()
435  {
436  return $this->Id;
437  }
438 
444  public function DBFieldName()
445  {
446  return $this->DBFields["DBFieldName"];
447  }
448 
454  public function Description($NewValue = DB_NOVALUE)
455  {
456  return $this->UpdateValue("Description", $NewValue);
457  }
458 
464  public function Instructions($NewValue = DB_NOVALUE)
465  {
466  return $this->UpdateValue("Instructions", $NewValue);
467  }
468 
474  public function Owner($NewValue = DB_NOVALUE)
475  {
476  return $this->UpdateValue("Owner", $NewValue);
477  }
478 
485  public function Enabled($NewValue = DB_NOVALUE)
486  {
487  return $this->UpdateBoolValue("Enabled", $NewValue);
488  }
489 
496  public function Optional($NewValue = DB_NOVALUE)
497  {
498  return $this->UpdateBoolValue("Optional", $NewValue);
499  }
500 
507  public function Editable($NewValue = DB_NOVALUE)
508  {
509  return $this->UpdateBoolValue("Editable", $NewValue);
510  }
511 
518  public function AllowMultiple($NewValue = DB_NOVALUE)
519  {
520  return $this->UpdateBoolValue("AllowMultiple", $NewValue);
521  }
522 
529  public function IncludeInKeywordSearch($NewValue = DB_NOVALUE)
530  {
531  return $this->UpdateBoolValue("IncludeInKeywordSearch", $NewValue);
532  }
533 
540  public function IncludeInAdvancedSearch($NewValue = DB_NOVALUE)
541  {
542  return $this->UpdateBoolValue("IncludeInAdvancedSearch", $NewValue);
543  }
544 
551  public function IncludeInFacetedSearch($NewValue = DB_NOVALUE)
552  {
553  return $this->UpdateBoolValue("IncludeInFacetedSearch", $NewValue);
554  }
555 
563  public function SearchGroupLogic($NewValue = DB_NOVALUE)
564  {
565  if ($NewValue !== DB_NOVALUE)
566  {
567  # if a new value was passed, verify that it's a legal value
568  if ($NewValue != SearchEngine::LOGIC_AND &&
569  $NewValue != SearchEngine::LOGIC_OR)
570  {
571  throw new Exception(
572  "Invalid NewValue for SearchGroupLogic(). "
573  ."Must be a SearchEngine::LOGIC_* constant.");
574  }
575  }
576 
577  return $this->UpdateIntValue("SearchGroupLogic", $NewValue);
578  }
579 
586  public function IncludeInSortOptions($NewValue = DB_NOVALUE)
587  {
588  return $this->UpdateBoolValue("IncludeInSortOptions", $NewValue);
589  }
590 
597  public function IncludeInRecommender($NewValue = DB_NOVALUE)
598  {
599  return $this->UpdateBoolValue("IncludeInRecommender", $NewValue);
600  }
601 
607  public function CopyOnResourceDuplication($NewValue = DB_NOVALUE)
608  {
609  return $this->UpdateBoolValue("CopyOnResourceDuplication", $NewValue);
610  }
611 
617  public function TextFieldSize($NewValue = DB_NOVALUE)
618  {
619  return $this->UpdateIntValue("TextFieldSize", $NewValue);
620  }
621 
627  public function MaxLength($NewValue = DB_NOVALUE)
628  {
629  return $this->UpdateIntValue("MaxLength", $NewValue);
630  }
631 
637  public function ParagraphRows($NewValue = DB_NOVALUE)
638  {
639  return $this->UpdateIntValue("ParagraphRows", $NewValue);
640  }
641 
647  public function ParagraphCols($NewValue = DB_NOVALUE)
648  {
649  return $this->UpdateIntValue("ParagraphCols", $NewValue);
650  }
651 
657  public function MinValue($NewValue = DB_NOVALUE)
658  {
659  return $this->UpdateFloatValue("MinValue", $NewValue);
660  }
661 
667  public function MaxValue($NewValue = DB_NOVALUE)
668  {
669  return $this->UpdateFloatValue("MaxValue", $NewValue);
670  }
671 
677  public function FlagOnLabel($NewValue = DB_NOVALUE)
678  {
679  return $this->UpdateValue("FlagOnLabel", $NewValue);
680  }
681 
687  public function FlagOffLabel($NewValue = DB_NOVALUE)
688  {
689  return $this->UpdateValue("FlagOffLabel", $NewValue);
690  }
691 
697  public function DateFormat($NewValue = DB_NOVALUE)
698  {
699  return $this->UpdateValue("DateFormat", $NewValue);
700  }
701 
708  public function SearchWeight($NewValue = DB_NOVALUE)
709  {
710  return $this->UpdateIntValue("SearchWeight", $NewValue);
711  }
712 
719  public function RecommenderWeight($NewValue = DB_NOVALUE)
720  {
721  return $this->UpdateIntValue("RecommenderWeight", $NewValue);
722  }
723 
729  public function MaxHeight($NewValue = DB_NOVALUE)
730  {
731  return $this->UpdateIntValue("MaxHeight", $NewValue);
732  }
733 
739  public function MaxWidth($NewValue = DB_NOVALUE)
740  {
741  return $this->UpdateIntValue("MaxWidth", $NewValue);
742  }
743 
749  public function MaxPreviewHeight($NewValue = DB_NOVALUE)
750  {
751  return $this->UpdateIntValue("MaxPreviewHeight", $NewValue);
752  }
753 
759  public function MaxPreviewWidth($NewValue = DB_NOVALUE)
760  {
761  return $this->UpdateIntValue("MaxPreviewWidth", $NewValue);
762  }
763 
769  public function MaxThumbnailHeight($NewValue = DB_NOVALUE)
770  {
771  return $this->UpdateIntValue("MaxThumbnailHeight", $NewValue);
772  }
773 
779  public function MaxThumbnailWidth($NewValue = DB_NOVALUE)
780  {
781  return $this->UpdateIntValue("MaxThumbnailWidth", $NewValue);
782  }
783 
789  public function DefaultAltText($NewValue = DB_NOVALUE)
790  {
791  return $this->UpdateValue("DefaultAltText", $NewValue);
792  }
793 
799  public function UsesQualifiers($NewValue = DB_NOVALUE)
800  {
801  return $this->UpdateBoolValue("UsesQualifiers", $NewValue);
802  }
803 
809  public function ShowQualifiers($NewValue = DB_NOVALUE)
810  {
811  return $this->UpdateBoolValue("ShowQualifiers", $NewValue);
812  }
813 
819  public function DefaultQualifier($NewValue = DB_NOVALUE)
820  {
821  return $this->UpdateValue("DefaultQualifier", $NewValue);
822  }
823 
829  public function AllowHTML($NewValue = DB_NOVALUE)
830  {
831  return $this->UpdateBoolValue("AllowHTML", $NewValue);
832  }
833 
839  public function UseWysiwygEditor($NewValue = DB_NOVALUE)
840  {
841  return $this->UpdateBoolValue("UseWysiwygEditor", $NewValue);
842  }
843 
849  public function UseForOaiSets($NewValue = DB_NOVALUE)
850  {
851  return $this->UpdateBoolValue("UseForOaiSets", $NewValue);
852  }
853 
860  public function DisplayAsListForAdvancedSearch($NewValue = DB_NOVALUE)
861  {
862  return $this->UpdateBoolValue("DisplayAsListForAdvancedSearch", $NewValue);
863  }
864 
871  public function MaxDepthForAdvancedSearch($NewValue = DB_NOVALUE)
872  {
873  return $this->UpdateIntValue("MaxDepthForAdvancedSearch", $NewValue);
874  }
875 
881  public function OptionListThreshold($NewValue = DB_NOVALUE)
882  {
883  return $this->UpdateIntValue("OptionListThreshold", $NewValue);
884  }
885 
891  public function AjaxThreshold($NewValue = DB_NOVALUE)
892  {
893  return $this->UpdateIntValue("AjaxThreshold", $NewValue);
894  }
895 
902  public function NumAjaxResults($NewValue = DB_NOVALUE)
903  {
904  return $this->UpdateIntValue("NumAjaxResults", $NewValue);
905  }
906 
907 
908 
914  public function RequiredBySPT($NewValue = DB_NOVALUE)
915  {
916  return $this->UpdateBoolValue("RequiredBySPT", $NewValue);
917  }
918 
924  public function PointPrecision($NewValue = DB_NOVALUE)
925  {
926  if ($NewValue !== DB_NOVALUE && $this->Id() >= 0
927  && $this->Type() == MetadataSchema::MDFTYPE_POINT)
928  {
929  $OldValue = $this->UpdateValue("PointPrecision", DB_NOVALUE);
930 
931  if ($NewValue != $OldValue)
932  {
933  $Decimals = $this->UpdateValue("PointDecimalDigits", DB_NOVALUE);
934  $TotalDigits = $NewValue + $Decimals;
935 
936  $this->DB->Query("ALTER TABLE Resources MODIFY COLUMN "
937  ."`".$this->DBFields["DBFieldName"]."X` "
938  ."DECIMAL(".$TotalDigits.",".$Decimals.")");
939  $this->DB->Query("ALTER TABLE Resources MODIFY COLUMN "
940  ."`".$this->DBFields["DBFieldName"]."Y` "
941  ."DECIMAL(".$TotalDigits.",".$Decimals.")");
942  }
943  }
944 
945  return $this->UpdateValue("PointPrecision", $NewValue);
946  }
947 
953  public function PointDecimalDigits($NewValue = DB_NOVALUE)
954  {
955  if ($NewValue !== DB_NOVALUE && $this->Id() >= 0
956  && $this->Type() == MetadataSchema::MDFTYPE_POINT)
957  {
958  $OldValue = $this->UpdateValue("PointDecimalDigits", DB_NOVALUE);
959 
960  if ($NewValue != $OldValue)
961  {
962  $Precision = $this->UpdateValue("PointPrecision", DB_NOVALUE);
963 
964  $TotalDigits = $NewValue + $Precision;
965 
966  $this->DB->Query("ALTER TABLE Resources MODIFY COLUMN "
967  ."`".$this->DBFields["DBFieldName"]."X` "
968  ."DECIMAL(".$TotalDigits.",".$NewValue.")");
969  $this->DB->Query("ALTER TABLE Resources MODIFY COLUMN "
970  ."`".$this->DBFields["DBFieldName"]."Y` "
971  ."DECIMAL(".$TotalDigits.",".$NewValue.")");
972  }
973  }
974 
975  return $this->UpdateValue("PointDecimalDigits", $NewValue);
976  }
977 
983  public function DefaultValue($NewValue = DB_NOVALUE)
984  {
985  if ($this->Type() == MetadataSchema::MDFTYPE_POINT)
986  {
987  # valid value given
988  if ($NewValue !== DB_NOVALUE &&
989  isset($NewValue["X"]) && isset($NewValue["Y"]))
990  {
991  $NewValue = $NewValue["X"].",".$NewValue["Y"];
992  }
993 
994  # invalid value given
995  else
996  {
997  $NewValue = DB_NOVALUE;
998  }
999 
1000  $Value = $this->UpdateValue("DefaultValue", $NewValue);
1001 
1002  if (is_array($Value))
1003  {
1004  $tmp = explode(",", $Value);
1005 
1006  if (count($tmp)==2)
1007  {
1008  return array("X" => $tmp[0], "Y" => $tmp[1]);
1009  }
1010  }
1011 
1012  return array("X" => NULL, "Y" => NULL);
1013  }
1014 
1015  else if ($this->Type() == MetadataSchema::MDFTYPE_OPTION)
1016  {
1017  # multiple default values to set
1018  if (is_array($NewValue))
1019  {
1020  # empty array
1021  if (count($NewValue) == 0)
1022  {
1023  $NewValue = NULL;
1024  }
1025 
1026  # multiple defaults are allowed
1027  else if ($this->AllowMultiple())
1028  {
1029  $NewValue = serialize($NewValue);
1030  }
1031 
1032  # only one default is allowed so get the first one
1033  else
1034  {
1035  $NewValue = array_shift($NewValue);
1036  }
1037  }
1038 
1039  $Result = $this->UpdateValue("DefaultValue", $NewValue);
1040 
1041  return empty($Result) || is_numeric($Result) ?
1042  $Result : unserialize($Result);
1043  }
1044 
1045  return $this->UpdateValue("DefaultValue", $NewValue);
1046  }
1047 
1053  public function UpdateMethod($NewValue = DB_NOVALUE)
1054  {
1055  return $this->UpdateValue("UpdateMethod", $NewValue);
1056  }
1057 
1065  public function GetPossibleValues($MaxNumberOfValues = NULL, $Offset=0)
1066  {
1067  # retrieve values based on field type
1068  switch ($this->Type())
1069  {
1071  $QueryString = "SELECT ClassificationId, ClassificationName"
1072  ." FROM Classifications WHERE FieldId = ".$this->Id()
1073  ." ORDER BY ClassificationName";
1074  if ($MaxNumberOfValues)
1075  {
1076  $QueryString .= " LIMIT ".intval($MaxNumberOfValues)." OFFSET "
1077  .intval($Offset);
1078  }
1079  $this->DB->Query($QueryString);
1080  $PossibleValues = $this->DB->FetchColumn(
1081  "ClassificationName", "ClassificationId");
1082  break;
1083 
1086  $QueryString = "SELECT ControlledNameId, ControlledName"
1087  ." FROM ControlledNames WHERE FieldId = ".$this->Id()
1088  ." ORDER BY ControlledName";
1089  if ($MaxNumberOfValues)
1090  {
1091  $QueryString .= " LIMIT ".intval($MaxNumberOfValues)." OFFSET "
1092  .intval($Offset);
1093  }
1094  $this->DB->Query($QueryString);
1095  $PossibleValues = $this->DB->FetchColumn(
1096  "ControlledName", "ControlledNameId");
1097  break;
1098 
1100  $PossibleValues[0] = $this->FlagOffLabel();
1101  $PossibleValues[1] = $this->FlagOnLabel();
1102  break;
1103 
1105  $UserFactory = new CWUserFactory();
1106  $Restrictions = $this->UserPrivilegeRestrictions();
1107  $PossibleValues = array();
1108 
1109  if (count($Restrictions))
1110  {
1111  $PossibleValues = call_user_func_array(
1112  array($UserFactory, "GetUsersWithPrivileges"),
1113  $Restrictions);
1114  }
1115 
1116  else
1117  {
1118  $Users = $UserFactory->GetMatchingUsers(".*.");
1119 
1120  foreach ($Users as $Id => $Data)
1121  {
1122  $PossibleValues[$Id] = $Data["UserName"];
1123  }
1124  }
1125 
1126  break;
1127 
1128  default:
1129  # for everything else return an empty array
1130  $PossibleValues = array();
1131  break;
1132  }
1133 
1134  # return array of possible values to caller
1135  return $PossibleValues;
1136  }
1137 
1143  public function GetCountOfPossibleValues()
1144  {
1145  # retrieve values based on field type
1146  switch ($this->Type())
1147  {
1149  $Count = $this->DB->Query("SELECT count(*) AS ValueCount"
1150  ." FROM Classifications WHERE FieldId = ".$this->Id(),
1151  "ValueCount");
1152  break;
1153 
1156  $Count = $this->DB->Query("SELECT count(*) AS ValueCount"
1157  ." FROM ControlledNames WHERE FieldId = ".$this->Id(),
1158  "ValueCount");
1159  break;
1160 
1162  $Count = 2;
1163  break;
1164 
1166  $Count = count($this->GetPossibleValues());
1167  break;
1168 
1169  default:
1170  # for everything else return an empty array
1171  $Count = 0;
1172  break;
1173  }
1174 
1175  # return count of possible values to caller
1176  return $Count;
1177  }
1178 
1184  public function GetIdForValue($Value)
1185  {
1186  # retrieve ID based on field type
1187  switch ($this->Type())
1188  {
1190  $Id = $this->DB->Query("SELECT ClassificationId FROM Classifications"
1191  ." WHERE ClassificationName = '".addslashes($Value)."'"
1192  ." AND FieldId = ".$this->Id(),
1193  "ClassificationId");
1194  break;
1195 
1198  $Id = $this->DB->Query("SELECT ControlledNameId FROM ControlledNames"
1199  ." WHERE ControlledName = '".addslashes($Value)."'"
1200  ." AND FieldId = ".$this->Id(),
1201  "ControlledNameId");
1202  break;
1203 
1204  default:
1205  # for everything else return NULL
1206  $Id = NULL;
1207  break;
1208  }
1209 
1210  # return ID for value to caller
1211  return $Id;
1212  }
1213 
1219  public function GetValueForId($Id)
1220  {
1221  # retrieve ID based on field type
1222  switch ($this->Type())
1223  {
1225  $Value = $this->DB->Query("SELECT ClassificationName FROM Classifications"
1226  ." WHERE ClassificationId = '".intval($Id)."'"
1227  ." AND FieldId = ".$this->Id(),
1228  "ClassificationName");
1229  break;
1230 
1233  $Value = $this->DB->Query("SELECT ControlledName FROM ControlledNames"
1234  ." WHERE ControlledNameId = '".intval($Id)."'"
1235  ." AND FieldId = ".$this->Id(),
1236  "ControlledName");
1237  break;
1238 
1239  default:
1240  # for everything else return NULL
1241  $Value = NULL;
1242  break;
1243  }
1244 
1245  # return ID for value to caller
1246  return $Value;
1247  }
1248 
1259  public function ValueUseCount($Value)
1260  {
1261  # retrieve ID if object passed in
1262  if (is_object($Value) && method_exists($Value, "Id"))
1263  {
1264  $Value = $Value->Id();
1265  }
1266 
1267  # check value based on field type
1268  $DBFieldName = $this->DBFields["DBFieldName"];
1269  switch ($this->Type())
1270  {
1280  $UseCount = $this->DB->Query("SELECT COUNT(*) AS UseCount"
1281  ." FROM Resources"
1282  ." WHERE `".$DBFieldName."` = '".addslashes($Value)."'"
1283  ." AND SchemaId = ".intval($this->DBFields["SchemaId"]),
1284  "UseCount");
1285  break;
1286 
1288  $UseCount = $this->DB->Query("SELECT COUNT(*) AS UseCount"
1289  ." FROM ResourceClassInts"
1290  ." WHERE ClassificationId = ".intval($Value),
1291  "UseCount");
1292  break;
1293 
1296  $UseCount = $this->DB->Query("SELECT COUNT(*) AS UseCount"
1297  ." FROM ResourceNameInts"
1298  ." WHERE ControlledNameId = ".intval($Value),
1299  "UseCount");
1300  break;
1301 
1303  $UseCount = $this->DB->Query("SELECT COUNT(*) AS UseCount"
1304  ." FROM Resources"
1305  ." WHERE `".$DBFieldName."X` = '".$Value["X"]."'"
1306  ." AND `".$DBFieldName."Y` = '".$Value["Y"]."'"
1307  ." AND SchemaId = ".intval($this->DBFields["SchemaId"]),
1308  "UseCount");
1309  break;
1310 
1311  default:
1312  throw new Exception(__CLASS__."::".__METHOD__."() called for"
1313  ." unsupported field type (".$this->Type().").");
1314  break;
1315  }
1316 
1317  # report use count to caller
1318  return $UseCount;
1319  }
1320 
1327  public function HasItemLevelQualifiers($NewValue = DB_NOVALUE)
1328  {
1329  # if value provided different from present value
1330  if (($NewValue != DB_NOVALUE)
1331  && ($NewValue != $this->DBFields["HasItemLevelQualifiers"]))
1332  {
1333  # check if qualifier column currently exists
1334  $QualColName = $this->DBFieldName()."Qualifier";
1335  $QualColExists = $this->DB->FieldExists("Resources", $QualColName);
1336 
1337  # if new value indicates qualifiers should now be used
1338  if ($NewValue == TRUE)
1339  {
1340  # if qualifier column does not exist in DB for this field
1341  if ($QualColExists == FALSE)
1342  {
1343  # add qualifier column in DB for this field
1344  $this->DB->Query("ALTER TABLE Resources ADD COLUMN `"
1345  .$QualColName."` INT");
1346  }
1347  }
1348  else
1349  {
1350  # if qualifier column exists in DB for this field
1351  if ($QualColExists == TRUE)
1352  {
1353  # remove qualifier column from DB for this field
1354  $this->DB->Query("ALTER TABLE Resources DROP COLUMN `"
1355  .$QualColName."`");
1356  }
1357  }
1358  }
1359 
1360  return $this->UpdateValue("HasItemLevelQualifiers", $NewValue);
1361  }
1362 
1367  public function AssociatedQualifierList()
1368  {
1369  # start with empty list
1370  $List = array();
1371 
1372  # for each associated qualifier
1373  $this->DB->Query("SELECT QualifierId FROM FieldQualifierInts"
1374  ." WHERE MetadataFieldId = ".$this->DBFields["FieldId"]);
1375  while ($Record = $this->DB->FetchRow())
1376  {
1377  # load qualifier object
1378  $Qual = new Qualifier($Record["QualifierId"]);
1379 
1380  # add qualifier ID and name to list
1381  $List[$Qual->Id()] = $Qual->Name();
1382  }
1383 
1384  # return list to caller
1385  return $List;
1386  }
1387 
1392  public function UnassociatedQualifierList()
1393  {
1394  # grab list of associated qualifiers
1395  $AssociatedQualifiers = $this->AssociatedQualifierList();
1396 
1397  # get list of all qualifiers
1398  $QFactory = new QualifierFactory();
1399  $AllQualifiers = $QFactory->GetItemNames();
1400 
1401  # return list of unassociated qualifiers
1402  return array_diff($AllQualifiers, $AssociatedQualifiers);
1403  }
1404 
1410  public function AddQualifier($Qualifier)
1411  {
1412  # if qualifier object passed in
1413  if (is_object($Qualifier))
1414  {
1415  # grab qualifier ID from object
1416  $Qualifier = $Qualifier->Id();
1417  }
1418  # else if string passed in does not look like ID
1419  elseif (!is_numeric($Qualifier))
1420  {
1421  # assume string passed in is name and use it to retrieve ID
1422  $QFact = new QualifierFactory();
1423  $Qualifier = $QFact->GetItemIdByName($Qualifier);
1424  if ($Qualifier === FALSE)
1425  {
1426  throw new InvalidArgumentException("Unknown qualifier name (\""
1427  .$Qualifier."\").");
1428  }
1429  }
1430 
1431  # if not already associated
1432  $RecordCount = $this->DB->Query(
1433  "SELECT COUNT(*) AS RecordCount FROM FieldQualifierInts"
1434  ." WHERE QualifierId = ".$Qualifier
1435  ." AND MetadataFieldId = ".$this->Id(), "RecordCount");
1436  if ($RecordCount < 1)
1437  {
1438  # associate field with qualifier
1439  $this->DB->Query("INSERT INTO FieldQualifierInts SET"
1440  ." QualifierId = ".$Qualifier.","
1441  ." MetadataFieldId = ".$this->Id());
1442  }
1443  }
1444 
1445 
1446 
1451  public function UnassociateWithQualifier($QualifierIdOrObject)
1452  {
1453  # if qualifier object passed in
1454  if (is_object($QualifierIdOrObject))
1455  {
1456  # grab qualifier ID from object
1457  $QualifierIdOrObject = $QualifierIdOrObject->Id();
1458  }
1459 
1460  # delete intersection record from database
1461  $this->DB->Query("DELETE FROM FieldQualifierInts WHERE QualifierId = "
1462  .$QualifierIdOrObject." AND MetadataFieldId = ".
1463  $this->Id());
1464  }
1465 
1470  public function GetFactory()
1471  {
1472  switch ($this->Type())
1473  {
1475  $Factory = new ClassificationFactory($this->Id());
1476  break;
1477 
1480  $Factory = new ControlledNameFactory($this->Id());
1481  break;
1482 
1483  default:
1484  $Factory = NULL;
1485  break;
1486  }
1487 
1488  return $Factory;
1489  }
1490 
1499  public function UserCanView($User, $AllowHooksToModify=TRUE)
1500  {
1501  $CacheKey = "View".$User->Id() ."-".
1502  ($AllowHooksToModify ? "1" : "0");
1503 
1504  # see if we have a cached permission for this field and user
1505  if (!isset($this->PermissionCache[$CacheKey]))
1506  {
1507  if (!$this->Enabled())
1508  {
1509  # the field should not be viewed if it is disabled
1510  $this->PermissionCache[$CacheKey] = FALSE;
1511  }
1512  else
1513  {
1514 
1515  $Schema = new MetadataSchema($this->SchemaId());
1516 
1517  # otherwise, evaluate the perms
1518  $CheckResult =
1519  $Schema->ViewingPrivileges()->MeetsRequirements($User) &&
1520  $this->ViewingPrivileges()->MeetsRequirements($User);
1521 
1522  # and optionally
1523  if ($AllowHooksToModify)
1524  {
1525  $SignalResult = $GLOBALS["AF"]->SignalEvent(
1526  "EVENT_FIELD_VIEW_PERMISSION_CHECK", array(
1527  "Field" => $this,
1528  "Resource" => NULL,
1529  "User" => $User,
1530  "CanView" => $CheckResult));
1531  $CheckResult = $SignalResult["CanView"];
1532  }
1533 
1534  $this->PermissionCache[$CacheKey] = $CheckResult;
1535  }
1536  }
1537 
1538  return $this->PermissionCache[$CacheKey];
1539  }
1540 
1547  public function ReferenceableSchemaIds($Ids = DB_NOVALUE)
1548  {
1549  # if a new value was provided, convert it to a string
1550  if ($Ids != DB_NOVALUE)
1551  {
1552  if (is_array($Ids))
1553  {
1554  $Ids = implode(",", $Ids);
1555  }
1556  }
1557 
1558  # update/retrieve the value
1559  $Value = $this->UpdateValue(
1560  "ReferenceableSchemaIds", $Ids);
1561 
1562  # and convert stored string to an array
1563  return explode(",", $Value);
1564  }
1565 
1566  # ---- PRIVATE INTERFACE -------------------------------------------------
1567 
1568  private $DB;
1569  private $Id;
1570  private $DBFields;
1571  private $ErrorStatus;
1572  private $AuthoringPrivileges;
1573  private $EditingPrivileges;
1574  private $ViewingPrivileges;
1575  private $PreviewingPrivileges;
1576  private $PermissionCache;
1577 
1582  public static $FieldTypeHumanEnums = array(
1583  MetadataSchema::MDFTYPE_TEXT => "Text",
1584  MetadataSchema::MDFTYPE_PARAGRAPH => "Paragraph",
1585  MetadataSchema::MDFTYPE_NUMBER => "Number",
1586  MetadataSchema::MDFTYPE_DATE => "Date",
1587  MetadataSchema::MDFTYPE_TIMESTAMP => "Timestamp",
1588  MetadataSchema::MDFTYPE_FLAG => "Flag",
1589  MetadataSchema::MDFTYPE_TREE => "Tree",
1590  MetadataSchema::MDFTYPE_CONTROLLEDNAME => "Controlled Name",
1591  MetadataSchema::MDFTYPE_OPTION => "Option",
1592  MetadataSchema::MDFTYPE_USER => "User",
1593  MetadataSchema::MDFTYPE_IMAGE => "Image",
1594  MetadataSchema::MDFTYPE_FILE => "File",
1595  MetadataSchema::MDFTYPE_URL => "URL",
1596  MetadataSchema::MDFTYPE_POINT => "Point",
1597  MetadataSchema::MDFTYPE_REFERENCE => "Reference");
1598 
1599  # field type DB/PHP enum translations
1600  public static $FieldTypeDBEnums = array(
1601  MetadataSchema::MDFTYPE_TEXT => "Text",
1602  MetadataSchema::MDFTYPE_PARAGRAPH => "Paragraph",
1603  MetadataSchema::MDFTYPE_NUMBER => "Number",
1604  MetadataSchema::MDFTYPE_DATE => "Date",
1605  MetadataSchema::MDFTYPE_TIMESTAMP => "TimeStamp",
1606  MetadataSchema::MDFTYPE_FLAG => "Flag",
1607  MetadataSchema::MDFTYPE_TREE => "Tree",
1608  MetadataSchema::MDFTYPE_CONTROLLEDNAME => "ControlledName",
1609  MetadataSchema::MDFTYPE_OPTION => "Option",
1610  MetadataSchema::MDFTYPE_USER => "User",
1611  MetadataSchema::MDFTYPE_IMAGE => "Still Image",
1612  MetadataSchema::MDFTYPE_FILE => "File",
1613  MetadataSchema::MDFTYPE_URL => "Url",
1614  MetadataSchema::MDFTYPE_POINT => "Point",
1615  MetadataSchema::MDFTYPE_REFERENCE => "Reference"
1616  );
1617  public static $FieldTypeDBAllowedEnums = array(
1618  MetadataSchema::MDFTYPE_TEXT => "Text",
1619  MetadataSchema::MDFTYPE_PARAGRAPH => "Paragraph",
1620  MetadataSchema::MDFTYPE_NUMBER => "Number",
1621  MetadataSchema::MDFTYPE_DATE => "Date",
1622  MetadataSchema::MDFTYPE_TIMESTAMP => "TimeStamp",
1623  MetadataSchema::MDFTYPE_FLAG => "Flag",
1624  MetadataSchema::MDFTYPE_TREE => "Tree",
1625  MetadataSchema::MDFTYPE_CONTROLLEDNAME => "ControlledName",
1626  MetadataSchema::MDFTYPE_OPTION => "Option",
1627  MetadataSchema::MDFTYPE_USER => "User",
1628  MetadataSchema::MDFTYPE_IMAGE => "Still Image",
1629  MetadataSchema::MDFTYPE_FILE => "File",
1630  MetadataSchema::MDFTYPE_URL => "Url",
1631  MetadataSchema::MDFTYPE_POINT => "Point",
1632  MetadataSchema::MDFTYPE_REFERENCE => "Reference"
1633  );
1634  public static $FieldTypePHPEnums = array(
1635  "Text" => MetadataSchema::MDFTYPE_TEXT,
1636  "Paragraph" => MetadataSchema::MDFTYPE_PARAGRAPH,
1637  "Number" => MetadataSchema::MDFTYPE_NUMBER,
1638  "Date" => MetadataSchema::MDFTYPE_DATE,
1639  "TimeStamp" => MetadataSchema::MDFTYPE_TIMESTAMP,
1640  "Flag" => MetadataSchema::MDFTYPE_FLAG,
1641  "Tree" => MetadataSchema::MDFTYPE_TREE,
1642  "ControlledName" => MetadataSchema::MDFTYPE_CONTROLLEDNAME,
1643  "Option" => MetadataSchema::MDFTYPE_OPTION,
1644  "User" => MetadataSchema::MDFTYPE_USER,
1645  "Still Image" => MetadataSchema::MDFTYPE_IMAGE,
1646  "File" => MetadataSchema::MDFTYPE_FILE,
1647  "Url" => MetadataSchema::MDFTYPE_URL,
1648  "Point" => MetadataSchema::MDFTYPE_POINT,
1649  "Reference" => MetadataSchema::MDFTYPE_REFERENCE
1650  );
1651 
1652  public static $UpdateTypes = array(
1653  self::UPDATEMETHOD_NOAUTOUPDATE => "Do not update automatically",
1654  self::UPDATEMETHOD_ONRECORDCREATE => "Update on record creation",
1655  self::UPDATEMETHOD_BUTTON => "Provide an update button",
1656  self::UPDATEMETHOD_ONRECORDEDIT => "Update when record is edited",
1657  self::UPDATEMETHOD_ONRECORDCHANGE => "Update when record is changed"
1658  );
1659 
1673  public static function Create($SchemaId, $FieldType, $FieldName,
1674  $Optional = NULL, $DefaultValue = NULL)
1675  {
1676  # error out if field type is bad
1677  if (empty(self::$FieldTypeDBEnums[$FieldType]))
1678  {
1679  throw new InvalidArgumentException("Bad field type (".$FieldType.").");
1680  }
1681 
1682  # error out if field name is duplicate
1683  $DB = new Database();
1684  $FieldName = trim($FieldName);
1685  $DuplicateCount = $DB->Query(
1686  "SELECT COUNT(*) AS RecordCount FROM MetadataFields"
1687  ." WHERE FieldName = '".addslashes($FieldName)."'"
1688  ." AND SchemaId = ".intval($SchemaId),
1689  "RecordCount");
1690  if ($DuplicateCount > 0)
1691  {
1692  throw new InvalidArgumentException("Duplicate field name (".$FieldName.").");
1693  }
1694 
1695  # grab current user ID
1696  $UserId = $GLOBALS["G_User"]->Get("UserId");
1697 
1698  # normalize schema ID
1699  $Schema = new MetadataSchema($SchemaId);
1700  $SchemaId = $Schema->Id();
1701 
1702  # use schema privileges as starting privilege values
1703  $AuthorPrivs = $Schema->AuthoringPrivileges();
1704  $EditPrivs = $Schema->EditingPrivileges();
1705  $ViewPrivs = $Schema->ViewingPrivileges();
1706  $PreviewPrivs = $Schema->ViewingPrivileges();
1707 
1708  # lock DB tables and get next temporary field ID
1709  $DB->Query("LOCK TABLES MetadataFields WRITE");
1710  $FieldId = $Schema->GetNextTempItemId();
1711 
1712  # add field to MDF table in database
1713  $DB->Query("INSERT INTO MetadataFields"
1714  ." (FieldId, SchemaId, FieldName, FieldType, LastModifiedById,"
1715  ." Optional, AuthoringPrivileges, EditingPrivileges,"
1716  ." ViewingPrivileges, PreviewingPrivileges)"
1717  ." VALUES ("
1718  .intval($FieldId).", "
1719  .intval($SchemaId).","
1720  ." '".addslashes($FieldName)."',"
1721  ." '".self::$FieldTypeDBEnums[$FieldType]."', "
1722  .intval($UserId).", "
1723  .($Optional ? "1" : "0").","
1724  ."'".$DB->EscapeString($AuthorPrivs->Data())."',"
1725  ."'".$DB->EscapeString($EditPrivs->Data())."',"
1726  ."'".$DB->EscapeString($ViewPrivs->Data())."',"
1727  ."'".$DB->EscapeString($PreviewPrivs->Data())."')");
1728 
1729  # release DB tables
1730  $DB->Query("UNLOCK TABLES");
1731 
1732  # nuke potentially stale cache information
1733  self::$FieldCache = NULL;
1734 
1735  # load field object
1736  $Field = new MetadataField($FieldId);
1737 
1738  # set field defaults
1739  $Field->SetDefaults();
1740 
1741  # set the default value if specified
1742  if ($DefaultValue !== NULL)
1743  {
1744  $Field->DefaultValue($DefaultValue);
1745  }
1746 
1747  # return newly-constructed field to caller
1748  return $Field;
1749  }
1750 
1757  public function __construct($FieldId)
1758  {
1759  # assume everything will be okay
1760  $this->ErrorStatus = MetadataSchema::MDFSTAT_OK;
1761 
1762  # check if we have cached field info
1763  $this->DB = new Database();
1764  if (self::$FieldCache === NULL)
1765  {
1766  # if not, retrieve field info from database
1767  $this->DB->Query("SELECT * FROM MetadataFields");
1768  while ($Row = $this->DB->FetchRow())
1769  {
1770  self::$FieldCache[$Row["FieldId"]] = $Row;
1771  }
1772  }
1773 
1774  # error if requested field did not exist
1775  if (!array_key_exists($FieldId, self::$FieldCache) )
1776  {
1777  throw new InvalidArgumentException("Invalid metadata field ID ("
1778  .$FieldId.") from "
1779  .StdLib::GetMyCaller().".");
1780  }
1781  $Row = self::$FieldCache[$FieldId];
1782  $this->DBFields = $Row;
1783  $this->Id = $FieldId;
1784 
1785  # if privileges have not yet been initialized
1786  if (!strlen($this->DBFields["AuthoringPrivileges"]))
1787  {
1788  # set default values for privileges from metadata schema
1789  $Schema = new MetadataSchema($Row["SchemaId"]);
1790  $this->AuthoringPrivileges($Schema->AuthoringPrivileges());
1791  $this->EditingPrivileges($Schema->EditingPrivileges());
1792  $this->ViewingPrivileges($Schema->ViewingPrivileges());
1793  $this->PreviewingPrivileges($Schema->ViewingPrivileges());
1794  }
1795  else
1796  {
1797  # set privileges from stored values
1798  $this->AuthoringPrivileges = new PrivilegeSet(
1799  $Row["AuthoringPrivileges"]);
1800  $this->EditingPrivileges = new PrivilegeSet(
1801  $Row["EditingPrivileges"]);
1802  $this->ViewingPrivileges = new PrivilegeSet(
1803  $Row["ViewingPrivileges"]);
1804  $this->PreviewingPrivileges = new PrivilegeSet(
1805  $Row["PreviewingPrivileges"]);
1806  }
1807 
1808  # set database column name
1809  $this->DBFields["DBFieldName"] =
1810  $this->NormalizeFieldNameForDB($this->DBFields["FieldName"]);
1811  }
1812 
1817  public static $FixedDefaults = array(
1818  "Label" => NULL,
1819  "Description" => NULL,
1820  "Instructions" => NULL,
1821  "Enabled" => TRUE,
1822  "Optional" => TRUE,
1823  "Editable" => TRUE,
1824  "CopyOnResourceDuplication" => TRUE,
1825  "AllowMultiple" => FALSE,
1826  "IncludeInKeywordSearch" => FALSE,
1827  "IncludeInAdvancedSearch" => FALSE,
1828  "IncludeInFacetedSearch" => FALSE,
1829  "SearchGroupLogic" => SearchEngine::LOGIC_OR,
1830  "IncludeInSortOptions" => TRUE,
1831  "IncludeInRecommender" => FALSE,
1832  "ParagraphRows" => 4,
1833  "ParagraphCols" => 50,
1834  "MinValue" => 1,
1835  "FlagOnLabel" => "On",
1836  "FlagOffLabel" => "Off",
1837  "DateFormat" => NULL,
1838  "RecommenderWeight" => 1,
1839  "MaxHeight" => 500,
1840  "MaxWidth" => 500,
1841  "MaxPreviewHeight" => 100,
1842  "MaxPreviewWidth" => 100,
1843  "MaxThumbnailHeight" => 50,
1844  "MaxThumbnailWidth" => 50,
1845  "DefaultAltText" => NULL,
1846  "UsesQualifiers" => FALSE,
1847  "HasItemLevelQualifiers" => FALSE,
1848  "ShowQualifiers" => FALSE,
1849  "DefaultQualifier" => NULL,
1850  "AllowHTML" => FALSE,
1851  "UseWysiwygEditor" => FALSE,
1852  "UseForOaiSets" => FALSE,
1853  "DisplayAsListForAdvancedSearch" => FALSE,
1854  "MaxDepthForAdvancedSearch" => 1,
1855  "OptionListThreshold" => 25,
1856  "AjaxThreshold" => 50,
1857  "NumAjaxResults" => 50,
1858  "PointPrecision" => 8,
1859  "PointDecimalDigits" => 5,
1860  "UserPrivilegeRestrictions" => array(),
1861  "UpdateMethod" => "NoAutoUpdate",
1862  # 9999 is the default max value because default number field length is 4
1863  "MaxValue" => 9999);
1864 
1869  public static $TypeBasedDefaults = array(
1871  "DefaultValue" => NULL,
1872  "SearchWeight" => 1,
1873  "TextFieldSize" => 50,
1874  "MaxLength" => 100),
1876  "DefaultValue" => NULL,
1877  "SearchWeight" => 1,
1878  "TextFieldSize" => 50,
1879  "MaxLength" => 100),
1881  "DefaultValue" => NULL,
1882  "SearchWeight" => 1,
1883  "TextFieldSize" => 4,
1884  "MaxLength" => 100),
1886  "DefaultValue" => NULL,
1887  "SearchWeight" => 1,
1888  "TextFieldSize" => 10,
1889  "MaxLength" => 100),
1891  "DefaultValue" => NULL,
1892  "SearchWeight" => 1,
1893  "TextFieldSize" => 50,
1894  "MaxLength" => 100),
1896  "DefaultValue" => NULL,
1897  "SearchWeight" => 1,
1898  "TextFieldSize" => 50,
1899  "MaxLength" => 100),
1901  "DefaultValue" => NULL,
1902  "SearchWeight" => 1,
1903  "AllowMultiple" => TRUE,
1904  "TextFieldSize" => 50,
1905  "MaxLength" => 100),
1907  "DefaultValue" => NULL,
1908  "SearchWeight" => 3,
1909  "AllowMultiple" => TRUE,
1910  "TextFieldSize" => 50,
1911  "MaxLength" => 100),
1913  "DefaultValue" => NULL,
1914  "SearchWeight" => 3,
1915  "TextFieldSize" => 50,
1916  "MaxLength" => 100),
1918  "DefaultValue" => NULL,
1919  "SearchWeight" => 1,
1920  "TextFieldSize" => 50,
1921  "MaxLength" => 100),
1923  "DefaultValue" => NULL,
1924  "CopyOnResourceDuplication" => FALSE,
1925  "SearchWeight" => 1,
1926  "TextFieldSize" => 50,
1927  "MaxLength" => 100),
1929  "DefaultValue" => NULL,
1930  "CopyOnResourceDuplication" => FALSE,
1931  "AllowMultiple" => TRUE,
1932  "SearchWeight" => 1,
1933  "TextFieldSize" => 50,
1934  "MaxLength" => 100),
1935  MetadataSchema::MDFTYPE_URL => array(
1936  "DefaultValue" => NULL,
1937  "SearchWeight" => 1,
1938  "TextFieldSize" => 50,
1939  "MaxLength" => 255),
1941  "DefaultValue" => array("X" => NULL, "Y" => NULL),
1942  "SearchWeight" => 1,
1943  "TextFieldSize" => 10,
1944  "MaxLength" => 100),
1946  "DefaultValue" => NULL,
1947  "SearchWeight" => 1,
1948  "TextFieldSize" => 50,
1949  "MaxLength" => 100,
1950  "ReferenceableSchemaIds" => array(
1952 
1956  public function SetDefaults()
1957  {
1958  # set defaults that are the same for every field
1959  foreach (self::$FixedDefaults as $Key => $Value)
1960  {
1961  $this->$Key($Value);
1962  }
1963 
1964  # set defaults that depend on the type of the field
1965  foreach (self::$TypeBasedDefaults[$this->Type()] as $Key => $Value)
1966  {
1967  $this->$Key($Value);
1968  }
1969 
1970  # tweak the update method if dealing with the date of record creation
1971  if ($this->Name() == "Date Of Record Creation")
1972  {
1973  $this->UpdateMethod("OnRecordCreate");
1974  }
1975  }
1976 
1977 
1981  public function Drop()
1982  {
1984  "MetadataSchema",
1985  "Attempt to update drop Metadata Field at %FILE%:%LINE%."
1986  ." (Fields may only be dropped by MetadataSchema.)");
1987 
1988  # clear other database entries as appropriate for field type
1989  $DB = $this->DB;
1990  $DBFieldName = $this->DBFields["DBFieldName"];
1991  $Schema = new MetadataSchema($this->SchemaId());
1992  switch (self::$FieldTypePHPEnums[$this->DBFields["FieldType"]])
1993  {
2002  # remove field from resources table
2003  if ($DB->FieldExists("Resources", $DBFieldName))
2004  {
2005  $DB->Query("ALTER TABLE Resources DROP COLUMN `".$DBFieldName."`");
2006  }
2007  break;
2008 
2010  if ($DB->FieldExists("Resources", $DBFieldName."X"))
2011  {
2012  $DB->Query("ALTER TABLE Resources DROP COLUMN `".$DBFieldName."X`");
2013  $DB->Query("ALTER TABLE Resources DROP COLUMN `".$DBFieldName."Y`");
2014  }
2015  break;
2016 
2018  # remove fields from resources table
2019  if ($DB->FieldExists("Resources", $DBFieldName."Begin"))
2020  {
2021  $DB->Query("ALTER TABLE Resources "
2022  ."DROP COLUMN `".$DBFieldName."Begin`");
2023  $DB->Query("ALTER TABLE Resources "
2024  ."DROP COLUMN `".$DBFieldName."End`");
2025  $DB->Query("ALTER TABLE Resources "
2026  ."DROP COLUMN `".$DBFieldName."Precision`");
2027  }
2028  break;
2029 
2031  $DB->Query("SELECT ClassificationId FROM Classifications "
2032  ."WHERE FieldId = ".$this->Id());
2033  $TempDB = new Database();
2034  while ($ClassificationId = $DB->FetchField("ClassificationId"))
2035  {
2036  # remove any resource / name intersections
2037  $TempDB->Query("DELETE FROM ResourceClassInts WHERE "
2038  ."ClassificationId = ".$ClassificationId);
2039 
2040  # remove controlled name
2041  $TempDB->Query("DELETE FROM Classifications WHERE "
2042  ."ClassificationId = ".$ClassificationId);
2043  }
2044  break;
2045 
2048  $DB->Query("SELECT ControlledNameId FROM ControlledNames "
2049  ."WHERE FieldId = ".$this->Id());
2050  $TempDB = new Database();
2051  while ($ControlledNameId = $DB->FetchField("ControlledNameId"))
2052  {
2053  # remove any resource / name intersections
2054  $TempDB->Query("DELETE FROM ResourceNameInts WHERE "
2055  ."ControlledNameId = ".$ControlledNameId);
2056 
2057  # remove any variant names
2058  $TempDB->Query("DELETE FROM VariantNames WHERE "
2059  ."ControlledNameId = ".$ControlledNameId);
2060 
2061  # remove controlled name
2062  $TempDB->Query("DELETE FROM ControlledNames WHERE "
2063  ."ControlledNameId = ".$ControlledNameId);
2064  }
2065  break;
2066 
2068  # for each file associated with this field
2069  $DB->Query("SELECT FileId FROM Files WHERE FieldId = '".$this->Id()."'");
2070  while ($FileId = $DB->FetchRow())
2071  {
2072  # delete file
2073  $File = new File(intval($FileId));
2074  $File->Delete();
2075  }
2076  break;
2077 
2079  # remove any resource references for the field
2080  $DB->Query("
2081  DELETE FROM ReferenceInts
2082  WHERE FieldId = '".addslashes($this->Id())."'");
2083  break;
2084  }
2085 
2086  # remove field from database
2087  $DB->Query("DELETE FROM MetadataFields "
2088  ."WHERE FieldId = '".$this->DBFields["FieldId"]."'");
2089 
2090  # remove any qualifier associations
2091  $DB->Query("DELETE FROM FieldQualifierInts WHERE MetadataFieldId = '"
2092  .$this->DBFields["FieldId"]."'");
2093 
2094  # get the order objects the field is part of
2095  foreach (MetadataFieldOrder::GetOrdersForSchema($Schema) as $Order)
2096  {
2097  # remove it if it's a direct descendant
2098  $Order->RemoveItem($this->Id(), "MetadataField");
2099 
2100  # also make sure to remove it if it's part of a group
2101  foreach ($Order->GetItemIds() as $Item)
2102  {
2103  if ($Item["Type"] == "MetadataFieldGroup")
2104  {
2105  $Group = new MetadataFieldGroup($Item["ID"]);
2106  $Group->RemoveItem($this->Id(), "MetadataField");
2107  }
2108  }
2109  }
2110 
2111  # nuke stale field cache
2112  self::$FieldCache = NULL;
2113  }
2114 
2122  private function ModifyField($NewName = NULL, $NewType = NULL)
2123  {
2124  # grab old DB field name
2125  $OldDBFieldName = $this->DBFields["DBFieldName"];
2126  $OldFieldType = NULL;
2127 
2128  # if new field name supplied
2129  if ($NewName != NULL)
2130  {
2131  # cache the old name for options and controllednames below
2132  $OldName = $this->DBFields["FieldName"];
2133 
2134  # store new name
2135  $this->UpdateValue("FieldName", $NewName);
2136 
2137  # determine new DB field name
2138  $NewDBFieldName = $this->NormalizeFieldNameForDB($NewName);
2139 
2140  # store new database field name
2141  $this->DBFields["DBFieldName"] = $NewDBFieldName;
2142  }
2143  else
2144  {
2145  # set new field name equal to old field name
2146  $NewDBFieldName = $OldDBFieldName;
2147  }
2148 
2149  # if new type supplied
2150  if ($NewType != NULL)
2151  {
2152  # grab old field type
2153  $OldFieldType = self::$FieldTypePHPEnums[$this->DBFields["FieldType"]];
2154 
2155  # store new field type
2156  $this->UpdateValue("FieldType", self::$FieldTypeDBEnums[$NewType]);
2157  }
2158 
2159  # if this is not a temporary field
2160  if ($this->Id() >= 0)
2161  {
2162  # modify field in DB as appropriate for field type
2163  $DB = $this->DB;
2164  $FieldType = self::$FieldTypePHPEnums[$this->DBFields["FieldType"]];
2165  switch ($FieldType)
2166  {
2170  # alter field declaration in Resources table
2171  $DB->Query("ALTER TABLE Resources CHANGE COLUMN `"
2172  .$OldDBFieldName."` `"
2173  .$NewDBFieldName."` TEXT DEFAULT NULL");
2174  break;
2175 
2177  # alter field declaration in Resources table
2178  $DB->Query("ALTER TABLE Resources CHANGE COLUMN `"
2179  .$OldDBFieldName."` `"
2180  .$NewDBFieldName."` INT DEFAULT NULL");
2181 
2182  break;
2183 
2185  $Precision = $this->UpdateValue("PointPrecision",
2186  DB_NOVALUE);
2187  $Digits = $this->UpdateValue("PointDecimalDigits",
2188  DB_NOVALUE);
2189  $DB->Query("ALTER TABLE Resources CHANGE COLUMN "
2190  ."`".$OldDBFieldName."X` "
2191  ."`".$NewDBFieldName."X`".
2192  " DECIMAL(".$Precision.",".$Digits.")");
2193  $DB->Query("ALTER TABLE Resources CHANGE COLUMN "
2194  ."`".$OldDBFieldName."Y` "
2195  ."`".$NewDBFieldName."Y`".
2196  " DECIMAL(".$Precision.",".$Digits.")");
2197  break;
2198 
2200  # alter field declaration in Resources table
2201  $DB->Query("ALTER TABLE Resources CHANGE COLUMN `"
2202  .$OldDBFieldName."` `"
2203  .$NewDBFieldName."` INT"
2204  ." DEFAULT ".intval($this->DefaultValue()));
2205 
2206  # set any unset values to default
2207  $DB->Query("UPDATE Resources SET `".$NewDBFieldName
2208  ."` = ".intval($this->DefaultValue())
2209  ." WHERE `".$NewDBFieldName."` IS NULL");
2210  break;
2211 
2213  # if new type supplied and new type is different from old
2214  if (($NewType != NULL) && ($NewType != $OldFieldType))
2215  {
2216  # if old type was time stamp
2217  if ($OldFieldType == MetadataSchema::MDFTYPE_TIMESTAMP)
2218  {
2219  # change time stamp field in resources table to begin date
2220  $DB->Query("ALTER TABLE Resources CHANGE COLUMN `"
2221  .$OldDBFieldName."` `"
2222  .$NewDBFieldName."Begin` DATE "
2223  ."DEFAULT NULL");
2224 
2225  # add end date and precision fields
2226  $DB->Query("ALTER TABLE Resources "
2227  ."ADD COLUMN `".$NewDBFieldName."End` DATE");
2228  $DB->Query("ALTER TABLE Resources "
2229  ."ADD COLUMN `".$NewDBFieldName."Precision`"
2230  ."INT DEFAULT NULL");
2231 
2232 
2233  # set precision to reflect time stamp content
2234  $DB->Query("UPDATE Resources "
2235  ."SET `".$NewDBFieldName."Precision` = "
2236  .(DATEPRE_BEGINYEAR|DATEPRE_BEGINMONTH
2237  |DATEPRE_BEGINDAY));
2238  }
2239  else
2240  {
2241  exit("<br>ERROR: Attempt to convert metadata field "
2242  ."to date from type other than timestamp<br>\n");
2243  }
2244  }
2245  else
2246  {
2247  # change name of fields
2248  $DB->Query("ALTER TABLE Resources CHANGE COLUMN `"
2249  .$OldDBFieldName."Begin` `"
2250  .$NewDBFieldName."Begin` DATE "
2251  ."DEFAULT NULL");
2252  $DB->Query("ALTER TABLE Resources CHANGE COLUMN `"
2253  .$OldDBFieldName."End` `"
2254  .$NewDBFieldName."End` DATE "
2255  ."DEFAULT NULL");
2256  $DB->Query("ALTER TABLE Resources CHANGE COLUMN `"
2257  .$OldDBFieldName."Precision` `"
2258  .$NewDBFieldName."Precision` INT "
2259  ."DEFAULT NULL");
2260  }
2261  break;
2262 
2264  # if new type supplied and new type is different from old
2265  if (($NewType != NULL) && ($NewType != $OldFieldType))
2266  {
2267  # if old type was date
2268  if ($OldFieldType == MetadataSchema::MDFTYPE_DATE)
2269  {
2270  # change begin date field in resource table to time stamp
2271  $DB->Query("ALTER TABLE Resources CHANGE COLUMN `"
2272  .$OldDBFieldName."Begin` `"
2273  .$NewDBFieldName."` DATETIME "
2274  ."DEFAULT NULL");
2275 
2276  # drop end date and precision fields
2277  $DB->Query("ALTER TABLE Resources DROP COLUMN `"
2278  .$OldDBFieldName."End`");
2279  $DB->Query("ALTER TABLE Resources DROP COLUMN `"
2280  .$OldDBFieldName."Precision`");
2281  }
2282  else
2283  {
2284  exit("<br>ERROR: Attempt to convert metadata field to "
2285  ."time stamp from type other than date<br>\n");
2286  }
2287  }
2288  else
2289  {
2290  # change name of field
2291  $DB->Query("ALTER TABLE Resources CHANGE COLUMN `"
2292  .$OldDBFieldName."` `"
2293  .$NewDBFieldName."` DATETIME "
2294  ."DEFAULT NULL");
2295  }
2296  break;
2297 
2304  break;
2305  }
2306 
2307  # if qualifier DB field exists
2308  if ($DB->FieldExists("Resources", $OldDBFieldName."Qualifier"))
2309  {
2310  # rename qualifier DB field
2311  $DB->Query("ALTER TABLE Resources CHANGE COLUMN `"
2312  .$OldDBFieldName."Qualifier` `"
2313  .$NewDBFieldName."Qualifier` INT ");
2314  }
2315  }
2316  }
2317 
2324  private function UpdateValue($FieldName, $NewValue)
2325  {
2326  # nuke stale field cache
2327  self::$FieldCache = NULL;
2328 
2329  return $this->DB->UpdateValue("MetadataFields", $FieldName, $NewValue,
2330  "FieldId = ".intval($this->DBFields["FieldId"]),
2331  $this->DBFields);
2332  }
2333 
2340  private function UpdateIntValue($FieldName, $NewValue)
2341  {
2342  # nuke stale field cache
2343  self::$FieldCache = NULL;
2344 
2345  return $this->DB->UpdateIntValue("MetadataFields", $FieldName, $NewValue,
2346  "FieldId = ".intval($this->DBFields["FieldId"]),
2347  $this->DBFields);
2348  }
2349 
2356  private function UpdateFloatValue($FieldName, $NewValue)
2357  {
2358  # nuke stale field cache
2359  self::$FieldCache = NULL;
2360 
2361  return $this->DB->UpdateFloatValue("MetadataFields", $FieldName, $NewValue,
2362  "FieldId = ".intval($this->DBFields["FieldId"]),
2363  $this->DBFields);
2364  }
2365 
2372  private function UpdateBoolValue($FieldName, $NewValue)
2373  {
2374  # nuke stale field cache
2375  self::$FieldCache = NULL;
2376 
2377  $NewValue = $this->TranslateStringToConstants($NewValue);
2378  return $this->DB->UpdateIntValue("MetadataFields", $FieldName, $NewValue,
2379  "FieldId = ".intval($this->DBFields["FieldId"]),
2380  $this->DBFields);
2381  }
2382 
2390  private function UpdateConstValue($FieldName, $NewValue, $ClassName=NULL)
2391  {
2392  # nuke stale field cache
2393  self::$FieldCache = NULL;
2394 
2395  $NewValue = $this->TranslateStringToConstants($NewValue, $ClassName);
2396  return $this->DB->UpdateIntValue("MetadataFields", $FieldName, $NewValue,
2397  "FieldId = ".intval($this->DBFields["FieldId"]),
2398  $this->DBFields);
2399  }
2400 
2406  private function NormalizeFieldNameForDB($Name)
2407  {
2408  return preg_replace("/[^a-z0-9]/i", "", $Name)
2409  .(($this->SchemaId() != MetadataSchema::SCHEMAID_DEFAULT)
2410  ? $this->SchemaId() : "");
2411  }
2412 
2416  private function AddDatabaseFields()
2417  {
2418  # grab values for common use
2419  $DB = $this->DB;
2420  $DBFieldName = $this->DBFieldName();
2421 
2422  # set up field(s) based on field type
2423  switch ($this->Type())
2424  {
2428  # add field to resources table (if not already present)
2429  if (!$DB->FieldExists("Resources", $DBFieldName))
2430  {
2431  $DB->Query("ALTER TABLE Resources ADD COLUMN `".$DBFieldName
2432  ."` TEXT DEFAULT NULL");
2433  }
2434 
2435  break;
2436 
2438  # add field to resources table (if not already present)
2439  if (!$DB->FieldExists("Resources", $DBFieldName))
2440  {
2441  $DB->Query("ALTER TABLE Resources ADD COLUMN `".$DBFieldName
2442  ."` INT DEFAULT NULL");
2443  }
2444  break;
2445 
2447  if (!$DB->FieldExists("Resources", $DBFieldName."X"))
2448  {
2449  $Precision = $this->UpdateValue("PointPrecision",
2450  DB_NOVALUE);
2451  $Digits = $this->UpdateValue("PointDecimalDigits",
2452  DB_NOVALUE);
2453 
2454  $DB->Query("ALTER TABLE Resources ADD COLUMN `"
2455  .$DBFieldName."X`".
2456  " DECIMAL(".$Precision.",".$Digits.") DEFAULT NULL");
2457  $DB->Query("ALTER TABLE Resources ADD COLUMN `"
2458  .$DBFieldName."Y`".
2459  " DECIMAL(".$Precision.",".$Digits.") DEFAULT NULL");
2460  }
2461 
2462  break;
2464  # if field is not already present in database
2465  if (!$DB->FieldExists("Resources", $DBFieldName))
2466  {
2467  # add field to resources table
2468  $DB->Query("ALTER TABLE Resources ADD COLUMN `".$DBFieldName
2469  ."` INT DEFAULT NULL");
2470  }
2471  break;
2472 
2474  # add fields to resources table (if not already present)
2475  if (!$DB->FieldExists("Resources", $DBFieldName."Begin"))
2476  {
2477  $DB->Query("ALTER TABLE Resources ADD COLUMN `".$DBFieldName."Begin`"
2478  ." DATE DEFAULT NULL");
2479  }
2480  if (!$DB->FieldExists("Resources", $DBFieldName."End"))
2481  {
2482  $DB->Query("ALTER TABLE Resources ADD COLUMN `".$DBFieldName."End`"
2483  ." DATE DEFAULT NULL");
2484  }
2485  if (!$DB->FieldExists("Resources", $DBFieldName."Precision"))
2486  {
2487  $DB->Query("ALTER TABLE Resources "
2488  ."ADD COLUMN `".$DBFieldName."Precision`"
2489  ." INT DEFAULT NULL");
2490  }
2491  break;
2492 
2494  # add fields to resources table (if not already present)
2495  if (!$DB->FieldExists("Resources", $DBFieldName))
2496  {
2497  $DB->Query("ALTER TABLE Resources ADD COLUMN `".$DBFieldName
2498  ."` DATETIME DEFAULT NULL");
2499  }
2500  break;
2501 
2509  break;
2510 
2511  default:
2512  exit("<br>ERROR: Attempt to add database fields "
2513  ."for illegal metadata field type<br>\n");
2514  break;
2515  }
2516  }
2517 
2525  private function TranslateStringToConstants($CString, $ClassName = NULL)
2526  {
2527  # if not a string return value unchanged to caller
2528  if (!is_string($CString) || ($CString === DB_NOVALUE))
2529  {
2530  $ReturnValue = $CString;
2531  }
2532  # handle booleans as a special case
2533  elseif (strtoupper(trim($CString)) == "TRUE")
2534  {
2535  $ReturnValue = TRUE;
2536  }
2537  elseif (strtoupper(trim($CString)) == "FALSE")
2538  {
2539  $ReturnValue = FALSE;
2540  }
2541  else
2542  {
2543  # assume no values will be found
2544  $ReturnValue = NULL;
2545 
2546  # split apart any ORed-together values
2547  $Values = explode("|", $CString);
2548 
2549  # for each value found
2550  foreach ($Values as $Value)
2551  {
2552  # trim off any extraneous whitespace
2553  $Value = trim($Value);
2554 
2555  # add class name prefix to constant name if requested
2556  if ($ClassName) { $Value = $ClassName."::".$Value; }
2557 
2558  # if value corresponds to a constant
2559  if (defined($Value))
2560  {
2561  # add constant to return value
2562  $ReturnValue = ($ReturnValue === NULL)
2563  ? constant($Value)
2564  : ($ReturnValue | constant($Value));
2565  }
2566  }
2567 
2568  # if no corresponding constants were found
2569  if ($ReturnValue === NULL)
2570  {
2571  # return original value to caller
2572  $ReturnValue = $CString;
2573  }
2574  }
2575 
2576  # return result to caller
2577  return $ReturnValue;
2578  }
2579 
2583  private static $FieldCache = NULL;
2584 
2585 
2586  # ---- DEPRECATED METHODS ------------------------------------------------
2587  #
2588  # These are maintained only for backward compatibility with older
2589  # code. Newer code should not use them.
2590  #
2591  // @codingStandardsIgnoreStart
2592 
2593  public function Viewable()
2594  {
2595  return $this->UserCanView( $GLOBALS["G_User"] );
2596  }
2597 
2601  public function AssociateWithQualifier($Qualifier)
2602  {
2603  $this->AddQualifier($Qualifier);
2604  }
2605 
2606  public function UserPrivilegeRestrictions($NewValue = DB_NOVALUE)
2607  {
2608  # new value
2609  if ($NewValue != DB_NOVALUE)
2610  {
2611  $NewValue = serialize((array) $NewValue);
2612  }
2613 
2614  $Value = $this->UpdateValue("UserPrivilegeRestrictions", $NewValue);
2615 
2616  # value set
2617  if (strlen($Value))
2618  {
2619  $Value = (array) unserialize($Value);
2620  }
2621 
2622  # no value set, set it to an empty array
2623  else
2624  {
2625  $Value = $this->UserPrivilegeRestrictions(array());
2626  }
2627 
2628  return $Value;
2629  }
2630 
2631  public function AuthoringUserIsValue($NewValue = DB_NOVALUE)
2632  {
2633  return $this->UpdateConstValue(
2634  "AuthoringUserIsValue", $NewValue, "MetadataField");
2635  }
2636 
2637  public function EditingUserIsValue($NewValue = DB_NOVALUE)
2638  {
2639  return $this->UpdateConstValue("EditingUserIsValue", $NewValue, "MetadataField");
2640  }
2641 
2642  public function ViewingUserValue($NewValue = DB_NOVALUE)
2643  {
2644  return $this->UpdateIntValue("ViewingUserValue", $NewValue, "MetadataField");
2645  }
2646 
2647  public function AuthoringUserValue($NewValue = DB_NOVALUE)
2648  {
2649  return $this->UpdateIntValue("AuthoringUserValue", $NewValue, "MetadataField");
2650  }
2651 
2652  public function EditingUserValue($NewValue = DB_NOVALUE)
2653  {
2654  return $this->UpdateIntValue("EditingUserValue", $NewValue, "MetadataField");
2655  }
2656 
2657  public function ViewingUserIsValue($NewValue = DB_NOVALUE)
2658  {
2659  return $this->UpdateConstValue("ViewingUserIsValue", $NewValue, "MetadataField");
2660  }
2661 
2662  public function EnableOnOwnerReturn($NewValue = DB_NOVALUE)
2663  {
2664  return $this->UpdateBoolValue("EnableOnOwnerReturn", $NewValue);
2665  }
2666 
2667  public function ViewingPrivilege($NewValue = DB_NOVALUE)
2668  {
2669  if ($NewValue === DB_NOVALUE)
2670  {
2671  return $this->ViewingPrivileges();
2672  }
2673  else
2674  {
2675  throw new Exception("Deprecated ".__METHOD__."() called -- ".
2676  __METHOD__."s() should be used instead.");
2677  }
2678  }
2679 
2680  public function AuthoringPrivilege($NewValue = DB_NOVALUE)
2681  {
2682  if ($NewValue === DB_NOVALUE)
2683  {
2684  return $this->AuthoringPrivileges();
2685  }
2686  else
2687  {
2688  throw new Exception("Deprecated ".__METHOD__."() called -- ".
2689  __METHOD__."s() should be used instead.");
2690  }
2691  }
2692 
2693  public function EditingPrivilege($NewValue = DB_NOVALUE)
2694  {
2695  if ($NewValue === DB_NOVALUE)
2696  {
2697  return $this->EditingPrivileges();
2698  }
2699  else
2700  {
2701  throw new Exception("Deprecated ".__METHOD__."() called -- ".
2702  __METHOD__."s() should be used instead.");
2703  }
2704  }
2705 
2706  public function ImagePreviewPrivilege($NewValue = DB_NOVALUE)
2707  {
2708  if ($NewValue === DB_NOVALUE)
2709  {
2710  return $this->ViewingPrivileges();
2711  }
2712  else
2713  {
2714  throw new Exception("Deprecated ".__METHOD__."() called -- ".
2715  "ViewingPrivileges() should be used instead.");
2716  }
2717  }
2718 
2719  public function TreeBrowsingPrivilege($NewValue = DB_NOVALUE)
2720  {
2721  if ($NewValue === DB_NOVALUE)
2722  {
2723  return $this->ViewingPrivileges();
2724  }
2725  else
2726  {
2727  throw new Exception("Deprecated ".__METHOD__."() called -- ".
2728  "this should probably be using ViewingPrivileges() instead.");
2729  }
2730  }
2731 
2732 
2733  // @codingStandardsIgnoreEnd
2734 }
const MDFSTAT_ILLEGALLABEL
DefaultQualifier($NewValue=DB_NOVALUE)
Get/set the default qualifier for this field.
static $FieldTypeDBEnums
static $FixedDefaults
The metadata field defaults that are the same for all field types.
static $FieldTypeDBAllowedEnums
SetDefaults()
Set defaults values for the field.
Owner($NewValue=DB_NOVALUE)
Get/set field owner.
MaxPreviewHeight($NewValue=DB_NOVALUE)
Get/set the max height (in pixels) of thumbnail images.
Metadata schema (in effect a Factory class for MetadataField).
static $FieldTypePHPEnums
Status()
Get current error status of object.
IncludeInFacetedSearch($NewValue=DB_NOVALUE)
Get/set whether to include field in faceted search.
const UPDATEMETHOD_ONRECORDCHANGE
GetValueForId($Id)
Get value for specified ID (only meaningful for Trees / Controlled Names / Options) ...
static CheckMyCaller($DesiredCaller, $ExceptionMsg=NULL)
Check the caller of the current function.
Definition: StdLib.php:47
__construct($FieldId)
Object contstructor, used to load an existing metadata field.
Instructions($NewValue=DB_NOVALUE)
Get/set field instructions.
static Create($SchemaId, $FieldType, $FieldName, $Optional=NULL, $DefaultValue=NULL)
Create a new metadata field.
ValueUseCount($Value)
Check how many times a specific value is currently used for this field.
UseForOaiSets($NewValue=DB_NOVALUE)
Get/set if this field should be used to create OAI sets.
AllowHTML($NewValue=DB_NOVALUE)
Get/set if this field should allow HTML.
UnassociatedQualifierList()
Get list of qualifiers not associated with field.
const USERISVALUE_UNSET
IncludeInRecommender($NewValue=DB_NOVALUE)
Get/set whether to include field in recommender system comparisons.
SQL database abstraction object with smart query caching.
Definition: Database.php:22
GetFactory()
Retrieve item factory object for this field.
ShowQualifiers($NewValue=DB_NOVALUE)
Get/set if this field should display qualifiers on EditResource.
FlagOffLabel($NewValue=DB_NOVALUE)
Get/set the label displayed when a flag field is &#39;off&#39;.
PointPrecision($NewValue=DB_NOVALUE)
Get/set the current number of digits after the decimal point.
OptionListThreshold($NewValue=DB_NOVALUE)
Get/set the number of results necessary to active option list menus.
ViewingPrivileges($NewValue=NULL)
Get/set privileges that allowing viewing values for this field.
ViewingUserValue($NewValue=DB_NOVALUE)
const USERISVALUE_OR
const USERISVALUE_AND
AllowMultiple($NewValue=DB_NOVALUE)
Get/set whether to allow multiple values for field.
static $TypeBasedDefaults
The metadata field defaults that vary depending on the field type.
Description($NewValue=DB_NOVALUE)
Get/set field description.
const DATEPRE_BEGINMONTH
Definition: Date.php:746
ReferenceableSchemaIds($Ids=DB_NOVALUE)
Get/set the list of SchemaIds that provide allowable values for a reference field.
EditingUserValue($NewValue=DB_NOVALUE)
MaxThumbnailHeight($NewValue=DB_NOVALUE)
Get/set the max height (in pixels) of thumbnail images.
UserCanView($User, $AllowHooksToModify=TRUE)
Determine if a user can view a specified field in the absence of a resource.
SearchWeight($NewValue=DB_NOVALUE)
Get/set the weight this field has for search results (higher weights have a larger impact)...
Set of privileges used to access resource information or other parts of the system.
HasItemLevelQualifiers($NewValue=DB_NOVALUE)
Get/set whether field uses item-level qualifiers.
AssociateWithQualifier($Qualifier)
AuthoringPrivilege($NewValue=DB_NOVALUE)
DefaultAltText($NewValue=DB_NOVALUE)
Get/set the default alt text for this field.
SearchGroupLogic($NewValue=DB_NOVALUE)
Get/set the search group logic, used for both facets and advanced search when more than one value is ...
Class that builds on the foldering functionality to provide groups of metadata fields.
AjaxThreshold($NewValue=DB_NOVALUE)
Get/set the number of results necessary to activate the AJAX dropdown.
Factory class for Qualifier.
const MDFTYPE_CONTROLLEDNAME
CWIS-specific user factory class.
static $FieldTypeHumanEnums
A map of metadata field types to human-readable strings.
MaxPreviewWidth($NewValue=DB_NOVALUE)
Get/set the max width (in pixels) of thumbnail images.
const UPDATEMETHOD_ONRECORDEDIT
UserPrivilegeRestrictions($NewValue=DB_NOVALUE)
AddQualifier($Qualifier)
Associate qualifier with field.
SchemaId()
Get ID of schema for field.
IncludeInSortOptions($NewValue=DB_NOVALUE)
Get/set whether to include field in search result sort options.
DefaultValue($NewValue=DB_NOVALUE)
Get/set default value.
DisplayAsListForAdvancedSearch($NewValue=DB_NOVALUE)
Get/set if this field should be displayed as a list on the advanced search page.
const DB_NOVALUE
Definition: Database.php:1396
PreviewingPrivileges($NewValue=NULL)
Get/set privileges that allowing previewing values for this field.
const DATEPRE_BEGINDAY
Definition: Date.php:747
TypeAsName()
Get type of field as string.
MaxLength($NewValue=DB_NOVALUE)
Get/set maximum length to store in a text field.
IsControlledVocabularyField()
Check whether field is a type that uses controlled vocabularies.
MaxValue($NewValue=DB_NOVALUE)
Get/set the maximum allowed value for a number field.
PointDecimalDigits($NewValue=DB_NOVALUE)
Get/set the total number of digits a point field should store.
GetAllowedConversionTypes()
Get metadata field types that this field can be converted to.
Optional($NewValue=DB_NOVALUE)
Get/set whether a value is required for this field.
ViewingPrivilege($NewValue=DB_NOVALUE)
ParagraphRows($NewValue=DB_NOVALUE)
Get/set the number of rows to display for a paragraph field.
EditingPrivilege($NewValue=DB_NOVALUE)
RequiredBySPT($NewValue=DB_NOVALUE)
Get/set &#39;RequiredBySPT&#39;.
AuthoringUserIsValue($NewValue=DB_NOVALUE)
UsesQualifiers($NewValue=DB_NOVALUE)
Get/set if this field uses qualifiers.
MaxThumbnailWidth($NewValue=DB_NOVALUE)
Get/set the max width (in pixels) of thumbnail images.
Enabled($NewValue=DB_NOVALUE)
Get/set whether field is enabled.
AssociatedQualifierList()
Get list of qualifiers associated with field.
EditingPrivileges($NewValue=NULL)
Get/set privileges that allowing editing values for this field.
Factory for manipulating ControlledName objects.
const UPDATEMETHOD_NOAUTOUPDATE
Object representing a locally-defined type of metadata field.
NumAjaxResults($NewValue=DB_NOVALUE)
Get/set the maximum number of results to display in an AJAX dropdown.
Drop()
Remove field from database (only for use by MetadataSchema object).
TextFieldSize($NewValue=DB_NOVALUE)
Get/set the width of text fields.
ViewingUserIsValue($NewValue=DB_NOVALUE)
EnableOnOwnerReturn($NewValue=DB_NOVALUE)
FlagOnLabel($NewValue=DB_NOVALUE)
Get/set the label displayed when a flag field is &#39;on&#39;.
TreeBrowsingPrivilege($NewValue=DB_NOVALUE)
const UPDATEMETHOD_BUTTON
UseWysiwygEditor($NewValue=DB_NOVALUE)
Get/set if this field should enable WYSIWYG editing.
EditingUserIsValue($NewValue=DB_NOVALUE)
GetPossibleValues($MaxNumberOfValues=NULL, $Offset=0)
get possible values (only meaningful for Trees, Controlled Names, Options, Flags, and Users) ...
const MDFSTAT_ILLEGALNAME
static GetOrdersForSchema(MetadataSchema $Schema)
Get all of the orders associated with a schema.
GetIdForValue($Value)
Get ID for specified value (only meaningful for Trees / Controlled Names / Options) ...
RecommenderWeight($NewValue=DB_NOVALUE)
Get/set the weight this field has for recommendations (higher weights have a larger impact)...
Label($NewLabel=DB_NOVALUE)
Get/set label for field.
Type($NewValue=DB_NOVALUE)
Get/set type of metadata field (enumerated value).
Id()
Get metadata field ID.
DBFieldName()
Get base name of database column used to store metadata field value.
ImagePreviewPrivilege($NewValue=DB_NOVALUE)
DateFormat($NewValue=DB_NOVALUE)
Get/set the date format.
MaxWidth($NewValue=DB_NOVALUE)
Get/set the max width (in pixels) of images.
MaxHeight($NewValue=DB_NOVALUE)
Get/set the max width (in pixels) of images.
const UPDATEMETHOD_ONRECORDCREATE
const MDFSTAT_DUPLICATENAME
Factory for producing and manipulating Classification objects.
ParagraphCols($NewValue=DB_NOVALUE)
Get/set the number of columns to display for a paragraph field.
UnassociateWithQualifier($QualifierIdOrObject)
Delete a qualifier association.
Class representing a stored (usually uploaded) file.
Definition: File.php:13
IncludeInKeywordSearch($NewValue=DB_NOVALUE)
Get/set whether to include field in keyword search.
Editable($NewValue=DB_NOVALUE)
Get/set whether this field is editable.
CopyOnResourceDuplication($NewValue=DB_NOVALUE)
Get/set whether to duplciate this field when a resource is duplicated.
IsTempItem($NewSetting=NULL)
Get/set whether field is temporary instance.
Name($NewName=DB_NOVALUE)
Get/set name of field.
MaxDepthForAdvancedSearch($NewValue=DB_NOVALUE)
Get/set maximum depth of classifications to display in the list view on the AdvancedSearch page...
IncludeInAdvancedSearch($NewValue=DB_NOVALUE)
Get/set whether to include field in advanced search.
GetCountOfPossibleValues()
Get count of possible values (only meaningful for Trees, Controlled Names, Options, and Users)
GetDisplayName()
Get display name for field.
AuthoringPrivileges($NewValue=NULL)
Get/set privileges that allowing authoring values for this field.
MinValue($NewValue=DB_NOVALUE)
Get/set the minimum value allowed for a number field.
AuthoringUserValue($NewValue=DB_NOVALUE)
UpdateMethod($NewValue=DB_NOVALUE)
Get/set method by which field is updated.