1 | <?php |
||
3 | class ApiKey extends Model |
||
4 | { |
||
5 | protected $name; |
||
6 | |||
7 | protected $owner; |
||
8 | |||
9 | protected $key; |
||
10 | |||
11 | protected $status; |
||
12 | |||
13 | /** |
||
14 | * The name of the database table used for queries |
||
15 | */ |
||
16 | const TABLE = "api_keys"; |
||
17 | |||
18 | /** |
||
19 | * {@inheritdoc} |
||
20 | */ |
||
21 | 1 | protected function assignResult($key) |
|
28 | |||
29 | 1 | public static function createKey($name, $owner) |
|
30 | { |
||
31 | 1 | $key = self::create(array( |
|
32 | 1 | 'name' => $name, |
|
33 | 1 | 'owner' => $owner, |
|
34 | 1 | 'key' => self::generateKey(), |
|
35 | 1 | 'status' => "active" |
|
36 | )); |
||
37 | |||
38 | 1 | return $key; |
|
39 | } |
||
40 | |||
41 | public static function getKeyByOwner($owner) |
||
51 | |||
52 | public function getKey() |
||
56 | |||
57 | public function getName() |
||
61 | |||
62 | 1 | public function getOwner() |
|
66 | |||
67 | public function getStatus() |
||
71 | |||
72 | public static function getKeys($owner = -1) |
||
73 | { |
||
74 | if ($owner > 0) { |
||
75 | $ids = self::fetchIdsFrom("owner", array($owner), false, "WHERE status = 'active'"); |
||
76 | return self::arrayIdToModel($ids); |
||
77 | } |
||
78 | |||
79 | $ids = self::fetchIdsFrom("status", array("active")); |
||
80 | return self::arrayIdToModel($ids); |
||
81 | } |
||
82 | |||
83 | 1 | protected static function generateKey() |
|
93 | } |
||
94 |