-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatasetModel.php
More file actions
91 lines (78 loc) · 1.87 KB
/
DatasetModel.php
File metadata and controls
91 lines (78 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
namespace App\Model;
use App\Entity\Dataset;
use App\Model\Interface\Configurable;
use App\Model\Interface\Exportable;
use App\Model\Interface\Persistable;
use App\Model\Trait\Config;
use App\Model\Trait\Data;
use App\Model\Trait\Entity;
use App\Model\Trait\Ref;
use App\Model\Trait\Relations;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* @method int getId()
* @method setId( int $id )
* @method string getName()
* @method setName( string $name )
* @method string getDescription()
* @method setDescription( string $description )
* @method string getType()
* @method setType( string $endpoint )
*/
class DatasetModel implements Exportable, Configurable, Persistable
{
use Entity;
use Ref;
use Config;
use Data;
use Relations;
public function __construct( Dataset $dataset )
{
$this->entity = $dataset;
$this->config = $dataset->getConfig();
}
public function handleRequest( Request $request ): Response
{
return new Response();
}
public static function getFields(): array
{
return [
'columns' => [
'label' => 'Columns',
'type' => 'columns',
'columns' => [
'key' => 'Key',
'name' => 'Name',
],
],
];
}
public function getDataAsMap( $leftKey = '', $rightKey = '' ): array
{
$data = $this->getData();
// Find column names.
if ( ! $leftKey || ! $rightKey ) {
$columns = $this->getConfig( 'columns' );
if ( ! $leftKey && ! empty( $columns[0]['key'] ) ) {
$leftKey = $columns[0]['key'];
}
if ( ! $leftKey && ! empty( $columns[1]['key'] ) ) {
$rightKey = $columns[1]['key'];
}
}
$return = [];
foreach ( $data as $key => $value ) {
$left = $value[ $leftKey ] ?? '';
$right = $value[ $rightKey ] ?? '';
$return[ $left ] = $right;
}
return $return;
}
public static function getEntityClass(): string
{
return Dataset::class;
}
}