forked from ushahidi/platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCSVRepository.php
More file actions
88 lines (72 loc) · 1.93 KB
/
Copy pathCSVRepository.php
File metadata and controls
88 lines (72 loc) · 1.93 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
<?php
/**
* Ushahidi CSV Repository
*
* @author Ushahidi Team <team@ushahidi.com>
* @package Ushahidi\Application
* @copyright 2014 Ushahidi
* @license https://www.gnu.org/licenses/agpl-3.0.html GNU Affero General Public License Version 3 (AGPL3)
*/
namespace Ushahidi\App\Repository;
use Ushahidi\Core\Data;
use Ushahidi\Core\SearchData;
use Ushahidi\Core\Entity;
use Ushahidi\Core\Entity\CSV;
use Ushahidi\Core\Entity\CSVRepository as CSVRepositoryContract;
use League\Event\ListenerInterface;
use Ushahidi\Core\Traits\Event;
class CSVRepository extends OhanzeeRepository implements
CSVRepositoryContract
{
// Use the JSON transcoder to encode properties
use JsonTranscodeRepository;
// Use Event trait to trigger events
use Event;
// JsonTranscodeRepository
protected function getJsonProperties()
{
return ['columns', 'maps_to', 'fixed'];
}
// OhanzeeRepository
protected function getTable()
{
return 'csv';
}
// CreateRepository
public function create(Entity $entity)
{
$state = [
'created' => time(),
];
return parent::create($entity->setState($state));
}
// UpdateRepository
public function update(Entity $entity)
{
$state = [
'updated' => time(),
];
return parent::update($entity->setState($state));
}
// OhanzeeRepository
public function getEntity(array $data = null)
{
return new CSV($data);
}
// SearchRepository
public function getSearchFields()
{
return ['columns', 'maps_to', 'fixed', 'filename'];
}
public function setSearchConditions(SearchData $search)
{
$query = $this->search_query;
foreach ([
'filename',
] as $key) {
if ($search->$key) {
$query->where($key, '=', $search->$key);
}
}
}
}