diff options
author | Florian Pritz <bluewind@xinu.at> | 2015-02-14 19:13:26 +0100 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2015-02-14 19:13:26 +0100 |
commit | d7fc5f46a8b6faec4ec0c18089d94d21e505c36c (patch) | |
tree | 0500e514d40db5052f82812d08743718fca50306 | |
parent | b8facbbd7a9a29c6274c435932b9c810155e2460 (diff) |
Use assoc array for service/user/apikeys
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rw-r--r-- | application/controllers/user.php | 2 | ||||
-rw-r--r-- | application/service/user.php | 6 | ||||
-rw-r--r-- | application/tests/test_api_v1.php | 8 |
3 files changed, 10 insertions, 6 deletions
diff --git a/application/controllers/user.php b/application/controllers/user.php index 5b4e85141..33d0efb6b 100644 --- a/application/controllers/user.php +++ b/application/controllers/user.php @@ -115,7 +115,7 @@ class User extends MY_Controller { $userid = $this->muser->get_userid(); $apikeys = \service\user::apikeys($userid); - $this->data["query"] = $apikeys; + $this->data["query"] = $apikeys["apikeys"]; $this->load->view('header', $this->data); $this->load->view($this->var->view_dir.'apikeys', $this->data); diff --git a/application/service/user.php b/application/service/user.php index 16fa62272..cab14dbab 100644 --- a/application/service/user.php +++ b/application/service/user.php @@ -53,6 +53,7 @@ class user { static public function apikeys($userid) { $CI =& get_instance(); + $ret = array(); $query = $CI->db->select('key, created, comment, access_level') ->from('apikeys') @@ -66,9 +67,12 @@ class user { if (!empty($record['created'])) { $record['created'] = strtotime($record['created']); } + $ret[$record["key"]] = $record; } unset($record); - return $query; + return array( + "apikeys" => $ret, + ); } } diff --git a/application/tests/test_api_v1.php b/application/tests/test_api_v1.php index e179abc69..44b559852 100644 --- a/application/tests/test_api_v1.php +++ b/application/tests/test_api_v1.php @@ -128,10 +128,10 @@ class test_api_v1 extends Test { )); $this->expectSuccess("get apikeys", $ret); - $this->t->is($ret["data"][0]["key"], $apikey, "expected key 1"); - $this->t->is($ret["data"][0]["access_level"], "apikey", "expected key 1 acces_level"); - $this->t->is($ret["data"][0]["comment"], "", "expected key 1 comment"); - $this->t->ok(is_int($ret["data"][0]["created"]) , "expected key 1 creation time is int"); + $this->t->is($ret["data"]["apikeys"][$apikey]["key"], $apikey, "expected key 1"); + $this->t->is($ret["data"]["apikeys"][$apikey]["access_level"], "apikey", "expected key 1 acces_level"); + $this->t->is($ret["data"]["apikeys"][$apikey]["comment"], "", "expected key 1 comment"); + $this->t->ok(is_int($ret["data"]["apikeys"][$apikey]["created"]) , "expected key 1 creation time is int"); } public function test_authentication_invalidPassword() |