CWIS Developer Documentation

- Home
- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

HumanMetadataField.php
Go to the documentation of this file.
1 <?PHP
2
7 class HumanMetadataField
8 {
9
14 public function __construct(MetadataField $Field)
15 {
16 $this->Field = $Field;
17 }
18
23 public function Status()
24 {
25 switch ($this->Field->Status())
26 {
27 case MetadataSchema::MDFSTAT_OK:
28 return "OK";
29 case MetadataSchema::MDFSTAT_ERROR:
30 return "Error";
31 case MetadataSchema::MDFSTAT_DUPLICATENAME:
32 return "Duplicate field name";
33 case MetadataSchema::MDFSTAT_DUPLICATEDBCOLUMN:
34 return "Duplicate database column";
35 case MetadataSchema::MDFSTAT_FIELDDOESNOTEXIST:
36 return "Field does not exist";
37 case MetadataSchema::MDFSTAT_ILLEGALNAME:
38 return "Illegal field name";
39 case MetadataSchema::MDFSTAT_DUPLICATELABEL:
40 return "Duplicate label name";
41 case MetadataSchema::MDFSTAT_ILLEGALLABEL:
42 return "Illegal label name";
43 }
44
45 return $this->NotSetText;
46 }
47
52 public function Type()
53 {
54 return MetadataField::$FieldTypeDBEnums[$this->Field->Type()];
55 }
56
61 public function TypeAsName()
62 {
63 return $this->Field->TypeAsName();
64 }
65
70 public function GetDisplayName()
71 {
72 return $this->Field->GetDisplayName();
73 }
74
79 public function Name()
80 {
81 return $this->Field->Name();
82 }
83
88 public function Label()
89 {
90 return $this->GetValueCheckingLength($this->Field->Label());
91 }
92
97 public function GetAllowedConversionTypes()
98 {
99 $Value = $this->Field->GetAllowedConversionTypes();
100
101 return count($Value) ? implode(", ", $Value) : $this->NotSetText;
102 }
103
109 public function IsTempItem()
110 {
111 return $this->GetYesNo($this->Field->IsTempItem());
112 }
113
118 public function Id()
119 {
120 return $this->Field->Id();
121 }
122
127 public function DBFieldName()
128 {
129 return $this->Field->DBFieldName();
130 }
131
136 public function Description()
137 {
138 # for our purposes, HTML code and some whitespace are not human-readable
139 $Value = strip_tags($this->Field->Description());
140 $Value = trim(str_replace(array("\r", "\n", "\t"), " ", $Value));
141 $Value = preg_replace('/ +/', " ", $Value);
142
143 return $this->GetValueCheckingLength($Value);
144 }
145
150 public function Instructions()
151 {
152 # for our purposes, HTML code and some whitespace are not human-readable
153 $Value = strip_tags($this->Field->Instructions());
154 $Value = trim(str_replace(array("\r", "\n", "\t"), " ", $Value));
155 $Value = preg_replace('/ +/', " ", $Value);
156
157 return $this->GetValueCheckingLength($Value);
158 }
159
164 public function Owner()
165 {
166 return $this->GetValueCheckingLength($this->Field->Owner());
167 }
168
174 public function RequiredBySPT()
175 {
176 return $this->GetYesNo($this->Field->RequiredBySPT());
177 }
178
183 public function Enabled()
184 {
185 return $this->GetYesNo($this->Field->Enabled());
186 }
187
192 public function Optional()
193 {
194 return $this->GetYesNo($this->Field->Optional());
195 }
196
201 public function Editable()
202 {
203 return $this->GetYesNo($this->Field->Editable());
204 }
205
210 public function Viewable()
211 {
212 return $this->GetYesNo($this->Field->Viewable());
213 }
214
221 public function AllowMultiple()
222 {
223 return $this->GetYesNo($this->Field->AllowMultiple());
224 }
225
232 public function IncludeInKeywordSearch()
233 {
234 return $this->GetYesNo($this->Field->IncludeInKeywordSearch());
235 }
236
243 public function IncludeInAdvancedSearch()
244 {
245 return $this->GetYesNo($this->Field->IncludeInAdvancedSearch());
246 }
247
254 public function IncludeInSortOptions()
255 {
256 return $this->GetYesNo($this->Field->IncludeInSortOptions());
257 }
258
265 public function IncludeInRecommender()
266 {
267 return $this->GetYesNo($this->Field->IncludeInRecommender());
268 }
269
274 public function TextFieldSize()
275 {
276 return $this->GetValueCheckingLength($this->Field->TextFieldSize());
277 }
278
283 public function MaxLength()
284 {
285 return $this->GetValueCheckingLength($this->Field->MaxLength());
286 }
287
292 public function ParagraphRows()
293 {
294 return $this->GetValueCheckingLength($this->Field->ParagraphRows());
295 }
296
301 public function ParagraphCols()
302 {
303 return $this->GetValueCheckingLength($this->Field->ParagraphCols());
304 }
305
310 public function MinValue()
311 {
312 return $this->GetValueCheckingLength($this->Field->MinValue());
313 }
314
319 public function MaxValue()
320 {
321 return $this->GetValueCheckingLength($this->Field->MaxValue());
322 }
323
328 public function FlagOnLabel()
329 {
330 return $this->GetValueCheckingLength($this->Field->FlagOnLabel());
331 }
332
337 public function FlagOffLabel()
338 {
339 return $this->GetValueCheckingLength($this->Field->FlagOffLabel());
340 }
341
346 public function DateFormat()
347 {
348 return $this->GetValueCheckingLength($this->Field->DateFormat());
349 }
350
355 public function SearchWeight()
356 {
357 return $this->GetValueCheckingLength($this->Field->SearchWeight());
358 }
359
364 public function RecommenderWeight()
365 {
366 return $this->GetValueCheckingLength($this->Field->RecommenderWeight());
367 }
368
373 public function MaxHeight()
374 {
375 return $this->GetValueCheckingLength($this->Field->MaxHeight());
376 }
377
382 public function MaxWidth()
383 {
384 return $this->GetValueCheckingLength($this->Field->MaxWidth());
385 }
386
392 public function MaxPreviewHeight()
393 {
394 return $this->GetValueCheckingLength($this->Field->MaxPreviewHeight());
395 }
396
402 public function MaxPreviewWidth()
403 {
404 return $this->GetValueCheckingLength($this->Field->MaxPreviewWidth());
405 }
406
413 public function MaxThumbnailHeight()
414 {
415 return $this->GetValueCheckingLength($this->Field->MaxThumbnailHeight());
416 }
417
423 public function MaxThumbnailWidth()
424 {
425 return $this->GetValueCheckingLength($this->Field->MaxThumbnailWidth());
426 }
427
433 public function DefaultAltText()
434 {
435 return $this->GetValueCheckingLength($this->Field->DefaultAltText());
436 }
437
443 public function UsesQualifiers()
444 {
445 return $this->GetYesNo($this->Field->UsesQualifiers());
446 }
447
454 public function ShowQualifiers()
455 {
456 return $this->GetYesNo($this->Field->ShowQualifiers());
457 }
458
463 public function DefaultQualifier()
464 {
465 $DefaultQualifier = $this->Field->DefaultQualifier();
466
467 if ($DefaultQualifier > 0)
468 {
469 $Qualifier = new Qualifier($DefaultQualifier);
470
471 return $Qualifier->Name();
472 }
473
474 return $this->NotSetText;
475 }
476
482 public function AllowHTML()
483 {
484 return $this->GetYesNo($this->Field->AllowHTML());
485 }
486
493 public function UseWysiwygEditor()
494 {
495 return $this->GetYesNo($this->Field->UseWysiwygEditor());
496 }
497
504 public function UseForOaiSets()
505 {
506 return $this->GetYesNo($this->Field->UseForOaiSets());
507 }
508
514 public function NumAjaxResults()
515 {
516 return $this->Field->NumAjaxResults();
517 }
518
523 public function ViewingPrivilege()
524 {
525 $Value = $this->MapPrivilege($this->Field->ViewingPrivilege());
526
527 return $this->GetValueCheckingLength($Value);
528 }
529
534 public function AuthoringPrivilege()
535 {
536 $Value = $this->MapPrivilege($this->Field->AuthoringPrivilege());
537
538 return $this->GetValueCheckingLength($Value);
539 }
540
545 public function EditingPrivilege()
546 {
547 $Value = $this->MapPrivilege($this->Field->EditingPrivilege());
548
549 return $this->GetValueCheckingLength($Value);
550 }
551
556 public function ImagePreviewPrivilege()
557 {
558 $Value = $this->MapPrivilege($this->Field->ImagePreviewPrivilege());
559
560 return $this->GetValueCheckingLength($Value);
561 }
562
567 public function TreeBrowsingPrivilege()
568 {
569 $Value = $this->MapPrivilege($this->Field->TreeBrowsingPrivilege());
570
571 return $this->GetValueCheckingLength($Value);
572 }
573
580 public function EnableOnOwnerReturn()
581 {
582 return $this->GetYesNo($this->Field->EnableOnOwnerReturn());
583 }
584
589 public function ViewingUserIsValue()
590 {
591 $Value = $this->MapUserIsValue($this->Field->ViewingUserIsValue());
592
593 return $this->GetValueCheckingLength($Value);
594 }
595
600 public function AuthoringUserIsValue()
601 {
602 $Value = $this->MapUserIsValue($this->Field->AuthoringUserIsValue());
603
604 return $this->GetValueCheckingLength($Value);
605 }
606
611 public function EditingUserIsValue()
612 {
613 $Value = $this->MapUserIsValue($this->Field->EditingUserIsValue());
614
615 return $this->GetValueCheckingLength($Value);
616 }
617
622 public function ViewingUserValue()
623 {
624 $Value = $this->MapUserValue($this->Field->ViewingUserValue());
625
626 return $this->GetValueCheckingLength($Value);
627 }
628
633 public function AuthoringUserValue()
634 {
635 $Value = $this->MapUserValue($this->Field->AuthoringUserValue());
636
637 return $this->GetValueCheckingLength($Value);
638 }
639
644 public function EditingUserValue()
645 {
646 $Value = $this->MapUserValue($this->Field->EditingUserValue());
647
648 return $this->GetValueCheckingLength($Value);
649 }
650
655 public function UserPrivilegeRestrictions()
656 {
657 $Value = $this->Field->UserPrivilegeRestrictions();
658 $Values = array();
659
660 # need to map each privilege ID to its text
661 foreach ($Value as $Id)
662 {
663 $Values[] = $this->MapPrivilege($Id);
664 }
665
666 return count($Values) ? implode(", ", $Values) : $this->NotSetText;
667 }
668
673 public function PointPrecision()
674 {
675 return $this->GetValueCheckingLength($this->Field->PointPrecision());
676 }
677
682 public function PointDecimalDigits()
683 {
684 return $this->GetValueCheckingLength($this->Field->PointDecimalDigits());
685 }
686
691 public function DefaultValue()
692 {
693 $Type = $this->Field->Type();
694 $Value = $this->Field->DefaultValue();
695
696 if ($Type == MetadataSchema::MDFTYPE_POINT)
697 {
698 $XText = NULL;
699 $X = $Value["X"];
700 $Y = $Value["Y"];
701
702 if (strlen($X))
703 {
704 $XText = "X: " . $X;
705 }
706
707 if (strlen($Y))
708 {
709 return (strlen($XText) ? $XText . ", " : "") . "Y: " . $Y;
710 }
711
712 return $this->NotSetText;
713 }
714
715 if ($Type == MetadataSchema::MDFTYPE_OPTION)
716 {
717 # multiple default values are set
718 if (is_array($Value))
719 {
720 foreach ($Value as $Id)
721 {
722 $ControlledName = new ControlledName($Id);
723
724 $Names[] = $ControlledName->Name();
725 }
726
727 return implode(", ", $Names);
728 }
729
730 # only one default value
731 else if ($Value)
732 {
733 $ControlledName = new ControlledName($Value);
734
735 return $ControlledName->Name();
736 }
737
738 return $this->NotSetText;
739 }
740
741 if ($Type == MetadataSchema::MDFTYPE_FLAG)
742 {
743 return $Value ? $this->FlagOnLabel() : $this->FlagOffLabel();
744 }
745
746 return $this->GetValueCheckingLength($Value);
747 }
748
753 public function UpdateMethod()
754 {
755 $Value = $this->Field->UpdateMethod();
756 $String = $this->GetArrayValue(MetadataField::$UpdateTypes, $Value);
757
758 return $this->GetValueCheckingLength($String);
759 }
760
766 public function GetPossibleValues()
767 {
768 $Value = $this->Field->GetPossibleValues();
769
770 return count($Value) ? implode(", ", $Value) : $this->NotSetText;
771 }
772
778 public function GetCountOfPossibleValues()
779 {
780 return $this->GetValueCheckingLength($this->Field->GetCountOfPossibleValues());
781 }
782
789 public function HasItemLevelQualifiers()
790 {
791 return $this->GetYesNo($this->Field->HasItemLevelQualifiers());
792 }
793
798 public function AssociatedQualifierList()
799 {
800 $Value = $this->Field->AssociatedQualifierList();
801
802 return count($Value) ? implode(", ", $Value) : $this->NotSetText;
803 }
808 public function UnassociatedQualifierList()
809 {
810 $Value = $this->Field->UnassociatedQualifierList();
811
812 return count($Value) ? implode(", ", $Value) : $this->NotSetText;
813 }
814
820 public function GetViewingPrivilegeString()
821 {
822 return $this->GetPrivilegeString("Viewing");
823 }
824
831 public function GetAuthoringPrivilegeString()
832 {
833 return $this->GetPrivilegeString("Authoring");
834 }
835
841 public function GetEditingPrivilegeString()
842 {
843 return $this->GetPrivilegeString("Editing");
844 }
845
850 public function GetNotSetText()
851 {
852 return $this->NotSetText;
853 }
854
859 public function SetNotSetText($Text)
860 {
861 $this->NotSetText = $Text;
862 }
863
869 protected function GetYesNo($Value)
870 {
871 return $Value ? "Yes" : "No";
872 }
873
880 protected function GetValueCheckingLength($Value)
881 {
882 return strlen($Value) ? $Value : $this->NotSetText;
883 }
884
891 protected function GetPrivilegeString($Mode)
892 {
893 $Privilege = $this->MapPrivilege($this->Field->{$Mode."Privilege"}());
894 $UserIsValue = $this->MapUserIsValue($this->Field->{$Mode."UserIsValue"}());
895 $UserValue = $this->MapUserValue($this->Field->{$Mode."UserValue"}());
896
897 $String = NULL;
898
899 # add the user privilege constraint first, if set
900 if (!is_null($Privilege))
901 {
902 $String = $Privilege;
903 }
904
905 # then add the "user is value of field" constraint, if set
906 if (!is_null($UserIsValue) && !is_null($UserValue))
907 {
908 if (is_null($String))
909 {
910 $String = "User is value of " . $UserValue;
911 }
912
913 else
914 {
915 $String .= " " . $UserIsValue . " user is value of ";
916 $String .= $UserValue;
917 }
918 }
919
920 return is_null($String) ? $this->NotSetText : $String;
921 }
922
928 protected function MapPrivilege($Value)
929 {
930 if (!isset(self::$PrivilegeList))
931 {
932 $this->LoadPrivilegeList();
933 }
934
935 return $this->GetArrayValue(self::$PrivilegeList, $Value);
936 }
937
941 protected function LoadPrivilegeList()
942 {
943 $PrivilegeFactory = new PrivilegeFactory();
944
945 self::$PrivilegeList = $PrivilegeFactory->GetPrivileges(TRUE, FALSE);
946 }
947
953 protected function MapUserIsValue($Value)
954 {
955 return $this->GetArrayValue(self::$UserIsValueList, $Value);
956 }
957
963 protected function MapUserValue($Value)
964 {
965 if (!isset(self::$UserFieldList))
966 {
967 $this->LoadUserFieldList();
968 }
969
970 return $this->GetArrayValue(self::$UserFieldList, $Value);
971 }
972
976 protected function LoadUserFieldList()
977 {
978 $Schema = new MetadataSchema();
979 $UserFields = $Schema->GetFields(MetadataSchema::MDFTYPE_USER);
980
981 # make sure the list is set to something even if there are no user
982 # fields
983 self::$UserFieldList = array();
984
985 foreach ($UserFields as $Field)
986 {
987 self::$UserFieldList[$Field->Id()] = $Field->GetDisplayName();
988 }
989 }
990
1001 protected function GetArrayValue(array $Array, $Key, $Default=NULL)
1002 {
1003 return array_key_exists($Key, $Array) ? $Array[$Key] : $Default;
1004 }
1005
1009 protected $Field;
1010
1014 protected $NotSetText = "--";
1015
1019 protected static $PrivilegeList;
1020
1024 protected static $UserIsValueList = array(
1025 MetadataField::USERISVALUE_OR => "or",
1026 MetadataField::USERISVALUE_AND => "and");
1027
1031 protected static $UserFieldList;
1032
1033 }