Skip to content

Commit

Permalink
Added a is_tool_in_use query as per #8
Browse files Browse the repository at this point in the history
  • Loading branch information
mentarus committed Mar 4, 2015
1 parent ce3cdf3 commit 719b671
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
5 changes: 5 additions & 0 deletions application/config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
30 changes: 30 additions & 0 deletions application/controllers/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions application/models/tool_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}
}
?>

0 comments on commit 719b671

Please sign in to comment.