forked from AppStateESS/InternshipInventory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChangeHistory.php
109 lines (90 loc) · 2.89 KB
/
ChangeHistory.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
namespace Intern;
class ChangeHistory extends Model{
public $internship_id;
public $username;
public $timestamp;
public $from_state;
public $to_state;
public $note;
/**
* NB: All of the params are optional for compatibility with db->getObjects() .. Database is done wrong. Don't have time to fix it.
* @param Internship $i
* @param PHPWS_User $phpwsUser
* @param int $timestamp
* @param WorkflowState $fromState
* @param WorkflowState $toState
*/
public function __construct(Internship $i = null, \PHPWS_User $phpwsUser = null, $timestamp = null, WorkflowState $fromState = null, WorkflowState $toState = null, $note = null)
{
if(!is_null($i)){
$this->id = 0;
$this->internship_id = $i->getId();
$this->timestamp = $timestamp;
if(is_null($phpwsUser)) {
$this->username = 'InternshipInventory';
} else {
$this->username = $phpwsUser->getUsername();
}
// Strip namespace from start of from and to states, all four backspaces are required to escaping backslash
if($fromState !== null){
$this->from_state = preg_replace("/Intern\\\\WorkflowState\\\\/", '', $fromState->getName());
}
if($toState !== null){
$this->to_state = preg_replace("/Intern\\\\WorkflowState\\\\/", '', $toState->getName());
}
$this->note = $note;
}
}
public function getDB(){
return new \PHPWS_DB('intern_change_history');
}
public function getCSV()
{
return array();
}
public function getRelativeDate($now = NULL)
{
$time = $this->timestamp;
$curr = !is_null($now) ? $now : time();
$shift = $curr - $time;
if ($shift < 45){
$diff = $shift;
$term = "second";
}elseif ($shift < 2700){
$diff = round($shift / 60);
$term = "minute";
}elseif ($shift < 64800){
$diff = round($shift / 60 / 60);
$term = "hour";
}else{
$diff = round($shift / 60 / 60 / 24);
$term = "day";
}
if ($diff > 1){
$term .= "s";
}
return "$diff $term";
}
public function getFormattedDate(){
return date("M j, Y h:ia", $this->timestamp);
}
public function getFromStateFriendlyName()
{
$fromState = WorkflowStateFactory::getState($this->from_state);
return $fromState->getFriendlyName();
}
public function getToStateFriendlyName()
{
$toState = WorkflowStateFactory::getState($this->to_state);
return $toState->getFriendlyName();
}
public function getUsername()
{
return $this->username;
}
public function getNote()
{
return $this->note;
}
}