From 719b6714c6461eaddc6ae5f49af405aa90a95d9a Mon Sep 17 00:00:00 2001 From: mentarus Date: Wed, 4 Mar 2015 23:23:28 +0000 Subject: [PATCH] Added a is_tool_in_use query as per https://github.com/londonhackspace/acserver/issues/8 --- application/config/routes.php | 5 +++++ application/controllers/api.php | 30 ++++++++++++++++++++++++++++++ application/models/tool_model.php | 10 ++++++++++ 3 files changed, 45 insertions(+) diff --git a/application/config/routes.php b/application/config/routes.php index 06ee989..b27dc03 100644 --- a/application/config/routes.php +++ b/application/config/routes.php @@ -93,6 +93,11 @@ // http://wiki.london.hackspace.org.uk/view/Project:Tool_Access_Control/Solexious_Proposal#Case_alert $route[':num/case/:any'] = "api/case_change"; +// Is tool in use +// Reports wether the tool is being used +// https://github.com/londonhackspace/acserver/issues/8 +$route[':num/is_tool_in_use'] = "api/is_tool_in_use"; + /* End of file routes.php */ /* Location: ./application/config/routes.php */ \ No newline at end of file diff --git a/application/controllers/api.php b/application/controllers/api.php index 79df141..b03d4c2 100644 --- a/application/controllers/api.php +++ b/application/controllers/api.php @@ -524,6 +524,36 @@ public function case_change() { $this->response(RESPONSE_SUCCESS); } + + /* + TITLE: Is tool in use () + + DESCRIPTION: + Returns weather someone is using the tool at this very moment + + URL STRUCTURE: + GET /[nodeID]/is_tool_in_use + + DESCRIPTION URL: + https://github.com/londonhackspace/acserver/issues/8 + + EXAMPLES: + (Using test data set) + + Checks wether the tool is in use. Returns 1 if it is, 0 if not. + curl http://acserver:1234/1/is_tool_in_use + + */ + public function is_tool_in_use() { + $tool_id = (int) $this->uri->segment(1); + + $logged_event = $this->Tool_model->get_last_tool_status($tool_id); + + //$this->Tool_model->log_usage($acnode_id, $user_id, $card_unique_identifier, 'Time Used', $time_used); + //$this->response(RESPONSE_SUCCESS); + //$this->response($logged_event); + echo ($logged_event == "Access Started")? "yes":"no" ; + } protected function response($data) { diff --git a/application/models/tool_model.php b/application/models/tool_model.php index 9237863..8d2f148 100644 --- a/application/models/tool_model.php +++ b/application/models/tool_model.php @@ -47,5 +47,15 @@ public function log_case_status_change($acnode_id, $status) { } $this->log_usage($acnode_id, NULL, NULL, $narrative, 0); } + + public function get_last_tool_status($tool_id) { + + $query = $this->db->order_by("logged_at","desc")->limit(1) + ->get_where('toolusage',array('tool_id' => $tool_id)); + + $row = $query->row_array(); + + return $row['logged_event']; + } } ?> \ No newline at end of file