1
|
|
|
<?php |
2
|
|
|
|
|
|
|
|
3
|
|
|
namespace BristolSU\ControlDB\Export; |
4
|
|
|
|
5
|
|
|
use BristolSU\ControlDB\Contracts\Repositories\Group; |
6
|
|
|
use BristolSU\ControlDB\Contracts\Repositories\Position; |
7
|
|
|
use BristolSU\ControlDB\Contracts\Repositories\Role; |
8
|
|
|
use BristolSU\ControlDB\Contracts\Repositories\User; |
9
|
|
|
use BristolSU\ControlDB\Export\Formatter\Role\SortByGroupName; |
|
|
|
|
10
|
|
|
use BristolSU\ControlDB\Export\Formatter\Shared\SortByColumn; |
11
|
|
|
use Illuminate\Console\Command; |
12
|
|
|
use Symfony\Component\Console\Exception\InvalidArgumentException; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Seed the database |
16
|
|
|
*/ |
|
|
|
|
17
|
|
|
class ExportControlCommand extends Command |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Signature for the command |
21
|
|
|
* |
22
|
|
|
* @var string |
23
|
|
|
*/ |
24
|
|
|
protected $signature = 'control:export |
25
|
|
|
{type : The type of resource to export} |
26
|
|
|
{--exporter= : The name of the exporter to use}'; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Name for the commmand |
30
|
|
|
* |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $name = 'Export Control'; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Description of the command |
37
|
|
|
* |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
protected $description = 'Export control to an external service'; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Handle the command execution |
44
|
|
|
* |
45
|
|
|
* Seed the database with fake data. |
46
|
|
|
*/ |
|
|
|
|
47
|
5 |
|
public function handle() |
48
|
|
|
{ |
49
|
5 |
|
Exporter::driver($this->option('exporter'))->export($this->exportData()); |
|
|
|
|
50
|
5 |
|
$this->info('Export complete'); |
51
|
5 |
|
} |
52
|
|
|
|
53
|
5 |
|
private function exportData() |
|
|
|
|
54
|
|
|
{ |
55
|
5 |
|
switch($this->argument('type')) { |
56
|
5 |
|
case 'user': |
|
|
|
|
57
|
2 |
|
return app(User::class)->all(); |
58
|
|
|
break; |
|
|
|
|
59
|
3 |
|
case 'group': |
|
|
|
|
60
|
1 |
|
return app(Group::class)->all(); |
61
|
|
|
break; |
62
|
2 |
|
case 'role': |
|
|
|
|
63
|
1 |
|
return app(Role::class)->all(); |
64
|
|
|
break; |
65
|
1 |
|
case 'position': |
|
|
|
|
66
|
1 |
|
return app(Position::class)->all(); |
67
|
|
|
break; |
68
|
|
|
default: |
|
|
|
|
69
|
|
|
throw new InvalidArgumentException(sprintf('The type option %s is not allowed.', $this->argument('type'))); |
|
|
|
|
70
|
|
|
break; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
} |