1 | <?php |
||
2 | |||
3 | class ajax extends Controller { |
||
4 | |||
5 | function __construct() { |
||
0 ignored issues
–
show
|
|||
6 | $this->load_library("http_lib", "http"); |
||
7 | $this->load_library("auth_lib", "auth"); |
||
8 | |||
9 | $this->load_model("jugaad_model"); |
||
10 | $this->load_model("perms_model"); |
||
11 | $this->load_model("auth_model"); |
||
12 | |||
13 | $this->user = $this->auth->get_user() ?: ""; |
||
0 ignored issues
–
show
|
|||
14 | } |
||
15 | |||
16 | /** |
||
17 | * @param string $param Get GET parameter called $param |
||
18 | * @return mixed GET parameter or false if not found |
||
19 | */ |
||
20 | private function get_param($param) { |
||
21 | if (isset($_GET[$param])) { |
||
22 | return $_GET[$param]; |
||
23 | } |
||
24 | return false; |
||
25 | } |
||
26 | |||
27 | function latest_version_id() { |
||
0 ignored issues
–
show
|
|||
28 | $file_id = $this->get_param("file_id"); |
||
29 | |||
30 | $file = $this->jugaad_model->get_file($file_id); |
||
0 ignored issues
–
show
|
|||
31 | |||
32 | if ($file === false || $file["type"] != "file") { |
||
33 | $this->http->response_code(404); |
||
0 ignored issues
–
show
|
|||
34 | } |
||
35 | |||
36 | $user_can = $this->perms_model->get_permissions($file_id, $this->user); |
||
0 ignored issues
–
show
|
|||
37 | |||
38 | if (!$user_can['read_file']) { |
||
39 | $this->http->response_code(403); |
||
40 | } |
||
41 | |||
42 | $version_id = $this->jugaad_model->get_latest_version_id($file_id); |
||
43 | |||
44 | echo $version_id; |
||
45 | } |
||
46 | |||
47 | } |
||
48 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.