Reorders blocks based on the order provided via POST.

@return bool True on success, false otherwise
359781
protected function _reorder()
    {
        if (!empty($this->request->data['regions'])) {
            foreach ($this->request->data['regions'] as $theme => $regions) {
                foreach ($regions as $region => $ids) {
                    $ordering = 0;
                    foreach ($ids as $id) {
                        $blockRegion = $this->Blocks
                            ->BlockRegions
                            ->newEntity([
                                'id' => $id,
                                'theme' => $theme,
                                'region' => $region,
                                'ordering' => $ordering
                            ]);
                        $blockRegion->isNew(false);
                        $this->Blocks->BlockRegions->save($blockRegion);
                        $ordering++;
                    }
                }
            }

            return true;
        }

        return false;
    }
393839
public function orderIndexes() {
        $result = $this->orderElements($this->indexes);
        if ($result) {
            $this->setIndexes($result);
            return true;
        } else {
            return false;
        }
    }
86476
public function reorderAction(Request $request)
    {
        $this->init($request);
        $nodes = array();
        $nodeIds = $request->get('nodes');
        $changeParents = $request->get('parent');

        foreach ($nodeIds as $id) {
            /* @var Node $node */
            $node = $this->em->getRepository('KunstmaanNodeBundle:Node')->find($id);
            $this->denyAccessUnlessGranted(PermissionMap::PERMISSION_EDIT, $node);
            $nodes[] = $node;
        }

        $weight = 1;
        foreach ($nodes as $node) {
            $newParentId = isset($changeParents[$node->getId()]) ? $changeParents[$node->getId()] : null;
            if ($newParentId) {
                $parent = $this->em->getRepository('KunstmaanNodeBundle:Node')->find($newParentId);
                $this->denyAccessUnlessGranted(PermissionMap::PERMISSION_EDIT, $parent);
                $node->setParent($parent);
                $this->em->persist($node);
                $this->em->flush($node);
            }

            /* @var NodeTranslation $nodeTranslation */
            $nodeTranslation = $node->getNodeTranslation($this->locale, true);

            if ($nodeTranslation) {
                $nodeVersion = $nodeTranslation->getPublicNodeVersion();
                $page = $nodeVersion->getRef($this->em);

                $this->get('event_dispatcher')->dispatch(
                    Events::PRE_PERSIST,
                    new NodeEvent($node, $nodeTranslation, $nodeVersion, $page)
                );

                $nodeTranslation->setWeight($weight);
                $this->em->persist($nodeTranslation);
                $this->em->flush($nodeTranslation);

                $this->get('event_dispatcher')->dispatch(
                    Events::POST_PERSIST,
                    new NodeEvent($node, $nodeTranslation, $nodeVersion, $page)
                );

                ++$weight;
            }
        }

        return new JsonResponse(
            array(
                'Success' => 'The node-translations for [' . $this->locale . '] have got new weight values',
            )
        );
    }
175172
public function reorder(Menu $menu, $field = 'position')
    {
        $roots = $this->menuItemRepository->getRootNodes();
        $rootItem = null;

        foreach ($roots as $root) {
            if ($root->getMenu() == $menu) {
                $rootItem = $root;
            }
        }

        if ($rootItem) {
            $this->menuItemRepository->reorder($rootItem, $field);
            return true;
        }

        return false;
    }
6014
public function reorder($middle = true)
    {
        $result = 0;
        \Yii::$app->getDb()->transaction(function () use (&$result, $middle) {
            $list = $this->getQueryInternal()
                ->select($this->owner->primaryKey())
                ->orderBy([$this->sortAttribute => SORT_ASC])
                ->asArray()
                ->all();
            $from = $middle ? count($list) >> 1 : 0;
            foreach ($list as $i => $item) {
                $result += $this->owner->updateAll([$this->sortAttribute => ($i - $from) * $this->step], $item);
            }
        });

        return $result;
    }
