forked from ushahidi/platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsonTranscodeRepository.php
More file actions
72 lines (59 loc) · 1.87 KB
/
Copy pathJsonTranscodeRepository.php
File metadata and controls
72 lines (59 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
<?php
/**
* Ushahidi Json Transcoding Repo Trait
*
* JSON encodes properties defined `json_properties`
* during `executeUpdate` and `executeInsert`
*
* @author Ushahidi Team <team@ushahidi.com>
* @package Ushahidi\Application\Controllers
* @copyright 2013 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\Tool\JsonTranscode;
trait JsonTranscodeRepository
{
protected $json_transcoder;
/**
* Return an array of properties to be json encoded
* @return Array
*/
abstract protected function getJsonProperties();
public function setTranscoder(JsonTranscode $transcoder)
{
$this->json_transcoder = $transcoder;
}
// Temporary override function for attribute addition
public function executeInsertAttribute(array $input)
{
// JSON Encode defined properties
$input = $this->json_transcoder->encode(
$input,
$this->getJsonProperties()
);
return parent::executeInsert($input);
}
// OhanzeeRepository
public function executeInsert(array $input)
{
// JSON Encode defined properties
// The use of array_filter causes issues with array items set as 0
// the items are removed. This code should ultimately be refactored.
$input = array_filter($this->json_transcoder->encode(
$input,
$this->getJsonProperties()
));
return parent::executeInsert($input);
}
// OhanzeeRepository
public function executeUpdate(array $where, array $input)
{
// JSON Encode defined properties
$input = $this->json_transcoder->encode(
$input,
$this->getJsonProperties()
);
return parent::executeUpdate($where, $input);
}
}