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 
1759  public function Duplicate()
1760  {
1761  # create new field
1762  $NewName = $this->Name()." (duplicate ".date("ymd-His").")";
1763  $NewField = self::Create($this->SchemaId(), $this->Type(), $NewName);
1764 
1765  # copy all attributes to database record for new field
1766  $TableName = "MetadataFields";
1767  $IdColumn = "FieldId";
1768  $SrcId = $this->Id();
1769  $DstId = $NewField->Id();
1770  $ColumnsToExclude = array("FieldName");
1771  $this->DB->CopyValues(
1772  $TableName, $IdColumn, $SrcId, $DstId, $ColumnsToExclude);
1773 
1774  # reload new field and return to caller
1775  return new MetadataField($NewField->Id());
1776  }
1777 
1784  public function __construct($FieldId)
1785  {
1786  # assume everything will be okay
1787  $this->ErrorStatus = MetadataSchema::MDFSTAT_OK;
1788 
1789  # check if we have cached field info
1790  $this->DB = new Database();
1791  if (self::$FieldCache === NULL)
1792  {
1793  # if not, retrieve field info from database
1794  $this->DB->Query("SELECT * FROM MetadataFields");
1795  while ($Row = $this->DB->FetchRow())
1796  {
1797  self::$FieldCache[$Row["FieldId"]] = $Row;
1798  }
1799  }
1800 
1801  # error if requested field did not exist
1802  if (!array_key_exists($FieldId, self::$FieldCache) )
1803  {
1804  throw new InvalidArgumentException("Invalid metadata field ID ("
1805  .$FieldId.") from "
1806  .StdLib::GetMyCaller().".");
1807  }
1808  $Row = self::$FieldCache[$FieldId];
1809  $this->DBFields = $Row;
1810  $this->Id = $FieldId;
1811 
1812  # if privileges have not yet been initialized
1813  if (!strlen($this->DBFields["AuthoringPrivileges"]))
1814  {
1815  # set default values for privileges from metadata schema
1816  $Schema = new MetadataSchema($Row["SchemaId"]);
1817  $this->AuthoringPrivileges($Schema->AuthoringPrivileges());
1818  $this->EditingPrivileges($Schema->EditingPrivileges());
1819  $this->ViewingPrivileges($Schema->ViewingPrivileges());
1820  $this->PreviewingPrivileges($Schema->ViewingPrivileges());
1821  }
1822  else
1823  {
1824  # set privileges from stored values
1825  $this->AuthoringPrivileges = new PrivilegeSet(
1826  $Row["AuthoringPrivileges"]);
1827  $this->EditingPrivileges = new PrivilegeSet(
1828  $Row["EditingPrivileges"]);
1829  $this->ViewingPrivileges = new PrivilegeSet(
1830  $Row["ViewingPrivileges"]);
1831  $this->PreviewingPrivileges = new PrivilegeSet(
1832  $Row["PreviewingPrivileges"]);
1833  }
1834 
1835  # set database column name
1836  $this->DBFields["DBFieldName"] =
1837  $this->NormalizeFieldNameForDB($this->DBFields["FieldName"]);
1838  }
1839 
1844  public static $FixedDefaults = array(
1845  "Label" => NULL,
1846  "Description" => NULL,
1847  "Instructions" => NULL,
1848  "Enabled" => TRUE,
1849  "Optional" => TRUE,
1850  "Editable" => TRUE,
1851  "CopyOnResourceDuplication" => TRUE,
1852  "AllowMultiple" => FALSE,
1853  "IncludeInKeywordSearch" => FALSE,
1854  "IncludeInAdvancedSearch" => FALSE,
1855  "IncludeInFacetedSearch" => FALSE,
1856  "SearchGroupLogic" => SearchEngine::LOGIC_OR,
1857  "IncludeInSortOptions" => TRUE,
1858  "IncludeInRecommender" => FALSE,
1859  "ParagraphRows" => 4,
1860  "ParagraphCols" => 50,
1861  "MinValue" => 1,
1862  "FlagOnLabel" => "On",
1863  "FlagOffLabel" => "Off",
1864  "DateFormat" => NULL,
1865  "RecommenderWeight" => 1,
1866  "MaxHeight" => 500,
1867  "MaxWidth" => 500,
1868  "MaxPreviewHeight" => 100,
1869  "MaxPreviewWidth" => 100,
1870  "MaxThumbnailHeight" => 50,
1871  "MaxThumbnailWidth" => 50,
1872  "DefaultAltText" => NULL,
1873  "UsesQualifiers" => FALSE,
1874  "HasItemLevelQualifiers" => FALSE,
1875  "ShowQualifiers" => FALSE,
1876  "DefaultQualifier" => NULL,
1877  "AllowHTML" => FALSE,
1878  "UseWysiwygEditor" => FALSE,
1879  "UseForOaiSets" => FALSE,
1880  "DisplayAsListForAdvancedSearch" => FALSE,
1881  "MaxDepthForAdvancedSearch" => 1,
1882  "OptionListThreshold" => 25,
1883  "AjaxThreshold" => 50,
1884  "NumAjaxResults" => 50,
1885  "PointPrecision" => 8,
1886  "PointDecimalDigits" => 5,
1887  "UserPrivilegeRestrictions" => array(),
1888  "UpdateMethod" => "NoAutoUpdate",
1889  # 9999 is the default max value because default number field length is 4
1890  "MaxValue" => 9999);
1891 
1896  public static $TypeBasedDefaults = array(
1898  "DefaultValue" => NULL,
1899  "SearchWeight" => 1,
1900  "TextFieldSize" => 50,
1901  "MaxLength" => 100),
1903  "DefaultValue" => NULL,
1904  "SearchWeight" => 1,
1905  "TextFieldSize" => 50,
1906  "MaxLength" => 100),
1908  "DefaultValue" => NULL,
1909  "SearchWeight" => 1,
1910  "TextFieldSize" => 4,
1911  "MaxLength" => 100),
1913  "DefaultValue" => NULL,
1914  "SearchWeight" => 1,
1915  "TextFieldSize" => 10,
1916  "MaxLength" => 100),
1918  "DefaultValue" => NULL,
1919  "SearchWeight" => 1,
1920  "TextFieldSize" => 50,
1921  "MaxLength" => 100),
1923  "DefaultValue" => NULL,
1924  "SearchWeight" => 1,
1925  "TextFieldSize" => 50,
1926  "MaxLength" => 100),
1928  "DefaultValue" => NULL,
1929  "SearchWeight" => 1,
1930  "AllowMultiple" => TRUE,
1931  "TextFieldSize" => 50,
1932  "MaxLength" => 100),
1934  "DefaultValue" => NULL,
1935  "SearchWeight" => 3,
1936  "AllowMultiple" => TRUE,
1937  "TextFieldSize" => 50,
1938  "MaxLength" => 100),
1940  "DefaultValue" => NULL,
1941  "SearchWeight" => 3,
1942  "TextFieldSize" => 50,
1943  "MaxLength" => 100),
1945  "DefaultValue" => NULL,
1946  "SearchWeight" => 1,
1947  "TextFieldSize" => 50,
1948  "MaxLength" => 100),
1950  "DefaultValue" => NULL,
1951  "CopyOnResourceDuplication" => FALSE,
1952  "SearchWeight" => 1,
1953  "TextFieldSize" => 50,
1954  "MaxLength" => 100),
1956  "DefaultValue" => NULL,
1957  "CopyOnResourceDuplication" => FALSE,
1958  "AllowMultiple" => TRUE,
1959  "SearchWeight" => 1,
1960  "TextFieldSize" => 50,
1961  "MaxLength" => 100),
1962  MetadataSchema::MDFTYPE_URL => array(
1963  "DefaultValue" => NULL,
1964  "SearchWeight" => 1,
1965  "TextFieldSize" => 50,
1966  "MaxLength" => 255),
1968  "DefaultValue" => array("X" => NULL, "Y" => NULL),
1969  "SearchWeight" => 1,
1970  "TextFieldSize" => 10,
1971  "MaxLength" => 100),
1973  "DefaultValue" => NULL,
1974  "SearchWeight" => 1,
1975  "TextFieldSize" => 50,
1976  "MaxLength" => 100,
1977  "ReferenceableSchemaIds" => array(
1979 
1983  public function SetDefaults()
1984  {
1985  # set defaults that are the same for every field
1986  foreach (self::$FixedDefaults as $Key => $Value)
1987  {
1988  $this->$Key($Value);
1989  }
1990 
1991  # set defaults that depend on the type of the field
1992  foreach (self::$TypeBasedDefaults[$this->Type()] as $Key => $Value)
1993  {
1994  $this->$Key($Value);
1995  }
1996 
1997  # tweak the update method if dealing with the date of record creation
1998  if ($this->Name() == "Date Of Record Creation")
1999  {
2000  $this->UpdateMethod("OnRecordCreate");
2001  }
2002  }
2003 
2004 
2008  public function Drop()
2009  {
2011  "MetadataSchema",
2012  "Attempt to update drop Metadata Field at %FILE%:%LINE%."
2013  ." (Fields may only be dropped by MetadataSchema.)");
2014 
2015  # clear other database entries as appropriate for field type
2016  $DB = $this->DB;
2017  $DBFieldName = $this->DBFields["DBFieldName"];
2018  $Schema = new MetadataSchema($this->SchemaId());
2019  switch (self::$FieldTypePHPEnums[$this->DBFields["FieldType"]])
2020  {
2029  # remove field from resources table
2030  if ($DB->FieldExists("Resources", $DBFieldName))
2031  {
2032  $DB->Query("ALTER TABLE Resources DROP COLUMN `".$DBFieldName."`");
2033  }
2034  break;
2035 
2037  if ($DB->FieldExists("Resources", $DBFieldName."X"))
2038  {
2039  $DB->Query("ALTER TABLE Resources DROP COLUMN `".$DBFieldName."X`");
2040  $DB->Query("ALTER TABLE Resources DROP COLUMN `".$DBFieldName."Y`");
2041  }
2042  break;
2043 
2045  # remove fields from resources table
2046  if ($DB->FieldExists("Resources", $DBFieldName."Begin"))
2047  {
2048  $DB->Query("ALTER TABLE Resources "
2049  ."DROP COLUMN `".$DBFieldName."Begin`");
2050  $DB->Query("ALTER TABLE Resources "
2051  ."DROP COLUMN `".$DBFieldName."End`");
2052  $DB->Query("ALTER TABLE Resources "
2053  ."DROP COLUMN `".$DBFieldName."Precision`");
2054  }
2055  break;
2056 
2058  $DB->Query("SELECT ClassificationId FROM Classifications "
2059  ."WHERE FieldId = ".$this->Id());
2060  $TempDB = new Database();
2061  while ($ClassificationId = $DB->FetchField("ClassificationId"))
2062  {
2063  # remove any resource / name intersections
2064  $TempDB->Query("DELETE FROM ResourceClassInts WHERE "
2065  ."ClassificationId = ".$ClassificationId);
2066 
2067  # remove controlled name
2068  $TempDB->Query("DELETE FROM Classifications WHERE "
2069  ."ClassificationId = ".$ClassificationId);
2070  }
2071  break;
2072 
2075  $DB->Query("SELECT ControlledNameId FROM ControlledNames "
2076  ."WHERE FieldId = ".$this->Id());
2077  $TempDB = new Database();
2078  while ($ControlledNameId = $DB->FetchField("ControlledNameId"))
2079  {
2080  # remove any resource / name intersections
2081  $TempDB->Query("DELETE FROM ResourceNameInts WHERE "
2082  ."ControlledNameId = ".$ControlledNameId);
2083 
2084  # remove any variant names
2085  $TempDB->Query("DELETE FROM VariantNames WHERE "
2086  ."ControlledNameId = ".$ControlledNameId);
2087 
2088  # remove controlled name
2089  $TempDB->Query("DELETE FROM ControlledNames WHERE "
2090  ."ControlledNameId = ".$ControlledNameId);
2091  }
2092  break;
2093 
2095  # for each file associated with this field
2096  $DB->Query("SELECT FileId FROM Files WHERE FieldId = '".$this->Id()."'");
2097  while ($FileId = $DB->FetchRow())
2098  {
2099  # delete file
2100  $File = new File(intval($FileId));
2101  $File->Delete();
2102  }
2103  break;
2104 
2106  # remove any resource references for the field
2107  $DB->Query("
2108  DELETE FROM ReferenceInts
2109  WHERE FieldId = '".addslashes($this->Id())."'");
2110  break;
2111  }
2112 
2113  # remove field from database
2114  $DB->Query("DELETE FROM MetadataFields "
2115  ."WHERE FieldId = '".$this->DBFields["FieldId"]."'");
2116 
2117  # remove any qualifier associations
2118  $DB->Query("DELETE FROM FieldQualifierInts WHERE MetadataFieldId = '"
2119  .$this->DBFields["FieldId"]."'");
2120 
2121  # get the order objects the field is part of
2122  foreach (MetadataFieldOrder::GetOrdersForSchema($Schema) as $Order)
2123  {
2124  # remove it if it's a direct descendant
2125  $Order->RemoveItem($this->Id(), "MetadataField");
2126 
2127  # also make sure to remove it if it's part of a group
2128  foreach ($Order->GetItemIds() as $Item)
2129  {
2130  if ($Item["Type"] == "MetadataFieldGroup")
2131  {
2132  $Group = new MetadataFieldGroup($Item["ID"]);
2133  $Group->RemoveItem($this->Id(), "MetadataField");
2134  }
2135  }
2136  }
2137 
2138  # nuke stale field cache
2139  self::$FieldCache = NULL;
2140  }
2141 
2149  private function ModifyField($NewName = NULL, $NewType = NULL)
2150  {
2151  # grab old DB field name
2152  $OldDBFieldName = $this->DBFields["DBFieldName"];
2153  $OldFieldType = NULL;
2154 
2155  # if new field name supplied
2156  if ($NewName != NULL)
2157  {
2158  # cache the old name for options and controllednames below
2159  $OldName = $this->DBFields["FieldName"];
2160 
2161  # store new name
2162  $this->UpdateValue("FieldName", $NewName);
2163 
2164  # determine new DB field name
2165  $NewDBFieldName = $this->NormalizeFieldNameForDB($NewName);
2166 
2167  # store new database field name
2168  $this->DBFields["DBFieldName"] = $NewDBFieldName;
2169  }
2170  else
2171  {
2172  # set new field name equal to old field name
2173  $NewDBFieldName = $OldDBFieldName;
2174  }
2175 
2176  # if new type supplied
2177  if ($NewType != NULL)
2178  {
2179  # grab old field type
2180  $OldFieldType = self::$FieldTypePHPEnums[$this->DBFields["FieldType"]];
2181 
2182  # store new field type
2183  $this->UpdateValue("FieldType", self::$FieldTypeDBEnums[$NewType]);
2184  }
2185 
2186  # if this is not a temporary field
2187  if ($this->Id() >= 0)
2188  {
2189  # modify field in DB as appropriate for field type
2190  $DB = $this->DB;
2191  $FieldType = self::$FieldTypePHPEnums[$this->DBFields["FieldType"]];
2192  switch ($FieldType)
2193  {
2197  # alter field declaration in Resources table
2198  $DB->Query("ALTER TABLE Resources CHANGE COLUMN `"
2199  .$OldDBFieldName."` `"
2200  .$NewDBFieldName."` TEXT DEFAULT NULL");
2201  break;
2202 
2204  # alter field declaration in Resources table
2205  $DB->Query("ALTER TABLE Resources CHANGE COLUMN `"
2206  .$OldDBFieldName."` `"
2207  .$NewDBFieldName."` INT DEFAULT NULL");
2208 
2209  break;
2210 
2212  $Precision = $this->UpdateValue("PointPrecision",
2213  DB_NOVALUE);
2214  $Digits = $this->UpdateValue("PointDecimalDigits",
2215  DB_NOVALUE);
2216  $DB->Query("ALTER TABLE Resources CHANGE COLUMN "
2217  ."`".$OldDBFieldName."X` "
2218  ."`".$NewDBFieldName."X`".
2219  " DECIMAL(".$Precision.",".$Digits.")");
2220  $DB->Query("ALTER TABLE Resources CHANGE COLUMN "
2221  ."`".$OldDBFieldName."Y` "
2222  ."`".$NewDBFieldName."Y`".
2223  " DECIMAL(".$Precision.",".$Digits.")");
2224  break;
2225 
2227  # alter field declaration in Resources table
2228  $DB->Query("ALTER TABLE Resources CHANGE COLUMN `"
2229  .$OldDBFieldName."` `"
2230  .$NewDBFieldName."` INT"
2231  ." DEFAULT ".intval($this->DefaultValue()));
2232 
2233  # set any unset values to default
2234  $DB->Query("UPDATE Resources SET `".$NewDBFieldName
2235  ."` = ".intval($this->DefaultValue())
2236  ." WHERE `".$NewDBFieldName."` IS NULL");
2237  break;
2238 
2240  # if new type supplied and new type is different from old
2241  if (($NewType != NULL) && ($NewType != $OldFieldType))
2242  {
2243  # if old type was time stamp
2244  if ($OldFieldType == MetadataSchema::MDFTYPE_TIMESTAMP)
2245  {
2246  # change time stamp field in resources table to begin date
2247  $DB->Query("ALTER TABLE Resources CHANGE COLUMN `"
2248  .$OldDBFieldName."` `"
2249  .$NewDBFieldName."Begin` DATE "
2250  ."DEFAULT NULL");
2251 
2252  # add end date and precision fields
2253  $DB->Query("ALTER TABLE Resources "
2254  ."ADD COLUMN `".$NewDBFieldName."End` DATE");
2255  $DB->Query("ALTER TABLE Resources "
2256  ."ADD COLUMN `".$NewDBFieldName."Precision`"
2257  ."INT DEFAULT NULL");
2258 
2259 
2260  # set precision to reflect time stamp content
2261  $DB->Query("UPDATE Resources "
2262  ."SET `".$NewDBFieldName."Precision` = "
2263  .(DATEPRE_BEGINYEAR|DATEPRE_BEGINMONTH
2264  |DATEPRE_BEGINDAY));
2265  }
2266  else
2267  {
2268  exit("<br>ERROR: Attempt to convert metadata field "
2269  ."to date from type other than timestamp<br>\n");
2270  }
2271  }
2272  else
2273  {
2274  # change name of fields
2275  $DB->Query("ALTER TABLE Resources CHANGE COLUMN `"
2276  .$OldDBFieldName."Begin` `"
2277  .$NewDBFieldName."Begin` DATE "
2278  ."DEFAULT NULL");
2279  $DB->Query("ALTER TABLE Resources CHANGE COLUMN `"
2280  .$OldDBFieldName."End` `"
2281  .$NewDBFieldName."End` DATE "
2282  ."DEFAULT NULL");
2283  $DB->Query("ALTER TABLE Resources CHANGE COLUMN `"
2284  .$OldDBFieldName."Precision` `"
2285  .$NewDBFieldName."Precision` INT "
2286  ."DEFAULT NULL");
2287  }
2288  break;
2289 
2291  # if new type supplied and new type is different from old
2292  if (($NewType != NULL) && ($NewType != $OldFieldType))
2293  {
2294  # if old type was date
2295  if ($OldFieldType == MetadataSchema::MDFTYPE_DATE)
2296  {
2297  # change begin date field in resource table to time stamp
2298  $DB->Query("ALTER TABLE Resources CHANGE COLUMN `"
2299  .$OldDBFieldName."Begin` `"
2300  .$NewDBFieldName."` DATETIME "
2301  ."DEFAULT NULL");
2302 
2303  # drop end date and precision fields
2304  $DB->Query("ALTER TABLE Resources DROP COLUMN `"
2305  .$OldDBFieldName."End`");
2306  $DB->Query("ALTER TABLE Resources DROP COLUMN `"
2307  .$OldDBFieldName."Precision`");
2308  }
2309  else
2310  {
2311  exit("<br>ERROR: Attempt to convert metadata field to "
2312  ."time stamp from type other than date<br>\n");
2313  }
2314  }
2315  else
2316  {
2317  # change name of field
2318  $DB->Query("ALTER TABLE Resources CHANGE COLUMN `"
2319  .$OldDBFieldName."` `"
2320  .$NewDBFieldName."` DATETIME "
2321  ."DEFAULT NULL");
2322  }
2323  break;
2324 
2331  break;
2332  }
2333 
2334  # if qualifier DB field exists
2335  if ($DB->FieldExists("Resources", $OldDBFieldName."Qualifier"))
2336  {
2337  # rename qualifier DB field
2338  $DB->Query("ALTER TABLE Resources CHANGE COLUMN `"
2339  .$OldDBFieldName."Qualifier` `"
2340  .$NewDBFieldName."Qualifier` INT ");
2341  }
2342  }
2343  }
2344 
2351  private function UpdateValue($FieldName, $NewValue)
2352  {
2353  # nuke stale field cache
2354  self::$FieldCache = NULL;
2355 
2356  return $this->DB->UpdateValue("MetadataFields", $FieldName, $NewValue,
2357  "FieldId = ".intval($this->DBFields["FieldId"]),
2358  $this->DBFields);
2359  }
2360 
2367  private function UpdateIntValue($FieldName, $NewValue)
2368  {
2369  # nuke stale field cache
2370  self::$FieldCache = NULL;
2371 
2372  return $this->DB->UpdateIntValue("MetadataFields", $FieldName, $NewValue,
2373  "FieldId = ".intval($this->DBFields["FieldId"]),
2374  $this->DBFields);
2375  }
2376 
2383  private function UpdateFloatValue($FieldName, $NewValue)
2384  {
2385  # nuke stale field cache
2386  self::$FieldCache = NULL;
2387 
2388  return $this->DB->UpdateFloatValue("MetadataFields", $FieldName, $NewValue,
2389  "FieldId = ".intval($this->DBFields["FieldId"]),
2390  $this->DBFields);
2391  }
2392 
2399  private function UpdateBoolValue($FieldName, $NewValue)
2400  {
2401  # nuke stale field cache
2402  self::$FieldCache = NULL;
2403 
2404  $NewValue = $this->TranslateStringToConstants($NewValue);
2405  return $this->DB->UpdateIntValue("MetadataFields", $FieldName, $NewValue,
2406  "FieldId = ".intval($this->DBFields["FieldId"]),
2407  $this->DBFields);
2408  }
2409 
2417  private function UpdateConstValue($FieldName, $NewValue, $ClassName=NULL)
2418  {
2419  # nuke stale field cache
2420  self::$FieldCache = NULL;
2421 
2422  $NewValue = $this->TranslateStringToConstants($NewValue, $ClassName);
2423  return $this->DB->UpdateIntValue("MetadataFields", $FieldName, $NewValue,
2424  "FieldId = ".intval($this->DBFields["FieldId"]),
2425  $this->DBFields);
2426  }
2427 
2433  private function NormalizeFieldNameForDB($Name)
2434  {
2435  return preg_replace("/[^a-z0-9]/i", "", $Name)
2436  .(($this->SchemaId() != MetadataSchema::SCHEMAID_DEFAULT)
2437  ? $this->SchemaId() : "");
2438  }
2439 
2443  private function AddDatabaseFields()
2444  {
2445  # grab values for common use
2446  $DB = $this->DB;
2447  $DBFieldName = $this->DBFieldName();
2448 
2449  # set up field(s) based on field type
2450  switch ($this->Type())
2451  {
2455  # add field to resources table (if not already present)
2456  if (!$DB->FieldExists("Resources", $DBFieldName))
2457  {
2458  $DB->Query("ALTER TABLE Resources ADD COLUMN `".$DBFieldName
2459  ."` TEXT DEFAULT NULL");
2460  }
2461 
2462  break;
2463 
2465  # add field to resources table (if not already present)
2466  if (!$DB->FieldExists("Resources", $DBFieldName))
2467  {
2468  $DB->Query("ALTER TABLE Resources ADD COLUMN `".$DBFieldName
2469  ."` INT DEFAULT NULL");
2470  }
2471  break;
2472 
2474  if (!$DB->FieldExists("Resources", $DBFieldName."X"))
2475  {
2476  $Precision = $this->UpdateValue("PointPrecision",
2477  DB_NOVALUE);
2478  $Digits = $this->UpdateValue("PointDecimalDigits",
2479  DB_NOVALUE);
2480 
2481  $DB->Query("ALTER TABLE Resources ADD COLUMN `"
2482  .$DBFieldName."X`".
2483  " DECIMAL(".$Precision.",".$Digits.") DEFAULT NULL");
2484  $DB->Query("ALTER TABLE Resources ADD COLUMN `"
2485  .$DBFieldName."Y`".
2486  " DECIMAL(".$Precision.",".$Digits.") DEFAULT NULL");
2487  }
2488 
2489  break;
2491  # if field is not already present in database
2492  if (!$DB->FieldExists("Resources", $DBFieldName))
2493  {
2494  # add field to resources table
2495  $DB->Query("ALTER TABLE Resources ADD COLUMN `".$DBFieldName
2496  ."` INT DEFAULT NULL");
2497  }
2498  break;
2499 
2501  # add fields to resources table (if not already present)
2502  if (!$DB->FieldExists("Resources", $DBFieldName."Begin"))
2503  {
2504  $DB->Query("ALTER TABLE Resources ADD COLUMN `".$DBFieldName."Begin`"
2505  ." DATE DEFAULT NULL");
2506  }
2507  if (!$DB->FieldExists("Resources", $DBFieldName."End"))
2508  {
2509  $DB->Query("ALTER TABLE Resources ADD COLUMN `".$DBFieldName."End`"
2510  ." DATE DEFAULT NULL");
2511  }
2512  if (!$DB->FieldExists("Resources", $DBFieldName."Precision"))
2513  {
2514  $DB->Query("ALTER TABLE Resources "
2515  ."ADD COLUMN `".$DBFieldName."Precision`"
2516  ." INT DEFAULT NULL");
2517  }
2518  break;
2519 
2521  # add fields to resources table (if not already present)
2522  if (!$DB->FieldExists("Resources", $DBFieldName))
2523  {
2524  $DB->Query("ALTER TABLE Resources ADD COLUMN `".$DBFieldName
2525  ."` DATETIME DEFAULT NULL");
2526  }
2527  break;
2528 
2536  break;
2537 
2538  default:
2539  exit("<br>ERROR: Attempt to add database fields "
2540  ."for illegal metadata field type<br>\n");
2541  break;
2542  }
2543  }
2544 
2552  private function TranslateStringToConstants($CString, $ClassName = NULL)
2553  {
2554  # if not a string return value unchanged to caller
2555  if (!is_string($CString) || ($CString === DB_NOVALUE))
2556  {
2557  $ReturnValue = $CString;
2558  }
2559  # handle booleans as a special case
2560  elseif (strtoupper(trim($CString)) == "TRUE")
2561  {
2562  $ReturnValue = TRUE;
2563  }
2564  elseif (strtoupper(trim($CString)) == "FALSE")
2565  {
2566  $ReturnValue = FALSE;
2567  }
2568  else
2569  {
2570  # assume no values will be found
2571  $ReturnValue = NULL;
2572 
2573  # split apart any ORed-together values
2574  $Values = explode("|", $CString);
2575 
2576  # for each value found
2577  foreach ($Values as $Value)
2578  {
2579  # trim off any extraneous whitespace
2580  $Value = trim($Value);
2581 
2582  # add class name prefix to constant name if requested
2583  if ($ClassName) { $Value = $ClassName."::".$Value; }
2584 
2585  # if value corresponds to a constant
2586  if (defined($Value))
2587  {
2588  # add constant to return value
2589  $ReturnValue = ($ReturnValue === NULL)
2590  ? constant($Value)
2591  : ($ReturnValue | constant($Value));
2592  }
2593  }
2594 
2595  # if no corresponding constants were found
2596  if ($ReturnValue === NULL)
2597  {
2598  # return original value to caller
2599  $ReturnValue = $CString;
2600  }
2601  }
2602 
2603  # return result to caller
2604  return $ReturnValue;
2605  }
2606 
2610  private static $FieldCache = NULL;
2611 
2612 
2613  # ---- DEPRECATED METHODS ------------------------------------------------
2614  #
2615  # These are maintained only for backward compatibility with older
2616  # code. Newer code should not use them.
2617  #
2618  // @codingStandardsIgnoreStart
2619 
2620  public function Viewable()
2621  {
2622  return $this->UserCanView( $GLOBALS["G_User"] );
2623  }
2624 
2628  public function AssociateWithQualifier($Qualifier)
2629  {
2630  $this->AddQualifier($Qualifier);
2631  }
2632 
2633  public function UserPrivilegeRestrictions($NewValue = DB_NOVALUE)
2634  {
2635  # new value
2636  if ($NewValue != DB_NOVALUE)
2637  {
2638  $NewValue = serialize((array) $NewValue);
2639  }
2640 
2641  $Value = $this->UpdateValue("UserPrivilegeRestrictions", $NewValue);
2642 
2643  # value set
2644  if (strlen($Value))
2645  {
2646  $Value = (array) unserialize($Value);
2647  }
2648 
2649  # no value set, set it to an empty array
2650  else
2651  {
2652  $Value = $this->UserPrivilegeRestrictions(array());
2653  }
2654 
2655  return $Value;
2656  }
2657 
2658  public function AuthoringUserIsValue($NewValue = DB_NOVALUE)
2659  {
2660  return $this->UpdateConstValue(
2661  "AuthoringUserIsValue", $NewValue, "MetadataField");
2662  }
2663 
2664  public function EditingUserIsValue($NewValue = DB_NOVALUE)
2665  {
2666  return $this->UpdateConstValue("EditingUserIsValue", $NewValue, "MetadataField");
2667  }
2668 
2669  public function ViewingUserValue($NewValue = DB_NOVALUE)
2670  {
2671  return $this->UpdateIntValue("ViewingUserValue", $NewValue, "MetadataField");
2672  }
2673 
2674  public function AuthoringUserValue($NewValue = DB_NOVALUE)
2675  {
2676  return $this->UpdateIntValue("AuthoringUserValue", $NewValue, "MetadataField");
2677  }
2678 
2679  public function EditingUserValue($NewValue = DB_NOVALUE)
2680  {
2681  return $this->UpdateIntValue("EditingUserValue", $NewValue, "MetadataField");
2682  }
2683 
2684  public function ViewingUserIsValue($NewValue = DB_NOVALUE)
2685  {
2686  return $this->UpdateConstValue("ViewingUserIsValue", $NewValue, "MetadataField");
2687  }
2688 
2689  public function EnableOnOwnerReturn($NewValue = DB_NOVALUE)
2690  {
2691  return $this->UpdateBoolValue("EnableOnOwnerReturn", $NewValue);
2692  }
2693 
2694  public function ViewingPrivilege($NewValue = DB_NOVALUE)
2695  {
2696  if ($NewValue === DB_NOVALUE)
2697  {
2698  return $this->ViewingPrivileges();
2699  }
2700  else
2701  {
2702  throw new Exception("Deprecated ".__METHOD__."() called -- ".
2703  __METHOD__."s() should be used instead.");
2704  }
2705  }
2706 
2707  public function AuthoringPrivilege($NewValue = DB_NOVALUE)
2708  {
2709  if ($NewValue === DB_NOVALUE)
2710  {
2711  return $this->AuthoringPrivileges();
2712  }
2713  else
2714  {
2715  throw new Exception("Deprecated ".__METHOD__."() called -- ".
2716  __METHOD__."s() should be used instead.");
2717  }
2718  }
2719 
2720  public function EditingPrivilege($NewValue = DB_NOVALUE)
2721  {
2722  if ($NewValue === DB_NOVALUE)
2723  {
2724  return $this->EditingPrivileges();
2725  }
2726  else
2727  {
2728  throw new Exception("Deprecated ".__METHOD__."() called -- ".
2729  __METHOD__."s() should be used instead.");
2730  }
2731  }
2732 
2733  public function ImagePreviewPrivilege($NewValue = DB_NOVALUE)
2734  {
2735  if ($NewValue === DB_NOVALUE)
2736  {
2737  return $this->ViewingPrivileges();
2738  }
2739  else
2740  {
2741  throw new Exception("Deprecated ".__METHOD__."() called -- ".
2742  "ViewingPrivileges() should be used instead.");
2743  }
2744  }
2745 
2746  public function TreeBrowsingPrivilege($NewValue = DB_NOVALUE)
2747  {
2748  if ($NewValue === DB_NOVALUE)
2749  {
2750  return $this->ViewingPrivileges();
2751  }
2752  else
2753  {
2754  throw new Exception("Deprecated ".__METHOD__."() called -- ".
2755  "this should probably be using ViewingPrivileges() instead.");
2756  }
2757  }
2758 
2759 
2760  // @codingStandardsIgnoreEnd
2761 }
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:1541
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.
Duplicate()
Create duplicate of field.
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.