1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Syntax\SteamApi\Containers; |
4
|
|
|
|
5
|
|
|
class Game extends BaseContainer |
6
|
|
|
{ |
7
|
|
|
public $appId; |
8
|
|
|
|
9
|
|
|
public $name; |
10
|
|
|
|
11
|
|
|
public $playtimeTwoWeeks; |
12
|
|
|
|
13
|
|
|
public $playtimeTwoWeeksReadable; |
14
|
|
|
|
15
|
|
|
public $playtimeForever; |
16
|
|
|
|
17
|
|
|
public $playtimeForeverReadable; |
18
|
|
|
|
19
|
|
|
public $icon; |
20
|
|
|
|
21
|
|
|
public $logo; |
22
|
|
|
|
23
|
|
|
public $header; |
24
|
|
|
|
25
|
|
|
public $hasCommunityVisibleStats; |
26
|
|
|
|
27
|
3 |
|
public function __construct($app) |
28
|
|
|
{ |
29
|
3 |
|
$this->appId = $app->appid; |
30
|
3 |
|
$this->name = $this->checkIssetField($app, 'name'); |
31
|
3 |
|
$this->playtimeTwoWeeks = $this->checkIssetField($app, 'playtime_2weeks', 0); |
32
|
3 |
|
$this->playtimeTwoWeeksReadable = $this->convertFromMinutes($this->playtimeTwoWeeks); |
33
|
3 |
|
$this->playtimeForever = $this->checkIssetField($app, 'playtime_forever', 0); |
34
|
3 |
|
$this->playtimeForeverReadable = $this->convertFromMinutes($this->playtimeForever); |
35
|
3 |
|
$this->icon = $this->checkIssetImage($app, 'img_icon_url'); |
36
|
3 |
|
$this->logo = $this->checkIssetImage($app, 'img_logo_url'); |
37
|
3 |
|
$this->header = 'http://cdn.akamai.steamstatic.com/steam/apps/' . $this->appId . '/header.jpg'; |
38
|
3 |
|
$this->hasCommunityVisibleStats = $this->checkIssetField($app, 'has_community_visible_stats', 0); |
39
|
3 |
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param $app |
43
|
|
|
* @param string $field |
44
|
|
|
* @param string $value |
45
|
|
|
* |
46
|
|
|
* @return null|string |
47
|
|
|
*/ |
48
|
3 |
|
protected function checkIssetImage($app, $field, $value = null) |
49
|
|
|
{ |
50
|
3 |
|
return isset($app->$field) ? $this->getImageForGame($app->appid, $app->$field) : $value; |
51
|
|
|
} |
52
|
|
|
|
53
|
2 |
|
protected function getImageForGame($appId, $hash) |
54
|
|
|
{ |
55
|
2 |
|
if ($hash != null) { |
56
|
2 |
|
return 'http://media.steampowered.com/steamcommunity/public/images/apps/' . $appId . '/' . $hash . '.jpg'; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
return null; |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|