/**
  * @param string $methodName
  * @param array  $args
  */
 public function load($entities, DcCompat $compat)
 {
     $providerName = $compat->getModel()->getProviderName();
     $enviroment = $compat->getEnvironment();
     /** @var EntityDataProvider $dataProvider */
     $dataProvider = $enviroment->getDataProvider($providerName);
     $entityManager = $dataProvider->getEntityManager();
     $metaFactory = $entityManager->getMetadataFactory();
     $metaData = $metaFactory->getMetadataFor($dataProvider->getEntityRepository()->getClassName());
     $associationNames = $metaData->getAssociationNames();
     $entityAccessor = EntityHelper::getEntityAccessor();
     $ids = array();
     if (is_array($entities) || $entities instanceof \Traversable) {
         foreach ($entities as $entity) {
             if (is_object($entity)) {
                 $ids[] = $entityAccessor->getPrimaryKey($entity);
                 continue;
             }
             if (!empty($associationNames) && in_array($compat->getPropertyName(), $associationNames)) {
                 $ids[] = $entity;
             }
         }
     }
     return $ids;
 }
 /**
  * @param null $limit
  * @param null $offset
  *
  * @return array
  * @SuppressWarnings(PHPMD.CamelCaseVariableName)
  */
 public function getRecipients($limit = null, $offset = null)
 {
     global $container, $TL_LANG;
     $queryBuilder = EntityHelper::getEntityManager()->createQueryBuilder();
     $queryBuilder->select('r')->from('Avisota\\Contao:Recipient', 'r');
     $this->prepareQuery($queryBuilder);
     if ($limit > 0) {
         $queryBuilder->setMaxResults($limit);
     }
     if ($offset > 0) {
         $queryBuilder->setFirstResult($offset);
     }
     $queryBuilder->orderBy('r.email');
     $query = $queryBuilder->getQuery();
     $recipients = $query->getResult();
     $entityAccessor = EntityHelper::getEntityAccessor();
     $mutableRecipients = array();
     /** @var EventDispatcherInterface $eventDispatcher */
     $eventDispatcher = $container['event-dispatcher'];
     /** @var Recipient $recipient */
     foreach ($recipients as $recipient) {
         $properties = $entityAccessor->getPublicProperties($recipient, true);
         if ($this->manageSubscriptionUrlPattern) {
             $loadLanguageEvent = new LoadLanguageFileEvent('fe_avisota_subscription');
             $eventDispatcher->dispatch(ContaoEvents::SYSTEM_LOAD_LANGUAGE_FILE, $loadLanguageEvent);
             $url = $this->manageSubscriptionUrlPattern;
             $url = preg_replace_callback('~##([^#]+)##~', function ($matches) use($properties) {
                 if (isset($properties[$matches[1]])) {
                     return $properties[$matches[1]];
                 }
                 return $matches[0];
             }, $url);
             $properties['manage_subscription_link'] = array('url' => $url, 'text' => &$TL_LANG['fe_avisota_subscription']['manage_subscription']);
         }
         if ($this->unsubscribeUrlPattern) {
             $loadLanguageEvent = new LoadLanguageFileEvent('fe_avisota_subscription');
             $eventDispatcher->dispatch(ContaoEvents::SYSTEM_LOAD_LANGUAGE_FILE, $loadLanguageEvent);
             $url = $this->unsubscribeUrlPattern;
             $url = preg_replace_callback('~##([^#]+)##~', function ($matches) use($properties) {
                 if (isset($properties[$matches[1]])) {
                     return $properties[$matches[1]];
                 }
                 return $matches[0];
             }, $url);
             $properties['unsubscribe_link'] = array('url' => $url, 'text' => &$TL_LANG['fe_avisota_subscription']['unsubscribe_direct']);
         }
         $mutableRecipients[] = new MutableRecipient($recipient->getEmail(), $properties);
     }
     return $mutableRecipients;
 }