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  function Status() { return $this->ErrorStatus; }
35 
42  function Type($NewValue = DB_NOVALUE)
43  {
44  # if new value supplied
45  if (($NewValue != DB_NOVALUE)
46  && ($NewValue != MetadataField::$FieldTypePHPEnums[
47  $this->DBFields["FieldType"]]))
48  {
49  # update database fields and store new type
50  $this->ModifyField(NULL, $NewValue);
51  }
52 
53  # return type to caller
54  return MetadataField::$FieldTypePHPEnums[$this->DBFields["FieldType"]];
55  }
56 
61  function TypeAsName()
62  {
63  return $this->DBFields["FieldType"];
64  }
65 
70  function SchemaId()
71  {
72  return $this->DBFields["SchemaId"];
73  }
74 
80  function GetDisplayName()
81  {
82  return strlen($this->Label()) ? $this->Label() : $this->Name();
83  }
84 
91  function Name($NewName = DB_NOVALUE)
92  {
93  # if new name specified
94  if ($NewName != DB_NOVALUE
95  && trim($NewName) != $this->DBFields["FieldName"])
96  {
97  $NewName = trim($NewName);
98  $NormalizedName = $this->NormalizeFieldNameForDB(strtolower($NewName));
99 
100  # if field name is invalid
101  if (!preg_match("/^[[:alnum:] \(\)]+$/", $NewName))
102  {
103  # set error status to indicate illegal name
104  $this->ErrorStatus = MetadataSchema::MDFSTAT_ILLEGALNAME;
105  }
106 
107  # if the new name is a reserved word
108  else if ($NormalizedName == "resourceid" || $NormalizedName == "schemaid")
109  {
110  # set error status to indicate illegal name
111  $this->ErrorStatus = MetadataSchema::MDFSTAT_ILLEGALNAME;
112  }
113 
114  # the name is okay but might be a duplicate
115  else
116  {
117  # check for duplicate name
118  $DuplicateCount = $this->DB->Query(
119  "SELECT COUNT(*) AS RecordCount FROM MetadataFields"
120  ." WHERE FieldName = '".addslashes($NewName)."'"
121  ." AND SchemaId = ".intval($this->DBFields["SchemaId"]),
122  "RecordCount");
123 
124  # if field name is duplicate
125  if ($DuplicateCount > 0)
126  {
127  # set error status to indicate duplicate name
128  $this->ErrorStatus = MetadataSchema::MDFSTAT_DUPLICATENAME;
129  }
130  else
131  {
132  # modify database declaration to reflect new field name
133  $this->ErrorStatus = MetadataSchema::MDFSTAT_OK;
134  $this->ModifyField($NewName);
135  }
136  }
137  }
138 
139  # return value to caller
140  return $this->DBFields["FieldName"];
141  }
142 
148  function Label($NewLabel = DB_NOVALUE)
149  {
150  $ValidValueExp = '/^[[:alnum:] ]*$/';
151  $Value = $this->DBFields["Label"];
152 
153  # if a new label was specified
154  if ($NewLabel !== DB_NOVALUE && trim($NewLabel) != $Value)
155  {
156  $NewLabel = trim($NewLabel);
157 
158  # if field label is valid
159  if (preg_match($ValidValueExp, $NewLabel))
160  {
161  $this->UpdateValue("Label", $NewLabel);
162  $Value = $NewLabel;
163  }
164  # the field label is invalid
165  else
166  {
167  $this->ErrorStatus = MetadataSchema::MDFSTAT_ILLEGALLABEL;
168  }
169  }
170 
171  return $Value;
172  }
173 
180  {
181  # determine type list based on our type
182  switch ($this->Type())
183  {
189  $AllowedTypes = array(
191  MetadataSchema::MDFTYPE_PARAGRAPH => "Paragraph",
192  MetadataSchema::MDFTYPE_NUMBER => "Number",
195  );
196  break;
197 
200  $AllowedTypes = array(
201  MetadataSchema::MDFTYPE_CONTROLLEDNAME => "ControlledName",
202  MetadataSchema::MDFTYPE_OPTION => "Option",
203  );
204  break;
205 
207  $AllowedTypes = array(
210  );
211  break;
212 
214  $AllowedTypes = array(
216  MetadataSchema::MDFTYPE_IMAGE => "Still Image",
217  );
218  break;
219 
225  default:
226  $AllowedTypes = array();
227  break;
228  }
229 
230  # return type list to caller
231  return $AllowedTypes;
232  }
233 
241  function IsTempItem($NewSetting = NULL)
242  {
243  $Schema = new MetadataSchema($this->SchemaId());
244  $ItemTableName = "MetadataFields";
245  $ItemIdFieldName = "FieldId";
246  $ItemFactoryObjectName = "MetadataSchema";
247  $ItemAssociationTables = array(
248  "FieldQualifierInts",
249  );
250  $ItemAssociationFieldName = "MetadataFieldId";
251 
252  # if new temp item setting supplied
253  if (!is_null($NewSetting))
254  {
255  # if caller requested to switch
256  if (($this->Id() < 0 && $NewSetting == FALSE)
257  || ($this->Id() >= 0 && $NewSetting == TRUE))
258  {
259  # if field name is invalid
260  if (strlen($this->NormalizeFieldNameForDB($this->Name())) < 1)
261  {
262  # set error status to indicate illegal name
263  $this->ErrorStatus = MetadataSchema::MDFSTAT_ILLEGALNAME;
264  }
265  else
266  {
267  # lock DB tables to prevent next ID from being grabbed
268  $DB = $this->DB;
269  $DB->Query("
270  LOCK TABLES ".$ItemTableName." WRITE,
271  APSessions WRITE, APSessionData WRITE,
272  MetadataSchemas WRITE");
273 
274  # get next temp item ID
275  $OldItemId = $this->Id();
276  $Factory = new $ItemFactoryObjectName();
277  if ($NewSetting == TRUE)
278  {
279  $NewId = $Factory->GetNextTempItemId();
280  }
281  else
282  {
283  $NewId = $Factory->GetNextItemId();
284  }
285 
286  # change item ID
287  $DB->Query("UPDATE ".$ItemTableName." SET ".$ItemIdFieldName." = ".
288  $NewId. " WHERE ".$ItemIdFieldName." = ".$OldItemId);
289 
290  # release DB tables
291  $DB->Query("UNLOCK TABLES");
292 
293  # change associations
294  foreach ($ItemAssociationTables as $TableName)
295  {
296  $DB->Query("UPDATE ".$TableName." SET ".$ItemAssociationFieldName." = ".
297  $NewId. " WHERE ".$ItemAssociationFieldName." = ".$OldItemId);
298  }
299 
300  # if changing item from temp to non-temp
301  if ($NewSetting == FALSE)
302  {
303  # add any needed database fields and/or entries
304  $this->AddDatabaseFields();
305 
306  # set field order values for new field
307  $Schema->GetDisplayOrder()->AppendItem($NewId, "MetadataField");
308  $Schema->GetEditOrder()->AppendItem($NewId, "MetadataField");
309  }
310 
311  # update metadata field id
312  $this->DBFields["FieldId"] = $NewId;
313  }
314  }
315  }
316 
317  # report to caller whether we are a temp item
318  return ($this->Id() < 0) ? TRUE : FALSE;
319  }
320 
326  function AuthoringPrivileges(PrivilegeSet $NewValue = NULL)
327  {
328  # if new privileges supplied
329  if ($NewValue !== NULL)
330  {
331  # store new privileges in database
332  $this->UpdateValue("AuthoringPrivileges", $NewValue->Data());
333  $this->AuthoringPrivileges = $NewValue;
334  }
335 
336  # return current value to caller
337  return $this->AuthoringPrivileges;
338  }
339 
345  function EditingPrivileges(PrivilegeSet $NewValue = NULL)
346  {
347  # if new privileges supplied
348  if ($NewValue !== NULL)
349  {
350  # store new privileges in database
351  $this->UpdateValue("EditingPrivileges", $NewValue->Data());
352  $this->EditingPrivileges = $NewValue;
353  }
354 
355  # return current value to caller
356  return $this->EditingPrivileges;
357  }
358 
364  function ViewingPrivileges(PrivilegeSet $NewValue = NULL)
365  {
366  # if new privileges supplied
367  if ($NewValue !== NULL)
368  {
369  # store new privileges in database
370  $this->UpdateValue("ViewingPrivileges", $NewValue->Data());
371  $this->ViewingPrivileges = $NewValue;
372  }
373 
374  # return current value to caller
375  return $this->ViewingPrivileges;
376  }
377 
383  function PreviewingPrivileges(PrivilegeSet $NewValue = NULL)
384  {
385  # if new privileges supplied
386  if ($NewValue !== NULL)
387  {
388  # store new privileges in database
389  $this->UpdateValue("PreviewingPrivileges", $NewValue->Data());
390  $this->PreviewingPrivileges = $NewValue;
391  }
392 
393  # return current value to caller
394  return $this->PreviewingPrivileges;
395  }
396 
401  function Id() { return $this->Id; }
402 
408  function DBFieldName() { return $this->DBFields["DBFieldName"]; }
409 
415  function Description($NewValue = DB_NOVALUE)
416  { return $this->UpdateValue("Description", $NewValue); }
417 
423  function Instructions($NewValue = DB_NOVALUE)
424  { return $this->UpdateValue("Instructions", $NewValue); }
425 
431  function Owner($NewValue = DB_NOVALUE)
432  { return $this->UpdateValue("Owner", $NewValue); }
433 
440  function Enabled($NewValue = DB_NOVALUE)
441  { return $this->UpdateBoolValue("Enabled", $NewValue); }
442 
449  function Optional($NewValue = DB_NOVALUE)
450  { return $this->UpdateBoolValue("Optional", $NewValue); }
451 
458  function Editable($NewValue = DB_NOVALUE)
459  { return $this->UpdateBoolValue("Editable", $NewValue); }
460 
467  function AllowMultiple($NewValue = DB_NOVALUE)
468  { return $this->UpdateBoolValue("AllowMultiple", $NewValue); }
469 
476  function IncludeInKeywordSearch($NewValue = DB_NOVALUE)
477  { return $this->UpdateBoolValue("IncludeInKeywordSearch", $NewValue); }
478 
485  function IncludeInAdvancedSearch($NewValue = DB_NOVALUE)
486  { return $this->UpdateBoolValue("IncludeInAdvancedSearch", $NewValue); }
487 
494  function IncludeInFacetedSearch($NewValue = DB_NOVALUE)
495  { return $this->UpdateBoolValue("IncludeInFacetedSearch", $NewValue); }
496 
503  function IncludeInSortOptions($NewValue = DB_NOVALUE)
504  { return $this->UpdateBoolValue("IncludeInSortOptions", $NewValue); }
505 
512  function IncludeInRecommender($NewValue = DB_NOVALUE)
513  { return $this->UpdateBoolValue("IncludeInRecommender", $NewValue); }
514  function TextFieldSize($NewValue = DB_NOVALUE)
515  { return $this->UpdateIntValue("TextFieldSize", $NewValue); }
516  function MaxLength($NewValue = DB_NOVALUE)
517  { return $this->UpdateIntValue("MaxLength", $NewValue); }
518  function ParagraphRows($NewValue = DB_NOVALUE)
519  { return $this->UpdateIntValue("ParagraphRows", $NewValue); }
520  function ParagraphCols($NewValue = DB_NOVALUE)
521  { return $this->UpdateIntValue("ParagraphCols", $NewValue); }
522  function MinValue($NewValue = DB_NOVALUE)
523  { return $this->UpdateFloatValue("MinValue", $NewValue); }
524  function MaxValue($NewValue = DB_NOVALUE)
525  { return $this->UpdateFloatValue("MaxValue", $NewValue); }
526  function FlagOnLabel($NewValue = DB_NOVALUE)
527  { return $this->UpdateValue("FlagOnLabel", $NewValue); }
528  function FlagOffLabel($NewValue = DB_NOVALUE)
529  { return $this->UpdateValue("FlagOffLabel", $NewValue); }
530  function DateFormat($NewValue = DB_NOVALUE)
531  { return $this->UpdateValue("DateFormat", $NewValue); }
532  function SearchWeight($NewValue = DB_NOVALUE)
533  { return $this->UpdateIntValue("SearchWeight", $NewValue); }
534  function RecommenderWeight($NewValue = DB_NOVALUE)
535  { return $this->UpdateIntValue("RecommenderWeight", $NewValue); }
536  function MaxHeight($NewValue = DB_NOVALUE)
537  { return $this->UpdateIntValue("MaxHeight", $NewValue); }
538  function MaxWidth($NewValue = DB_NOVALUE)
539  { return $this->UpdateIntValue("MaxWidth", $NewValue); }
540  function MaxPreviewHeight($NewValue = DB_NOVALUE)
541  { return $this->UpdateIntValue("MaxPreviewHeight", $NewValue); }
542  function MaxPreviewWidth($NewValue = DB_NOVALUE)
543  { return $this->UpdateIntValue("MaxPreviewWidth", $NewValue); }
544  function MaxThumbnailHeight($NewValue = DB_NOVALUE)
545  { return $this->UpdateIntValue("MaxThumbnailHeight", $NewValue); }
546  function MaxThumbnailWidth($NewValue = DB_NOVALUE)
547  { return $this->UpdateIntValue("MaxThumbnailWidth", $NewValue); }
548  function DefaultAltText($NewValue = DB_NOVALUE)
549  { return $this->UpdateValue("DefaultAltText", $NewValue); }
550  function UsesQualifiers($NewValue = DB_NOVALUE)
551  { return $this->UpdateBoolValue("UsesQualifiers", $NewValue); }
552  function ShowQualifiers($NewValue = DB_NOVALUE)
553  { return $this->UpdateBoolValue("ShowQualifiers", $NewValue); }
554  function DefaultQualifier($NewValue = DB_NOVALUE)
555  { return $this->UpdateValue("DefaultQualifier", $NewValue); }
556  function AllowHTML($NewValue = DB_NOVALUE)
557  { return $this->UpdateBoolValue("AllowHTML", $NewValue); }
558  function UseWysiwygEditor($NewValue = DB_NOVALUE)
559  { return $this->UpdateBoolValue("UseWysiwygEditor", $NewValue); }
560  function UseForOaiSets($NewValue = DB_NOVALUE)
561  { return $this->UpdateBoolValue("UseForOaiSets", $NewValue); }
562  function OptionListThreshold($NewValue = DB_NOVALUE)
563  { return $this->UpdateIntValue("OptionListThreshold", $NewValue); }
564  function AjaxThreshold($NewValue = DB_NOVALUE)
565  { return $this->UpdateIntValue("AjaxThreshold", $NewValue); }
566  function NumAjaxResults($NewValue = DB_NOVALUE)
567  { return $this->UpdateIntValue("NumAjaxResults", $NewValue); }
568  function ViewingPrivilege($NewValue = DB_NOVALUE)
569  { return $this->UpdateConstValue("ViewingPrivilege", $NewValue); }
570  function AuthoringPrivilege($NewValue = DB_NOVALUE)
571  { return $this->UpdateConstValue("AuthoringPrivilege", $NewValue); }
572  function EditingPrivilege($NewValue = DB_NOVALUE)
573  { return $this->UpdateConstValue("EditingPrivilege", $NewValue); }
574  function ImagePreviewPrivilege($NewValue = DB_NOVALUE)
575  { return $this->UpdateConstValue("ImagePreviewPrivilege", $NewValue); }
576  function TreeBrowsingPrivilege($NewValue = DB_NOVALUE)
577  { return $this->UpdateConstValue("TreeBrowsingPrivilege", $NewValue); }
578  function EnableOnOwnerReturn($NewValue = DB_NOVALUE)
579  { return $this->UpdateBoolValue("EnableOnOwnerReturn", $NewValue); }
580  function ViewingUserIsValue($NewValue = DB_NOVALUE)
581  { return $this->UpdateConstValue("ViewingUserIsValue", $NewValue, "MetadataField"); }
582  function AuthoringUserIsValue($NewValue = DB_NOVALUE)
583  { return $this->UpdateConstValue("AuthoringUserIsValue", $NewValue, "MetadataField"); }
584  function EditingUserIsValue($NewValue = DB_NOVALUE)
585  { return $this->UpdateConstValue("EditingUserIsValue", $NewValue, "MetadataField"); }
586  function ViewingUserValue($NewValue = DB_NOVALUE)
587  { return $this->UpdateIntValue("ViewingUserValue", $NewValue, "MetadataField"); }
588  function AuthoringUserValue($NewValue = DB_NOVALUE)
589  { return $this->UpdateIntValue("AuthoringUserValue", $NewValue, "MetadataField"); }
590  function EditingUserValue($NewValue = DB_NOVALUE)
591  { return $this->UpdateIntValue("EditingUserValue", $NewValue, "MetadataField"); }
592  function RequiredBySPT($NewValue = DB_NOVALUE)
593  { return $this->UpdateBoolValue("RequiredBySPT", $NewValue); }
594 
595  function UserPrivilegeRestrictions($NewValue = DB_NOVALUE)
596  {
597  # new value
598  if ($NewValue != DB_NOVALUE)
599  {
600  $NewValue = serialize((array) $NewValue);
601  }
602 
603  $Value = $this->UpdateValue("UserPrivilegeRestrictions", $NewValue);
604 
605  # value set
606  if (strlen($Value))
607  {
608  $Value = (array) unserialize($Value);
609  }
610 
611  # no value set, set it to an empty array
612  else
613  {
614  $Value = $this->UserPrivilegeRestrictions(array());
615  }
616 
617  return $Value;
618  }
619 
620  function PointPrecision($NewValue = DB_NOVALUE)
621  {
622  if ($NewValue !== DB_NOVALUE && $this->Id() >= 0
623  && $this->Type() == MetadataSchema::MDFTYPE_POINT)
624  {
625  $OldValue = $this->UpdateValue("PointPrecision", DB_NOVALUE);
626 
627  if ($NewValue != $OldValue)
628  {
629  $Decimals = $this->UpdateValue("PointDecimalDigits", DB_NOVALUE);
630  $TotalDigits = $NewValue + $Decimals;
631 
632  $this->DB->Query("ALTER TABLE Resources MODIFY COLUMN "
633  ."`".$this->DBFields["DBFieldName"]."X` "
634  ."DECIMAL(".$TotalDigits.",".$Decimals.")");
635  $this->DB->Query("ALTER TABLE Resources MODIFY COLUMN "
636  ."`".$this->DBFields["DBFieldName"]."Y` "
637  ."DECIMAL(".$TotalDigits.",".$Decimals.")");
638  }
639  }
640 
641  return $this->UpdateValue("PointPrecision", $NewValue);
642  }
643 
644  function PointDecimalDigits($NewValue = DB_NOVALUE)
645  {
646  if ($NewValue !== DB_NOVALUE && $this->Id() >= 0
647  && $this->Type() == MetadataSchema::MDFTYPE_POINT)
648  {
649  $OldValue = $this->UpdateValue("PointDecimalDigits", DB_NOVALUE);
650 
651  if ($NewValue != $OldValue)
652  {
653  $Precision = $this->UpdateValue("PointPrecision", DB_NOVALUE);
654 
655  $TotalDigits = $NewValue + $Precision;
656 
657  $this->DB->Query("ALTER TABLE Resources MODIFY COLUMN "
658  ."`".$this->DBFields["DBFieldName"]."X` "
659  ."DECIMAL(".$TotalDigits.",".$NewValue.")");
660  $this->DB->Query("ALTER TABLE Resources MODIFY COLUMN "
661  ."`".$this->DBFields["DBFieldName"]."Y` "
662  ."DECIMAL(".$TotalDigits.",".$NewValue.")");
663  }
664  }
665 
666  return $this->UpdateValue("PointDecimalDigits", $NewValue);
667  }
668 
669  function DefaultValue($NewValue = DB_NOVALUE)
670  {
671  if ($this->Type() == MetadataSchema::MDFTYPE_POINT)
672  {
673  # valid value given
674  if ($NewValue !== DB_NOVALUE &&
675  isset($NewValue["X"]) && isset($NewValue["Y"]))
676  {
677  $NewValue = $NewValue["X"].",".$NewValue["Y"];
678  }
679 
680  # invalid value given
681  else
682  {
683  $NewValue = DB_NOVALUE;
684  }
685 
686  $Value = $this->UpdateValue("DefaultValue", $NewValue);
687 
688  if (is_array($Value))
689  {
690  $tmp = explode(",", $Value);
691 
692  if (count($tmp)==2)
693  {
694  return array("X" => $tmp[0], "Y" => $tmp[1]);
695  }
696  }
697 
698  return array("X" => NULL, "Y" => NULL);
699  }
700 
701  else if ($this->Type() == MetadataSchema::MDFTYPE_OPTION)
702  {
703  # multiple default values to set
704  if (is_array($NewValue))
705  {
706  # empty array
707  if (count($NewValue) == 0)
708  {
709  $NewValue = NULL;
710  }
711 
712  # multiple defaults are allowed
713  else if ($this->AllowMultiple())
714  {
715  $NewValue = serialize($NewValue);
716  }
717 
718  # only one default is allowed so get the first one
719  else
720  {
721  $NewValue = array_shift($NewValue);
722  }
723  }
724 
725  $Result = $this->UpdateValue("DefaultValue", $NewValue);
726 
727  return empty($Result) || is_numeric($Result) ?
728  $Result : unserialize($Result);
729  }
730 
731  return $this->UpdateValue("DefaultValue", $NewValue);
732  }
733 
739  function UpdateMethod($NewValue = DB_NOVALUE)
740  {
741  return $this->UpdateValue("UpdateMethod", $NewValue);
742  }
743 
744  # get possible values (only meaningful for Trees, Controlled Names, Options,
745  # Flags, and Users)
746  # (index for returned array is IDs for values)
747  function GetPossibleValues($MaxNumberOfValues = NULL, $Offset=0)
748  {
749  # retrieve values based on field type
750  switch ($this->Type())
751  {
753  $QueryString = "SELECT ClassificationId, ClassificationName"
754  ." FROM Classifications WHERE FieldId = ".$this->Id()
755  ." ORDER BY ClassificationName";
756  if ($MaxNumberOfValues)
757  {
758  $QueryString .= " LIMIT ".intval($MaxNumberOfValues)." OFFSET "
759  .intval($Offset);
760  }
761  $this->DB->Query($QueryString);
762  $PossibleValues = $this->DB->FetchColumn(
763  "ClassificationName", "ClassificationId");
764  break;
765 
768  $QueryString = "SELECT ControlledNameId, ControlledName"
769  ." FROM ControlledNames WHERE FieldId = ".$this->Id()
770  ." ORDER BY ControlledName";
771  if ($MaxNumberOfValues)
772  {
773  $QueryString .= " LIMIT ".intval($MaxNumberOfValues)." OFFSET "
774  .intval($Offset);
775  }
776  $this->DB->Query($QueryString);
777  $PossibleValues = $this->DB->FetchColumn(
778  "ControlledName", "ControlledNameId");
779  break;
780 
782  $PossibleValues[0] = $this->FlagOffLabel();
783  $PossibleValues[1] = $this->FlagOnLabel();
784  break;
785 
787  $UserFactory = new CWUserFactory();
788  $Restrictions = $this->UserPrivilegeRestrictions();
789  $PossibleValues = array();
790 
791  if (count($Restrictions))
792  {
793  $PossibleValues = call_user_func_array(
794  array($UserFactory, "GetUsersWithPrivileges"),
795  $Restrictions);
796  }
797 
798  else
799  {
800  $Users = $UserFactory->GetMatchingUsers(".*.");
801 
802  foreach ($Users as $Id => $Data)
803  {
804  $PossibleValues[$Id] = $Data["UserName"];
805  }
806  }
807 
808  break;
809 
810  default:
811  # for everything else return an empty array
812  $PossibleValues = array();
813  break;
814  }
815 
816  # return array of possible values to caller
817  return $PossibleValues;
818  }
819 
820  # get count of possible values (only meaningful for Trees, Controlled Names,
821  # Options, and Users)
823  {
824  # retrieve values based on field type
825  switch ($this->Type())
826  {
828  $Count = $this->DB->Query("SELECT count(*) AS ValueCount"
829  ." FROM Classifications WHERE FieldId = ".$this->Id(),
830  "ValueCount");
831  break;
832 
835  $Count = $this->DB->Query("SELECT count(*) AS ValueCount"
836  ." FROM ControlledNames WHERE FieldId = ".$this->Id(),
837  "ValueCount");
838  break;
839 
841  $Count = 2;
842  break;
843 
845  $Count = count($this->GetPossibleValues());
846  break;
847 
848  default:
849  # for everything else return an empty array
850  $Count = 0;
851  break;
852  }
853 
854  # return count of possible values to caller
855  return $Count;
856  }
857 
858  # get ID for specified value (only meaningful for Trees / Controlled Names / Options)
859  # (returns NULL if value not found)
860  function GetIdForValue($Value)
861  {
862  # retrieve ID based on field type
863  switch ($this->Type())
864  {
866  $Id = $this->DB->Query("SELECT ClassificationId FROM Classifications"
867  ." WHERE ClassificationName = '".addslashes($Value)."'"
868  ." AND FieldId = ".$this->Id(),
869  "ClassificationId");
870  break;
871 
874  $Id = $this->DB->Query("SELECT ControlledNameId FROM ControlledNames"
875  ." WHERE ControlledName = '".addslashes($Value)."'"
876  ." AND FieldId = ".$this->Id(),
877  "ControlledNameId");
878  break;
879 
880  default:
881  # for everything else return NULL
882  $Id = NULL;
883  break;
884  }
885 
886  # return ID for value to caller
887  return $Id;
888  }
889 
890  # get value for specified ID (only meaningful for Trees / Controlled Names / Options)
891  # (returns NULL if ID not found)
892  function GetValueForId($Id)
893  {
894  # retrieve ID based on field type
895  switch ($this->Type())
896  {
898  $Value = $this->DB->Query("SELECT ClassificationName FROM Classifications"
899  ." WHERE ClassificationId = '".intval($Id)."'"
900  ." AND FieldId = ".$this->Id(),
901  "ClassificationName");
902  break;
903 
906  $Value = $this->DB->Query("SELECT ControlledName FROM ControlledNames"
907  ." WHERE ControlledNameId = '".intval($Id)."'"
908  ." AND FieldId = ".$this->Id(),
909  "ControlledName");
910  break;
911 
912  default:
913  # for everything else return NULL
914  $Value = NULL;
915  break;
916  }
917 
918  # return ID for value to caller
919  return $Value;
920  }
921 
932  function ValueUseCount($Value)
933  {
934  # retrieve ID if object passed in
935  if (is_object($Value) && method_exists($Value, "Id"))
936  {
937  $Value = $Value->Id();
938  }
939 
940  # check value based on field type
941  $DBFieldName = $this->DBFields["DBFieldName"];
942  switch ($this->Type())
943  {
953  $UseCount = $this->DB->Query("SELECT COUNT(*) AS UseCount"
954  ." FROM Resources"
955  ." WHERE `".$DBFieldName."` = '".addslashes($Value)."'"
956  ." AND SchemaId = ".intval($this->DBFields["SchemaId"]),
957  "UseCount");
958  break;
959 
961  $UseCount = $this->DB->Query("SELECT COUNT(*) AS UseCount"
962  ." FROM ResourceClassInts"
963  ." WHERE ClassificationId = ".intval($Value),
964  "UseCount");
965  break;
966 
969  $UseCount = $this->DB->Query("SELECT COUNT(*) AS UseCount"
970  ." FROM ResourceNameInts"
971  ." WHERE ControlledNameId = ".intval($Value),
972  "UseCount");
973  break;
974 
976  $UseCount = $this->DB->Query("SELECT COUNT(*) AS UseCount"
977  ." FROM Resources"
978  ." WHERE `".$DBFieldName."X` = '".$Value["X"]."'"
979  ." AND `".$DBFieldName."Y` = '".$Value["Y"]."'"
980  ." AND SchemaId = ".intval($this->DBFields["SchemaId"]),
981  "UseCount");
982  break;
983 
984  default:
985  throw new Exception(__CLASS__."::".__METHOD__."() called for"
986  ." unsupported field type (".$this->Type().").");
987  break;
988  }
989 
990  # report use count to caller
991  return $UseCount;
992  }
993 
994  # get/set whether field uses item-level qualifiers
995  function HasItemLevelQualifiers($NewValue = DB_NOVALUE)
996  {
997  # if value provided different from present value
998  if (($NewValue != DB_NOVALUE)
999  && ($NewValue != $this->DBFields["HasItemLevelQualifiers"]))
1000  {
1001  # check if qualifier column currently exists
1002  $QualColName = $this->DBFieldName()."Qualifier";
1003  $QualColExists = $this->DB->FieldExists("Resources", $QualColName);
1004 
1005  # if new value indicates qualifiers should now be used
1006  if ($NewValue == TRUE)
1007  {
1008  # if qualifier column does not exist in DB for this field
1009  if ($QualColExists == FALSE)
1010  {
1011  # add qualifier column in DB for this field
1012  $this->DB->Query("ALTER TABLE Resources ADD COLUMN `"
1013  .$QualColName."` INT");
1014  }
1015  }
1016  else
1017  {
1018  # if qualifier column exists in DB for this field
1019  if ($QualColExists == TRUE)
1020  {
1021  # remove qualifier column from DB for this field
1022  $this->DB->Query("ALTER TABLE Resources DROP COLUMN `"
1023  .$QualColName."`");
1024  }
1025  }
1026  }
1027 
1028  return $this->UpdateValue("HasItemLevelQualifiers", $NewValue);
1029  }
1030 
1031  # get list of qualifiers associated with field
1033  {
1034  # start with empty list
1035  $List = array();
1036 
1037  # for each associated qualifier
1038  $this->DB->Query("SELECT QualifierId FROM FieldQualifierInts"
1039  ." WHERE MetadataFieldId = ".$this->DBFields["FieldId"]);
1040  while ($Record = $this->DB->FetchRow())
1041  {
1042  # load qualifier object
1043  $Qual = new Qualifier($Record["QualifierId"]);
1044 
1045  # add qualifier ID and name to list
1046  $List[$Qual->Id()] = $Qual->Name();
1047  }
1048 
1049  # return list to caller
1050  return $List;
1051  }
1052 
1053  # get list of qualifiers not associated with field
1055  {
1056  # grab list of associated qualifiers
1057  $AssociatedQualifiers = $this->AssociatedQualifierList();
1058 
1059  # get list of all qualifiers
1060  $QFactory = new QualifierFactory();
1061  $AllQualifiers = $QFactory->GetItemNames();
1062 
1063  # return list of unassociated qualifiers
1064  return array_diff($AllQualifiers, $AssociatedQualifiers);
1065  }
1066 
1071  function AddQualifier($Qualifier)
1072  {
1073  # if qualifier object passed in
1074  if (is_object($Qualifier))
1075  {
1076  # grab qualifier ID from object
1077  $Qualifier = $Qualifier->Id();
1078  }
1079  # else if string passed in does not look like ID
1080  elseif (!preg_match('/^[0-9]+$/', $Qualifier))
1081  {
1082  # assume string passed in is name and use it to retrieve ID
1083  $QFact = new QualifierFactory();
1084  $Qualifier = $QFact->GetItemIdByName($Qualifier);
1085  }
1086 
1087  # if not already associated
1088  $RecordCount = $this->DB->Query(
1089  "SELECT COUNT(*) AS RecordCount FROM FieldQualifierInts"
1090  ." WHERE QualifierId = ".$Qualifier
1091  ." AND MetadataFieldId = ".$this->Id(), "RecordCount");
1092  if ($RecordCount < 1)
1093  {
1094  # associate field with qualifier
1095  $this->DB->Query("INSERT INTO FieldQualifierInts SET"
1096  ." QualifierId = ".$Qualifier.","
1097  ." MetadataFieldId = ".$this->Id());
1098  }
1099  }
1105  function AssociateWithQualifier($Qualifier)
1106  { $this->AddQualifier($Qualifier); }
1107 
1108  # delete qualifier association
1109  function UnassociateWithQualifier($QualifierIdOrObject)
1110  {
1111  # if qualifier object passed in
1112  if (is_object($QualifierIdOrObject))
1113  {
1114  # grab qualifier ID from object
1115  $QualifierIdOrObject = $QualifierIdOrObject->Id();
1116  }
1117 
1118  # delete intersection record from database
1119  $this->DB->Query("DELETE FROM FieldQualifierInts WHERE QualifierId = "
1120  .$QualifierIdOrObject." AND MetadataFieldId = ".
1121  $this->Id());
1122  }
1123 
1124  # retrieve item factory object for this field
1125  function GetFactory()
1126  {
1127  switch ($this->Type())
1128  {
1130  $Factory = new ClassificationFactory($this->Id());
1131  break;
1132 
1135  $Factory = new ControlledNameFactory($this->Id());
1136  break;
1137 
1138  default:
1139  $Factory = NULL;
1140  break;
1141  }
1142 
1143  return $Factory;
1144  }
1145 
1150  function Viewable()
1151  {
1152  # the field should not be viewed if it is disabled
1153  if (!$this->Enabled())
1154  {
1155  return FALSE;
1156  }
1157 
1158  $UserPrivs = $GLOBALS["G_User"]->Privileges();
1159 
1160  # the user can view the field if they can edit it
1161  if ($UserPrivs->IsGreaterThan($this->EditingPrivileges()))
1162  {
1163  return TRUE;
1164  }
1165 
1166  # if the user can view the field
1167  if ($UserPrivs->IsGreaterThan($this->ViewingPrivileges()))
1168  {
1169  return TRUE;
1170  }
1171 
1172  # the user can't view the field
1173  return FALSE;
1174  }
1175 
1176  # ---- PRIVATE INTERFACE -------------------------------------------------
1177 
1178  private $DB;
1179  private $Id;
1180  private $DBFields;
1181  private $ErrorStatus;
1182  private $AuthoringPrivileges;
1183  private $EditingPrivileges;
1184  private $ViewingPrivileges;
1185  private $PreviewingPrivileges;
1186 
1191  public static $FieldTypeHumanEnums = array(
1192  MetadataSchema::MDFTYPE_TEXT => "Text",
1193  MetadataSchema::MDFTYPE_PARAGRAPH => "Paragraph",
1194  MetadataSchema::MDFTYPE_NUMBER => "Number",
1195  MetadataSchema::MDFTYPE_DATE => "Date",
1196  MetadataSchema::MDFTYPE_TIMESTAMP => "Timestamp",
1197  MetadataSchema::MDFTYPE_FLAG => "Flag",
1198  MetadataSchema::MDFTYPE_TREE => "Tree",
1199  MetadataSchema::MDFTYPE_CONTROLLEDNAME => "Controlled Name",
1200  MetadataSchema::MDFTYPE_OPTION => "Option",
1201  MetadataSchema::MDFTYPE_USER => "User",
1202  MetadataSchema::MDFTYPE_IMAGE => "Image",
1203  MetadataSchema::MDFTYPE_FILE => "File",
1204  MetadataSchema::MDFTYPE_URL => "URL",
1205  MetadataSchema::MDFTYPE_POINT => "Point",
1206  MetadataSchema::MDFTYPE_REFERENCE => "Reference");
1207 
1208  # field type DB/PHP enum translations
1209  public static $FieldTypeDBEnums = array(
1210  MetadataSchema::MDFTYPE_TEXT => "Text",
1211  MetadataSchema::MDFTYPE_PARAGRAPH => "Paragraph",
1212  MetadataSchema::MDFTYPE_NUMBER => "Number",
1213  MetadataSchema::MDFTYPE_DATE => "Date",
1214  MetadataSchema::MDFTYPE_TIMESTAMP => "TimeStamp",
1215  MetadataSchema::MDFTYPE_FLAG => "Flag",
1216  MetadataSchema::MDFTYPE_TREE => "Tree",
1217  MetadataSchema::MDFTYPE_CONTROLLEDNAME => "ControlledName",
1218  MetadataSchema::MDFTYPE_OPTION => "Option",
1219  MetadataSchema::MDFTYPE_USER => "User",
1220  MetadataSchema::MDFTYPE_IMAGE => "Still Image",
1221  MetadataSchema::MDFTYPE_FILE => "File",
1222  MetadataSchema::MDFTYPE_URL => "Url",
1223  MetadataSchema::MDFTYPE_POINT => "Point",
1224  MetadataSchema::MDFTYPE_REFERENCE => "Reference"
1225  );
1226  public static $FieldTypeDBAllowedEnums = array(
1227  MetadataSchema::MDFTYPE_TEXT => "Text",
1228  MetadataSchema::MDFTYPE_PARAGRAPH => "Paragraph",
1229  MetadataSchema::MDFTYPE_NUMBER => "Number",
1230  MetadataSchema::MDFTYPE_DATE => "Date",
1231  MetadataSchema::MDFTYPE_TIMESTAMP => "TimeStamp",
1232  MetadataSchema::MDFTYPE_FLAG => "Flag",
1233  MetadataSchema::MDFTYPE_TREE => "Tree",
1234  MetadataSchema::MDFTYPE_CONTROLLEDNAME => "ControlledName",
1235  MetadataSchema::MDFTYPE_OPTION => "Option",
1236  MetadataSchema::MDFTYPE_USER => "User",
1237  MetadataSchema::MDFTYPE_IMAGE => "Still Image",
1238  MetadataSchema::MDFTYPE_FILE => "File",
1239  MetadataSchema::MDFTYPE_URL => "Url",
1240  MetadataSchema::MDFTYPE_POINT => "Point",
1241  MetadataSchema::MDFTYPE_REFERENCE => "Reference"
1242  );
1243  public static $FieldTypePHPEnums = array(
1244  "Text" => MetadataSchema::MDFTYPE_TEXT,
1245  "Paragraph" => MetadataSchema::MDFTYPE_PARAGRAPH,
1246  "Number" => MetadataSchema::MDFTYPE_NUMBER,
1247  "Date" => MetadataSchema::MDFTYPE_DATE,
1248  "TimeStamp" => MetadataSchema::MDFTYPE_TIMESTAMP,
1249  "Flag" => MetadataSchema::MDFTYPE_FLAG,
1250  "Tree" => MetadataSchema::MDFTYPE_TREE,
1251  "ControlledName" => MetadataSchema::MDFTYPE_CONTROLLEDNAME,
1252  "Option" => MetadataSchema::MDFTYPE_OPTION,
1253  "User" => MetadataSchema::MDFTYPE_USER,
1254  "Still Image" => MetadataSchema::MDFTYPE_IMAGE,
1255  "File" => MetadataSchema::MDFTYPE_FILE,
1256  "Url" => MetadataSchema::MDFTYPE_URL,
1257  "Point" => MetadataSchema::MDFTYPE_POINT,
1258  "Reference" => MetadataSchema::MDFTYPE_REFERENCE
1259  );
1260 
1261  public static $UpdateTypes = array(
1262  MetadataField::UPDATEMETHOD_NOAUTOUPDATE => "Do not update automatically",
1263  MetadataField::UPDATEMETHOD_ONRECORDCREATE => "Update on record creation",
1264  MetadataField::UPDATEMETHOD_BUTTON => "Provide an update button",
1265  MetadataField::UPDATEMETHOD_ONRECORDEDIT => "Update when record is edited",
1266  MetadataField::UPDATEMETHOD_ONRECORDCHANGE => "Update when record is changed"
1267  );
1268 
1282  static function Create($SchemaId, $FieldType, $FieldName,
1283  $Optional = NULL, $DefaultValue = NULL)
1284  {
1285  # error out if field type is bad
1286  if (empty(MetadataField::$FieldTypeDBEnums[$FieldType]))
1287  {
1288  throw new InvalidArgumentException("Bad field type (".$FieldType.").");
1289  }
1290 
1291  # error out if field name is duplicate
1292  $DB = new Database();
1293  $FieldName = trim($FieldName);
1294  $DuplicateCount = $DB->Query(
1295  "SELECT COUNT(*) AS RecordCount FROM MetadataFields"
1296  ." WHERE FieldName = '".addslashes($FieldName)."'"
1297  ." AND SchemaId = ".intval($SchemaId),
1298  "RecordCount");
1299  if ($DuplicateCount > 0)
1300  {
1301  throw new InvalidArgumentException("Duplicate field name (".$FieldName.").");
1302  }
1303 
1304  # grab current user ID
1305  $UserId = $GLOBALS["G_User"]->Get("UserId");
1306 
1307  # normalize schema ID
1308  $Schema = new MetadataSchema($SchemaId);
1309  $SchemaId = $Schema->Id();
1310 
1311  # use schema privileges as starting privilege values
1312  $AuthorPrivs = $Schema->AuthoringPrivileges();
1313  $EditPrivs = $Schema->EditingPrivileges();
1314  $ViewPrivs = $Schema->ViewingPrivileges();
1315  $PreviewPrivs = $Schema->ViewingPrivileges();
1316 
1317  # lock DB tables and get next temporary field ID
1318  $DB->Query("LOCK TABLES MetadataFields WRITE");
1319  $FieldId = $Schema->GetNextTempItemId();
1320 
1321  # add field to MDF table in database
1322  $DB->Query("INSERT INTO MetadataFields"
1323  ." (FieldId, SchemaId, FieldName, FieldType, LastModifiedById,"
1324  ." Optional, AuthoringPrivileges, EditingPrivileges,"
1325  ." ViewingPrivileges, PreviewingPrivileges)"
1326  ." VALUES ("
1327  .intval($FieldId).", "
1328  .intval($SchemaId).","
1329  ." '".addslashes($FieldName)."',"
1330  ." '".MetadataField::$FieldTypeDBEnums[$FieldType]."', "
1331  .intval($UserId).", "
1332  .($Optional ? "1" : "0").","
1333  ."'".mysql_escape_string($AuthorPrivs->Data())."',"
1334  ."'".mysql_escape_string($EditPrivs->Data())."',"
1335  ."'".mysql_escape_string($ViewPrivs->Data())."',"
1336  ."'".mysql_escape_string($PreviewPrivs->Data())."')");
1337 
1338  # release DB tables
1339  $DB->Query("UNLOCK TABLES");
1340 
1341  # load field object
1342  $Field = new MetadataField($FieldId);
1343 
1344  # set field defaults
1345  $Field->SetDefaults();
1346 
1347  # set the default value if specified
1348  if ($DefaultValue !== NULL)
1349  {
1350  $Field->DefaultValue($DefaultValue);
1351  }
1352 
1353  # return newly-constructed field to caller
1354  return $Field;
1355  }
1356 
1363  function __construct($FieldId)
1364  {
1365  # assume everything will be okay
1366  $this->ErrorStatus = MetadataSchema::MDFSTAT_OK;
1367 
1368  # retrieve field info from database
1369  $this->DB = new Database();
1370  $Result = $this->DB->Query("SELECT * FROM MetadataFields"
1371  ." WHERE FieldId = ".intval($FieldId));
1372  if ($this->DB->NumRowsSelected() == 0)
1373  {
1374  throw new InvalidArgumentException("Invalid metadata field ID ("
1375  .$FieldId.")");
1376  }
1377  $Row = $this->DB->FetchRow();
1378  $this->DBFields = $Row;
1379  $this->Id = $FieldId;
1380 
1381  # if privileges have not yet been initialized
1382  if (!strlen($this->DBFields["AuthoringPrivileges"]))
1383  {
1384  # set default values for privileges from metadata schema
1385  $Schema = new MetadataSchema($Row["SchemaId"]);
1386  $this->AuthoringPrivileges($Schema->AuthoringPrivileges());
1387  $this->EditingPrivileges($Schema->EditingPrivileges());
1388  $this->ViewingPrivileges($Schema->ViewingPrivileges());
1389  $this->PreviewingPrivileges($Schema->ViewingPrivileges());
1390  }
1391  else
1392  {
1393  # set privileges from stored values
1394  $this->AuthoringPrivileges = new PrivilegeSet(
1395  $Row["AuthoringPrivileges"]);
1396  $this->EditingPrivileges = new PrivilegeSet(
1397  $Row["EditingPrivileges"]);
1398  $this->ViewingPrivileges = new PrivilegeSet(
1399  $Row["ViewingPrivileges"]);
1400  $this->PreviewingPrivileges = new PrivilegeSet(
1401  $Row["PreviewingPrivileges"]);
1402  }
1403 
1404  # set database column name
1405  $this->DBFields["DBFieldName"] =
1406  $this->NormalizeFieldNameForDB($this->DBFields["FieldName"]);
1407  }
1408 
1413  public static $FixedDefaults = array(
1414  "Label" => NULL,
1415  "Description" => NULL,
1416  "Instructions" => NULL,
1417  "Enabled" => TRUE,
1418  "Optional" => TRUE,
1419  "Editable" => TRUE,
1420  "AllowMultiple" => FALSE,
1421  "IncludeInKeywordSearch" => FALSE,
1422  "IncludeInAdvancedSearch" => FALSE,
1423  "IncludeInFacetedSearch" => FALSE,
1424  "IncludeInSortOptions" => TRUE,
1425  "IncludeInRecommender" => FALSE,
1426  "ParagraphRows" => 4,
1427  "ParagraphCols" => 50,
1428  "MinValue" => 1,
1429  "FlagOnLabel" => "On",
1430  "FlagOffLabel" => "Off",
1431  "DateFormat" => NULL,
1432  "RecommenderWeight" => 1,
1433  "MaxHeight" => 500,
1434  "MaxWidth" => 500,
1435  "MaxPreviewHeight" => 100,
1436  "MaxPreviewWidth" => 100,
1437  "MaxThumbnailHeight" => 50,
1438  "MaxThumbnailWidth" => 50,
1439  "DefaultAltText" => NULL,
1440  "UsesQualifiers" => FALSE,
1441  "HasItemLevelQualifiers" => FALSE,
1442  "ShowQualifiers" => FALSE,
1443  "DefaultQualifier" => NULL,
1444  "AllowHTML" => FALSE,
1445  "UseWysiwygEditor" => FALSE,
1446  "UseForOaiSets" => FALSE,
1447  "OptionListThreshold" => 25,
1448  "AjaxThreshold" => 50,
1449  "NumAjaxResults" => 50,
1450  "ViewingPrivilege" => NULL,
1451  "AuthoringPrivilege" => PRIV_MYRESOURCEADMIN,
1452  "EditingPrivilege" => PRIV_RESOURCEADMIN,
1453  "ImagePreviewPrivilege" => NULL,
1454  "TreeBrowsingPrivilege" => NULL,
1455  "ViewingUserIsValue" => self::USERISVALUE_UNSET,
1456  "AuthoringUserIsValue" => self::USERISVALUE_UNSET,
1457  "EditingUserIsValue" => self::USERISVALUE_UNSET,
1458  "ViewingUserValue" => NULL,
1459  "AuthoringUserValue" => NULL,
1460  "EditingUserValue" => NULL,
1461  "PointPrecision" => 8,
1462  "PointDecimalDigits" => 5,
1463  "UserPrivilegeRestrictions" => array(),
1464  "UpdateMethod" => "NoAutoUpdate",
1465  # 9999 is the default max value because default number field length is 4
1466  "MaxValue" => 9999);
1467 
1472  public static $TypeBasedDefaults = array(
1474  "DefaultValue" => NULL,
1475  "SearchWeight" => 1,
1476  "TextFieldSize" => 50,
1477  "MaxLength" => 100),
1479  "DefaultValue" => NULL,
1480  "SearchWeight" => 1,
1481  "TextFieldSize" => 50,
1482  "MaxLength" => 100),
1484  "DefaultValue" => NULL,
1485  "SearchWeight" => 1,
1486  "TextFieldSize" => 4,
1487  "MaxLength" => 100),
1489  "DefaultValue" => NULL,
1490  "SearchWeight" => 1,
1491  "TextFieldSize" => 10,
1492  "MaxLength" => 100),
1494  "DefaultValue" => NULL,
1495  "SearchWeight" => 1,
1496  "TextFieldSize" => 50,
1497  "MaxLength" => 100),
1499  "DefaultValue" => NULL,
1500  "SearchWeight" => 1,
1501  "TextFieldSize" => 50,
1502  "MaxLength" => 100),
1504  "DefaultValue" => NULL,
1505  "SearchWeight" => 1,
1506  "TextFieldSize" => 50,
1507  "MaxLength" => 100),
1509  "DefaultValue" => NULL,
1510  "SearchWeight" => 3,
1511  "TextFieldSize" => 50,
1512  "MaxLength" => 100),
1514  "DefaultValue" => NULL,
1515  "SearchWeight" => 3,
1516  "TextFieldSize" => 50,
1517  "MaxLength" => 100),
1519  "DefaultValue" => NULL,
1520  "SearchWeight" => 1,
1521  "TextFieldSize" => 50,
1522  "MaxLength" => 100),
1524  "DefaultValue" => NULL,
1525  "SearchWeight" => 1,
1526  "TextFieldSize" => 50,
1527  "MaxLength" => 100),
1529  "DefaultValue" => NULL,
1530  "SearchWeight" => 1,
1531  "TextFieldSize" => 50,
1532  "MaxLength" => 100),
1533  MetadataSchema::MDFTYPE_URL => array(
1534  "DefaultValue" => NULL,
1535  "SearchWeight" => 1,
1536  "TextFieldSize" => 50,
1537  "MaxLength" => 255),
1539  "DefaultValue" => array("X" => NULL, "Y" => NULL),
1540  "SearchWeight" => 1,
1541  "TextFieldSize" => 10,
1542  "MaxLength" => 100),
1544  "DefaultValue" => NULL,
1545  "SearchWeight" => 1,
1546  "TextFieldSize" => 50,
1547  "MaxLength" => 100));
1548 
1553  public function SetDefaults()
1554  {
1555  # set defaults that are the same for every field
1556  foreach (self::$FixedDefaults as $Key => $Value)
1557  {
1558  $this->$Key($Value);
1559  }
1560 
1561  # set defaults that depend on the type of the field
1562  foreach (self::$TypeBasedDefaults[$this->Type()] as $Key => $Value)
1563  {
1564  $this->$Key($Value);
1565  }
1566 
1567  # tweak the update method if dealing with the date of record creation
1568  if ($this->Name() == "Date Of Record Creation")
1569  {
1570  $this->UpdateMethod("OnRecordCreate");
1571  }
1572  }
1573 
1574  # remove field from database (only for use by MetadataSchema object)
1575  function Drop()
1576  {
1577  # clear other database entries as appropriate for field type
1578  $DB = $this->DB;
1579  $DBFieldName = $this->DBFields["DBFieldName"];
1580  $Schema = new MetadataSchema($this->SchemaId());
1581  switch (MetadataField::$FieldTypePHPEnums[$this->DBFields["FieldType"]])
1582  {
1591  # remove field from resources table
1592  if ($DB->FieldExists("Resources", $DBFieldName))
1593  {
1594  $DB->Query("ALTER TABLE Resources DROP COLUMN `".$DBFieldName."`");
1595  }
1596  break;
1597 
1599  if ($DB->FieldExists("Resources", $DBFieldName."X"))
1600  {
1601  $DB->Query("ALTER TABLE Resources DROP COLUMN `".$DBFieldName."X`");
1602  $DB->Query("ALTER TABLE Resources DROP COLUMN `".$DBFieldName."Y`");
1603  }
1604  break;
1605 
1607  # remove fields from resources table
1608  if ($DB->FieldExists("Resources", $DBFieldName."Begin"))
1609  {
1610  $DB->Query("ALTER TABLE Resources DROP COLUMN `".$DBFieldName."Begin`");
1611  $DB->Query("ALTER TABLE Resources DROP COLUMN `".$DBFieldName."End`");
1612  $DB->Query("ALTER TABLE Resources DROP COLUMN `".$DBFieldName."Precision`");
1613  }
1614  break;
1615 
1617  $DB->Query("SELECT ClassificationId FROM Classifications "
1618  ."WHERE FieldId = ".$this->Id());
1619  $TempDB = new Database();
1620  while ($ClassificationId = $DB->FetchField("ClassificationId"))
1621  {
1622  # remove any resource / name intersections
1623  $TempDB->Query("DELETE FROM ResourceClassInts WHERE "
1624  ."ClassificationId = ".$ClassificationId);
1625 
1626  # remove controlled name
1627  $TempDB->Query("DELETE FROM Classifications WHERE "
1628  ."ClassificationId = ".$ClassificationId);
1629  }
1630  break;
1631 
1634  $DB->Query("SELECT ControlledNameId FROM ControlledNames "
1635  ."WHERE FieldId = ".$this->Id());
1636  $TempDB = new Database();
1637  while ($ControlledNameId = $DB->FetchField("ControlledNameId"))
1638  {
1639  # remove any resource / name intersections
1640  $TempDB->Query("DELETE FROM ResourceNameInts WHERE "
1641  ."ControlledNameId = ".$ControlledNameId);
1642 
1643  # remove any variant names
1644  $TempDB->Query("DELETE FROM VariantNames WHERE "
1645  ."ControlledNameId = ".$ControlledNameId);
1646 
1647  # remove controlled name
1648  $TempDB->Query("DELETE FROM ControlledNames WHERE "
1649  ."ControlledNameId = ".$ControlledNameId);
1650  }
1651  break;
1652 
1654  # for each file associated with this field
1655  $DB->Query("SELECT FileId FROM Files WHERE FieldId = '".$this->Id()."'");
1656  while ($FileId = $DB->FetchRow())
1657  {
1658  # delete file
1659  $File = new File(intval($FileId));
1660  $File->Delete();
1661  }
1662  break;
1663 
1665  # remove any resource references for the field
1666  $DB->Query("
1667  DELETE FROM ReferenceInts
1668  WHERE FieldId = '".addslashes($this->Id())."'");
1669  break;
1670  }
1671 
1672  # remove field from database
1673  $DB->Query("DELETE FROM MetadataFields "
1674  ."WHERE FieldId = '".$this->DBFields["FieldId"]."'");
1675 
1676  # remove any qualifier associations
1677  $DB->Query("DELETE FROM FieldQualifierInts WHERE MetadataFieldId = '"
1678  .$this->DBFields["FieldId"]."'");
1679 
1680  # get the order objects the field is part of
1681  foreach (MetadataFieldOrder::GetOrdersForSchema($Schema) as $Order)
1682  {
1683  # remove it if it's a direct descendant
1684  $Order->RemoveItem($this->Id(), "MetadataField");
1685 
1686  # also make sure to remove it if it's part of a group
1687  foreach ($Order->GetItemIds() as $Item)
1688  {
1689  if ($Item["Type"] == "MetadataFieldGroup")
1690  {
1691  $Group = new MetadataFieldGroup($Item["ID"]);
1692  $Group->RemoveItem($this->Id(), "MetadataField");
1693  }
1694  }
1695  }
1696  }
1697 
1698  # modify any database fields
1699  private function ModifyField($NewName = NULL, $NewType = NULL)
1700  {
1701  # grab old DB field name
1702  $OldDBFieldName = $this->DBFields["DBFieldName"];
1703  $OldFieldType = NULL;
1704 
1705  # if new field name supplied
1706  if ($NewName != NULL)
1707  {
1708  # cache the old name for options and controllednames below
1709  $OldName = $this->DBFields["FieldName"];
1710 
1711  # store new name
1712  $this->UpdateValue("FieldName", $NewName);
1713 
1714  # determine new DB field name
1715  $NewDBFieldName = $this->NormalizeFieldNameForDB($NewName);
1716 
1717  # store new database field name
1718  $this->DBFields["DBFieldName"] = $NewDBFieldName;
1719  }
1720  else
1721  {
1722  # set new field name equal to old field name
1723  $NewDBFieldName = $OldDBFieldName;
1724  }
1725 
1726  # if new type supplied
1727  if ($NewType != NULL)
1728  {
1729  # grab old field type
1730  $OldFieldType = MetadataField::$FieldTypePHPEnums[$this->DBFields["FieldType"]];
1731 
1732  # store new field type
1733  $this->UpdateValue("FieldType", MetadataField::$FieldTypeDBEnums[$NewType]);
1734  }
1735 
1736  # if this is not a temporary field
1737  if ($this->Id() >= 0)
1738  {
1739  # modify field in DB as appropriate for field type
1740  $DB = $this->DB;
1741  $FieldType = MetadataField::$FieldTypePHPEnums[$this->DBFields["FieldType"]];
1742  switch ($FieldType)
1743  {
1747  # alter field declaration in Resources table
1748  $DB->Query("ALTER TABLE Resources CHANGE COLUMN `"
1749  .$OldDBFieldName."` `"
1750  .$NewDBFieldName."` TEXT "
1751  .($this->DBFields["Optional"] ? "" : "NOT NULL"));
1752  break;
1753 
1756  # alter field declaration in Resources table
1757  $DB->Query("ALTER TABLE Resources CHANGE COLUMN `"
1758  .$OldDBFieldName."` `"
1759  .$NewDBFieldName."` INT "
1760  .($this->DBFields["Optional"] ? "" : "NOT NULL"));
1761  break;
1762 
1764  $Precision = $this->UpdateValue("PointPrecision",
1765  DB_NOVALUE);
1766  $Digits = $this->UpdateValue("PointDecimalDigits",
1767  DB_NOVALUE);
1768  $DB->Query("ALTER TABLE Resources CHANGE COLUMN "
1769  ."`".$OldDBFieldName."X` "
1770  ."`".$NewDBFieldName."X`".
1771  " DECIMAL(".$Precision.",".$Digits.")");
1772  $DB->Query("ALTER TABLE Resources CHANGE COLUMN "
1773  ."`".$OldDBFieldName."Y` "
1774  ."`".$NewDBFieldName."Y`".
1775  " DECIMAL(".$Precision.",".$Digits.")");
1776  break;
1777 
1779  # if DB field name has changed
1780  if ($NewDBFieldName != $OldDBFieldName)
1781  {
1782  # alter field declaration in Resources table
1783  $DB->Query("ALTER TABLE Resources CHANGE COLUMN `"
1784  .$OldDBFieldName."` `"
1785  .$NewDBFieldName."` TEXT");
1786  }
1787  break;
1788 
1790  # alter field declaration in Resources table
1791  $DB->Query("ALTER TABLE Resources CHANGE COLUMN `"
1792  .$OldDBFieldName."` `"
1793  .$NewDBFieldName."` INT"
1794  ." DEFAULT ".intval($this->DefaultValue()));
1795 
1796  # set any unset values to default
1797  $DB->Query("UPDATE Resources SET `".$NewDBFieldName
1798  ."` = ".intval($this->DefaultValue())
1799  ." WHERE `".$NewDBFieldName."` IS NULL");
1800  break;
1801 
1803  # if new type supplied and new type is different from old
1804  if (($NewType != NULL) && ($NewType != $OldFieldType))
1805  {
1806  # if old type was time stamp
1807  if ($OldFieldType == MetadataSchema::MDFTYPE_TIMESTAMP)
1808  {
1809  # change time stamp field in resources table to begin date
1810  $DB->Query("ALTER TABLE Resources CHANGE COLUMN `"
1811  .$OldDBFieldName."` `"
1812  .$NewDBFieldName."Begin` DATE "
1813  .($this->DBFields["Optional"] ? "" : "NOT NULL"));
1814 
1815  # add end date and precision fields
1816  $DB->Query("ALTER TABLE Resources ADD COLUMN `".$NewDBFieldName."End"
1817  ."` DATE");
1818  $DB->Query("ALTER TABLE Resources ADD COLUMN `".$NewDBFieldName."Precision`"
1819  ." INT ".($Optional ? "" : "NOT NULL"));
1820 
1821  # set precision to reflect time stamp content
1822  $DB->Query("UPDATE Resources SET `".$NewDBFieldName."Precision` = "
1823  .(DATEPRE_BEGINYEAR|DATEPRE_BEGINMONTH|DATEPRE_BEGINDAY));
1824  }
1825  else
1826  {
1827  exit("<br>ERROR: Attempt to convert metadata field to date from type other than timestamp<br>\n");
1828  }
1829  }
1830  else
1831  {
1832  # change name of fields
1833  $DB->Query("ALTER TABLE Resources CHANGE COLUMN `"
1834  .$OldDBFieldName."Begin` `"
1835  .$NewDBFieldName."Begin` DATE "
1836  .($this->DBFields["Optional"] ? "" : "NOT NULL"));
1837  $DB->Query("ALTER TABLE Resources CHANGE COLUMN `"
1838  .$OldDBFieldName."End` `"
1839  .$NewDBFieldName."End` DATE "
1840  .($this->DBFields["Optional"] ? "" : "NOT NULL"));
1841  $DB->Query("ALTER TABLE Resources CHANGE COLUMN `"
1842  .$OldDBFieldName."Precision` `"
1843  .$NewDBFieldName."Precision` INT "
1844  .($this->DBFields["Optional"] ? "" : "NOT NULL"));
1845  }
1846  break;
1847 
1849  # if new type supplied and new type is different from old
1850  if (($NewType != NULL) && ($NewType != $OldFieldType))
1851  {
1852  # if old type was date
1853  if ($OldFieldType == MetadataSchema::MDFTYPE_DATE)
1854  {
1855  # change begin date field in resource table to time stamp
1856  $DB->Query("ALTER TABLE Resources CHANGE COLUMN `"
1857  .$OldDBFieldName."Begin` `"
1858  .$NewDBFieldName."` DATETIME "
1859  .($this->DBFields["Optional"] ? "" : "NOT NULL"));
1860 
1861  # drop end date and precision fields
1862  $DB->Query("ALTER TABLE Resources DROP COLUMN `"
1863  .$OldDBFieldName."End`");
1864  $DB->Query("ALTER TABLE Resources DROP COLUMN `"
1865  .$OldDBFieldName."Precision`");
1866  }
1867  else
1868  {
1869  exit("<br>ERROR: Attempt to convert metadata field to time stamp from type other than date<br>\n");
1870  }
1871  }
1872  else
1873  {
1874  # change name of field
1875  $DB->Query("ALTER TABLE Resources CHANGE COLUMN `"
1876  .$OldDBFieldName."` `"
1877  .$NewDBFieldName."` DATETIME "
1878  .($this->DBFields["Optional"] ? "" : "NOT NULL"));
1879  }
1880  break;
1881 
1887  break;
1888  }
1889 
1890  # if qualifier DB field exists
1891  if ($DB->FieldExists("Resources", $OldDBFieldName."Qualifier"))
1892  {
1893  # rename qualifier DB field
1894  $DB->Query("ALTER TABLE Resources CHANGE COLUMN `"
1895  .$OldDBFieldName."Qualifier` `"
1896  .$NewDBFieldName."Qualifier` INT ");
1897  }
1898  }
1899  }
1900 
1901  # convenience functions to supply parameters to Database->UpdateValue()
1902  private function UpdateValue($FieldName, $NewValue)
1903  {
1904  return $this->DB->UpdateValue("MetadataFields", $FieldName, $NewValue,
1905  "FieldId = ".intval($this->DBFields["FieldId"]),
1906  $this->DBFields);
1907  }
1908  private function UpdateIntValue($FieldName, $NewValue)
1909  {
1910  return $this->DB->UpdateIntValue("MetadataFields", $FieldName, $NewValue,
1911  "FieldId = ".intval($this->DBFields["FieldId"]),
1912  $this->DBFields);
1913  }
1914  private function UpdateFloatValue($FieldName, $NewValue)
1915  {
1916  return $this->DB->UpdateFloatValue("MetadataFields", $FieldName, $NewValue,
1917  "FieldId = ".intval($this->DBFields["FieldId"]),
1918  $this->DBFields);
1919  }
1920  private function UpdateBoolValue($FieldName, $NewValue)
1921  {
1922  $NewValue = $this->TranslateStringToConstants($NewValue);
1923  return $this->DB->UpdateIntValue("MetadataFields", $FieldName, $NewValue,
1924  "FieldId = ".intval($this->DBFields["FieldId"]),
1925  $this->DBFields);
1926  }
1927  private function UpdateConstValue($FieldName, $NewValue, $ClassName=NULL)
1928  {
1929  $NewValue = $this->TranslateStringToConstants($NewValue, $ClassName);
1930  return $this->DB->UpdateIntValue("MetadataFields", $FieldName, $NewValue,
1931  "FieldId = ".intval($this->DBFields["FieldId"]),
1932  $this->DBFields);
1933  }
1934 
1935  # normalize field name for use as database field name
1936  private function NormalizeFieldNameForDB($Name)
1937  {
1938  return preg_replace("/[^a-z0-9]/i", "", $Name)
1939  .(($this->SchemaId() != MetadataSchema::SCHEMAID_DEFAULT)
1940  ? $this->SchemaId() : "");
1941  }
1942 
1943  # add any needed database fields and/or entries
1944  private function AddDatabaseFields()
1945  {
1946  # grab values for common use
1947  $DB = $this->DB;
1948  $FieldName = $this->Name();
1949  $DBFieldName = $this->DBFieldName();
1950  $Optional = $this->Optional();
1951  $DefaultValue = $this->DefaultValue();
1952 
1953  # set up field(s) based on field type
1954  switch ($this->Type())
1955  {
1959  # add field to resources table (if not already present)
1960  if (!$DB->FieldExists("Resources", $DBFieldName))
1961  {
1962  $DB->Query("ALTER TABLE Resources ADD COLUMN `".$DBFieldName
1963  ."` TEXT ".($Optional ? "" : "NOT NULL"));
1964  }
1965 
1966  # if default value supplied
1967  if ($DefaultValue != NULL)
1968  {
1969  # set all existing records to default value
1970  $DB->Query("UPDATE Resources SET `"
1971  .$DBFieldName."` = '".addslashes($DefaultValue)."'");
1972  }
1973  break;
1974 
1976  # add field to resources table (if not already present)
1977  if (!$DB->FieldExists("Resources", $DBFieldName))
1978  {
1979  $DB->Query("ALTER TABLE Resources ADD COLUMN `".$DBFieldName
1980  ."` INT ".($Optional ? "" : "NOT NULL"));
1981  }
1982 
1983  # if default value supplied
1984  if ($DefaultValue != NULL)
1985  {
1986  # set all existing records to default value
1987  $DB->Query("UPDATE Resources SET `"
1988  .$DBFieldName."` = '".addslashes($DefaultValue)."'");
1989  }
1990  break;
1991 
1993  if (!$DB->FieldExists("Resources", $DBFieldName."X"))
1994  {
1995  $Precision = $this->UpdateValue("PointPrecision",
1996  DB_NOVALUE);
1997  $Digits = $this->UpdateValue("PointDecimalDigits",
1998  DB_NOVALUE);
1999 
2000  $DB->Query("ALTER TABLE Resources ADD COLUMN `"
2001  .$DBFieldName."X`".
2002  " DECIMAL(".$Precision.",".$Digits.")");
2003  $DB->Query("ALTER TABLE Resources ADD COLUMN `"
2004  .$DBFieldName."Y`".
2005  " DECIMAL(".$Precision.",".$Digits.")");
2006  }
2007 
2008  break;
2010  # if field is not already present in database
2011  if (!$DB->FieldExists("Resources", $DBFieldName))
2012  {
2013  # add field to resources table
2014  $DB->Query("ALTER TABLE Resources ADD COLUMN `".$DBFieldName
2015  ."` INT DEFAULT ".intval($DefaultValue));
2016 
2017  # set all existing records to default value
2018  $DB->Query("UPDATE Resources SET `"
2019  .$DBFieldName."` = ".intval($DefaultValue));
2020  }
2021  break;
2022 
2024  # add field to resources table (if not already present)
2025  if (!$DB->FieldExists("Resources", $DBFieldName))
2026  {
2027  $DB->Query("ALTER TABLE Resources ADD COLUMN `".$DBFieldName
2028  ."` INT ".($Optional ? "" : "NOT NULL"));
2029  }
2030  break;
2031 
2033  # add fields to resources table (if not already present)
2034  if (!$DB->FieldExists("Resources", $DBFieldName))
2035  {
2036  $DB->Query("ALTER TABLE Resources ADD COLUMN `"
2037  .$DBFieldName."` TEXT");
2038  }
2039  break;
2040 
2042  # add fields to resources table (if not already present)
2043  if (!$DB->FieldExists("Resources", $DBFieldName))
2044  {
2045  $DB->Query("ALTER TABLE Resources ADD COLUMN `"
2046  .$DBFieldName."` INT");
2047  }
2048  break;
2049 
2051  # add fields to resources table (if not already present)
2052  if (!$DB->FieldExists("Resources", $DBFieldName."Begin"))
2053  {
2054  $DB->Query("ALTER TABLE Resources ADD COLUMN `".$DBFieldName."Begin`"
2055  ." DATE ".($Optional ? "" : "NOT NULL"));
2056  }
2057  if (!$DB->FieldExists("Resources", $DBFieldName."End"))
2058  {
2059  $DB->Query("ALTER TABLE Resources ADD COLUMN `".$DBFieldName."End`"
2060  ." DATE");
2061  }
2062  if (!$DB->FieldExists("Resources", $DBFieldName."Precision"))
2063  {
2064  $DB->Query("ALTER TABLE Resources ADD COLUMN `".$DBFieldName."Precision`"
2065  ." INT ".($Optional ? "" : "NOT NULL"));
2066  }
2067  break;
2068 
2070  # add fields to resources table (if not already present)
2071  if (!$DB->FieldExists("Resources", $DBFieldName))
2072  {
2073  $DB->Query("ALTER TABLE Resources ADD COLUMN `".$DBFieldName
2074  ."` DATETIME ".($Optional ? "" : "NOT NULL"));
2075  }
2076  break;
2077 
2082  break;
2083 
2084  default:
2085  exit("<br>ERROR: Attempt to add database fields for illegal metadata field type<br>\n");
2086  break;
2087  }
2088  }
2089 
2097  private function TranslateStringToConstants($CString, $ClassName = NULL)
2098  {
2099  # if not a string return value unchanged to caller
2100  if (!is_string($CString) || ($CString === DB_NOVALUE))
2101  {
2102  $ReturnValue = $CString;
2103  }
2104  # handle booleans as a special case
2105  elseif (strtoupper(trim($CString)) == "TRUE")
2106  {
2107  $ReturnValue = TRUE;
2108  }
2109  elseif (strtoupper(trim($CString)) == "FALSE")
2110  {
2111  $ReturnValue = FALSE;
2112  }
2113  else
2114  {
2115  # assume no values will be found
2116  $ReturnValue = NULL;
2117 
2118  # split apart any ORed-together values
2119  $Values = explode("|", $CString);
2120 
2121  # for each value found
2122  foreach ($Values as $Value)
2123  {
2124  # trim off any extraneous whitespace
2125  $Value = trim($Value);
2126 
2127  # add class name prefix to constant name if requested
2128  if ($ClassName) { $Value = $ClassName."::".$Value; }
2129 
2130  # if value corresponds to a constant
2131  if (defined($Value))
2132  {
2133  # add constant to return value
2134  $ReturnValue = ($ReturnValue === NULL)
2135  ? constant($Value)
2136  : ($ReturnValue | constant($Value));
2137  }
2138  }
2139 
2140  # if no corresponding constants were found
2141  if ($ReturnValue === NULL)
2142  {
2143  # return original value to caller
2144  $ReturnValue = $CString;
2145  }
2146  }
2147 
2148  # return result to caller
2149  return $ReturnValue;
2150  }
2151 
2152 }
const MDFSTAT_ILLEGALLABEL
DefaultQualifier($NewValue=DB_NOVALUE)
static $FieldTypeDBEnums
ViewingPrivileges(PrivilegeSet $NewValue=NULL)
Get/set privileges that allowing viewing values for this field.
static $FixedDefaults
The metadata field defaults that are the same for all field types.
const DATEPRE_BEGINDAY
Definition: Axis--Date.php:747
static $FieldTypeDBAllowedEnums
SetDefaults()
Set defaults values for the field.
Owner($NewValue=DB_NOVALUE)
Get/set field owner.
MaxPreviewHeight($NewValue=DB_NOVALUE)
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
__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)
AllowHTML($NewValue=DB_NOVALUE)
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.
const DB_NOVALUE
AuthoringPrivileges(PrivilegeSet $NewValue=NULL)
Get/set privileges that allowing authoring values for this field.
ShowQualifiers($NewValue=DB_NOVALUE)
FlagOffLabel($NewValue=DB_NOVALUE)
PointPrecision($NewValue=DB_NOVALUE)
OptionListThreshold($NewValue=DB_NOVALUE)
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.
EditingUserValue($NewValue=DB_NOVALUE)
MaxThumbnailHeight($NewValue=DB_NOVALUE)
SearchWeight($NewValue=DB_NOVALUE)
Set of privileges used to access resource information or other parts of the system.
HasItemLevelQualifiers($NewValue=DB_NOVALUE)
AssociateWithQualifier($Qualifier)
DEPRECATED METHOD.
AuthoringPrivilege($NewValue=DB_NOVALUE)
DefaultAltText($NewValue=DB_NOVALUE)
Class that builds on the foldering functionality to provide groups of metadata fields.
AjaxThreshold($NewValue=DB_NOVALUE)
Factory class for Qualifier.
const MDFTYPE_CONTROLLEDNAME
Viewable()
This function has been deprecated and should not be used.
CWIS-specific user factory class.
static $FieldTypeHumanEnums
A map of metadata field types to human-readable strings.
MaxPreviewWidth($NewValue=DB_NOVALUE)
const UPDATEMETHOD_ONRECORDEDIT
PHP
Definition: OAIClient.php:39
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)
TypeAsName()
Get type of field as string.
const DATEPRE_BEGINMONTH
Definition: Axis--Date.php:746
MaxLength($NewValue=DB_NOVALUE)
MaxValue($NewValue=DB_NOVALUE)
PointDecimalDigits($NewValue=DB_NOVALUE)
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)
EditingPrivilege($NewValue=DB_NOVALUE)
RequiredBySPT($NewValue=DB_NOVALUE)
AuthoringUserIsValue($NewValue=DB_NOVALUE)
UsesQualifiers($NewValue=DB_NOVALUE)
MaxThumbnailWidth($NewValue=DB_NOVALUE)
Enabled($NewValue=DB_NOVALUE)
Get/set whether field is enabled.
Factory for manipulating ControlledName objects.
const UPDATEMETHOD_NOAUTOUPDATE
Object representing a locally-defined type of metadata field.
NumAjaxResults($NewValue=DB_NOVALUE)
TextFieldSize($NewValue=DB_NOVALUE)
ViewingUserIsValue($NewValue=DB_NOVALUE)
EnableOnOwnerReturn($NewValue=DB_NOVALUE)
FlagOnLabel($NewValue=DB_NOVALUE)
TreeBrowsingPrivilege($NewValue=DB_NOVALUE)
const UPDATEMETHOD_BUTTON
UseWysiwygEditor($NewValue=DB_NOVALUE)
EditingUserIsValue($NewValue=DB_NOVALUE)
GetPossibleValues($MaxNumberOfValues=NULL, $Offset=0)
const MDFSTAT_ILLEGALNAME
EditingPrivileges(PrivilegeSet $NewValue=NULL)
Get/set privileges that allowing editing values for this field.
static GetOrdersForSchema(MetadataSchema $Schema)
Get all of the orders associated with a schema.
GetIdForValue($Value)
RecommenderWeight($NewValue=DB_NOVALUE)
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)
MaxWidth($NewValue=DB_NOVALUE)
MaxHeight($NewValue=DB_NOVALUE)
const UPDATEMETHOD_ONRECORDCREATE
const MDFSTAT_DUPLICATENAME
Factory for producing and manipulating Classification objects.
PreviewingPrivileges(PrivilegeSet $NewValue=NULL)
Get/set privileges that allowing previewing values for this field.
ParagraphCols($NewValue=DB_NOVALUE)
UnassociateWithQualifier($QualifierIdOrObject)
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.
IsTempItem($NewSetting=NULL)
Get/set whether field is temporary instance.
Name($NewName=DB_NOVALUE)
Get/set name of field.
IncludeInAdvancedSearch($NewValue=DB_NOVALUE)
Get/set whether to include field in advanced search.
GetDisplayName()
Get display name for field.
MinValue($NewValue=DB_NOVALUE)
AuthoringUserValue($NewValue=DB_NOVALUE)
UpdateMethod($NewValue=DB_NOVALUE)
Get/set method by which field is updated.