responsiv / campaign-plugin

[PREMIUM] Send professional campaign messages to your subscribers.
http://octobercms.com/plugin/responsiv-campaign
5 stars 2 forks source link

reverseExtendBackendUser #30

Closed jvanremoortere closed 7 years ago

jvanremoortere commented 7 years ago

Is it possible to reverse extend the Backend User like you extend the RainLab.User in the plugin?

jvanremoortere commented 7 years ago

Can't seem to get it to work...

public function boot()
{
// Register recipient groups for newsletter
if (class_exists('\Backend\Models\User')) {
    $this->reverseExtendBackendUser();
}

}

protected function reverseExtendBackendUser()
    {
        Event::listen('responsiv.campaign.listRecipientGroups', function() {
            return [
                'backend-users-all' => 'All backend users',
            ];
        });

        Event::listen('responsiv.campaign.getRecipientsData', function($type) {
            if ($type == 'backend-users-all') {
                $result = [];
                $allBackendUsers = \Backend\Models\User::all();
                foreach ($allBackendUsers as $user) {
                    $result[$user->email] = ['first_name' => $user->first_name, 'last_name' => $user->last_name];
                }
                return $result;
            }
        });
    }
daftspunk commented 7 years ago

Looks fine, where are you registering this code?

jvanremoortere commented 7 years ago

In my Plugin.php of my plugin...

daftspunk commented 7 years ago

Works great over here!

image

jvanremoortere commented 7 years ago

Yes ok. That part works for me too... But for some reason I always get the "Oops! It looks like your campaign hasn't got any subscribers... You can restore this campaign and try launching it again." error when trying to send a campaign to that group.

jvanremoortere commented 7 years ago

Ok. Added this to another project and seems to work just fine there. I will have to check everything else getting called in my boot...