|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Qwertee.php, qwertee-php. |
|
4
|
|
|
* |
|
5
|
|
|
* This File belongs to to Project qwertee-php |
|
6
|
|
|
* |
|
7
|
|
|
* @author Oliver Kaufmann <[email protected]> |
|
8
|
|
|
* |
|
9
|
|
|
* @version 1.0 |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Okaufmann\QwerteePhp; |
|
13
|
|
|
|
|
14
|
|
|
use Carbon\Carbon; |
|
15
|
|
|
use Illuminate\Support\Collection; |
|
16
|
|
|
|
|
17
|
|
|
class Qwertee |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var QwerteeClient |
|
21
|
|
|
*/ |
|
22
|
|
|
private static $client = null; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Get Todays qwertee tees. |
|
26
|
|
|
* |
|
27
|
|
|
* @return Collection |
|
28
|
|
|
*/ |
|
29
|
|
|
public static function today() |
|
30
|
|
|
{ |
|
31
|
|
|
return self::getFirstThreeItems(); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Get last chance tees. |
|
36
|
|
|
* |
|
37
|
|
|
* @return Collection |
|
38
|
|
|
*/ |
|
39
|
|
|
public static function lastChance() |
|
40
|
|
|
{ |
|
41
|
|
|
return self::getNextThreeItems(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @return Collection |
|
46
|
|
|
*/ |
|
47
|
|
|
public static function getFirstThreeItems() |
|
48
|
|
|
{ |
|
49
|
|
|
return self::getClient()->feedItems()->take(3)->values(); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @return Collection |
|
54
|
|
|
*/ |
|
55
|
|
|
public static function getNextThreeItems() |
|
56
|
|
|
{ |
|
57
|
|
|
return self::getClient()->feedItems()->slice(3)->take(3)->values(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
private static function getHour() |
|
61
|
|
|
{ |
|
62
|
|
|
return Carbon::now()->hour; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @return bool |
|
67
|
|
|
*/ |
|
68
|
|
|
public static function isReleaseTime() |
|
69
|
|
|
{ |
|
70
|
|
|
// if it is between 23h and 11h return 3 |
|
71
|
|
|
$hour = self::getHour(); |
|
72
|
|
|
|
|
73
|
|
|
return $hour >= 23 || $hour < 11; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* @return bool |
|
78
|
|
|
*/ |
|
79
|
|
|
public static function isLastChanceTime() |
|
80
|
|
|
{ |
|
81
|
|
|
// if it is between 11h and 23h (but not 23h!) |
|
82
|
|
|
$hour = self::getHour(); |
|
83
|
|
|
|
|
84
|
|
|
return $hour >= 11 && $hour < 23; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* @param null $client |
|
89
|
|
|
*/ |
|
90
|
|
|
public static function setClient($client) |
|
91
|
|
|
{ |
|
92
|
|
|
self::$client = $client; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* @return QwerteeClient |
|
97
|
|
|
*/ |
|
98
|
|
|
public static function getClient() |
|
99
|
|
|
{ |
|
100
|
|
|
if (self::$client == null) { |
|
101
|
|
|
$qClient = new QwerteeClient(); |
|
102
|
|
|
$qClient->initializeFeed(); |
|
103
|
|
|
self::setClient($qClient); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
return self::$client; |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|