public function prePersist(EventArgs $args)
    {
        $em = $args->getEntityManager();
        $object = $args->getObject();
        $class = get_class($object);
        $meta = $em->getClassMetadata($class);

        $reflectionClass = $meta->getReflectionClass();

        if (!$reflectionClass || !$this->hasTrait($reflectionClass, 'Blast\BaseEntitiesBundle\Entity\Traits\Sortable')) {
            return;
        } // return if current entity doesn't use Sortable trait

        if ($object->getSortRank()) {
            return;
        }

        $maxPos = $this->getMaxPosition($em, $meta);
        $maxPos = $maxPos ? $maxPos + 1000 : 65536;

        $object->setSortRank($maxPos);
        $this->maxPositions[$class] = $maxPos;
    }
public function prePersist(EventArgs $args)
    {
        $em = $args->getEntityManager();
        $object = $args->getObject();
        $class = get_class($object);
        $meta = $em->getClassMetadata($class);

        $reflectionClass = $meta->getReflectionClass();

        if (!$reflectionClass || !$this->hasTrait($reflectionClass, 'Blast\BaseEntitiesBundle\Entity\Traits\Sortable')) {
            return;
        } // return if current entity doesn't use Sortable trait

        if ($object->getSortRank()) {
            return;
        }

        $maxPos = $this->getMaxPosition($em, $meta);
        $maxPos = $maxPos ? $maxPos + 1000 : 65536;

        $object->setSortRank($maxPos);
        $this->maxPositions[$class] = $maxPos;
    }
public function prePersist ( EventArgs $ args ) { $ em = $ args -> getEntityManager ( ) ; $ object = $ args -> getObject ( ) ; $ class = get_class ( $ object ) ; $ meta = $ em -> getClassMetadata ( $ class ) ; $ reflectionClass = $ meta -> getReflectionClass ( ) ; if ( ! $ reflectionClass || ! $ this -> hasTrait ( $ reflectionClass , 'Blast\BaseEntitiesBundle\Entity\Traits\Sortable' ) ) { return ; } // return if current entity doesn't use Sortable trait if ( $ object -> getSortRank ( ) ) { return ; } $ maxPos = $ this -> getMaxPosition ( $ em , $ meta ) ; $ maxPos = $ maxPos ? $ maxPos + 1000 : 65536 ; $ object -> setSortRank ( $ maxPos ) ; $ this -> maxPositions [ $ class ] = $ maxPos ; }
Compute sortRank for entities that are created.

@param EventArgs $args
Compute sortRank for entities that are created .