29 foreach ($ItemIds as $Info)
31 $Items[] =
new $Info[
"Type"]($Info[
"ID"]);
46 # create the new group
47 $Folder = $FolderFactory->CreateMixedFolder($Name);
50 # and add it to this ordering
51 $this->
AppendItem($Group->Id(),
"MetadataFieldGroup");
81 # add fields to the list
84 $Fields[$Item->Id()] = $Item;
87 # add fields of groups to the list
90 foreach ($Item->GetFields() as $Field)
92 $Fields[$Field->Id()] = $Field;
107 $GroupIds = array_filter($ItemIds, array($this,
"GroupFilterCallback"));
111 # transform group info to group objects
112 foreach ($GroupIds as $GroupId)
116 $Groups[$GroupId[
"ID"]] =
new $GroupId[
"Type"]($GroupId[
"ID"]);
117 }
catch (Exception $Exception) {}
134 # make sure the item is a field or group
137 throw new Exception(
"Item must be a field or group");
140 # make sure the item is in the order
143 throw new Exception(
"Item must exist in the ordering");
146 # make sure the filter is callable if set
147 if (!is_null($Filter) && !is_callable($Filter))
149 throw new Exception(
"Filter callback must be callable");
156 $PreviousId = $this->
GetItemId($Previous);
159 # determine if the item is at the top of the list
160 $ItemAtTop = is_null($Previous);
162 # determine if a field needs to be moved into a group
163 $FieldToGroup = $ItemType ==
"MetadataField";
164 $FieldToGroup = $FieldToGroup && $EnclosureType ==
"MetadataFieldOrder";
165 $FieldToGroup = $FieldToGroup && $PreviousType ==
"MetadataFieldGroup";
167 # determine if a field needs to be moved out of a group
168 $FieldToOrder = $ItemType ==
"MetadataField";
169 $FieldToOrder = $FieldToOrder && $EnclosureType ==
"MetadataFieldGroup";
170 $FieldToOrder = $FieldToOrder && $ItemAtTop;
172 # move a field into a group if necessary
178 # or move a field from a group to the order if necessary
179 else if ($FieldToOrder)
184 # otherwise just move the item up if not at the top of the list
185 else if (!$ItemAtTop)
202 # make sure the item is a field or group
205 throw new Exception(
"Item must be a field or group");
208 # make sure the item is in the order
211 throw new Exception(
"Item must exist in the ordering");
214 # make sure the filter is callable if set
215 if (!is_null($Filter) && !is_callable($Filter))
217 throw new Exception(
"Filter callback must be callable");
227 # determine if the item is at the bottom of the list
228 $ItemAtBottom = is_null($Next);
230 # determine if a field needs to be moved into a group
231 $FieldToGroup = $ItemType ==
"MetadataField";
232 $FieldToGroup = $FieldToGroup && $EnclosureType ==
"MetadataFieldOrder";
233 $FieldToGroup = $FieldToGroup && $NextType ==
"MetadataFieldGroup";
235 # determine if a field needs to be moved out of a group
236 $FieldToOrder = $ItemType ==
"MetadataField";
237 $FieldToOrder = $FieldToOrder && $EnclosureType ==
"MetadataFieldGroup";
238 $FieldToOrder = $FieldToOrder && $ItemAtBottom;
240 # move a field into a group if necessary
246 # or move a field from a group to the order if necessary
247 else if ($FieldToOrder)
252 # otherwise just move the item down if not at the bottom
253 else if (!$ItemAtBottom)
267 # make sure the item is either a field or group
270 throw new Exception(
"Item must be a either field or group");
273 # make sure the item is in the order
276 throw new Exception(
"Item must exist in the ordering");
284 $ItemEnclosureId = $this->
GetItemId($ItemEnclosure);
285 $ItemEnclosureType = $this->
GetItemType($ItemEnclosure);
287 $SameEnclosureId = $OrderId == $ItemEnclosureId;
288 $SameEnclosureType = $OrderType == $ItemEnclosureType;
290 # remove the item from its enclosure if necessary
291 if (!$SameEnclosureId || !$SameEnclosureType)
293 $ItemEnclosure->RemoveItem($ItemId, $ItemType);
296 # move the item to the top of the order
309 # make sure the items are in the order
312 throw new Exception(
"Item must exist in the ordering");
320 $FieldEnclosureId = $this->
GetItemId($FieldEnclosure);
321 $FieldEnclosureType = $this->
GetItemType($FieldEnclosure);
323 $SameEnclosureId = $GroupId == $FieldEnclosureId;
324 $SameEnclosureType = $GroupType == $FieldEnclosureType;
326 # remove the item from its enclosure if necessary
327 if (!$SameEnclosureId || !$SameEnclosureType)
329 $FieldEnclosure->RemoveItem($FieldId, $FieldType);
332 # move the item to the top of the group
347 # make sure the items are either a field or group
350 throw new Exception(
"Items must be a either field or group");
353 # make sure the items are in the order
356 throw new Exception(
"Items must exist in the ordering");
364 $TargetEnclosureId = $this->
GetItemId($TargetEnclosure);
365 $TargetEnclosureType = $this->
GetItemType($TargetEnclosure);
367 $ItemEnclosureId = $this->
GetItemId($ItemEnclosure);
368 $ItemEnclosureType = $this->
GetItemType($ItemEnclosure);
373 # make sure only fields are placed in groups
374 if ($TargetInGroup && !$ItemIsField)
376 throw new Exception(
"Only fields can go into field groups");
379 $SameEnclosureId = $TargetEnclosureId == $ItemEnclosureId;
380 $SameEnclosureType = $TargetEnclosureType == $ItemEnclosureType;
382 # move a field into a group if necessary
383 if (!$SameEnclosureId || !$SameEnclosureType)
385 $ItemEnclosure->RemoveItem($ItemId, $ItemType);
388 # move the item after the target
389 $TargetEnclosure->InsertItemAfter(
403 # the item would have to be a field or group to be in the order
412 # if the item is in the order, i.e., not in a group
418 # the item is in one of the groups, so search each one for it
421 if ($Group->ContainsItem($ItemId, $ItemType))
427 # the item was not found
442 # create the display folder and update the system configuration if
446 $Order = self::CreateOrderingObject(
447 self::DISPLAY_FOLDER_NAME,
453 # create the edit folder and update the system configuration if
457 $Order = self::CreateOrderingObject(
458 self::EDIT_FOLDER_NAME,
475 self::CheckOrderingConfiguration();
487 self::CheckOrderingConfiguration();
500 $DisplayOrder = self::GetDisplayOrderObject();
501 $EditOrder = self::GetEditOrderObject();
503 $Fields = $Schema->GetFields(NULL, NULL, TRUE);
505 foreach ($Fields as $Field)
507 if (!$DisplayOrder->ItemInOrder($Field))
509 $DisplayOrder->AppendItem($Field->Id(),
"MetadataField");
512 if (!$EditOrder->ItemInOrder($Field))
514 $EditOrder->AppendItem($Field->Id(),
"MetadataField");
517 }
catch (Exception $Exception){}
547 return is_object($Item) ? $Item->Id() : NULL;
557 return is_object($Item) ? get_class($Item) : NULL;
568 return $Item[
"Type"] ==
"MetadataFieldGroup";
583 # the item is in the order, i.e., not in a group
589 # the item is in one of the groups, so search each one for it
592 if ($Group->ContainsItem($ItemId, $ItemType))
598 # the item was not found
615 # the sibling is in the order, i.e., not in a group
621 # otherwise search for it in the groups
624 if ($Group->ContainsItem($Id, $Type))
638 }
catch (Exception $Exception) {}
658 $ItemIds = $Enclosure->GetItemIds();
660 # filter items if necessary
661 if (is_callable($Filter))
663 $ItemIds = array_filter($ItemIds, $Filter);
665 # maintain continuous indices
667 $ItemIds = array_values($ItemIds);
672 $Index = array_search(array(
"ID" => $Id,
"Type" => $Type), $ItemIds);
674 if (!is_null($Index) && array_key_exists($Index+$Offset, $ItemIds))
676 $SiblingInfo = $ItemIds[$Index+$Offset];
677 return new $SiblingInfo[
"Type"]($SiblingInfo[
"ID"]);
696 # determine which action to use based on the placement value
697 $Action = $Placement ==
"prepend" ?
"PrependItem" :
"AppendItem";
702 $OrderHasGroup = $this->
ContainsItem($GroupId,
"MetadataFieldGroup");
703 $OrderHasField = $this->
ContainsItem($FieldId,
"MetadataField");
705 # make sure the field and group are in the order before editing
706 if ($OrderHasGroup && $OrderHasField)
709 $Group->$Action($FieldId,
"MetadataField");
726 # determine which action to use based on the placement value
727 $Action = $Placement ==
"before" ?
"InsertItemBefore" :
"InsertItemAfter";
732 $OrderHasGroup = $this->
ContainsItem($GroupId,
"MetadataFieldGroup");
733 $GroupHasField = $Group->
ContainsItem($FieldId,
"MetadataField");
735 # make sure the field is in the group and the group is in the order
736 if ($OrderHasGroup && $GroupHasField)
738 $Group->
RemoveItem($FieldId,
"MetadataField");
742 "MetadataFieldGroup",
756 $PreviousItemId = $Group->
Id();
757 $PreviousItemType =
"MetadataFieldGroup";
759 foreach ($ItemIds as $ItemInfo)
761 $ItemId = $ItemInfo[
"ID"];
762 $ItemType = $ItemInfo[
"Type"];
770 $PreviousItemId = $ItemId;
771 $PreviousItemType = $ItemType;
783 if (!self::$DisplayFolderId || !self::$EditFolderId)
785 throw new Exception(
"Metadata field ordering configuration not set");
799 $Folder = $FolderFactory->CreateMixedFolder($NewFolderName);
801 # try to get the existing order from the MetadataFields table, which
802 # won't be available for newer sites
803 $RowsForUpgrade = self::GetRowsForUpgrade($Type);
805 # an upgrade should be performed instead of using the defaults
806 if (count($RowsForUpgrade))
808 # add each field to the folder
809 foreach ($RowsForUpgrade as $Row)
811 $Folder->AppendItem($Row[
"FieldId"],
"MetadataField");
815 # otherwise use the defaults
818 # used later as a variable variable to get the ordering
820 ?
"DefaultDisplayOrder" :
"DefaultEditOrder";
822 # add each field to the folder
823 foreach (
self::$$DefaultOrder as $Index => $FieldId)
825 $Folder->AppendItem($FieldId,
"MetadataField");
829 # wrap the folder in a MetadataFieldOrder object
844 # temporarily suppress errors
848 # see if the old columns exist
849 $Handle = $Database->Query(
"
850 SELECT EditingOrderPosition
854 # the columns do not exist so an upgrade cannot be performed
855 if ($Handle === FALSE)
860 # determine which column to use for ordering
862 ?
"DisplayOrderPosition" :
"EditingOrderPosition";
864 # query for the fields in their proper order
869 ORDER BY ".$Column.
" ASC");
871 # restore the earlier error setting
874 # return the resulting rows
875 return $Database->FetchRows();