|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Obblm\Core\Helper\Rule; |
|
4
|
|
|
|
|
5
|
|
|
use Obblm\Core\Contracts\RuleHelperInterface; |
|
6
|
|
|
use Obblm\Core\Entity\Rule; |
|
7
|
|
|
use Obblm\Core\Form\Player\ActionType; |
|
8
|
|
|
use Obblm\Core\Form\Player\InjuryType; |
|
9
|
|
|
use Obblm\Core\Helper\CoreTranslation; |
|
10
|
|
|
use Obblm\Core\Helper\Rule\Traits\AbstractInducementRuleTrait; |
|
11
|
|
|
use Obblm\Core\Helper\Rule\Traits\AbstractPlayerRuleTrait; |
|
12
|
|
|
use Obblm\Core\Helper\Rule\Traits\AbstractTeamRuleTrait; |
|
13
|
|
|
use Obblm\Core\Helper\Rule\Traits\AbstractTeamCreationTrait; |
|
14
|
|
|
use Obblm\Core\Traits\ClassNameAsKeyTrait; |
|
15
|
|
|
|
|
16
|
|
|
abstract class AbstractRuleHelper extends RuleConfigBuilder implements RuleHelperInterface |
|
17
|
|
|
{ |
|
18
|
|
|
use ClassNameAsKeyTrait, |
|
19
|
|
|
AbstractTeamRuleTrait, |
|
20
|
|
|
AbstractPlayerRuleTrait, |
|
21
|
|
|
AbstractInducementRuleTrait, |
|
22
|
|
|
AbstractTeamCreationTrait; |
|
23
|
|
|
|
|
24
|
|
|
protected $attachedRule; |
|
25
|
|
|
protected $rule = []; |
|
26
|
|
|
|
|
27
|
|
|
/**************** |
|
28
|
|
|
* COMPLIER PASS |
|
29
|
|
|
****************/ |
|
30
|
|
|
/** |
|
31
|
|
|
* @param Rule $rule |
|
32
|
|
|
* @return $this |
|
33
|
|
|
*/ |
|
34
|
1 |
|
public function attachRule(Rule $rule):RuleHelperInterface |
|
35
|
|
|
{ |
|
36
|
1 |
|
$this->setAttachedRule($rule); |
|
37
|
1 |
|
$this->build($rule->getRuleKey(), $rule->getRule()); |
|
38
|
1 |
|
return $this; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/********** |
|
42
|
|
|
* CACHING |
|
43
|
|
|
*********/ |
|
44
|
|
|
|
|
45
|
2 |
|
public function getAttachedRule():?Rule |
|
46
|
|
|
{ |
|
47
|
2 |
|
return $this->attachedRule; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
1 |
|
public function setAttachedRule(Rule $rule):RuleHelperInterface |
|
51
|
|
|
{ |
|
52
|
1 |
|
$this->attachedRule = $rule; |
|
53
|
1 |
|
$this->rule = $rule->getRule(); |
|
54
|
1 |
|
return $this; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/********************** |
|
58
|
|
|
* APPLICATION METHODS |
|
59
|
|
|
*********************/ |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @return string |
|
63
|
|
|
*/ |
|
64
|
1 |
|
public function getInjuriesFormClass():string |
|
65
|
|
|
{ |
|
66
|
1 |
|
return InjuryType::class; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @return string |
|
71
|
|
|
*/ |
|
72
|
1 |
|
public function getActionsFormClass():string |
|
73
|
|
|
{ |
|
74
|
1 |
|
return ActionType::class; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @return string |
|
79
|
|
|
*/ |
|
80
|
1 |
|
public function getTemplateKey():string |
|
81
|
|
|
{ |
|
82
|
1 |
|
return $this->getAttachedRule()->getTemplate(); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/*************** |
|
86
|
|
|
* MISC METHODS |
|
87
|
|
|
**************/ |
|
88
|
|
|
public function getWeatherChoices():array |
|
89
|
|
|
{ |
|
90
|
|
|
$weather = []; |
|
91
|
|
|
$ruleKey = $this->getAttachedRule()->getRuleKey(); |
|
92
|
|
|
$fields = $this->rule['fields']; |
|
93
|
|
|
foreach ($fields as $fieldKey => $field) { |
|
94
|
|
|
$fieldLabel = CoreTranslation::getFieldKey($ruleKey, $fieldKey); |
|
95
|
|
|
$weather[$fieldLabel] = []; |
|
96
|
|
|
foreach ($field['weather'] as $fieldWeather) { |
|
97
|
|
|
$label = CoreTranslation::getWeatherKey($ruleKey, $fieldKey, $fieldWeather); |
|
98
|
|
|
$value = join(CoreTranslation::TRANSLATION_GLUE, [$ruleKey, 'default', $fieldWeather]); |
|
99
|
|
|
$weather[$fieldLabel][$label] = $value; |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
return $weather; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|