Skip to content

Commit

Permalink
Skip empty rows (#33)
Browse files Browse the repository at this point in the history
* Skip empty rows

* WIP
  • Loading branch information
mako321 authored Feb 5, 2024
1 parent 3010828 commit 2c52b8b
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 15 deletions.
3 changes: 0 additions & 3 deletions src/EscolaLmsCsvUsersServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use EscolaLms\CsvUsers\Services\CsvUserGroupService;
use EscolaLms\CsvUsers\Services\CsvUserService;
use Illuminate\Support\ServiceProvider;
use Maatwebsite\Excel\Imports\HeadingRowFormatter;

/**
* SWAGGER_VERSION
Expand All @@ -23,8 +22,6 @@ public function boot()
{
$this->loadRoutesFrom(__DIR__.'/routes.php');
$this->loadTranslationsFrom(__DIR__ . '/../resources/lang', 'csv-users');

HeadingRowFormatter::default('none');
}

public function register()
Expand Down
2 changes: 2 additions & 0 deletions src/Import/AbstractUserImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Validator;
use Maatwebsite\Excel\Imports\HeadingRowFormatter;

abstract class AbstractUserImport
{
protected string $returnUrl;

public function __construct(string $returnUrl)
{
HeadingRowFormatter::default('none');
$this->returnUrl = $returnUrl;
}

Expand Down
5 changes: 2 additions & 3 deletions src/Import/UsersImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@

use EscolaLms\CsvUsers\Services\Contracts\CsvUserServiceContract;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Validator;
use Maatwebsite\Excel\Concerns\SkipsEmptyRows;
use Maatwebsite\Excel\Concerns\ToCollection;
use Maatwebsite\Excel\Concerns\WithHeadingRow;

class UsersImport extends AbstractUserImport implements ToCollection, WithHeadingRow
class UsersImport extends AbstractUserImport implements ToCollection, WithHeadingRow, SkipsEmptyRows
{
public function __construct(string $returnUrl)
{
Expand Down
4 changes: 0 additions & 4 deletions src/Services/CsvUserGroupService.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@

namespace EscolaLms\CsvUsers\Services;

use EscolaLms\Auth\Dtos\UserFilterCriteriaDto;
use EscolaLms\Auth\EscolaLmsAuthServiceProvider;
use EscolaLms\Auth\Repositories\Contracts\UserGroupRepositoryContract;
use EscolaLms\Auth\Repositories\Contracts\UserRepositoryContract;
use EscolaLms\CsvUsers\Services\Contracts\CsvUserGroupServiceContract;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Config;

class CsvUserGroupService implements CsvUserGroupServiceContract
{
Expand Down
9 changes: 4 additions & 5 deletions src/Services/CsvUserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@ public function getDataToExport(UserFilterCriteriaDto $userFilterCriteriaDto): C

public function saveUserFromImport(Collection $data, string $returnUrl): Model
{
if ($data->get('password')) {
$data->put('password', Hash::make($data->get('password')));
}

if ($user = $this->userRepository->findByEmail($data->get('email'))) {
$user = $this->userRepository->update($data->toArray(), $user->getKey());
} else {
$data->put('is_active', true);

if ($data->get('password')) {
$data->put('password', Hash::make($data->get('password')));
}

$user = $this->userRepository->create($data->toArray());
$user->markEmailAsVerified();
event(new EscolaLmsImportedNewUserTemplateEvent($user, $returnUrl));
Expand Down

0 comments on commit 2c52b8b

Please sign in to comment.