CWIS Developer Documentation
MetadataFieldOrder.php
Go to the documentation of this file.
1 <?PHP
2 #
3 # FILE: MetadataFieldOrder.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  const DEFAULT_FOLDER_NAME = "FieldOrder";
22 
28  public function __construct($Id)
29  {
30  # being loading by calling the superclass method
31  parent::__construct($Id);
32 
33  # create a class-wide database
34  $this->Database = new Database();
35 
36  # query for order associations from the database
37  $this->Database->Query("
38  SELECT * FROM MetadataFieldOrders
39  WHERE OrderId = '".addslashes($Id)."'");
40 
41  # the ID is invalid
42  if ($this->Database->NumRowsSelected() < 1)
43  {
44  throw new Exception("Unknown metadata field order ID");
45  }
46 
47  # fetch the data
48  $Row = $this->Database->FetchRow();
49 
50  # set the values
51  $this->SchemaId = $Row["SchemaId"];
52  $this->OrderName = $Row["OrderName"];
53  }
54 
61  public function SchemaId()
62  {
63  return $this->SchemaId;
64  }
65 
70  public function OrderName()
71  {
72  return $this->OrderName;
73  }
74 
80  public function Delete()
81  {
82  # remove the order from the orders associated with schemas
83  $this->Database->Query("
84  DELETE FROM MetadataFieldOrders
85  WHERE OrderId = '".addslashes($this->Id())."'");
86 
87  # remove the folder by calling the superclass method
88  parent::Delete();
89  }
90 
94  public function MendIssues()
95  {
96  $Schema = new MetadataSchema($this->SchemaId);
97 
98  # get all the fields including disabled fields but excluding temp fields
99  $Fields = $Schema->GetFields(NULL, NULL, TRUE);
100 
101  foreach ($Fields as $Field)
102  {
103  # add the field if it isn't already in the order
104  if (!$this->ItemInOrder($Field))
105  {
106  $this->AppendItem($Field->Id(), "MetadataField");
107  }
108  }
109  }
110 
115  public function GetItems()
116  {
117  $ItemIds = $this->GetItemIds();
118  $Items = array();
119 
120  foreach ($ItemIds as $Info)
121  {
122  try
123  {
124  $Items[] = new $Info["Type"]($Info["ID"]);
125  }
126 
127  # skip invalid fields
128  catch (InvalidArgumentException $Exception)
129  {
130  continue;
131  }
132  }
133 
134  return $Items;
135  }
136 
142  public function CreateGroup($Name)
143  {
144  $FolderFactory = new FolderFactory();
145 
146  # create the new group
147  $Folder = $FolderFactory->CreateMixedFolder($Name);
148  $Group = new MetadataFieldGroup($Folder->Id());
149 
150  # and add it to this ordering
151  $this->AppendItem($Group->Id(), "MetadataFieldGroup");
152 
153  return $Group;
154  }
155 
162  public function DeleteGroup(MetadataFieldGroup $Group)
163  {
164  if ($this->ContainsItem($Group->Id(), "MetadataFieldGroup"))
165  {
166  $this->MoveFieldsToOrder($Group);
167  $this->RemoveItem($Group->Id(), "MetadataFieldGroup");
168  }
169  }
170 
175  public function GetFields()
176  {
177  $Fields = array();
178 
179  foreach ($this->GetItems() as $Item)
180  {
181  # add fields to the list
182  if ($Item instanceof MetadataField)
183  {
184  $Fields[$Item->Id()] = $Item;
185  }
186 
187  # add fields of groups to the list
188  else if ($Item instanceof MetadataFieldGroup)
189  {
190  foreach ($Item->GetFields() as $Field)
191  {
192  $Fields[$Field->Id()] = $Field;
193  }
194  }
195  }
196 
197  return $Fields;
198  }
199 
204  public function GetGroups()
205  {
206  $ItemIds = $this->GetItemIds();
207  $GroupIds = array_filter($ItemIds, array($this, "GroupFilterCallback"));
208 
209  $Groups = array();
210 
211  # transform group info to group objects
212  foreach ($GroupIds as $GroupId)
213  {
214  try
215  {
216  $Groups[$GroupId["ID"]] = new $GroupId["Type"]($GroupId["ID"]);
217  }
218  catch (Exception $Exception)
219  {
220  # (moving to next item just to avoid empty catch statement)
221  continue;
222  }
223  }
224 
225  return $Groups;
226  }
227 
237  public function MoveItemUp($Item, $Filter=NULL)
238  {
239  # make sure the item is a field or group
240  if (!$this->IsFieldOrGroup($Item))
241  {
242  throw new Exception("Item must be a field or group");
243  }
244 
245  # make sure the item is in the order
246  if (!$this->ItemInOrder($Item))
247  {
248  throw new Exception("Item must exist in the ordering");
249  }
250 
251  # make sure the filter is callable if set
252  if (!is_null($Filter) && !is_callable($Filter))
253  {
254  throw new Exception("Filter callback must be callable");
255  }
256 
257  $ItemType = $this->GetItemType($Item);
258  $Enclosure = $this->GetEnclosure($Item);
259  $EnclosureType = $this->GetItemType($Enclosure);
260  $Previous = $this->GetSiblingItem($Item, -1, $Filter);
261  $PreviousId = $this->GetItemId($Previous);
262  $PreviousType = $this->GetItemType($Previous);
263 
264  # determine if the item is at the top of the list
265  $ItemAtTop = is_null($Previous);
266 
267  # determine if a field needs to be moved into a group
268  $FieldToGroup = $ItemType == "MetadataField";
269  $FieldToGroup = $FieldToGroup && $EnclosureType == "MetadataFieldOrder";
270  $FieldToGroup = $FieldToGroup && $PreviousType == "MetadataFieldGroup";
271 
272  # determine if a field needs to be moved out of a group
273  $FieldToOrder = $ItemType == "MetadataField";
274  $FieldToOrder = $FieldToOrder && $EnclosureType == "MetadataFieldGroup";
275  $FieldToOrder = $FieldToOrder && $ItemAtTop;
276 
277  # move a field into a group if necessary
278  if ($FieldToGroup)
279  {
280  $this->MoveFieldToGroup($Previous, $Item, "append");
281  }
282 
283  # or move a field from a group to the order if necessary
284  else if ($FieldToOrder)
285  {
286  $this->MoveFieldToOrder($Enclosure, $Item, "before");
287  }
288 
289  # otherwise just move the item up if not at the top of the list
290  else if (!$ItemAtTop)
291  {
292  $this->MoveItemAfter($Item, $Previous);
293  }
294  }
295 
305  public function MoveItemDown($Item, $Filter=NULL)
306  {
307  # make sure the item is a field or group
308  if (!$this->IsFieldOrGroup($Item))
309  {
310  throw new Exception("Item must be a field or group");
311  }
312 
313  # make sure the item is in the order
314  if (!$this->ItemInOrder($Item))
315  {
316  throw new Exception("Item must exist in the ordering");
317  }
318 
319  # make sure the filter is callable if set
320  if (!is_null($Filter) && !is_callable($Filter))
321  {
322  throw new Exception("Filter callback must be callable");
323  }
324 
325  $ItemType = $this->GetItemType($Item);
326  $Enclosure = $this->GetEnclosure($Item);
327  $EnclosureType = $this->GetItemType($Enclosure);
328  $Next = $this->GetSiblingItem($Item, 1, $Filter);
329  $NextId = $this->GetItemId($Next);
330  $NextType = $this->GetItemType($Next);
331 
332  # determine if the item is at the bottom of the list
333  $ItemAtBottom = is_null($Next);
334 
335  # determine if a field needs to be moved into a group
336  $FieldToGroup = $ItemType == "MetadataField";
337  $FieldToGroup = $FieldToGroup && $EnclosureType == "MetadataFieldOrder";
338  $FieldToGroup = $FieldToGroup && $NextType == "MetadataFieldGroup";
339 
340  # determine if a field needs to be moved out of a group
341  $FieldToOrder = $ItemType == "MetadataField";
342  $FieldToOrder = $FieldToOrder && $EnclosureType == "MetadataFieldGroup";
343  $FieldToOrder = $FieldToOrder && $ItemAtBottom;
344 
345  # move a field into a group if necessary
346  if ($FieldToGroup)
347  {
348  $this->MoveFieldToGroup($Next, $Item, "prepend");
349  }
350 
351  # or move a field from a group to the order if necessary
352  else if ($FieldToOrder)
353  {
354  $this->MoveFieldToOrder($Enclosure, $Item, "after");
355  }
356 
357  # otherwise just move the item down if not at the bottom
358  else if (!$ItemAtBottom)
359  {
360  $this->MoveItemAfter($Next, $Item);
361  }
362  }
363 
370  public function MoveItemToTop($Item)
371  {
372  # make sure the item is either a field or group
373  if (!$this->IsFieldOrGroup($Item))
374  {
375  throw new Exception("Item must be a either field or group");
376  }
377 
378  # make sure the item is in the order
379  if (!$this->ItemInOrder($Item))
380  {
381  throw new Exception("Item must exist in the ordering");
382  }
383 
384  $OrderId = $this->GetItemId($this);
385  $OrderType = $this->GetItemType($this);
386  $ItemId = $this->GetItemId($Item);
387  $ItemType = $this->GetItemType($Item);
388  $ItemEnclosure = $this->GetEnclosure($Item);
389  $ItemEnclosureId = $this->GetItemId($ItemEnclosure);
390  $ItemEnclosureType = $this->GetItemType($ItemEnclosure);
391 
392  $SameEnclosureId = $OrderId == $ItemEnclosureId;
393  $SameEnclosureType = $OrderType == $ItemEnclosureType;
394 
395  # remove the item from its enclosure if necessary
396  if (!$SameEnclosureId || !$SameEnclosureType)
397  {
398  $ItemEnclosure->RemoveItem($ItemId, $ItemType);
399  }
400 
401  # move the item to the top of the order
402  $this->PrependItem($ItemId, $ItemType);
403  }
404 
411  public function MoveFieldToTopOfGroup(
412  MetadataFieldGroup $Group,
413  MetadataField $Field)
414  {
415  # make sure the items are in the order
416  if (!$this->ItemInOrder($Group) || !$this->ItemInOrder($Field))
417  {
418  throw new Exception("Item must exist in the ordering");
419  }
420 
421  $GroupId = $this->GetItemId($Group);
422  $GroupType = $this->GetItemType($Group);
423  $FieldId = $this->GetItemId($Field);
424  $FieldType = $this->GetItemType($Field);
425  $FieldEnclosure = $this->GetEnclosure($Field);
426  $FieldEnclosureId = $this->GetItemId($FieldEnclosure);
427  $FieldEnclosureType = $this->GetItemType($FieldEnclosure);
428 
429  $SameEnclosureId = $GroupId == $FieldEnclosureId;
430  $SameEnclosureType = $GroupType == $FieldEnclosureType;
431 
432  # remove the item from its enclosure if necessary
433  if (!$SameEnclosureId || !$SameEnclosureType)
434  {
435  $FieldEnclosure->RemoveItem($FieldId, $FieldType);
436  }
437 
438  # move the item to the top of the group
439  $Group->PrependItem($FieldId, $FieldType);
440  }
441 
451  public function MoveItemAfter($Target, $Item)
452  {
453  # make sure the items are either a field or group
454  if (!$this->IsFieldOrGroup($Target) || !$this->IsFieldOrGroup($Item))
455  {
456  throw new Exception("Items must be a either field or group");
457  }
458 
459  # make sure the items are in the order
460  if (!$this->ItemInOrder($Target) || !$this->ItemInOrder($Item))
461  {
462  throw new Exception("Items must exist in the ordering");
463  }
464 
465  $TargetId = $this->GetItemId($Target);
466  $TargetType = $this->GetItemType($Target);
467  $ItemId = $this->GetItemId($Item);
468  $ItemType = $this->GetItemType($Item);
469  $TargetEnclosure = $this->GetEnclosure($Target);
470  $TargetEnclosureId = $this->GetItemId($TargetEnclosure);
471  $TargetEnclosureType = $this->GetItemType($TargetEnclosure);
472  $ItemEnclosure = $this->GetEnclosure($Item);
473  $ItemEnclosureId = $this->GetItemId($ItemEnclosure);
474  $ItemEnclosureType = $this->GetItemType($ItemEnclosure);
475 
476  $TargetInGroup = $TargetEnclosure instanceof MetadataFieldGroup;
477  $ItemIsField = $Item instanceof MetadataField;
478 
479  # make sure only fields are placed in groups
480  if ($TargetInGroup && !$ItemIsField)
481  {
482  throw new Exception("Only fields can go into field groups");
483  }
484 
485  $SameEnclosureId = $TargetEnclosureId == $ItemEnclosureId;
486  $SameEnclosureType = $TargetEnclosureType == $ItemEnclosureType;
487 
488  # move a field into a group if necessary
489  if (!$SameEnclosureId || !$SameEnclosureType)
490  {
491  $ItemEnclosure->RemoveItem($ItemId, $ItemType);
492  }
493 
494  # move the item after the target
495  $TargetEnclosure->InsertItemAfter(
496  $TargetId,
497  $ItemId,
498  $TargetType,
499  $ItemType);
500  }
501 
507  public function ItemInOrder($Item)
508  {
509  # the item would have to be a field or group to be in the order
510  if (!$this->IsFieldOrGroup($Item))
511  {
512  return FALSE;
513  }
514 
515  $ItemId = $this->GetItemId($Item);
516  $ItemType = $this->GetItemType($Item);
517 
518  # if the item is in the order, i.e., not in a group
519  if ($this->ContainsItem($ItemId, $ItemType))
520  {
521  return TRUE;
522  }
523 
524  # the item is in one of the groups, so search each one for it
525  foreach ($this->GetGroups() as $Group)
526  {
527  if ($Group->ContainsItem($ItemId, $ItemType))
528  {
529  return TRUE;
530  }
531  }
532 
533  # the item was not found
534  return FALSE;
535  }
536 
547  public static function Create(
548  MetadataSchema $Schema,
549  $Name,
550  array $FieldOrder=array())
551  {
552  $ExistingOrders = self::GetOrdersForSchema($Schema);
553 
554  # remove existing orders with the same name
555  if (array_key_exists($Name, $ExistingOrders))
556  {
557  $ExistingOrders[$Name]->Delete();
558  }
559 
560  # create the folder
561  $FolderFactory = new FolderFactory();
562  $Folder = $FolderFactory->CreateMixedFolder(self::DEFAULT_FOLDER_NAME);
563 
564  # get all the fields including disabled fields but excluding temp fields
565  $Fields = $Schema->GetFields(NULL, NULL, TRUE);
566 
567  # first, add each field from the given order
568  foreach ($FieldOrder as $FieldId)
569  {
570  # skip invalid field IDs
571  if (!array_key_exists($FieldId, $Fields))
572  {
573  continue;
574  }
575 
576  # remove the field from the array of fields so that we'll know after
577  # looping which fields weren't added
578  unset($Fields[$FieldId]);
579 
580  # add the metadata field to the folder
581  $Folder->AppendItem($FieldId, "MetadataField");
582  }
583 
584  # finally, add any remaining fields that weren't removed in the loop
585  # above
586  foreach ($Fields as $FieldId => $Field)
587  {
588  $Folder->AppendItem($FieldId, "MetadataField");
589  }
590 
591  $Database = new Database();
592 
593  # associate the order with the schema in the database
594  $Database->Query("
595  INSERT INTO MetadataFieldOrders
596  SET SchemaId = '".addslashes($Schema->Id())."',
597  OrderId = '".addslashes($Folder->Id())."',
598  OrderName = '".addslashes($Name)."'");
599 
600  # reconstruct the folder as a metadata schema order object and return
601  return new MetadataFieldOrder($Folder->Id());
602  }
603 
612  public static function GetOrderForSchema(MetadataSchema $Schema, $Name)
613  {
614  return self::GetOrderForSchemaId($Schema->Id(), $Name);
615  }
616 
625  public static function GetOrderForSchemaId($SchemaId, $Name)
626  {
627  $Orders = self::GetOrdersForSchemaId($SchemaId);
628 
629  # return NULL if the order doesn't exist
630  if (!array_key_exists($Name, $Orders))
631  {
632  return NULL;
633  }
634 
635  # return the order
636  return $Orders[$Name];
637  }
638 
645  public static function GetOrdersForSchema(MetadataSchema $Schema)
646  {
647  return self::GetOrdersForSchemaId($Schema->Id());
648  }
649 
656  public static function GetOrdersForSchemaId($SchemaId)
657  {
658  $Orders = array();
659  $Database = new Database();
660 
661  # query the database for the orders associated with the schema
662  $Database->Query("
663  SELECT * FROM MetadataFieldOrders
664  WHERE SchemaId = '".addslashes($SchemaId)."'");
665 
666  # loop through each found record
667  foreach ($Database->FetchRows() as $Row)
668  {
669  try
670  {
671  # construct an object using the ID and add it to the array
672  $Orders[$Row["OrderName"]] = new MetadataFieldOrder($Row["OrderId"]);
673  }
674 
675  # remove invalid orders when encountered
676  catch (Exception $Exception)
677  {
678  $Database->Query("
679  DELETE FROM MetadataFieldOrders
680  WHERE OrderId = '".addslashes($Row["OrderId"])."'");
681  }
682  }
683 
684  return $Orders;
685  }
686 
692  protected function IsFieldOrGroup($Item)
693  {
694  if ($Item instanceof MetadataField)
695  {
696  return TRUE;
697  }
698 
699  if ($Item instanceof MetadataFieldGroup)
700  {
701  return TRUE;
702  }
703 
704  return FALSE;
705  }
706 
712  protected function GetItemId($Item)
713  {
714  return is_object($Item) ? $Item->Id() : NULL;
715  }
716 
722  protected function GetItemType($Item)
723  {
724  return is_object($Item) ? get_class($Item) : NULL;
725  }
726 
733  protected function GroupFilterCallback($Item)
734  {
735  return $Item["Type"] == "MetadataFieldGroup";
736  }
737 
745  protected function GetEnclosure($Item)
746  {
747  $ItemId = $this->GetItemId($Item);
748  $ItemType = $this->GetItemType($Item);
749 
750  # the item is in the order, i.e., not in a group
751  if ($this->ContainsItem($ItemId, $ItemType))
752  {
753  return $this;
754  }
755 
756  # the item is in one of the groups, so search each one for it
757  foreach ($this->GetGroups() as $Group)
758  {
759  if ($Group->ContainsItem($ItemId, $ItemType))
760  {
761  return $Group;
762  }
763  }
764 
765  # the item was not found
766  return NULL;
767  }
768 
776  protected function GetSiblingItem($Item, $Offset, $Filter=NULL)
777  {
778  $Id = $this->GetItemId($Item);
779  $Type = $this->GetItemType($Item);
780  $Sibling = NULL;
781 
782  # the sibling is in the order, i.e., not in a group
783  if ($this->ContainsItem($Id, $Type))
784  {
785  return $this->FindSiblingItem($this, $Item, $Offset, $Filter);
786  }
787 
788  # otherwise search for it in the groups
789  foreach ($this->GetGroups() as $Group)
790  {
791  if ($Group->ContainsItem($Id, $Type))
792  {
793  try
794  {
795  $Sibling = $this->FindSiblingItem(
796  $Group,
797  $Item,
798  $Offset,
799  $Filter);
800 
801  if ($Sibling)
802  {
803  return $Sibling;
804  }
805  }
806  catch (Exception $Exception)
807  {
808  # (moving to next item just to avoid empty catch statement)
809  continue;
810  }
811 
812  break;
813  }
814  }
815 
816  return NULL;
817  }
818 
828  protected function FindSiblingItem($Enclosure, $Item, $Offset, $Filter=NULL)
829  {
830  $ItemIds = $Enclosure->GetItemIds();
831 
832  # filter items if necessary
833  if (is_callable($Filter))
834  {
835  $ItemIds = array_filter($ItemIds, $Filter);
836 
837  # maintain continuous indices
838  ksort($ItemIds);
839  $ItemIds = array_values($ItemIds);
840  }
841 
842  $Id = $this->GetItemId($Item);
843  $Type = $this->GetItemType($Item);
844  $Index = array_search(array("ID" => $Id, "Type" => $Type), $ItemIds);
845 
846  if (!is_null($Index) && array_key_exists($Index+$Offset, $ItemIds))
847  {
848  $SiblingInfo = $ItemIds[$Index+$Offset];
849  return new $SiblingInfo["Type"]($SiblingInfo["ID"]);
850  }
851 
852  return NULL;
853  }
854 
862  protected function MoveFieldToGroup(
863  MetadataFieldGroup $Group,
864  MetadataField $Field,
865  $Placement)
866  {
867  # determine which action to use based on the placement value
868  $Action = $Placement == "prepend" ? "PrependItem" : "AppendItem";
869 
870  $GroupId = $this->GetItemId($Group);
871  $FieldId = $this->GetItemId($Field);
872 
873  $OrderHasGroup = $this->ContainsItem($GroupId, "MetadataFieldGroup");
874  $OrderHasField = $this->ContainsItem($FieldId, "MetadataField");
875 
876  # make sure the field and group are in the order before editing
877  if ($OrderHasGroup && $OrderHasField)
878  {
879  $this->RemoveItem($FieldId, "MetadataField");
880  $Group->$Action($FieldId, "MetadataField");
881  }
882  }
883 
892  protected function MoveFieldToOrder(
893  MetadataFieldGroup $Group,
894  MetadataField $Field,
895  $Placement)
896  {
897  # determine which action to use based on the placement value
898  $Action = $Placement == "before" ? "InsertItemBefore" : "InsertItemAfter";
899 
900  $GroupId = $this->GetItemId($Group);
901  $FieldId = $this->GetItemId($Field);
902 
903  $OrderHasGroup = $this->ContainsItem($GroupId, "MetadataFieldGroup");
904  $GroupHasField = $Group->ContainsItem($FieldId, "MetadataField");
905 
906  # make sure the field is in the group and the group is in the order
907  if ($OrderHasGroup && $GroupHasField)
908  {
909  $Group->RemoveItem($FieldId, "MetadataField");
910  $this->$Action(
911  $GroupId,
912  $FieldId,
913  "MetadataFieldGroup",
914  "MetadataField");
915  }
916  }
917 
924  protected function MoveFieldsToOrder(MetadataFieldGroup $Group)
925  {
926  $ItemIds = $Group->GetItemIds();
927  $PreviousItemId = $Group->Id();
928  $PreviousItemType = "MetadataFieldGroup";
929 
930  foreach ($ItemIds as $ItemInfo)
931  {
932  $ItemId = $ItemInfo["ID"];
933  $ItemType = $ItemInfo["Type"];
934 
935  $this->InsertItemAfter(
936  $PreviousItemId,
937  $ItemId,
938  $PreviousItemType,
939  $ItemType);
940 
941  $PreviousItemId = $ItemId;
942  $PreviousItemType = $ItemType;
943  }
944  }
945 
949  protected $Database;
950 
955  protected $SchemaId;
956 
960  protected $OrderName;
961 
962 }
MoveFieldToOrder(MetadataFieldGroup $Group, MetadataField $Field, $Placement)
Move the field with the given ID from the group with the given ID to the order, optionally specifying...
MoveFieldsToOrder(MetadataFieldGroup $Group)
Move all the metadata fields out of the given metadata field group and into the main order...
const DEFAULT_FOLDER_NAME
The default name given to the folders that are really metadata field orders.
Metadata schema (in effect a Factory class for MetadataField).
Class to build metadata field ordering functionality on top of the foldering functionality.
AppendItem($ItemOrItemId, $ItemType=NULL)
Add item to folder as the last item.
Definition: Folder.php:255
$OrderName
The name of the metadata field order.
Id()
Get folder ID.
Definition: Folder.php:109
GetGroups()
Get all the groups in this metadata field ordering in order.
GetSiblingItem($Item, $Offset, $Filter=NULL)
Get the item object of the item that is the given distance from the item.
SQL database abstraction object with smart query caching.
Definition: Database.php:22
MoveItemDown($Item, $Filter=NULL)
Move the given item down in the order.
GroupFilterCallback($Item)
Callback for the filter to retrieve groups only from the metadata field order.
__construct($Id)
Load an existing metadata field order.
FetchRow()
Get next database row retrieved by most recent query.
Definition: Database.php:640
Delete()
Delete the metadata field order.
GetItems()
Transform the item IDs of the metadata field order object into objects.
ItemInOrder($Item)
Determine whether the given item is a member of this order.
Factory object for Folder class, used to retrieve and manage Folders and groups of Folders...
Class that builds on the foldering functionality to provide groups of metadata fields.
Folder object used to create and manage groups of items.
Definition: Folder.php:17
GetItemType($Item)
Get the type of the given item.
RemoveItem($ItemId, $ItemType=NULL)
Remove item from folder, if present.
Definition: Folder.php:376
InsertItemAfter($TargetItemOrItemId, $NewItemOrItemId, $TargetItemType=NULL, $NewItemType=NULL)
Insert item into folder after specified item.
Definition: Folder.php:226
MoveItemUp($Item, $Filter=NULL)
Move the given item up in the order.
GetItemId($Item)
Get the ID of the given item.
NumRowsSelected()
Get number of rows returned by last SELECT or SHOW query.
Definition: Database.php:597
$SchemaId
The ID of the metadata schema this metadata field order is associated with.
GetEnclosure($Item)
Get the metadata field order or metadata field group that encloses the given item.
MoveFieldToTopOfGroup(MetadataFieldGroup $Group, MetadataField $Field)
Move the given item to the top of the order.
Query($QueryString, $FieldName="")
Query database (with caching if enabled).
Definition: Database.php:327
static Create(MetadataSchema $Schema, $Name, array $FieldOrder=array())
Create a new metadata field order, optionally specifying the order of the fields. ...
GetFields($FieldTypes=NULL, $OrderType=NULL, $IncludeDisabledFields=FALSE, $IncludeTempFields=FALSE)
Retrieve array of fields.
ContainsItem($ItemId, $ItemType=NULL)
Check whether specified item is contained in folder.
Definition: Folder.php:429
GetFields()
Get all the fields in this metadata field ordering in order.
Object representing a locally-defined type of metadata field.
SchemaId()
Get the ID of the metadata schema with which the metadata field order is associated.
FindSiblingItem($Enclosure, $Item, $Offset, $Filter=NULL)
Attempt to find the item that is the given distance from the item within the given enclosure...
static GetOrderForSchema(MetadataSchema $Schema, $Name)
Get a metadata field order with a specific name for a given metadata schema.
static GetOrdersForSchema(MetadataSchema $Schema)
Get all of the orders associated with a schema.
MendIssues()
Fix any issues found in case an unfound bug causes something to go awry.
Id()
Get schema ID.
MoveItemAfter($Target, $Item)
Move the given item after the given target item.
CreateGroup($Name)
Create a new metadata field group with the given name.
static GetOrderForSchemaId($SchemaId, $Name)
Get a metadata field order with a specific name for a given metadata schema ID.
DeleteGroup(MetadataFieldGroup $Group)
Move the metadata fields out of the given metadata group to the metadata field order and then delete ...
MoveItemToTop($Item)
Move the given item to the top of the order.
PrependItem($ItemOrItemId, $ItemType=NULL)
Add item to folder as the first item.
Definition: Folder.php:242
MoveFieldToGroup(MetadataFieldGroup $Group, MetadataField $Field, $Placement)
Move the field with the given ID to the group with the given ID, optionally specifying the place wher...
GetItemIds($Offset=NULL, $Length=NULL)
Retrieve array of IDs of items in folder, in the order that they appear in the folder.
Definition: Folder.php:322
static GetOrdersForSchemaId($SchemaId)
Get all of the orders associated with a schema ID.
OrderName()
Get the name of the metadata field order.
IsFieldOrGroup($Item)
Determine if the given item is a metadata field or metadata field group.
$Database
Database object with which to query the database.