1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Syntax\SteamApi\Containers; |
4
|
|
|
|
5
|
|
|
use Illuminate\Support\Collection; |
6
|
|
|
|
7
|
|
|
abstract class BaseContainer |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @param $app |
11
|
|
|
* @param string $field |
12
|
|
|
* @param mixed $value |
13
|
|
|
* |
14
|
|
|
* @return mixed |
15
|
|
|
*/ |
16
|
1 |
|
protected function checkIsNullField($app, $field, $value = null) |
17
|
|
|
{ |
18
|
1 |
|
return ! is_null($app->$field) ? $app->$field : $value; |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @param $app |
23
|
|
|
* @param string $field |
24
|
|
|
* @param mixed $value |
25
|
|
|
* |
26
|
|
|
* @return mixed |
27
|
|
|
*/ |
28
|
12 |
|
protected function checkIssetField($app, $field, $value = null) |
29
|
|
|
{ |
30
|
12 |
|
return isset($app->$field) ? $app->$field : $value; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param $app |
35
|
|
|
* @param string $field |
36
|
|
|
* @param mixed $value |
37
|
|
|
* |
38
|
|
|
* @return mixed |
39
|
|
|
*/ |
40
|
1 |
|
protected function checkIssetCollection($app, $field, $value = null) |
41
|
|
|
{ |
42
|
1 |
|
return isset($app->$field) ? new Collection($app->$field) : $value; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param string $image |
47
|
|
|
* |
48
|
|
|
* @return string |
49
|
|
|
*/ |
50
|
6 |
|
protected function getImageForAvatar($image) |
51
|
|
|
{ |
52
|
6 |
|
return '<img src="' . $image . '" />'; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Very simple pluralize helper for days, hours, minutes. |
57
|
|
|
* This is not an end all solution to pluralization. |
58
|
|
|
* |
59
|
|
|
* @param $word |
60
|
|
|
* @param $count |
61
|
|
|
* |
62
|
|
|
* @return string |
63
|
|
|
*/ |
64
|
5 |
|
protected function pluralize($word, $count) |
65
|
|
|
{ |
66
|
5 |
|
if ((int) $count === 1) { |
67
|
5 |
|
return $word .' '; |
68
|
|
|
} |
69
|
|
|
|
70
|
5 |
|
return $word .'s '; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Convert a value from pure minutes into something easily digestible. |
75
|
|
|
* |
76
|
|
|
* @param $minutes |
77
|
|
|
* |
78
|
|
|
* @return string |
79
|
|
|
*/ |
80
|
5 |
|
protected function convertFromMinutes($minutes) |
81
|
|
|
{ |
82
|
5 |
|
$seconds = $minutes * 60; |
83
|
|
|
|
84
|
5 |
|
$secondsInAMinute = 60; |
85
|
5 |
|
$secondsInAnHour = 60 * $secondsInAMinute; |
86
|
5 |
|
$secondsInADay = 24 * $secondsInAnHour; |
87
|
|
|
|
88
|
|
|
// extract days |
89
|
5 |
|
$days = floor($seconds / $secondsInADay); |
90
|
|
|
|
91
|
|
|
// extract hours |
92
|
5 |
|
$hourSeconds = $seconds % $secondsInADay; |
93
|
5 |
|
$hours = floor($hourSeconds / $secondsInAnHour); |
94
|
|
|
|
95
|
|
|
// extract minutes |
96
|
5 |
|
$minuteSeconds = $hourSeconds % $secondsInAnHour; |
97
|
5 |
|
$minutes = floor($minuteSeconds / $secondsInAMinute); |
98
|
|
|
|
99
|
|
|
// return the final string |
100
|
5 |
|
$output = ''; |
101
|
|
|
|
102
|
5 |
|
if ($days > 0) { |
103
|
5 |
|
$output .= $days . ' ' . $this->pluralize('day', $days); |
104
|
|
|
} |
105
|
|
|
|
106
|
5 |
|
if ($hours > 0) { |
107
|
4 |
|
$output .= $hours . ' ' . $this->pluralize('hour', $hours); |
108
|
|
|
} |
109
|
|
|
|
110
|
5 |
|
$output .= $minutes . ' ' . $this->pluralize('minute', $minutes); |
111
|
|
|
|
112
|
5 |
|
return $output; |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|