vojtasvoboda / oc-userimportexport-plugin

User import export plugin for OctoberCMS
MIT License
12 stars 6 forks source link

How to export Location Country name? #7

Closed wardemi closed 7 years ago

wardemi commented 7 years ago

Hi,

How to export User Location Country name? I extended your "export columns.yaml" but I had empty string.

Thanks

vojtasvoboda commented 7 years ago

Hi, yes you are right, it doesn't work. But after extending columns.yaml you can try this dirty workaround in UserExportModel.php:

public function exportData($columns, $sessionKey = null)
{
    $return = [];
    $users = User::all();
    $users->each(function($user) use ($columns, &$return) {
        $user->addVisible($columns);
        $array = $user->toArray();
        $array['country'] = $user->country->name;
        $array['state'] = $user->state->name;
        $return[] = $array;
    });

    return $return;
}

Please send PR if you solve it by some systematic way.