Ergebnis 1 bis 6 von 6

Thema: Funktionsweise von "Details zusammenführen aus"

  1. #1
    Contao-Nutzer
    Registriert seit
    29.01.2013.
    Beiträge
    157

    Standard Funktionsweise von "Details zusammenführen aus"

    Heyho,

    eine weitere Frage zum neuen Avisota2. Ich habe in meiner Newsletter-Empfängerquelle bei der Eigenschaft "Details zusammenführen aus" die Option "Nut Mitgliederdetails" gewählt. Ich dachte, dann werden die Anreden korrekt gesetzt immer dann, wenn zu einer Mail-Adresse im Verteiler ein entsprechendes Mitglied gefunden wird. Mein Mitglied hat das Geschlecht, Vor- und Nachnamen gesetzt. Das muss für meine Anrede reichen. Eine entsprechende Regel habe ich gesetzt.

    Aber in der versendeten Mail steht leider immer noch der letzte Fallback der Anrede-Entität, d.h. "Sehr geehrte Damen und Herren". Mache ich irgendetwas falsch?

    Ciao The_Unknown

  2. #2
    Contao-Nutzer
    Registriert seit
    29.01.2013.
    Beiträge
    157

    Standard

    Weiß hier denn niemand Rat? Das wäre recht dringend

  3. #3
    Contao-Nutzer
    Registriert seit
    29.01.2013.
    Beiträge
    157

    Standard

    OK, ich habe es jetzt eben selbst gebaut, da ich die Vermutung habe, die Funktion ist einfach noch nicht implementiert. Wer es braucht:

    PHP-Code:
    <?php

    namespace Custom123\XAvisotaRecipientSourceSalutations;

    use 
    Avisota\Contao\Entity\MailingList;
    use 
    Avisota\Contao\Entity\Recipient;
    use 
    Avisota\Contao\SubscriptionRecipient\RecipientSource\RecipientsRecipientSourceFactory;
    use 
    Avisota\Recipient\MutableRecipient;
    use 
    Avisota\RecipientSource\RecipientSourceInterface;
    use 
    Contao\Doctrine\ORM\EntityHelper;
    use 
    ContaoCommunityAlliance\Contao\Bindings\ContaoEvents;
    use 
    ContaoCommunityAlliance\Contao\Bindings\Events\System\LoadLanguageFileEvent;
    use 
    Doctrine\ORM\Query;
    use 
    Doctrine\ORM\QueryBuilder;
    use 
    Symfony\Component\EventDispatcher\EventDispatcherInterface;

    /**
     * Class AvisotaRecipientSourceIntegratedRecipients
     *
     *
     * @copyright  bit3 UG 2013
     * @author     Tristan Lins <tristan.lins@bit3.de>
     * @package    avisota/contao-subscription-recipient
     */
    class RecipientsRecipientSourceSalutations extends \Avisota\Contao\SubscriptionRecipient\RecipientSource\RecipientsRecipientSource
    {
        public function 
    getRecipients($limit null$offset null)
        {
            
    $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 $GLOBALS['container']['event-dispatcher'];

            
    /** @var Recipient $recipient */
            
    foreach ($recipients as $recipient) {
                
    $properties $entityAccessor->getPublicProperties($recipienttrue);
                
    $properties = static::addMemberProperties($properties);

                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' => &$GLOBALS['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' => &$GLOBALS['TL_LANG']['fe_avisota_subscription']['unsubscribe_direct']
                    );
                }

                
    $mutableRecipients[] = new MutableRecipient(
                    
    $recipient->getEmail(),
                    
    $properties
                
    );
            }

            return 
    $mutableRecipients;
        }

        protected function 
    prepareQuery(QueryBuilder $queryBuilder)
        {
            
    $expr $queryBuilder->expr();

            if (
    count($this->filteredMailingLists)) {
                
    $queryBuilder->innerJoin('r.subscriptions''s');

                
    $or $expr->orX();
                foreach (
    $this->filteredMailingLists as $index => $mailingList) {
                    
    $or->add($expr->eq('s.mailingList'':mailingList' $index));
                    
    $queryBuilder->setParameter('mailingList' $index$mailingList->getId());
                }

                
    $queryBuilder->andWhere($or);
            }

            if (
    count($this->filteredProperties)) {
                foreach (
    $this->filteredProperties as $index => $filteredProperty) {
                    
    $property   'r.' $filteredProperty['recipientsPropertyFilter_property'];
                    
    $comparator $filteredProperty['recipientsPropertyFilter_comparator'];
                    
    $value      $filteredProperty['recipientsPropertyFilter_value'];

                    switch (
    $comparator) {
                        case 
    'empty':
                            
    $queryBuilder->andWhere(
                                
    $expr->orX(
                                    
    $expr->eq($property':property' $index),
                                    
    $expr->isNull($property)
                                )
                            );
                            
    $value '';
                            break;

                        case 
    'not empty':
                            
    $queryBuilder->andWhere(
                                
    $expr->gt($property':property' $index)
                            );
                            
    $value '';
                            break;

                        case 
    'eq':
                            
    $queryBuilder->andWhere(
                                
    $expr->eq($property':property' $index)
                            );
                            break;

                        case 
    'neq':
                            
    $queryBuilder->andWhere(
                                
    $expr->neq($property':property' $index)
                            );
                            break;

                        case 
    'gt':
                            
    $queryBuilder->andWhere(
                                
    $expr->gt($property':property' $index)
                            );
                            break;

                        case 
    'gte':
                            
    $queryBuilder->andWhere(
                                
    $expr->gte($property':property' $index)
                            );
                            break;

                        case 
    'lt':
                            
    $queryBuilder->andWhere(
                                
    $expr->lt($property':property' $index)
                            );
                            break;

                        case 
    'lte':
                            
    $queryBuilder->andWhere(
                                
    $expr->lte($property':property' $index)
                            );
                            break;
                    }

                    
    $queryBuilder->setParameter(
                        
    ':property' $index,
                        
    $value
                    
    );
                }
            }
        }

        public static function 
    addMemberProperties($arrProperties)
        {
            
    $arrResult = array();

            foreach (
    $arrProperties as $strName => $strValue)
            {
                
    // ignore salutations inserted in the backend
                
    if ($strName == 'salutation')
                    continue;

                if (!
    $strValue)
                {
                    
    // first store the existing name-value pair
                    
    $arrResult[$strName] = $strValue;

                    
    // enhance member data if existing
                    
    if (($objMember = \MemberModel::findActiveByEmailAndUsername($arrProperties['email'])) !== null)
                    {
                        if (
    $objMember->$strName)
                            
    $arrResult[$strName] = $objMember->$strName;
                        else
                        {
                            
    // try synonyms
                            
    $synonymizer $GLOBALS['container']['avisota.recipient.synonymizer'];
                            
    $arrSynonyms    $synonymizer->findSynonyms($strName);

                            if (
    $arrSynonyms) {
                                foreach (
    $arrSynonyms as $strSynonym) {
                                    if (
    $objMember->$strSynonym)
                                    {
                                        
    $arrResult[$strName] = $objMember->$strSynonym;
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    
    $arrResult[$strName] = $strValue;
                }
            }

            return 
    $arrResult;
        }

    }
    Es wurde zur Elternklasse lediglich die Funktion addMemberProperties hinzugefügt und in Zeile 54 aufgerufen:

    PHP-Code:
    $properties = static::addMemberProperties($properties); 
    Die obige Klasse wird dann in einer eigenen RecipientsRecipientSourceFactory aufgerufen, welche dann wiederum in der config-Datei eingebunden wird:

    PHP-Code:
    $GLOBALS['AVISOTA_RECIPIENT_SOURCE']['recipients'] = 'Custom123\XAvisotaRecipientSourceSalutations\RecipientsRecipientSourceSalutationsFactory'

  4. #4
    Contao-Urgestein Avatar von tril
    Registriert seit
    07.01.2010.
    Ort
    Bad Marienberg
    Beiträge
    2.939
    User beschenken
    Wunschliste

    Standard

    Klingt gut, werde ich mir anschauen wenn ich zu dem Ticket komme und ggf. was von deinem Code übernehmen

  5. #5
    Contao-Nutzer
    Registriert seit
    29.01.2013.
    Beiträge
    157

    Standard

    Freut mich, wenn ich dir auch mal helfen konnte

  6. #6
    Contao-Nutzer
    Registriert seit
    29.01.2013.
    Beiträge
    157

    Standard

    Hier noch die entsprechend abgewandelte Variante für CSV-Files:

    PHP-Code:
    <?php

    namespace Custom\XAvisotaRecipientSourceAdvanced;

    use 
    Avisota\Recipient\MutableRecipient;
    use 
    Avisota\RecipientSource\RecipientSourceInterface;
    use 
    Contao\Doctrine\ORM\EntityHelper;

    /**
     * A recipient source that read the recipients from a csv file.
     *
     * @package avisota-core
     */
    class CSVFileRecipientSourceSalutations implements RecipientSourceInterface
    {

        private 
    $file;

        private 
    $columnAssignment;

        private 
    $delimiter;

        private 
    $enclosure;

        private 
    $escape;

        
    /**
         * @var \Swift_Mime_Grammar
         */
        
    private $grammar;

        
    /**
         * @param string $fileData
         */
        
    public function __construct($file, array $columnAssignment$delimiter ','$enclosure '"'$escape '\\')
        {
            
    $this->file             = (string) $file;
            
    $this->columnAssignment $columnAssignment;
            
    $this->delimiter        $delimiter;
            
    $this->enclosure        $enclosure;
            
    $this->escape           $escape;
        }

        
    /**
         * @return \Swift_Mime_Grammar
         */
        
    public function getGrammar()
        {
            if (!
    $this->grammar) {
                
    $this->grammar = new \Swift_Mime_Grammar();
            }
            return 
    $this->grammar;
        }

        
    /**
         * @param \Swift_Mime_Grammar $grammar
         *
         * @return CSVFile
         */
        
    public function setGrammar(\Swift_Mime_Grammar $grammar)
        {
            
    $this->grammar $grammar;
            return 
    $this;
        }

        
    /**
         * Count the recipients.
         *
         * @return int
         */
        
    public function countRecipients()
        {
            
    $in fopen($this->file'r');

            if (!
    $in) {
                return 
    0;
            }

            
    $recipients 0;
            
    $regexp     '/^' $this->getGrammar()->getDefinition('addr-spec') . '$/D';
            
    $index      array_search('email'$this->columnAssignment);
            
    $emails     = array();

            while (
    $row fgetcsv($in0$this->delimiter$this->enclosure$this->escape)) {
                
    $email trim($row[$index]);

                if (!empty(
    $email) && preg_match($regexp$email) && !in_array($email$emails)) {
                    
    $recipients++;
                    
    $emails[] = $email;
                }
            }

            
    fclose($in);

            return 
    $recipients;
        }

        
    /**
         * {@inheritdoc}
         */
        
    public function getRecipients($limit null$offset null)
        {
            
    $in fopen($this->file'r');

            if (!
    $in) {
                return 
    null;
            }

            
    $recipients = array();
            
    $regexp     '/^' $this->getGrammar()->getDefinition('addr-spec') . '$/D';
            
    $index      array_search('email'$this->columnAssignment);
            
    $emails     = array();

            
    // skip offset lines
            
    for (; $offset && !feof($in); $offset--) {
                
    $row   fgetcsv($in0$this->delimiter$this->enclosure$this->escape);
                
    $email trim($row[$index]);

                
    // skip invalid lines without counting them
                
    if (empty($email) || !preg_match($regexp$email) || in_array($email$emails)) {
                    
    $offset++;
                }
                else {
                    
    $emails[] = $email;
                }
            }

            
    // read lines
            
    while (
                (!
    $limit || count($recipients) < $limit) &&
                
    $row fgetcsv($in0$this->delimiter$this->enclosure$this->escape)
            ) {
                
    $details = array();

                foreach (
    $this->columnAssignment as $index => $field) {
                    if (isset(
    $row[$index])) {
                        
    $details[$field] = trim($row[$index]);
                    }
                }

                if (
                    !empty(
    $details['email']) &&
                    
    preg_match($regexp$details['email']) &&
                    !
    in_array($details['email'], $emails)
                ) {
                    
    $details = static::addMemberProperties($details);
                    
    $recipients[] = new MutableRecipient($details['email'], $details);
                    
    $emails[]     = $details['email'];
                }
            }

            
    fclose($in);

            return 
    $recipients;
        }

        public static function 
    addMemberProperties($arrDetails)
        {
            
    $arrRecipientFields = array();

            
    $objController = \System::importStatic('Controller');

            
    $objController->loadDataContainer('orm_avisota_recipient');

            foreach (
    $GLOBALS['TL_DCA']['orm_avisota_recipient']['metapalettes']['default'] as $strPalette => $arrFields)
            {
                
    $arrRecipientFields array_merge($arrRecipientFields$arrFields);
            }

            foreach (
    $arrRecipientFields as $strName)
            {
                
    // ignore salutations inserted in the backend
                
    if ($strName == 'salutation')
                    continue;

                if (
    $strName != 'email')
                    
    $arrDetails[$strName] = '';

                
    // enhance member data if existing
                
    if (($objMember = \MemberModel::findByEmail($arrDetails['email'])) !== null)
                {
                    if (
    $objMember->$strName)
                        
    $arrDetails[$strName] = $objMember->$strName;
                    else
                    {
                        
    // try synonyms
                        
    $synonymizer $GLOBALS['container']['avisota.recipient.synonymizer'];
                        
    $arrSynonyms    $synonymizer->findSynonyms($strName);

                        if (
    $arrSynonyms) {
                            foreach (
    $arrSynonyms as $strSynonym) {
                                if (
    $objMember->$strSynonym)
                                {
                                    
    $arrDetails[$strName] = $objMember->$strSynonym;
                                }
                            }
                        }
                    }
                }
            }

            return 
    $arrDetails;
        }
    }

Aktive Benutzer

Aktive Benutzer

Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)

Lesezeichen

Lesezeichen

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •