/**
  * Finds first available image for listing purposes
  *
  * @param Content $content
  *
  * @return string
  */
 public function getCoverImage(Content $content)
 {
     if ($content->getValueSet() === null) {
         return false;
     }
     foreach ($content->getValueSet()->getValues() as $value) {
         switch (get_class($value)) {
             case 'Opifer\\EavBundle\\Entity\\NestedValue':
                 foreach ($value->getNested() as $nested) {
                     if (false !== ($cv = $this->getCoverImage($nested))) {
                         return $cv;
                     }
                 }
                 break;
             case 'Opifer\\EavBundle\\Entity\\MediaValue':
                 foreach ($value->getMedias() as $media) {
                     return $media->getReference();
                     break;
                 }
                 break;
         }
     }
     return false;
 }
Esempio n. 2
0
 /**
  * Find related content.
  *
  * @param Content $content
  * @param int     $limit
  *
  * @return ArrayCollection
  */
 public function findRelated(Content $content, $limit = 10)
 {
     $city = $content->getValueSet()->getValueFor('address')->getAddress()->getCity();
     $query = $this->createQueryBuilder('c')->innerJoin('c.valueSet', 'vs')->innerJoin('vs.values', 'v')->innerJoin('v.attribute', 'a')->innerJoin('v.address', 'addr')->where('addr.city = :city')->andWhere('c.active = 1')->andWhere('c.nestedIn IS NULL')->andWhere('c.id <> :id')->setParameter('id', $content->getId())->setParameter('city', $city)->setMaxResults($limit)->getQuery();
     return $query->getResult();
 }