-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUser.php
More file actions
75 lines (68 loc) · 1.74 KB
/
User.php
File metadata and controls
75 lines (68 loc) · 1.74 KB
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
72
73
74
75
<?php //Bismillah
/*-------------------*\
| userModel Class |
\*-------------------*/
/*
DESCRIPTION:
Provides interface between userController and cookie contianing user information
MVC MIGRATION:
- Copy to Models folder
Migration Steps:
1. Extend a proper Model parent class (e.g. CI_Model or AppModel)
*/
class User // <- Step 1.) extend proper Model class
{
protected $lastVote;
//Sets cookie with last vote as Unix timestamp
public function setLastVote()
{
$lv = time();
$expires = $lv + (60*60*24); //Expires in one day
setcookie('lastVote', $lv, $expires, '/' );
return $lv;
}
//Gets last vote from cookie
public function getLastVote()
{
//Return cookie if it is set, or return false
return (isset($_COOKIE['lastVote'])) ? $_COOKIE['lastVote'] : false;
}
//DEBUG: resets vote for debugging purposes
public function resetLastVote()
{
$expires = 0; //Expired
setcookie('lastVote', 0, $expires, '/' );
return true;
}
//Return the eligibility bool of the user to a controller
public function checkEligible()
{
$eligible = false;
$t = time();
//Set default timezone (prevents E_STRICT notice from date())
date_default_timezone_set('America/Chicago');
//if it's not a weekend ( dayofweek mod 6 will return 0 if it is either Sunday (0) or Saturday (6) )
if (date('w', $t)%6)
{
$lv = $this->getLastVote();
//If lastVote cookie is set
if ($lv)
{
//If today isn't the same as the last vote
if (date('mdY', $t)!=date('mdY',$lv))
{
//Then the user is Eligible because it's not the same day
$eligible = true;
}
}
else
{
//The user is eligible because there's no record of voting
$eligible = true;
}
}
//Return bool of eligibility
return $eligible;
}
}
?>