-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUsersController.php
71 lines (62 loc) · 1.71 KB
/
UsersController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php //Bismillah
/*------------------------*\
| userController Class |
\*------------------------*/
/*
DESCRIPTION:
Provides interface between xbox.js + gamesController and userModel
MVC MIGRATION:
- Copy to Controllers folder
- All migration steps are found within the class declaration line or the constructor
Migration Steps:
1. Change the parent class to a proper Controller parent class (e.g. CI_Controller or AppController)
- That's all for CodeIgniter, next step is for CakePHP
2. Delete whole __construct() function
*/
class UsersController extends fakeMVCController // <- Step 1.) Change to proper Controller class when migrating to MVC framework
{
//Posted Data
public $data;
//Response Data
public $error = false;
public $eligible = false;
//Constructor - Load User Model
public function __construct() // <- Step 3.) DELETE whole __construct() function for CakePHP
{
//MVC: call parent constructor
parent::__construct();
//MVC: Create instance of userModel
$this->load->model('User');
}
//MVC: default action
public function index()
{
$this->isEligible();
}
//MVC: Sends JSON Response to View
public function respond()
{
$json = array('eligible'=>$this->eligible, 'error'=>$this->error);
$this->json = json_encode($json);
header("Content-Type:text/json");
die($this->json);
}
//Check Eligibility and return bool
public function checkEligible()
{
return $this->User->checkEligible();
}
//Return Eligibility to a View via JSON
public function isEligible()
{
$this->eligible = $this->checkEligible();
$this->respond();
}
//DEBUG: Resets user's last vote
public function resetVote()
{
$this->eligible = $this->User->resetLastVote();
$this->respond();
}
}
?>