CWIS Developer Documentation
HumanMetadataField.php
Go to the documentation of this file.
1 <?PHP
2 #
3 # FILE: ItemFactory.php
4 #
5 # Part of the Collection Workflow Integration System (CWIS)
6 # Copyright 2013 Edward Almasy and Internet Scout Research Group
7 # http://scout.wisc.edu/cwis/
8 #
9 
15 {
16 
21  public function __construct(MetadataField $Field)
22  {
23  $this->Field = $Field;
24  }
25 
30  public function Status()
31  {
32  switch ($this->Field->Status())
33  {
35  return "OK";
37  return "Error";
39  return "Duplicate field name";
41  return "Duplicate database column";
43  return "Field does not exist";
45  return "Illegal field name";
47  return "Duplicate label name";
49  return "Illegal label name";
50  }
51 
52  return $this->NotSetText;
53  }
54 
59  public function Type()
60  {
61  return MetadataField::$FieldTypeDBEnums[$this->Field->Type()];
62  }
63 
68  public function TypeAsName()
69  {
70  return $this->Field->TypeAsName();
71  }
72 
77  public function GetDisplayName()
78  {
79  return $this->Field->GetDisplayName();
80  }
81 
86  public function Name()
87  {
88  return $this->Field->Name();
89  }
90 
95  public function Label()
96  {
97  return $this->GetValueCheckingLength($this->Field->Label());
98  }
99 
104  public function GetAllowedConversionTypes()
105  {
106  $Value = $this->Field->GetAllowedConversionTypes();
107 
108  return count($Value) ? implode(", ", $Value) : $this->NotSetText;
109  }
110 
116  public function IsTempItem()
117  {
118  return $this->GetYesNo($this->Field->IsTempItem());
119  }
120 
125  public function Id()
126  {
127  return $this->Field->Id();
128  }
129 
134  public function DBFieldName()
135  {
136  return $this->Field->DBFieldName();
137  }
138 
143  public function Description()
144  {
145  # for our purposes, HTML code and some whitespace are not human-readable
146  $Value = strip_tags($this->Field->Description());
147  $Value = trim(str_replace(array("\r", "\n", "\t"), " ", $Value));
148  $Value = preg_replace('/ +/', " ", $Value);
149 
150  return $this->GetValueCheckingLength($Value);
151  }
152 
157  public function Instructions()
158  {
159  # for our purposes, HTML code and some whitespace are not human-readable
160  $Value = strip_tags($this->Field->Instructions());
161  $Value = trim(str_replace(array("\r", "\n", "\t"), " ", $Value));
162  $Value = preg_replace('/ +/', " ", $Value);
163 
164  return $this->GetValueCheckingLength($Value);
165  }
166 
171  public function Owner()
172  {
173  return $this->GetValueCheckingLength($this->Field->Owner());
174  }
175 
181  public function RequiredBySPT()
182  {
183  return $this->GetYesNo($this->Field->RequiredBySPT());
184  }
185 
190  public function Enabled()
191  {
192  return $this->GetYesNo($this->Field->Enabled());
193  }
194 
199  public function Optional()
200  {
201  return $this->GetYesNo($this->Field->Optional());
202  }
203 
208  public function Editable()
209  {
210  return $this->GetYesNo($this->Field->Editable());
211  }
212 
217  public function Viewable()
218  {
219  return $this->GetYesNo($this->Field->Viewable());
220  }
221 
228  public function AllowMultiple()
229  {
230  return $this->GetYesNo($this->Field->AllowMultiple());
231  }
232 
239  public function IncludeInKeywordSearch()
240  {
241  return $this->GetYesNo($this->Field->IncludeInKeywordSearch());
242  }
243 
250  public function IncludeInAdvancedSearch()
251  {
252  return $this->GetYesNo($this->Field->IncludeInAdvancedSearch());
253  }
254 
261  public function IncludeInFacetedSearch()
262  {
263  return $this->GetYesNo($this->Field->IncludeInFacetedSearch());
264  }
265 
272  public function IncludeInSortOptions()
273  {
274  return $this->GetYesNo($this->Field->IncludeInSortOptions());
275  }
276 
283  public function IncludeInRecommender()
284  {
285  return $this->GetYesNo($this->Field->IncludeInRecommender());
286  }
287 
292  public function TextFieldSize()
293  {
294  return $this->GetValueCheckingLength($this->Field->TextFieldSize());
295  }
296 
301  public function MaxLength()
302  {
303  return $this->GetValueCheckingLength($this->Field->MaxLength());
304  }
305 
310  public function ParagraphRows()
311  {
312  return $this->GetValueCheckingLength($this->Field->ParagraphRows());
313  }
314 
319  public function ParagraphCols()
320  {
321  return $this->GetValueCheckingLength($this->Field->ParagraphCols());
322  }
323 
328  public function MinValue()
329  {
330  return $this->GetValueCheckingLength($this->Field->MinValue());
331  }
332 
337  public function MaxValue()
338  {
339  return $this->GetValueCheckingLength($this->Field->MaxValue());
340  }
341 
346  public function FlagOnLabel()
347  {
348  return $this->GetValueCheckingLength($this->Field->FlagOnLabel());
349  }
350 
355  public function FlagOffLabel()
356  {
357  return $this->GetValueCheckingLength($this->Field->FlagOffLabel());
358  }
359 
364  public function DateFormat()
365  {
366  return $this->GetValueCheckingLength($this->Field->DateFormat());
367  }
368 
373  public function SearchWeight()
374  {
375  return $this->GetValueCheckingLength($this->Field->SearchWeight());
376  }
377 
382  public function RecommenderWeight()
383  {
384  return $this->GetValueCheckingLength($this->Field->RecommenderWeight());
385  }
386 
391  public function MaxHeight()
392  {
393  return $this->GetValueCheckingLength($this->Field->MaxHeight());
394  }
395 
400  public function MaxWidth()
401  {
402  return $this->GetValueCheckingLength($this->Field->MaxWidth());
403  }
404 
410  public function MaxPreviewHeight()
411  {
412  return $this->GetValueCheckingLength($this->Field->MaxPreviewHeight());
413  }
414 
420  public function MaxPreviewWidth()
421  {
422  return $this->GetValueCheckingLength($this->Field->MaxPreviewWidth());
423  }
424 
431  public function MaxThumbnailHeight()
432  {
433  return $this->GetValueCheckingLength($this->Field->MaxThumbnailHeight());
434  }
435 
441  public function MaxThumbnailWidth()
442  {
443  return $this->GetValueCheckingLength($this->Field->MaxThumbnailWidth());
444  }
445 
451  public function DefaultAltText()
452  {
453  return $this->GetValueCheckingLength($this->Field->DefaultAltText());
454  }
455 
461  public function UsesQualifiers()
462  {
463  return $this->GetYesNo($this->Field->UsesQualifiers());
464  }
465 
472  public function ShowQualifiers()
473  {
474  return $this->GetYesNo($this->Field->ShowQualifiers());
475  }
476 
481  public function DefaultQualifier()
482  {
483  $DefaultQualifier = $this->Field->DefaultQualifier();
484 
485  if ($DefaultQualifier > 0)
486  {
487  $Qualifier = new Qualifier($DefaultQualifier);
488 
489  return $Qualifier->Name();
490  }
491 
492  return $this->NotSetText;
493  }
494 
500  public function AllowHTML()
501  {
502  return $this->GetYesNo($this->Field->AllowHTML());
503  }
504 
511  public function UseWysiwygEditor()
512  {
513  return $this->GetYesNo($this->Field->UseWysiwygEditor());
514  }
515 
522  public function UseForOaiSets()
523  {
524  return $this->GetYesNo($this->Field->UseForOaiSets());
525  }
526 
532  public function NumAjaxResults()
533  {
534  return $this->Field->NumAjaxResults();
535  }
536 
541  public function ViewingPrivilege()
542  {
543  $Value = $this->MapPrivilege($this->Field->ViewingPrivilege());
544 
545  return $this->GetValueCheckingLength($Value);
546  }
547 
552  public function AuthoringPrivilege()
553  {
554  $Value = $this->MapPrivilege($this->Field->AuthoringPrivilege());
555 
556  return $this->GetValueCheckingLength($Value);
557  }
558 
563  public function EditingPrivilege()
564  {
565  $Value = $this->MapPrivilege($this->Field->EditingPrivilege());
566 
567  return $this->GetValueCheckingLength($Value);
568  }
569 
576  public function ImagePreviewPrivilege()
577  {
578  $Value = $this->MapPrivilege($this->Field->ImagePreviewPrivilege());
579 
580  return $this->GetValueCheckingLength($Value);
581  }
582 
589  public function EnableOnOwnerReturn()
590  {
591  return $this->GetYesNo($this->Field->EnableOnOwnerReturn());
592  }
593 
598  public function ViewingUserIsValue()
599  {
600  $Value = $this->MapUserIsValue($this->Field->ViewingUserIsValue());
601 
602  return $this->GetValueCheckingLength($Value);
603  }
604 
609  public function AuthoringUserIsValue()
610  {
611  $Value = $this->MapUserIsValue($this->Field->AuthoringUserIsValue());
612 
613  return $this->GetValueCheckingLength($Value);
614  }
615 
620  public function EditingUserIsValue()
621  {
622  $Value = $this->MapUserIsValue($this->Field->EditingUserIsValue());
623 
624  return $this->GetValueCheckingLength($Value);
625  }
626 
631  public function ViewingUserValue()
632  {
633  $Value = $this->MapUserValue($this->Field->ViewingUserValue());
634 
635  return $this->GetValueCheckingLength($Value);
636  }
637 
642  public function AuthoringUserValue()
643  {
644  $Value = $this->MapUserValue($this->Field->AuthoringUserValue());
645 
646  return $this->GetValueCheckingLength($Value);
647  }
648 
653  public function EditingUserValue()
654  {
655  $Value = $this->MapUserValue($this->Field->EditingUserValue());
656 
657  return $this->GetValueCheckingLength($Value);
658  }
659 
664  public function UserPrivilegeRestrictions()
665  {
666  $Value = $this->Field->UserPrivilegeRestrictions();
667  $Values = array();
668 
669  # need to map each privilege ID to its text
670  foreach ($Value as $Id)
671  {
672  $Values[] = $this->MapPrivilege($Id);
673  }
674 
675  return count($Values) ? implode(", ", $Values) : $this->NotSetText;
676  }
677 
682  public function PointPrecision()
683  {
684  return $this->GetValueCheckingLength($this->Field->PointPrecision());
685  }
686 
691  public function PointDecimalDigits()
692  {
693  return $this->GetValueCheckingLength($this->Field->PointDecimalDigits());
694  }
695 
700  public function DefaultValue()
701  {
702  $Type = $this->Field->Type();
703  $Value = $this->Field->DefaultValue();
704 
705  if ($Type == MetadataSchema::MDFTYPE_POINT)
706  {
707  $XText = NULL;
708  $X = $Value["X"];
709  $Y = $Value["Y"];
710 
711  if (strlen($X))
712  {
713  $XText = "X: " . $X;
714  }
715 
716  if (strlen($Y))
717  {
718  return (strlen($XText) ? $XText . ", " : "") . "Y: " . $Y;
719  }
720 
721  return $this->NotSetText;
722  }
723 
724  if ($Type == MetadataSchema::MDFTYPE_OPTION)
725  {
726  # multiple default values are set
727  if (is_array($Value))
728  {
729  foreach ($Value as $Id)
730  {
731  $ControlledName = new ControlledName($Id);
732 
733  $Names[] = $ControlledName->Name();
734  }
735 
736  return implode(", ", $Names);
737  }
738 
739  # only one default value
740  else if ($Value)
741  {
742  $ControlledName = new ControlledName($Value);
743 
744  return $ControlledName->Name();
745  }
746 
747  return $this->NotSetText;
748  }
749 
750  if ($Type == MetadataSchema::MDFTYPE_FLAG)
751  {
752  return $Value ? $this->FlagOnLabel() : $this->FlagOffLabel();
753  }
754 
755  return $this->GetValueCheckingLength($Value);
756  }
757 
762  public function UpdateMethod()
763  {
764  $Value = $this->Field->UpdateMethod();
765  $String = $this->GetArrayValue(MetadataField::$UpdateTypes, $Value);
766 
767  return $this->GetValueCheckingLength($String);
768  }
769 
775  public function GetPossibleValues()
776  {
777  $Value = $this->Field->GetPossibleValues();
778 
779  return count($Value) ? implode(", ", $Value) : $this->NotSetText;
780  }
781 
787  public function GetCountOfPossibleValues()
788  {
789  return $this->GetValueCheckingLength($this->Field->GetCountOfPossibleValues());
790  }
791 
798  public function HasItemLevelQualifiers()
799  {
800  return $this->GetYesNo($this->Field->HasItemLevelQualifiers());
801  }
802 
807  public function AssociatedQualifierList()
808  {
809  $Value = $this->Field->AssociatedQualifierList();
810 
811  return count($Value) ? implode(", ", $Value) : $this->NotSetText;
812  }
813 
818  public function UnassociatedQualifierList()
819  {
820  $Value = $this->Field->UnassociatedQualifierList();
821 
822  return count($Value) ? implode(", ", $Value) : $this->NotSetText;
823  }
824 
830  public function GetViewingPrivilegeString()
831  {
832  return $this->GetPrivilegeString("Viewing");
833  }
834 
841  public function GetAuthoringPrivilegeString()
842  {
843  return $this->GetPrivilegeString("Authoring");
844  }
845 
851  public function GetEditingPrivilegeString()
852  {
853  return $this->GetPrivilegeString("Editing");
854  }
855 
860  public function GetNotSetText()
861  {
862  return $this->NotSetText;
863  }
864 
869  public function SetNotSetText($Text)
870  {
871  $this->NotSetText = $Text;
872  }
873 
879  protected function GetYesNo($Value)
880  {
881  return $Value ? "Yes" : "No";
882  }
883 
890  protected function GetValueCheckingLength($Value)
891  {
892  return strlen($Value) ? $Value : $this->NotSetText;
893  }
894 
901  protected function GetPrivilegeString($Mode)
902  {
903  $Privilege = $this->MapPrivilege($this->Field->{$Mode."Privileges"}());
904  $UserIsValue = $this->MapUserIsValue($this->Field->{$Mode."UserIsValue"}());
905  $UserValue = $this->MapUserValue($this->Field->{$Mode."UserValue"}());
906 
907  $String = NULL;
908 
909  # add the user privilege constraint first, if set
910  if (!is_null($Privilege))
911  {
912  $String = $Privilege;
913  }
914 
915  # then add the "user is value of field" constraint, if set
916  if (!is_null($UserIsValue) && !is_null($UserValue))
917  {
918  if (is_null($String))
919  {
920  $String = "User is value of " . $UserValue;
921  }
922 
923  else
924  {
925  $String .= " " . $UserIsValue . " user is value of ";
926  $String .= $UserValue;
927  }
928  }
929 
930  return is_null($String) ? $this->NotSetText : $String;
931  }
932 
938  protected function MapPrivilege($Value)
939  {
940  if (!isset(self::$PrivilegeList))
941  {
942  $this->LoadPrivilegeList();
943  }
944 
945  return $this->GetArrayValue(self::$PrivilegeList, $Value);
946  }
947 
951  protected function LoadPrivilegeList()
952  {
953  $PrivilegeFactory = new PrivilegeFactory();
954 
955  self::$PrivilegeList = $PrivilegeFactory->GetPrivileges(TRUE, FALSE);
956  }
957 
963  protected function MapUserIsValue($Value)
964  {
965  return $this->GetArrayValue(self::$UserIsValueList, $Value);
966  }
967 
973  protected function MapUserValue($Value)
974  {
975  if (!isset(self::$UserFieldList))
976  {
977  $this->LoadUserFieldList();
978  }
979 
980  return $this->GetArrayValue(self::$UserFieldList, $Value);
981  }
982 
986  protected function LoadUserFieldList()
987  {
988  $Schema = new MetadataSchema($this->Field->SchemaId());
989  $UserFields = $Schema->GetFields(MetadataSchema::MDFTYPE_USER);
990 
991  # make sure the list is set to something even if there are no user
992  # fields
993  self::$UserFieldList = array();
994 
995  foreach ($UserFields as $Field)
996  {
997  self::$UserFieldList[$Field->Id()] = $Field->GetDisplayName();
998  }
999  }
1000 
1011  protected function GetArrayValue(array $Array, $Key, $Default=NULL)
1012  {
1013  return array_key_exists($Key, $Array) ? $Array[$Key] : $Default;
1014  }
1015 
1021  protected $Field;
1022 
1027  protected $NotSetText = "--";
1028 
1033  protected static $PrivilegeList;
1034 
1039  protected static $UserIsValueList = array(
1042 
1047  protected static $UserFieldList;
1048 }
const MDFSTAT_ILLEGALLABEL
PointDecimalDigits()
Get the human-readable point decimal digits of point fields.
MapUserIsValue($Value)
Map a UserIsValue value to a name.
static $FieldTypeDBEnums
MaxHeight()
Get the human-readable maximum height of images of image fields.
$NotSetText
The text used when a value is not set.
DBFieldName()
Get the human-readable database field name of the field.
MaxPreviewHeight()
Get the human-readable maximum height of preview images of image fields.
static $UserIsValueList
A static array of UserIsValue strings.
GetYesNo($Value)
Get the human-readable string for a boolean-like value.
AuthoringUserIsValue()
Get the human-readable authoring user is value of the field.
GetPossibleValues()
Get the human-readable possible values of the field.
Metadata schema (in effect a Factory class for MetadataField).
DefaultAltText()
Get the human-readable default alternate text of images of image fields.
DefaultQualifier()
Get the human-readable default qualifier of the field.
SetNotSetText($Text)
Set the text that is used when a value is not set.
EditingUserValue()
Get the human-readable editing user value of the field.
EditingPrivilege()
Get the human-readable editing privilege of the field.
HasItemLevelQualifiers()
Get the human-readable string that indicates if the field has item-level qualifiers.
Given a metadata field, this class returns human-readable values for each value of the field...
Instructions()
Get the human-readable instructions of the field.
AssociatedQualifierList()
Get the human-readable list of associated qualifiers of the field.
MaxLength()
Get the human-readable maximum size of text field values.
Factory which extracts all defined privileges from the database.
DefaultValue()
Get the human-readable default value of the field.
const MDFSTAT_FIELDDOESNOTEXIST
const USERISVALUE_OR
UnassociatedQualifierList()
Get the human-readable list of unassociated qualifiers of the field.
MapPrivilege($Value)
Map a privilege value to a privilege name.
const USERISVALUE_AND
FlagOffLabel()
Get the human-readable flag-off label for flag fields.
ViewingUserValue()
Get the human-readable viewing user value of the field.
LoadUserFieldList()
Load the static user field list.
EditingUserIsValue()
Get the human-readable editing user is value of the field.
ViewingUserIsValue()
Get the human-readable viewing user is value of the field.
MaxValue()
Get the human-readable maximum value for number fields.
AllowMultiple()
Get the human-readable string that indicates if multiple field values are permitted.
ParagraphRows()
Get the human-readable number of rows of paragraph field inputs.
FlagOnLabel()
Get the human-readable flag-on label for flag fields.
AllowHTML()
Get the human-readable string indicating if HTML is allowed as the value.
SearchWeight()
Get the human-readable search weight of the field.
Metadata type representing non-hierarchical controlled vocabulary values.
ShowQualifiers()
Get the human-readable string indicating if qualifiers are shown for the field.
IncludeInSortOptions()
Get the human-readable string that indicates if the field is included in sort options.
UserPrivilegeRestrictions()
Get the human-readable user privilege restrictions of user fields.
Name()
Get the human-readable name of the field.
MaxPreviewWidth()
Get the human-readable maximum width of preview images of image fields.
ViewingPrivilege()
Get the human-readable viewing privilege of the field.
GetEditingPrivilegeString()
Get the human-readable editing privilege string that includes the editing privilege required...
UseWysiwygEditor()
Get the human-readable string indicating if a WYSIWYG editor should be used when editing the field va...
IncludeInAdvancedSearch()
Get the human-readable string that indicates if the field is included in advanced search options...
RequiredBySPT()
Get the human-readable string that indicates if the field is required by SPT.
MinValue()
Get the human-readable minimum value for number fields.
NumAjaxResults()
Get the human-readable number of AJAX search results to display for the field.
const MDFSTAT_DUPLICATEDBCOLUMN
MaxThumbnailWidth()
Get the human-readable maximum width of thumbnail images of image fields.
UseForOaiSets()
Get the human-readable string indicating if the field should be used for OAI sets.
PointPrecision()
Get the human-readable point precision of point fields.
GetValueCheckingLength($Value)
Get the value or the not-set text depending on the length of the value.
Id()
Get the human-readable field ID.
RecommenderWeight()
Get the human-readable recommender weight of the field.
Type()
Get the human-readable field type of the field.
Optional()
Get the human-readable string that indicates if the field is optional.
const MDFSTAT_DUPLICATELABEL
AuthoringPrivilege()
Get the human-readable authoring privilege of the field.
TypeAsName()
Get the human-readable field type of the field.
MapUserValue($Value)
Map a UserValue value to a field display name.
GetFields($FieldTypes=NULL, $OrderType=NULL, $IncludeDisabledFields=FALSE, $IncludeTempFields=FALSE)
Retrieve array of fields.
TextFieldSize()
Get the human-readable size of text field inputs.
LoadPrivilegeList()
Load the static privilege list.
MaxThumbnailHeight()
Get the human-readable maximum height of thumbnail images of image fields.
MaxWidth()
Get the human-readable maximum width of images of image fields.
Object representing a locally-defined type of metadata field.
Viewable()
Get the human-readable string that indicates if the field is viewable.
GetArrayValue(array $Array, $Key, $Default=NULL)
Get the value from an array with a given index or a default value if it does not exist.
ImagePreviewPrivilege()
THIS FUNCTION HAS BEEN DEPRECATED Get the human-readable image preview privilege of image fields...
IsTempItem()
Get the human-readable string that indicates if the field is a temporary field.
DateFormat()
Get the human-readable field date format.
IncludeInRecommender()
Get the human-readable string that indicates if the field is included in the recommender system...
const MDFSTAT_ILLEGALNAME
GetPrivilegeString($Mode)
This method makes getting privilege strings for viewing, authoring, and editing a little more conveni...
GetNotSetText()
Get the text that is used when a value is not set.
static $UserFieldList
A static array of user fields.
UsesQualifiers()
Get the human-readable string indicating if the field uses qualifiers.
Enabled()
Get the human-readable string that indicates if the field is enabled.
GetAllowedConversionTypes()
Get the human-readable allowed conversion types of the field.
static $PrivilegeList
A static array of privilege values and names.
$Field
The metadata field that is having its values returned in human-readable form.
UpdateMethod()
Get the human-readable update method of the field.
Editable()
Get the human-readable string that indicates if the field is editable.
const MDFSTAT_DUPLICATENAME
IncludeInFacetedSearch()
Get the human-readable string that indicates if the field is included in faceted search options...
GetViewingPrivilegeString()
Get the human-readable viewing privilege string that includes the viewing privilege required...
GetDisplayName()
Get the human-readable display name of the field.
GetCountOfPossibleValues()
Get the human-readable count of possible values of the field.
Status()
Get the human-readable error status of the field.
Label()
Get the human-readable label of the field.
Owner()
Get the human-readable field owner.
IncludeInKeywordSearch()
Get the human-readable string that indicates if the field is included in keyword searches.
__construct(MetadataField $Field)
Save the field that will be used to generate the human-readable values.
Description()
Get the human-readable description of the field.
ParagraphCols()
Get the human-readable number of columns of paragraph field inputs.
EnableOnOwnerReturn()
Get the human-readable string indicating if the field should be enabled when the owner/plugin is avai...
AuthoringUserValue()
Get the human-readable authoring user value of the field.
GetAuthoringPrivilegeString()
Get the human-readable authoring privilege string that includes the authoring privilege required...