src/Controller/DefaultController.php
public function sort(): void
    {
        $aConfig = $this->getConfig();
        if (!$aConfig['CAN_EDIT']) {
            show404();
        } elseif (!static::userCan('edit')) {
            unauthorised();
        }

        $oModel = $this->getModel();
        $oInput = Factory::service('Input');
        $oDb    = Factory::service('Database');

        if ($oInput->post()) {
            try {

                $oDb->trans_begin();
                $aItems = array_values((array) $oInput->post('order'));
                foreach ($aItems as $iOrder => $iId) {

                    if (classUses($oModel, Localised::class)) {

                        $aItems = $oModel->getAll([
                            'NO_LOCALISE_FILTER' => true,
                            'where'              => [
                                ['id', $iId],
                            ],
                        ]);

                        foreach ($aItems as $oItem) {
                            if (!$oModel->update($iId, ['order' => $iOrder], $oItem->locale)) {
                                throw new NailsException(
                                    static::ORDER_ERROR_MESSAGE . ' ' . $oModel->lastError()
                                );
                            }
                        }

                    } elseif (!$oModel->update($iId, ['order' => $iOrder])) {
                        throw new NailsException(
                            static::ORDER_ERROR_MESSAGE . ' ' . $oModel->lastError()
                        );
                    }
                }

                $oDb->trans_commit();

                $oSession = Factory::service('Session', 'nails/module-auth');
                $oSession->setFlashData('success', static::ORDER_SUCCESS_MESSAGE);

                redirect($aConfig['BASE_URL'] . '/sort');

            } catch (\Exception $e) {
                $oDb->trans_rollback();
                $this->data['error'] = $e->getMessage();
            }
        }

        $aItems                    = $oModel->getAll($aConfig['SORT_DATA']);
        $this->data['items']       = $aItems;
        $this->data['page']->title = $aConfig['TITLE_PLURAL'] . ' &rsaquo; Sort';
        Helper::loadView('order');
    }
public function sort(): void
    {
        $aConfig = $this->getConfig();
        if (!$aConfig['CAN_EDIT']) {
            show404();
        } elseif (!static::userCan('edit')) {
            unauthorised();
        }

        $oModel = $this->getModel();
        $oInput = Factory::service('Input');
        $oDb    = Factory::service('Database');

        if ($oInput->post()) {
            try {

                $oDb->trans_begin();
                $aItems = array_values((array) $oInput->post('order'));
                foreach ($aItems as $iOrder => $iId) {

                    if (classUses($oModel, Localised::class)) {

                        $aItems = $oModel->getAll([
                            'NO_LOCALISE_FILTER' => true,
                            'where'              => [
                                ['id', $iId],
                            ],
                        ]);

                        foreach ($aItems as $oItem) {
                            if (!$oModel->update($iId, ['order' => $iOrder], $oItem->locale)) {
                                throw new NailsException(
                                    static::ORDER_ERROR_MESSAGE . ' ' . $oModel->lastError()
                                );
                            }
                        }

                    } elseif (!$oModel->update($iId, ['order' => $iOrder])) {
                        throw new NailsException(
                            static::ORDER_ERROR_MESSAGE . ' ' . $oModel->lastError()
                        );
                    }
                }

                $oDb->trans_commit();

                $oSession = Factory::service('Session', 'nails/module-auth');
                $oSession->setFlashData('success', static::ORDER_SUCCESS_MESSAGE);

                redirect($aConfig['BASE_URL'] . '/sort');

            } catch (\Exception $e) {
                $oDb->trans_rollback();
                $this->data['error'] = $e->getMessage();
            }
        }

        $aItems                    = $oModel->getAll($aConfig['SORT_DATA']);
        $this->data['items']       = $aItems;
        $this->data['page']->title = $aConfig['TITLE_PLURAL'] . ' &rsaquo; Sort';
        Helper::loadView('order');
    }
Sort items into order

@return void