1
|
|
|
<?php |
2
|
|
|
namespace Wabel\CertainAPI\Ressources; |
3
|
|
|
|
4
|
|
|
use Wabel\CertainAPI\Interfaces\CertainRessourceInterface; |
5
|
|
|
use Wabel\CertainAPI\CertainRessourceAbstract; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* RegistrationCertain about the Registration entity |
9
|
|
|
* |
10
|
|
|
* @author rbergina |
11
|
|
|
*/ |
12
|
|
|
class RegistrationCertain extends CertainRessourceAbstract implements CertainRessourceInterface |
13
|
|
|
{ |
14
|
|
|
public function getRessourceName(){ |
15
|
|
|
return 'Registration'; |
16
|
|
|
} |
17
|
|
|
public function getMandatoryFields() |
18
|
|
|
{ |
19
|
|
|
return array('profile'); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Return with all the result from certain. |
24
|
|
|
* @return RegistrationCertain[] |
25
|
|
|
*/ |
26
|
|
View Code Duplication |
public function getRegistrations($params = []) |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
$request= $this->get(null,$params); |
29
|
|
|
if($request->isSuccessFul()){ |
30
|
|
|
$registrationCertainResults = $request->getResults(); |
31
|
|
|
return $registrationCertainResults->registrations; |
32
|
|
|
} |
33
|
|
|
return null; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Return with all the result from certain. |
38
|
|
|
* @return RegistrationCertain[] |
39
|
|
|
*/ |
40
|
|
View Code Duplication |
public function getRegistrationsByEventCode($eventCode,$params = []) |
|
|
|
|
41
|
|
|
{ |
42
|
|
|
$request= $this->get($eventCode,$params); |
43
|
|
|
if($request->isSuccessFul()){ |
44
|
|
|
$registrationCertainResults = $request->getResults(); |
45
|
|
|
return $registrationCertainResults->registrations; |
46
|
|
|
} |
47
|
|
|
return null; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Return with all the result from certain. |
52
|
|
|
* @param string $eventCode eventCode |
53
|
|
|
* @param string $email email |
54
|
|
|
* @param boolean $returnRegCode To say if we want return a boolean or the regCode |
55
|
|
|
* @param string $orderBySecure in order to get the first registration when we have duplciates |
56
|
|
|
* @return registrationCode|null|boolean|[registrationCode=> "",attendeeTypeCode=>""] |
|
|
|
|
57
|
|
|
*/ |
58
|
|
|
public function hasRegistrationsByEventCodeAndEmail($eventCode,$email,$returnRegCode= true,$withAttenteeType=true,$orderBySecure='dateModified_asc') |
59
|
|
|
{ |
60
|
|
|
$request= $this->get($eventCode,[ |
61
|
|
|
'email'=> $email, |
62
|
|
|
'orderBy'=> $orderBySecure |
63
|
|
|
|
64
|
|
|
]); |
65
|
|
|
if($request->isSuccessFul()){ |
66
|
|
|
$registrationCertainResults = $request->getResults(); |
67
|
|
|
if($registrationCertainResults->size > 0 && $returnRegCode && $withAttenteeType){ |
68
|
|
|
return [ |
69
|
|
|
'registrationCode' => $registrationCertainResults->registrations[0]->registrationCode, |
70
|
|
|
'attendeeTypeCode' => (isset($registrationCertainResults->registrations[0]->attendeeTypeCode))?$registrationCertainResults->registrations[0]->attendeeTypeCode:'', |
71
|
|
|
]; |
72
|
|
|
} |
73
|
|
|
elseif($registrationCertainResults->size > 0 && $returnRegCode){ |
74
|
|
|
return $registrationCertainResults->registrations[0]->registrationCode; |
75
|
|
|
} elseif($registrationCertainResults->size > 0 && !$returnRegCode){ |
76
|
|
|
return true; |
77
|
|
|
} |
78
|
|
|
} elseif($request->isNotFound()){ |
79
|
|
|
return false; |
80
|
|
|
} |
81
|
|
|
return null; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Return with the result from certain. |
86
|
|
|
* @param string $eventCode |
87
|
|
|
* @param string $regCode |
88
|
|
|
* @return RegistrationObj |
89
|
|
|
*/ |
90
|
|
View Code Duplication |
public function getRegistrationByEventCodeAnRegCode($eventCode,$regCode) |
|
|
|
|
91
|
|
|
{ |
92
|
|
|
$request= $this->get($eventCode.'/'.$regCode); |
93
|
|
|
if($request->isSuccessFul()){ |
94
|
|
|
$registrationCertainResult= $request->getResults(); |
95
|
|
|
return $registrationCertainResult; |
96
|
|
|
} |
97
|
|
|
return null; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Update with the result from certain. |
102
|
|
|
* @param string $eventCode |
103
|
|
|
* @param string $regCode |
104
|
|
|
* @return RegistrationObj |
105
|
|
|
*/ |
106
|
|
View Code Duplication |
public function updateRegistrationByEventCodeAnRegCode($eventCode,$regCode,$data=[]) |
|
|
|
|
107
|
|
|
{ |
108
|
|
|
$request= $this->post($data,[],$eventCode.'/'.$regCode); |
109
|
|
|
if($request->isSuccessFul()){ |
110
|
|
|
$registrationCertainResult= $request->getResults(); |
111
|
|
|
return $registrationCertainResult; |
112
|
|
|
} |
113
|
|
|
return null; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
// public function substituateRegistration($eventCode,$regCode,$profilePin){ |
117
|
|
|
// return $this->updateRegistrationByEventCodeAnRegCode($eventCode, $regCode, [ |
118
|
|
|
// 'profile' => [ |
119
|
|
|
// 'pin'=> $profilePin |
120
|
|
|
// ] |
121
|
|
|
// ]); |
122
|
|
|
// } |
123
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.