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-2016 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 
161  public function DeleteGroup(MetadataFieldGroup $Group)
162  {
163  if ($this->ContainsItem($Group->Id(), "MetadataFieldGroup"))
164  {
165  $this->MoveFieldsToOrder($Group);
166  $this->RemoveItem($Group->Id(), "MetadataFieldGroup");
167  }
168  }
169 
174  public function GetFields()
175  {
176  $Fields = array();
177 
178  foreach ($this->GetItems() as $Item)
179  {
180  # add fields to the list
181  if ($Item instanceof MetadataField)
182  {
183  $Fields[$Item->Id()] = $Item;
184  }
185 
186  # add fields of groups to the list
187  else if ($Item instanceof MetadataFieldGroup)
188  {
189  foreach ($Item->GetFields() as $Field)
190  {
191  $Fields[$Field->Id()] = $Field;
192  }
193  }
194  }
195 
196  return $Fields;
197  }
198 
203  public function GetGroups()
204  {
205  $ItemIds = $this->GetItemIds();
206  $GroupIds = array_filter($ItemIds, array($this, "GroupFilterCallback"));
207 
208  $Groups = array();
209 
210  # transform group info to group objects
211  foreach ($GroupIds as $GroupId)
212  {
213  try
214  {
215  $Groups[$GroupId["ID"]] = new $GroupId["Type"]($GroupId["ID"]);
216  }
217  catch (Exception $Exception)
218  {
219  # (moving to next item just to avoid empty catch statement)
220  continue;
221  }
222  }
223 
224  return $Groups;
225  }
226 
235  public function MoveItemUp($Item, $Filter=NULL)
236  {
237  # make sure the item is a field or group
238  if (!$this->IsFieldOrGroup($Item))
239  {
240  throw new Exception("Item must be a field or group");
241  }
242 
243  # make sure the item is in the order
244  if (!$this->ItemInOrder($Item))
245  {
246  throw new Exception("Item must exist in the ordering");
247  }
248 
249  # make sure the filter is callable if set
250  if (!is_null($Filter) && !is_callable($Filter))
251  {
252  throw new Exception("Filter callback must be callable");
253  }
254 
255  $ItemType = $this->GetItemType($Item);
256  $Enclosure = $this->GetEnclosure($Item);
257  $EnclosureType = $this->GetItemType($Enclosure);
258  $Previous = $this->GetSiblingItem($Item, -1, $Filter);
259  $PreviousId = $this->GetItemId($Previous);
260  $PreviousType = $this->GetItemType($Previous);
261 
262  # determine if the item is at the top of the list
263  $ItemAtTop = is_null($Previous);
264 
265  # determine if a field needs to be moved into a group
266  $FieldToGroup = $ItemType == "MetadataField";
267  $FieldToGroup = $FieldToGroup && $EnclosureType == "MetadataFieldOrder";
268  $FieldToGroup = $FieldToGroup && $PreviousType == "MetadataFieldGroup";
269 
270  # determine if a field needs to be moved out of a group
271  $FieldToOrder = $ItemType == "MetadataField";
272  $FieldToOrder = $FieldToOrder && $EnclosureType == "MetadataFieldGroup";
273  $FieldToOrder = $FieldToOrder && $ItemAtTop;
274 
275  # move a field into a group if necessary
276  if ($FieldToGroup)
277  {
278  $this->MoveFieldToGroup($Previous, $Item, "append");
279  }
280 
281  # or move a field from a group to the order if necessary
282  else if ($FieldToOrder)
283  {
284  $this->MoveFieldToOrder($Enclosure, $Item, "before");
285  }
286 
287  # otherwise just move the item up if not at the top of the list
288  else if (!$ItemAtTop)
289  {
290  $this->MoveItemAfter($Item, $Previous);
291  }
292  }
293 
302  public function MoveItemDown($Item, $Filter=NULL)
303  {
304  # make sure the item is a field or group
305  if (!$this->IsFieldOrGroup($Item))
306  {
307  throw new Exception("Item must be a field or group");
308  }
309 
310  # make sure the item is in the order
311  if (!$this->ItemInOrder($Item))
312  {
313  throw new Exception("Item must exist in the ordering");
314  }
315 
316  # make sure the filter is callable if set
317  if (!is_null($Filter) && !is_callable($Filter))
318  {
319  throw new Exception("Filter callback must be callable");
320  }
321 
322  $ItemType = $this->GetItemType($Item);
323  $Enclosure = $this->GetEnclosure($Item);
324  $EnclosureType = $this->GetItemType($Enclosure);
325  $Next = $this->GetSiblingItem($Item, 1, $Filter);
326  $NextId = $this->GetItemId($Next);
327  $NextType = $this->GetItemType($Next);
328 
329  # determine if the item is at the bottom of the list
330  $ItemAtBottom = is_null($Next);
331 
332  # determine if a field needs to be moved into a group
333  $FieldToGroup = $ItemType == "MetadataField";
334  $FieldToGroup = $FieldToGroup && $EnclosureType == "MetadataFieldOrder";
335  $FieldToGroup = $FieldToGroup && $NextType == "MetadataFieldGroup";
336 
337  # determine if a field needs to be moved out of a group
338  $FieldToOrder = $ItemType == "MetadataField";
339  $FieldToOrder = $FieldToOrder && $EnclosureType == "MetadataFieldGroup";
340  $FieldToOrder = $FieldToOrder && $ItemAtBottom;
341 
342  # move a field into a group if necessary
343  if ($FieldToGroup)
344  {
345  $this->MoveFieldToGroup($Next, $Item, "prepend");
346  }
347 
348  # or move a field from a group to the order if necessary
349  else if ($FieldToOrder)
350  {
351  $this->MoveFieldToOrder($Enclosure, $Item, "after");
352  }
353 
354  # otherwise just move the item down if not at the bottom
355  else if (!$ItemAtBottom)
356  {
357  $this->MoveItemAfter($Next, $Item);
358  }
359  }
360 
367  public function MoveItemToTop($Item)
368  {
369  # make sure the item is either a field or group
370  if (!$this->IsFieldOrGroup($Item))
371  {
372  throw new Exception("Item must be a either field or group");
373  }
374 
375  # make sure the item is in the order
376  if (!$this->ItemInOrder($Item))
377  {
378  throw new Exception("Item must exist in the ordering");
379  }
380 
381  $OrderId = $this->GetItemId($this);
382  $OrderType = $this->GetItemType($this);
383  $ItemId = $this->GetItemId($Item);
384  $ItemType = $this->GetItemType($Item);
385  $ItemEnclosure = $this->GetEnclosure($Item);
386  $ItemEnclosureId = $this->GetItemId($ItemEnclosure);
387  $ItemEnclosureType = $this->GetItemType($ItemEnclosure);
388 
389  $SameEnclosureId = $OrderId == $ItemEnclosureId;
390  $SameEnclosureType = $OrderType == $ItemEnclosureType;
391 
392  # remove the item from its enclosure if necessary
393  if (!$SameEnclosureId || !$SameEnclosureType)
394  {
395  $ItemEnclosure->RemoveItem($ItemId, $ItemType);
396  }
397 
398  # move the item to the top of the order
399  $this->PrependItem($ItemId, $ItemType);
400  }
401 
408  public function MoveFieldToTopOfGroup(
409  MetadataFieldGroup $Group,
410  MetadataField $Field)
411  {
412  # make sure the items are in the order
413  if (!$this->ItemInOrder($Group) || !$this->ItemInOrder($Field))
414  {
415  throw new Exception("Item must exist in the ordering");
416  }
417 
418  $GroupId = $this->GetItemId($Group);
419  $GroupType = $this->GetItemType($Group);
420  $FieldId = $this->GetItemId($Field);
421  $FieldType = $this->GetItemType($Field);
422  $FieldEnclosure = $this->GetEnclosure($Field);
423  $FieldEnclosureId = $this->GetItemId($FieldEnclosure);
424  $FieldEnclosureType = $this->GetItemType($FieldEnclosure);
425 
426  $SameEnclosureId = $GroupId == $FieldEnclosureId;
427  $SameEnclosureType = $GroupType == $FieldEnclosureType;
428 
429  # remove the item from its enclosure if necessary
430  if (!$SameEnclosureId || !$SameEnclosureType)
431  {
432  $FieldEnclosure->RemoveItem($FieldId, $FieldType);
433  }
434 
435  # move the item to the top of the group
436  $Group->PrependItem($FieldId, $FieldType);
437  }
438 
447  public function MoveItemAfter($Target, $Item)
448  {
449  # make sure the items are either a field or group
450  if (!$this->IsFieldOrGroup($Target) || !$this->IsFieldOrGroup($Item))
451  {
452  throw new Exception("Items must be a either field or group");
453  }
454 
455  # make sure the items are in the order
456  if (!$this->ItemInOrder($Target) || !$this->ItemInOrder($Item))
457  {
458  throw new Exception("Items must exist in the ordering");
459  }
460 
461  $TargetId = $this->GetItemId($Target);
462  $TargetType = $this->GetItemType($Target);
463  $ItemId = $this->GetItemId($Item);
464  $ItemType = $this->GetItemType($Item);
465  $TargetEnclosure = $this->GetEnclosure($Target);
466  $TargetEnclosureId = $this->GetItemId($TargetEnclosure);
467  $TargetEnclosureType = $this->GetItemType($TargetEnclosure);
468  $ItemEnclosure = $this->GetEnclosure($Item);
469  $ItemEnclosureId = $this->GetItemId($ItemEnclosure);
470  $ItemEnclosureType = $this->GetItemType($ItemEnclosure);
471 
472  $TargetInGroup = $TargetEnclosure instanceof MetadataFieldGroup;
473  $ItemIsField = $Item instanceof MetadataField;
474 
475  # make sure only fields are placed in groups
476  if ($TargetInGroup && !$ItemIsField)
477  {
478  throw new Exception("Only fields can go into field groups");
479  }
480 
481  $SameEnclosureId = $TargetEnclosureId == $ItemEnclosureId;
482  $SameEnclosureType = $TargetEnclosureType == $ItemEnclosureType;
483 
484  # move a field into a group if necessary
485  if (!$SameEnclosureId || !$SameEnclosureType)
486  {
487  $ItemEnclosure->RemoveItem($ItemId, $ItemType);
488  }
489 
490  # move the item after the target
491  $TargetEnclosure->InsertItemAfter(
492  $TargetId,
493  $ItemId,
494  $TargetType,
495  $ItemType);
496  }
497 
503  public function ItemInOrder($Item)
504  {
505  # the item would have to be a field or group to be in the order
506  if (!$this->IsFieldOrGroup($Item))
507  {
508  return FALSE;
509  }
510 
511  $ItemId = $this->GetItemId($Item);
512  $ItemType = $this->GetItemType($Item);
513 
514  # if the item is in the order, i.e., not in a group
515  if ($this->ContainsItem($ItemId, $ItemType))
516  {
517  return TRUE;
518  }
519 
520  # the item is in one of the groups, so search each one for it
521  foreach ($this->GetGroups() as $Group)
522  {
523  if ($Group->ContainsItem($ItemId, $ItemType))
524  {
525  return TRUE;
526  }
527  }
528 
529  # the item was not found
530  return FALSE;
531  }
532 
543  public static function Create(
544  MetadataSchema $Schema,
545  $Name,
546  array $FieldOrder=array())
547  {
548  $ExistingOrders = self::GetOrdersForSchema($Schema);
549 
550  # remove existing orders with the same name
551  if (array_key_exists($Name, $ExistingOrders))
552  {
553  $ExistingOrders[$Name]->Delete();
554  }
555 
556  # create the folder
557  $FolderFactory = new FolderFactory();
558  $Folder = $FolderFactory->CreateMixedFolder(self::DEFAULT_FOLDER_NAME);
559 
560  # get all the fields including disabled fields but excluding temp fields
561  $Fields = $Schema->GetFields(NULL, NULL, TRUE);
562 
563  # first, add each field from the given order
564  foreach ($FieldOrder as $FieldId)
565  {
566  # skip invalid field IDs
567  if (!array_key_exists($FieldId, $Fields))
568  {
569  continue;
570  }
571 
572  # remove the field from the array of fields so that we'll know after
573  # looping which fields weren't added
574  unset($Fields[$FieldId]);
575 
576  # add the metadata field to the folder
577  $Folder->AppendItem($FieldId, "MetadataField");
578  }
579 
580  # finally, add any remaining fields that weren't removed in the loop
581  # above
582  foreach ($Fields as $FieldId => $Field)
583  {
584  $Folder->AppendItem($FieldId, "MetadataField");
585  }
586 
587  $Database = new Database();
588 
589  # associate the order with the schema in the database
590  $Database->Query("
591  INSERT INTO MetadataFieldOrders
592  SET SchemaId = '".addslashes($Schema->Id())."',
593  OrderId = '".addslashes($Folder->Id())."',
594  OrderName = '".addslashes($Name)."'");
595 
596  # reconstruct the folder as a metadata schema order object and return
597  return new MetadataFieldOrder($Folder->Id());
598  }
599 
609  public static function GetOrderForSchema(MetadataSchema $Schema, $Name)
610  {
611  return self::GetOrderForSchemaId($Schema->Id(), $Name);
612  }
613 
623  public static function GetOrderForSchemaId($SchemaId, $Name)
624  {
625  $Orders = self::GetOrdersForSchemaId($SchemaId);
626 
627  # return NULL if the order doesn't exist
628  if (!array_key_exists($Name, $Orders))
629  {
630  return NULL;
631  }
632 
633  # return the order
634  return $Orders[$Name];
635  }
636 
643  public static function GetOrdersForSchema(MetadataSchema $Schema)
644  {
645  return self::GetOrdersForSchemaId($Schema->Id());
646  }
647 
654  public static function GetOrdersForSchemaId($SchemaId)
655  {
656  $Orders = array();
657  $Database = new Database();
658 
659  # query the database for the orders associated with the schema
660  $Database->Query("
661  SELECT * FROM MetadataFieldOrders
662  WHERE SchemaId = '".addslashes($SchemaId)."'");
663 
664  # loop through each found record
665  foreach ($Database->FetchRows() as $Row)
666  {
667  try
668  {
669  # construct an object using the ID and add it to the array
670  $Orders[$Row["OrderName"]] = new MetadataFieldOrder($Row["OrderId"]);
671  }
672 
673  # remove invalid orders when encountered
674  catch (Exception $Exception)
675  {
676  $Database->Query("
677  DELETE FROM MetadataFieldOrders
678  WHERE OrderId = '".addslashes($Row["OrderId"])."'");
679  }
680  }
681 
682  return $Orders;
683  }
684 
690  protected function IsFieldOrGroup($Item)
691  {
692  if ($Item instanceof MetadataField)
693  {
694  return TRUE;
695  }
696 
697  if ($Item instanceof MetadataFieldGroup)
698  {
699  return TRUE;
700  }
701 
702  return FALSE;
703  }
704 
710  protected function GetItemId($Item)
711  {
712  return is_object($Item) ? $Item->Id() : NULL;
713  }
714 
720  protected function GetItemType($Item)
721  {
722  return is_object($Item) ? get_class($Item) : NULL;
723  }
724 
731  protected function GroupFilterCallback($Item)
732  {
733  return $Item["Type"] == "MetadataFieldGroup";
734  }
735 
743  protected function GetEnclosure($Item)
744  {
745  $ItemId = $this->GetItemId($Item);
746  $ItemType = $this->GetItemType($Item);
747 
748  # the item is in the order, i.e., not in a group
749  if ($this->ContainsItem($ItemId, $ItemType))
750  {
751  return $this;
752  }
753 
754  # the item is in one of the groups, so search each one for it
755  foreach ($this->GetGroups() as $Group)
756  {
757  if ($Group->ContainsItem($ItemId, $ItemType))
758  {
759  return $Group;
760  }
761  }
762 
763  # the item was not found
764  return NULL;
765  }
766 
774  protected function GetSiblingItem($Item, $Offset, $Filter=NULL)
775  {
776  $Id = $this->GetItemId($Item);
777  $Type = $this->GetItemType($Item);
778  $Sibling = NULL;
779 
780  # the sibling is in the order, i.e., not in a group
781  if ($this->ContainsItem($Id, $Type))
782  {
783  return $this->FindSiblingItem($this, $Item, $Offset, $Filter);
784  }
785 
786  # otherwise search for it in the groups
787  foreach ($this->GetGroups() as $Group)
788  {
789  if ($Group->ContainsItem($Id, $Type))
790  {
791  try
792  {
793  $Sibling = $this->FindSiblingItem(
794  $Group,
795  $Item,
796  $Offset,
797  $Filter);
798 
799  if ($Sibling)
800  {
801  return $Sibling;
802  }
803  }
804  catch (Exception $Exception)
805  {
806  # (moving to next item just to avoid empty catch statement)
807  continue;
808  }
809 
810  break;
811  }
812  }
813 
814  return NULL;
815  }
816 
826  protected function FindSiblingItem($Enclosure, $Item, $Offset, $Filter=NULL)
827  {
828  $ItemIds = $Enclosure->GetItemIds();
829 
830  # filter items if necessary
831  if (is_callable($Filter))
832  {
833  $ItemIds = array_filter($ItemIds, $Filter);
834 
835  # maintain continuous indices
836  ksort($ItemIds);
837  $ItemIds = array_values($ItemIds);
838  }
839 
840  $Id = $this->GetItemId($Item);
841  $Type = $this->GetItemType($Item);
842  $Index = array_search(array("ID" => $Id, "Type" => $Type), $ItemIds);
843 
844  if (!is_null($Index) && array_key_exists($Index+$Offset, $ItemIds))
845  {
846  $SiblingInfo = $ItemIds[$Index+$Offset];
847  return new $SiblingInfo["Type"]($SiblingInfo["ID"]);
848  }
849 
850  return NULL;
851  }
852 
860  protected function MoveFieldToGroup(
861  MetadataFieldGroup $Group,
862  MetadataField $Field,
863  $Placement)
864  {
865  # determine which action to use based on the placement value
866  $Action = $Placement == "prepend" ? "PrependItem" : "AppendItem";
867 
868  $GroupId = $this->GetItemId($Group);
869  $FieldId = $this->GetItemId($Field);
870 
871  $OrderHasGroup = $this->ContainsItem($GroupId, "MetadataFieldGroup");
872  $OrderHasField = $this->ContainsItem($FieldId, "MetadataField");
873 
874  # make sure the field and group are in the order before editing
875  if ($OrderHasGroup && $OrderHasField)
876  {
877  $this->RemoveItem($FieldId, "MetadataField");
878  $Group->$Action($FieldId, "MetadataField");
879  }
880  }
881 
889  protected function MoveFieldToOrder(
890  MetadataFieldGroup $Group,
891  MetadataField $Field,
892  $Placement)
893  {
894  # determine which action to use based on the placement value
895  $Action = $Placement == "before" ? "InsertItemBefore" : "InsertItemAfter";
896 
897  $GroupId = $this->GetItemId($Group);
898  $FieldId = $this->GetItemId($Field);
899 
900  $OrderHasGroup = $this->ContainsItem($GroupId, "MetadataFieldGroup");
901  $GroupHasField = $Group->ContainsItem($FieldId, "MetadataField");
902 
903  # make sure the field is in the group and the group is in the order
904  if ($OrderHasGroup && $GroupHasField)
905  {
906  $Group->RemoveItem($FieldId, "MetadataField");
907  $this->$Action(
908  $GroupId,
909  $FieldId,
910  "MetadataFieldGroup",
911  "MetadataField");
912  }
913  }
914 
920  protected function MoveFieldsToOrder(MetadataFieldGroup $Group)
921  {
922  $ItemIds = $Group->GetItemIds();
923  $PreviousItemId = $Group->Id();
924  $PreviousItemType = "MetadataFieldGroup";
925 
926  foreach ($ItemIds as $ItemInfo)
927  {
928  $ItemId = $ItemInfo["ID"];
929  $ItemType = $ItemInfo["Type"];
930 
931  $this->InsertItemAfter(
932  $PreviousItemId,
933  $ItemId,
934  $PreviousItemType,
935  $ItemType);
936 
937  $PreviousItemId = $ItemId;
938  $PreviousItemType = $ItemType;
939  }
940  }
941 
945  protected $Database;
946 
951  protected $SchemaId;
952 
956  protected $OrderName;
957 }
958 
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:669
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:626
$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:355
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.