forked from ushahidi/platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApiKeyRepository.php
More file actions
83 lines (64 loc) · 1.82 KB
/
Copy pathApiKeyRepository.php
File metadata and controls
83 lines (64 loc) · 1.82 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
<?php
/**
* Ushahidi ApiKey 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\SearchData;
use Ushahidi\Core\Entity\ApiKey;
use Ushahidi\Core\Entity\ApiKeyRepository as ApiKeyRepositoryContract;
use Ushahidi\Core\Traits\AdminAccess;
use Ramsey\Uuid\Uuid;
use Ramsey\Uuid\Exception\UnsatisfiedDependencyException;
class ApiKeyRepository extends OhanzeeRepository implements ApiKeyRepositoryContract
{
use AdminAccess;
protected function getTable()
{
return 'apikeys';
}
public function getEntity(array $data = null)
{
return new ApiKey($data);
}
// OhanzeeRepository
public function setSearchConditions(SearchData $search)
{
$query = $this->search_query;
return $query;
}
// CreateRepository
public function create(Entity $entity)
{
$record = $entity->asArray();
$uuid = Uuid::uuid4();
$record['api_key'] = $uuid->toString();
$state = [
'created' => time(),
];
return $this->executeInsert($this->removeNullValues($record));
}
// UpdateRepository
public function update(Entity $entity)
{
$record = $entity->asArray();
$record['updated'] = time();
$uuid = Uuid::uuid4();
$record['api_key'] = $uuid->toString();
return $this->executeUpdate(['id' => $entity->id], $record);
}
public function apiKeyExists($api_key)
{
return (bool) $this->selectCount(compact('api_key'));
}
public function getSearchFields()
{
return [
];
}
}