code: public function sort($entityName, $values)
      {
          $values = json_decode($values);
  
          for ($i=0; $i<count($values); $i++) {
              $this->entityManager
                  ->getRepository($entityName)
                  ->createQueryBuilder('e')
                  ->update()
                  ->set('e.order', $i)
                  ->where('e.id = :id')
                  ->setParameter('id', $values[$i]->id)
                  ->getQuery()
                  ->execute();
          }
      }
docs: Sort entities from the given IDs
  
  @param string $entityName
  @param string $values