public function sort(): ServiceResponse
    {
        $this->request->allowMethod('post');
        if (!empty($this->sortModelName) && !empty($this->request->getData('foreignKey'))) {
            $table = TableRegistry::getTableLocator()->get($this->sortModelName);
            $entity = $table->get($this->request->getData('foreignKey'));
            $entity->sort = $this->request->getData('sort');
            if ($table->save($entity)) {
                return new ServiceResponse(ApiReturnCode::SUCCESS, [
                    $entity->id,
                    $this->request->getData('sort'),
                ]);
            }

            return new ServiceResponse(ApiReturnCode::INTERNAL_ERROR, []);
        }
        throw new NotFoundException();
    }
public function sort(): ServiceResponse
    {
        $this->request->allowMethod('post');
        if (!empty($this->sortModelName) && !empty($this->request->getData('foreignKey'))) {
            $table = TableRegistry::getTableLocator()->get($this->sortModelName);
            $entity = $table->get($this->request->getData('foreignKey'));
            $entity->sort = $this->request->getData('sort');
            if ($table->save($entity)) {
                return new ServiceResponse(ApiReturnCode::SUCCESS, [
                    $entity->id,
                    $this->request->getData('sort'),
                ]);
            }

            return new ServiceResponse(ApiReturnCode::INTERNAL_ERROR, []);
        }
        throw new NotFoundException();
    }
public function sort ( ) : ServiceResponse { $ this -> request -> allowMethod ( 'post' ) ; if ( ! empty ( $ this -> sortModelName ) && ! empty ( $ this -> request -> getData ( 'foreignKey' ) ) ) { $ table = TableRegistry :: getTableLocator ( ) -> get ( $ this -> sortModelName ) ; $ entity = $ table -> get ( $ this -> request -> getData ( 'foreignKey' ) ) ; $ entity -> sort = $ this -> request -> getData ( 'sort' ) ; if ( $ table -> save ( $ entity ) ) { return new ServiceResponse ( ApiReturnCode :: SUCCESS , [ $ entity -> id , $ this -> request -> getData ( 'sort' ) , ] ) ; } return new ServiceResponse ( ApiReturnCode :: INTERNAL_ERROR , [ ] ) ; } throw new NotFoundException ( ) ; }
endpoint for sorting ajax calls

@return \FrontendBridge\Lib\ServiceResponse
@throws \Cake\Network\Exception\NotFoundException if either not a post request
or missing/wrong params
endpoint for sorting ajax calls