Bundle/BusinessPageBundle/Helper/BusinessPageHelper.php
public function guessBestPatternIdForEntity($refClass, $entityId, $em, $originalRefClassName = null)
    {
        $templateId = null;
        $refClassName = $em->getClassMetadata($refClass->name)->name;

        $viewReference = null;
        if (!$originalRefClassName) {
            $originalRefClassName = $refClassName;
        }

        $businessEntity = $this->businessEntityHelper->findByEntityClassname($refClassName);

        if ($businessEntity) {
            $parameters = [
                'entityId'        => $entityId,
                'entityNamespace' => $originalRefClassName,
            ];
            $viewReference = $this->viewReferenceRepository->getOneReferenceByParameters($parameters);
        }

        if (!$viewReference) {
            $parentRefClass = $refClass->getParentClass();
            if ($parentRefClass) {
                $templateId = $this->guessBestPatternIdForEntity($parentRefClass, $entityId, $em, $originalRefClassName);
            } else {
                throw new \Exception(sprintf('Cannot find a BusinessTemplate that can display the requested BusinessEntity ("%s", "%s".)', $refClassName, $entityId));
            }
        } elseif ($viewReference instanceof BusinessPageReference) {
            $templateId = $viewReference->getTemplateId();
        }

        return $templateId;
    }
public function guessBestPatternIdForEntity($refClass, $entityId, $em, $originalRefClassName = null)
    {
        $templateId = null;
        $refClassName = $em->getClassMetadata($refClass->name)->name;

        $viewReference = null;
        if (!$originalRefClassName) {
            $originalRefClassName = $refClassName;
        }

        $businessEntity = $this->businessEntityHelper->findByEntityClassname($refClassName);

        if ($businessEntity) {
            $parameters = [
                'entityId'        => $entityId,
                'entityNamespace' => $originalRefClassName,
            ];
            $viewReference = $this->viewReferenceRepository->getOneReferenceByParameters($parameters);
        }

        if (!$viewReference) {
            $parentRefClass = $refClass->getParentClass();
            if ($parentRefClass) {
                $templateId = $this->guessBestPatternIdForEntity($parentRefClass, $entityId, $em, $originalRefClassName);
            } else {
                throw new \Exception(sprintf('Cannot find a BusinessTemplate that can display the requested BusinessEntity ("%s", "%s".)', $refClassName, $entityId));
            }
        } elseif ($viewReference instanceof BusinessPageReference) {
            $templateId = $viewReference->getTemplateId();
        }

        return $templateId;
    }
public function guessBestPatternIdForEntity ( $ refClass , $ entityId , $ em , $ originalRefClassName = null ) { $ templateId = null ; $ refClassName = $ em -> getClassMetadata ( $ refClass -> name ) -> name ; $ viewReference = null ; if ( ! $ originalRefClassName ) { $ originalRefClassName = $ refClassName ; } $ businessEntity = $ this -> businessEntityHelper -> findByEntityClassname ( $ refClassName ) ; if ( $ businessEntity ) { $ parameters = [ 'entityId' => $ entityId , 'entityNamespace' => $ originalRefClassName , ] ; $ viewReference = $ this -> viewReferenceRepository -> getOneReferenceByParameters ( $ parameters ) ; } if ( ! $ viewReference ) { $ parentRefClass = $ refClass -> getParentClass ( ) ; if ( $ parentRefClass ) { $ templateId = $ this -> guessBestPatternIdForEntity ( $ parentRefClass , $ entityId , $ em , $ originalRefClassName ) ; } else { throw new \ Exception ( sprintf ( 'Cannot find a BusinessTemplate that can display the requested BusinessEntity ("%s", "%s".)' , $ refClassName , $ entityId ) ) ; } } elseif ( $ viewReference instanceof BusinessPageReference ) { $ templateId = $ viewReference -> getTemplateId ( ) ; } return $ templateId ; }
Guess the best pattern to represent given reflectionClass.

@param \ReflectionClass $refClass
@param int              $entityId
@param EntityManager    $em
@param string           $originalRefClassName When digging into parentClass, we do not have to forget originalClass to be able to get reference after all

@throws \Exception

@return View
Guess the best pattern to represent given reflectionClass .