forked from ushahidi/platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLayerRepository.php
More file actions
78 lines (63 loc) · 1.75 KB
/
Copy pathLayerRepository.php
File metadata and controls
78 lines (63 loc) · 1.75 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
<?php
/**
* Ushahidi Layer 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\Entity;
use Ushahidi\Core\Entity\Layer;
use Ushahidi\Core\SearchData;
class LayerRepository extends OhanzeeRepository
{
// Use the JSON transcoder to encode properties
use JsonTranscodeRepository;
// OhanzeeRepository
protected function getTable()
{
return 'layers';
}
// OhanzeeRepository
public function getEntity(array $data = null)
{
return new Layer($data);
}
// JsonTranscodeRepository
protected function getJsonProperties()
{
return ['options'];
}
// SearchRepository
public function getSearchFields()
{
return ['active', 'type'];
}
// OhanzeeRepository
protected function setSearchConditions(SearchData $search)
{
$query = $this->search_query;
if ($search->active !== null) {
$query->where('active', '=', $search->active);
}
if ($search->type) {
$query->where('type', '=', $search->type);
}
}
// CreateRepository
public function create(Entity $entity)
{
$record = array_filter($entity->asArray());
$record['created'] = time();
return $this->executeInsert($this->removeNullValues($record));
}
// UpdateRepository
public function update(Entity $entity)
{
$update = $entity->getChanged();
$update['updated'] = time();
return $this->executeUpdate(['id' => $entity->id], $update);
}
}