add export users module

This commit is contained in:
vedatakd 2020-09-08 19:34:22 +03:00
parent 5c5d11b1f2
commit fd5dae0320
5 changed files with 100 additions and 5 deletions

View File

@ -5,5 +5,8 @@
"psr-4": {
"Visiosoft\\ProfileModule\\": "src/"
}
},
"require": {
"maatwebsite/excel": "*"
}
}

View File

@ -14,4 +14,5 @@ return [
'go_user' => 'Go to User Detail',
'personal' => 'Personal',
'corporate' => 'Corporate',
'export' => 'Export CSV',
];

View File

@ -0,0 +1,13 @@
<?php namespace Visiosoft\ProfileModule\Http\Controller\Admin;
use Anomaly\Streams\Platform\Http\Controller\AdminController;
use Maatwebsite\Excel\Facades\Excel;
use Visiosoft\ProfileModule\Profile\UsersExport;
class UsersController extends AdminController
{
public function exportUsers()
{
return Excel::download(new UsersExport(), 'users-' . time() . '.csv');
}
}

View File

@ -0,0 +1,65 @@
<?php namespace Visiosoft\ProfileModule\Profile;
use Anomaly\UsersModule\User\User;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
class UsersExport implements WithMapping, FromCollection, WithHeadings
{
/**
* @return User[]|\Illuminate\Database\Eloquent\Collection|\Illuminate\Support\Collection
*/
public function collection()
{
return User::all();
}
public function map($user): array
{
return [
$user->email,
$user->username,
$user->first_name,
$user->last_name,
$user->display_name,
$user->ip_address,
$user->country_id,
$user->city,
$user->district,
$user->neighborhood,
$user->village,
$user->gsm_phone,
$user->land_phone,
$user->office_phone,
$user->phone_number,
$user->register_type,
$user->identification_number,
$user->created_at,
];
}
public function headings(): array
{
return [
'email address',
'username',
'first_name',
'last_name',
'display_name',
'ip_address',
'country_id',
'city',
'district',
'neighborhood',
'village',
'gsm_phone',
'land_phone',
'office_phone',
'phone_number',
'register_type',
'identification_number',
'created_at',
];
}
}

View File

@ -1,6 +1,9 @@
<?php namespace Visiosoft\ProfileModule;
use Anomaly\Streams\Platform\Addon\AddonCollection;
use Anomaly\Streams\Platform\Addon\AddonServiceProvider;
use Maatwebsite\Excel\ExcelServiceProvider;
use Maatwebsite\Excel\Facades\Excel;
use Visiosoft\ProfileModule\Adress\Contract\AdressRepositoryInterface;
use Visiosoft\ProfileModule\Adress\AdressRepository;
use Anomaly\Streams\Platform\Model\Profile\ProfileAdressEntryModel;
@ -133,6 +136,10 @@ class ProfileModuleServiceProvider extends AddonServiceProvider
'as' => 'visiosoft.module.profile::address_soft_delete',
'uses' => 'Visiosoft\ProfileModule\Http\Controller\AddressController@delete'
],
'admin/users/export' => [
'as' => 'users::exportUsers',
'uses' => 'Visiosoft\ProfileModule\Http\Controller\Admin\UsersController@exportUsers'
],
// Cache links
@ -183,7 +190,7 @@ class ProfileModuleServiceProvider extends AddonServiceProvider
* @type array|null
*/
protected $aliases = [
//'Example' => Visiosoft\ProfileModule\Example::class
'Excel' => Excel::class,
];
/**
@ -218,7 +225,9 @@ class ProfileModuleServiceProvider extends AddonServiceProvider
*
* @type array|null
*/
protected $providers = [];
protected $providers = [
ExcelServiceProvider::class,
];
/**
* The addon view overrides.
@ -252,10 +261,14 @@ class ProfileModuleServiceProvider extends AddonServiceProvider
/**
* Boot the addon.
*/
public function boot()
public function boot(AddonCollection $addonCollection)
{
// Run extra post-boot registration logic here.
// Use method injection or commands to bring in services.
$slug = 'export';
$section = [
'title' => 'visiosoft.module.profile::button.export',
'href' => route('users::exportUsers'),
];
$addonCollection->get('anomaly.module.users')->addSection($slug, $section);
}
/**