예제 #1
0
 private function getMaxPosition(SortableAdapter $ea, $meta, $config, $object, array $groups = array())
 {
     $em = $ea->getObjectManager();
     $uow = $em->getUnitOfWork();
     $maxPos = null;
     // Get groups
     if (!sizeof($groups)) {
         $groups = $this->getGroups($meta, $config, $object);
     }
     // Get hash
     $hash = $this->getHash($groups, $config);
     // Check for cached max position
     if (isset($this->maxPositions[$hash])) {
         return $this->maxPositions[$hash];
     }
     // Check for groups that are associations. If the value is an object and is
     // scheduled for insert, it has no identifier yet and is obviously new
     // see issue #226
     foreach ($groups as $val) {
         if (is_object($val) && ($uow->isScheduledForInsert($val) || !$em->getMetadataFactory()->isTransient(ClassUtils::getClass($val)) && $uow::STATE_MANAGED !== $ea->getObjectState($uow, $val))) {
             return -1;
         }
     }
     $maxPos = $ea->getMaxPosition($config, $meta, $groups);
     if (is_null($maxPos)) {
         $maxPos = -1;
     }
     return intval($maxPos);
 }