forked from exodus4d/pathfinder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcharactermodel.php
More file actions
145 lines (114 loc) · 3.27 KB
/
Copy pathcharactermodel.php
File metadata and controls
145 lines (114 loc) · 3.27 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
/**
* Created by PhpStorm.
* User: exodus4d
* Date: 11.04.15
* Time: 15:20
*/
namespace Model;
class CharacterModel extends BasicModel {
protected $table = 'character';
protected $fieldConf = [
'corporationId' => [
'belongs-to-one' => 'Model\CorporationModel'
],
'allianceId' => [
'belongs-to-one' => 'Model\AllianceModel'
],
'characterLog' => [
'has-one' => ['Model\CharacterLogModel', 'characterId']
]
];
/**
* get character data
* @param bool|false $addCharacterLogData
* @return object
*/
public function getData($addCharacterLogData = false){
// check if there is cached data
// temporary disabled (performance test)
$characterData = null; //$this->getCacheData();
if(is_null($characterData)){
// no cached character data found
$characterData = (object) [];
$characterData->id = $this->id;
$characterData->name = $this->name;
if($addCharacterLogData){
if($logModel = $this->getLog()){
$characterData->log = $logModel->getData();
}
}
// check for corporation
if($corporation = $this->getCorporation()){
$characterData->corporation = $corporation->getData();
}
// check for alliance
if($alliance = $this->getAlliance()){
$characterData->alliance = $alliance->getData();
}
// max caching time for a system
// the cached date has to be cleared manually on any change
// this includes system, connection,... changes (all dependencies)
$this->updateCacheData($characterData, '', 300);
}
return $characterData;
}
/**
* check whether this character has a corporation
* @return bool
*/
public function hasCorporation(){
$hasCorporation = false;
if($this->corporationId){
$hasCorporation = true;
}
return $hasCorporation;
}
/**
* check whether this character has an alliance
* @return bool
*/
public function hasAlliance(){
$hasAlliance = false;
if($this->allianceId){
$hasAlliance = true;
}
return $hasAlliance;
}
/**
* get the corporation for this user
* @return mixed|null
*/
public function getCorporation(){
$corporation = null;
if($this->hasCorporation()){
$corporation = $this->corporationId;
}
return $corporation;
}
/**
* get the alliance of this user
* @return mixed|null
*/
public function getAlliance(){
$alliance = null;
if($this->hasAlliance()){
$alliance = $this->allianceId;
}
return $alliance;
}
/**
* get the character log entry for this character
* @return bool|null
*/
public function getLog(){
$characterLog = false;
if(
is_object($this->characterLog) &&
!$this->characterLog->dry()
){
$characterLog = $this->characterLog;
}
return $characterLog;
}
}