1207866
public function saveReorder()
	{
		// if reorder_table_permission is false, abort
		if (isset($this->crud['reorder_permission']) && !$this->crud['reorder_permission']) {
			abort(403, 'Not allowed.');
		}

		$model = $this->crud['model'];
		$count = 0;
		$all_entries = \Request::input('tree');

		if (count($all_entries)) {
			foreach ($all_entries as $key => $entry) {
				if ($entry['item_id'] != "" && $entry['item_id'] != null) {
					$item = $model::find($entry['item_id']);
					$item->parent_id = $entry['parent_id'];
					$item->depth = $entry['depth'];
					$item->lft = $entry['left'];
					$item->rgt = $entry['right'];
					$item->save();

					$count++;
				}
			}
		}
		else
		{
			return false;
		}

		return 'success for '.$count." items";
	}
1064543
function reorder($expr, $direction = null)
    {
        $this->order(null);
        $this->order($expr, $direction);

        return $this;
    }
1368652
def reorder_view(self, request):
        """"""
        model = self.model

        if not self.has_change_permission(request):
            raise PermissionDenied

        if request.method == "POST":
            object_pks = request.POST.getlist('neworder[]')
            model.objects.set_orders(object_pks)

        return HttpResponse("OK")
702611
public function rewind()
    {
        usort(
            $this->entries, function ($a, $b) {
            return $a['priority'] - $b['priority'];
        }
        );
        $this->position = 0;
        $this->sorted = true;
    }
1199886
public function sort()
    {
        $this->sorted = array();
        $hasChanged   = true;
        while (count($this->sorted) < count($this->items) && $hasChanged) {
            $hasChanged = false;
            foreach ($this->dependencies as $item => $deps) {
                if ($this->satisfied($item)) {
                    $this->setSorted($item);
                    $this->removeDependents($item);
                    $hasChanged = true;
                }
                $this->hits[$item]++;
            }
        }

        return $this->sorted;
    }
282483
public function moveBlockToDisplayOrderPosition($afterBlock)
    {
        // first, we increase the display order of all blocks found after this one.
        $db = Loader::db();
        $c = $this->getBlockCollectionObject();
        if ($afterBlock instanceof self) {
            $block = self::getByID(
                $afterBlock->getBlockID(),
                $this->getBlockCollectionObject(),
                $this->getBlockAreaObject()
                );
            $q = 'update CollectionVersionBlocks set cbDisplayOrder = cbDisplayOrder + 1 where cID = ? and (cvID = ? or cbIncludeAll=1) and arHandle = ? and cbDisplayOrder > ?';
            $v = [$c->getCollectionID(), $c->getVersionID(), $this->getAreaHandle(), $block->getBlockDisplayOrder()];
            $db->Execute($q, $v);

            // now we set this block's display order to 1 + the current block
            $q = 'update CollectionVersionBlocks set cbDisplayOrder = ? where bID = ? and cID = ? and (cvID = ? or cbIncludeAll=1) and arHandle = ?';
            $v = [
                $block->getBlockDisplayOrder() + 1,
                $this->getBlockID(),
                $c->getCollectionID(),
                $c->getVersionID(),
                $this->getAreaHandle(),
            ];
            $db->Execute($q, $v);
        } else {
            $q = 'update CollectionVersionBlocks set cbDisplayOrder = cbDisplayOrder + 1 where cID = ? and (cvID = ? or cbIncludeAll=1) and arHandle = ?';
            $v = [$c->getCollectionID(), $c->getVersionID(), $this->getAreaHandle()];
            $db->Execute($q, $v);

            $q = 'update CollectionVersionBlocks set cbDisplayOrder = ? where bID = ? and cID = ? and (cvID = ? or cbIncludeAll=1) and arHandle = ?';
            $v = [0, $this->getBlockID(), $c->getCollectionID(), $c->getVersionID(), $this->getAreaHandle()];
            $db->Execute($q, $v);
        }
    }
