Reorder tree of subordinate employees.

@param bool $verify Whether or not to verify the tree before reorder.
@return bool true on success, false on failure
187600
public function reorderEmployeeTree($verify = true) {
		set_time_limit(REORDER_TREE_EMPLOYEE_TIME_LIMIT);
		if ($verify && ($this->verify() !== true)) {
			return false;
		}

		$dataSource = $this->getDataSource();
		$dataSource->begin();
		$result = $this->reorder(['verify' => false]);
		if ($result) {
			$dataSource->commit();
			$event = new CakeEvent('Model.afterUpdateTree', $this);
			$this->getEventManager()->dispatch($event);
		} else {
			$dataSource->rollback();
		}

		return $result;
	}
1333902
public function renumber(Tree $tree): ResponseInterface
    {
        $xrefs = $this->duplicateXrefs($tree);

        /* I18N: Renumber the records in a family tree */
        $title = I18N::translate('Renumber family tree') . ' — ' . e($tree->title());

        return $this->viewResponse('admin/trees-renumber', [
            'title' => $title,
            'xrefs' => $xrefs,
        ]);
    }
449371
public function reorderProfileUpdates($id, $order, $offset = null, $utc = false)
    {
        $payload = $this->buildReorderProfileUpdatesPayload((array) $order, $offset, $utc);

        return $this->send($this->getHttp()->post($this->url.'profiles/'.$id.'/updates/reorder.json', null, $payload));
    }
1024439
public function rebuild( $force = false )
	{
		$alreadyValid = forward_static_call( [get_class( $this->model ), 'isValidNestedSet'] );

		// Do not rebuild a valid Nested Set tree structure
		if ( !$force && $alreadyValid )
			return true;

		// Rebuild lefts and rights for each root node and its children (recursively).
		// We go by setting left (and keep track of the current left bound), then
		// search for each children and recursively set the left index (while
		// incrementing that index). When going back up the recursive chain we start
		// setting the right indexes and saving the nodes...
		$self = $this;

		$this->model->getConnection()->transaction( function () use ( $self )
		{
			foreach ( $self->roots() as $root )
				$self->rebuildBounds( $root, 0 );
		} );

		return false;
	}
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;
    }
875318
public function Distinct($Bool = TRUE) {
      $this->_Distinct = (is_bool($Bool)) ? $Bool : TRUE;
      return $this;
   }
1307899
function remove($ID, $Recursive = false)
	{
		$this->unassignRoles ( $ID );
		if (! $Recursive)
			return $this->permissions->deleteConditional ( "ID=?", $ID );
		else
			return $this->permissions->deleteSubtreeConditional ( "ID=?", $ID );
	}
522061
public static function reverseOrder($order)
	{
		if (!trim($order))
			return $order;

		$parts = explode(',',$order);

		for ($i=0,$n=count($parts); $i<$n; ++$i)
		{
			$v = strtolower($parts[$i]);

			if (strpos($v,' asc') !== false)
				$parts[$i] = preg_replace('/asc/i','DESC',$parts[$i]);
			elseif (strpos($v,' desc') !== false)
				$parts[$i] = preg_replace('/desc/i','ASC',$parts[$i]);
			else
				$parts[$i] .= ' DESC';
		}
		return join(',',$parts);
	}
135306
protected function checkActiveSort($update = true)
    {
        $request = request();

        if ($update && $request->has('sort')) {

            $this->activeSort = $request->get('sort');

            if ($request->filled('sortdir') && ! empty($request->get('sortdir'))) {
                $this->activeSortDescending = strtolower($request->get('sortdir')) === 'desc';
            } else {
                $this->activeSortDescending = null;
            }

            $this->markResetActivePage()
                 ->storeActiveSortInSession();

        } elseif ($this->getListMemory()->hasSortData()) {

            $this->retrieveActiveSortFromSession();
        }

        return $this;
    }
791193
public function reorderContent($type, $a, $b = null, $father = null)
    {
        $a = $this->getNode($type, $a, $father);
        $a->detach();

        if ($b) {
            $b = $this->getNode($type, $b, $father);
            $a->setBack($b->getBack());
            $a->setNext($b);

            if ($b->getBack()) {
                $b->getBack()->setNext($a);
            }

            $b->setBack($a);
        } else {
            $b = $this->getnode($type, null, $father);
            $a->setNext($b->getNext());
            $a->setBack($b);
            $b->setNext($a);
        }

        $this->manager->persist($a);
        $this->manager->persist($b);
        $this->manager->flush();
    }
604188
public function isSuperiorThen($user)
    {
        if( ! $this->maxRole()) return false;
        if( ! $user->maxRole()) return true;
        return $this->maxRole()->order > $user->maxRole()->order;
    }
1111659
public function hasOrder($orderId)
    {
        $orderIdList = $this->session->get(self::SESSIONNAME, array());

        return true === in_array($orderId, $orderIdList);
    }
685431
protected function reorder($parentId = 0)
    {
        $query = call_user_func("$this->ownerClassName::find")
            ->select("$this->primaryKey")
            ->orderBy("$this->sortField, $this->primaryKey");
        if ( $this->parentIdField ) {
            $query->where([ $this->parentIdField => $parentId ]);
        }
        $data = array_map('intval', $query->column());
        foreach ( $data as $i => $itemPK ) {
            call_user_func("$this->ownerClassName::updateAll",
                [ $this->sortField => ($i + 1) * 100 ],
                [ $this->primaryKey => $itemPK ]);
        }
    }
477452
public function success($first = false)
    {
        $success = false;
        if ($first === true) {
            // Sort them by timestamp, pop the first one and return pass/fail
            usort($this->responses, function(\Yubikey\Response $r1, \Yubikey\Response $r2) {
                return $r1->getMt() > $r2->getMt();
            });
            $response = $this->responses[0];
            return $response->success();
        } else {
            foreach ($this->responses as $response) {
                if ($response->success() === false
                    && $response->status !== Response::REPLAY_REQUEST) {
                    return false;
                } elseif ($response->success()) {
                    $success = true;
                }
            }
        }
        return $success;
    }
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;
    }
109489
public function moveFirst($parentId = false)
    {
        if ( $this->parentIdField && $parentId === false ) {
            $parentId = $this->owner->{$this->parentIdField};
        }
        $minIdx = $this->getMinIdx($parentId);
        if ( ! $minIdx ) {
            $this->reorder($parentId);
            $minIdx = $this->getMinIdx($parentId);
        }
        if ( $this->parentIdField ) {
            call_user_func("$this->ownerClassName::updateAll", [
                $this->sortField => floor($minIdx / 2),
                $this->parentIdField => $parentId,
            ], [ $this->primaryKey => $this->owner->primaryKey ]);
        } else {
            call_user_func("$this->ownerClassName::updateAll",
                [ $this->sortField => floor($minIdx / 2) ],
                [ $this->primaryKey => $this->owner->primaryKey ]);
        }
        $this->invalidateTagDependency();
    }
1064543
function reorder($expr, $direction = null)
    {
        $this->order(null);
        $this->order($expr, $direction);

        return $this;
    }