forked from cooperaj/wow-armory-character
-
Notifications
You must be signed in to change notification settings - Fork 0
/
class-wow-armory-character-feeditem.php
124 lines (106 loc) · 3.28 KB
/
class-wow-armory-character-feeditem.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
/*
Copyright 2014 Adam Cooper (email : adam@networkpie.co.uk)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* Wraps the JSON returned by the WoW community API to provide some
* extra properties and methods on that data. Since a feed item can
* consist of 3 different datatypes these methods homogenise the data
* into the properties we'll eventually want to display.
*
* @author Adam Cooper <adam@networkpie.co.uk>
*/
class WoW_Armory_Character_FeedItem {
const ITEM_ACHIEVEMENT = 'ACHIEVEMENT';
const ITEM_CRITERIA = 'CRITERIA';
const ITEM_LOOT = 'LOOT';
public $region;
public $locale;
// Setting these in the object makes things a little easier.
public $last_checked;
public $cache_name;
private $_api_data;
public function __construct( $region, $locale, stdClass $api_data ) {
$this->region = $region;
$this->locale = $locale;
$this->_api_data = $api_data;
}
public function __get( $name ) {
if ( isset( $this->_api_data->$name ) ) {
return $this->_api_data->$name;
}
}
public function __isset( $name ) {
return isset( $this->_api_data->$name );
}
public function get_item_title() {
switch ( $this->type ) {
case self::ITEM_ACHIEVEMENT :
return $this->achievement->title;
break;
case self::ITEM_CRITERIA :
return $this->criteria->description;
break;
case self::ITEM_LOOT :
$item = WoW_Armory_Character_DAL::fetch_item( $this->region, $this->locale, $this->itemId );
return $item->name;
break;
}
}
public function get_item_url_components() {
switch ( $this->type ) {
case self::ITEM_ACHIEVEMENT :
case self::ITEM_CRITERIA :
$achievements = WoW_Armory_Character_DAL::fetch_achievements( $this->region, $this->locale );
if ( is_wp_error( $achievements ) ) {
return null;
}
$achiev = $achievements->get_achievement_by_id( $this->achievement->id );
$components = array(
'id' => $achiev->id,
'section' => $achiev->section->id,
'category' => $achiev->category->id
);
return $components;
break;
case self::ITEM_LOOT :
return array( 'id' => $this->itemId );
break;
}
}
public function get_item_icon() {
switch ( $this->type ) {
case self::ITEM_ACHIEVEMENT :
return $this->achievement->icon;
break;
case self::ITEM_CRITERIA :
break;
case self::ITEM_LOOT :
$item = WoW_Armory_Character_DAL::fetch_item( $this->region, $this->locale, $this->itemId );
return $item->icon;
break;
}
}
public function get_item_related() {
switch ( $this->type ) {
case self::ITEM_ACHIEVEMENT :
return $this->achievement->points;
break;
case self::ITEM_CRITERIA :
return $this->achievement->title;
break;
case self::ITEM_LOOT :
break;
}
}
}