21465
public function setSortsByDirective($blocks, $sort)
    {
        $sort = array_values($sort); // we're using keys as positions
        $levels = array();

        // Split arrays into levels by owner (child - parent)
        foreach ($blocks as $block) {
            $pos = array_search($block->getId(), $sort, false);
            $ownerId = ($block->getOwner()) ? $block->getOwner()->getId() : 0;
            $levels[$ownerId][$pos] = $block->getId();
        }

        foreach ($levels as &$level) {
            ksort($level);
        }

        foreach ($blocks as $block) {
            $ownerId = ($block->getOwner()) ? $block->getOwner()->getId() : 0;
            $sortedIds = $levels[$ownerId];
            $pos = array_search(array_search($block->getId(), $sortedIds), array_keys($sortedIds));
            $block->setSort($pos);

            if ($block->getOwner() && $block->getOwner()->getSuper()) {
                $superId = $block->getOwner()->getSuper()->getId();
                // See if we need to position it below an inherited block
                $pos = array_search($block->getId(), $levels[$block->getOwner()->getId()], false);
                $prevBlockId = (isset($levels[$superId]) && isset($levels[$superId][$pos - 1])) ? $levels[$superId][$pos - 1] : null;
                if ($prevBlockId !== null) {
                    $prevBlockPos = array_search($prevBlockId, array_values($levels[$superId]));
                    $block->setSortParent(($prevBlockPos !== false) ? $prevBlockPos : -1);
                } else {
                    $block->setSortParent(-1);
                }
            } else {
                $block->setSortParent(-1);
            }
        }

        return $blocks;
    }
1174158
protected function fixOrder( $order ) {
		$fixed = [];
		$fm = [];
		foreach ( $order as $post_id => $val ) {
			if ( $val['post_type'] === 'front-matter' ) {
				$type = $this->taxonomy->getFrontMatterType( $post_id );
				if ( ! in_array( $type, [ 'before-title', 'title-page', 'dedication', 'epigraph' ], true ) ) {
					// Add front matter that isn't being reorderd without intervention.
					$fixed[ $post_id ] = $val;
				} else {
					// Add front matter that is being reordered to temporary array.
					$fm[ $post_id ] = array_merge( $val, [ 'type' => $type ] );
				}
			} else {
				// Add parts, chapters, and back matter without intervention.
				$fixed[ $post_id ] = $val;
			}
		}
		// Work our way backwards, starting with epigraph
		foreach ( [ 'epigraph', 'dedication', 'title-page', 'before-title' ] as $type ) {
			foreach ( $fm as $post_id => $val ) {
				if ( $val['type'] === $type ) {
					$fixed = [ $post_id => $val ] + $fixed;
					break;
				}
			}
		}
		return $fixed;
	}
716454
public function moveBlockUp( $currentIndex )
    {
        $array =& $this->attributes['blocks'];

        $newIndex = $currentIndex - 1;

        if ( $newIndex < 0 || $newIndex >= count( $array ) )
            return false;

        $tmpItem = $array[$newIndex];

        $array[$newIndex] =& $array[$currentIndex];
        $array[$currentIndex] =& $tmpItem;

        if ( $tmpItem->toBeRemoved() )
            $this->moveBlockUp( $newIndex );

        return true;
    }
869061
public function reorder( $table, $weight_field, $id_field, $ids ) {

		$success = false;
		$ids     = (array) $ids;

		list( $table, $weight_field, $id_field, $ids ) = self::do_hook(
			'reorder', array(
				$table,
				$weight_field,
				$id_field,
				$ids,
			), $this
		);

		if ( ! empty( $ids ) ) {
			$success = true;

			foreach ( $ids as $weight => $id ) {
				$updated = $this->update( $table, array( $weight_field => $weight ), array( $id_field => $id ), array( '%d' ), array( '%d' ) );

				if ( false === $updated ) {
					$success = false;
				}
			}
		}

		return $success;
	}
30273
public function MoveNext()
	{
		if ( ! $this->iteratorStarted )
		{
			$this->Init();
			$this->pos = -1;
			$this->iteratorStarted = true;
		}

		/**
		 * @var XPathItem $item
		 */
		$item = $this->NextItem();
		if ( ! is_null( $item ) )
		{
			$this->pos++;
			$this->curr = $item;
			return true;
		}

		$this->iteratorFinished = true;
		return false;
	}
508643
protected function pushOrder()
    {
        if( $this->order ) {
            $this->parts[] = 'ORDER BY';
            $this->parts[] = $this->quoteIdentifierIfNotExpression($this->order);
            $this->parts[] = $this->direction == self::DESC ? self::DESC : self::ASC;
        }
    }