|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Frontend module controller |
|
4
|
|
|
* |
|
5
|
|
|
* Basic parent controller for frontend functions, controller is not ready yet |
|
6
|
|
|
* |
|
7
|
|
|
* @category Controller |
|
8
|
|
|
* @subpackage Frontend |
|
9
|
|
|
* @package Olapus |
|
10
|
|
|
* @author Jan Drda <[email protected]> |
|
11
|
|
|
* @copyright Jan Drda |
|
12
|
|
|
* @license https://opensource.org/licenses/MIT MIT |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace App\Http\Controllers\Frontend; |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
use App\Http\Controllers\Controller; |
|
19
|
|
|
use App\Settings; |
|
20
|
|
|
use Illuminate\Support\Facades\View; |
|
21
|
|
|
use App\Page; |
|
22
|
|
|
use App\Transaction; |
|
23
|
|
|
use App\User; |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
|
|
27
|
|
|
class FrontendController extends Controller |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* Data for view |
|
31
|
|
|
* |
|
32
|
|
|
* @var array |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $_arViewData = []; |
|
35
|
|
|
|
|
36
|
|
|
protected $_arViewGeneratedData = []; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Check if view exists, if so - return, if not throw 404 |
|
40
|
|
|
* |
|
41
|
|
|
* @param string $strView |
|
42
|
|
|
* @return View|void |
|
43
|
|
|
*/ |
|
44
|
|
|
protected function _showViewOr404($strView){ |
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
if (view()->exists($strView)) { |
|
|
|
|
|
|
48
|
|
|
return view($strView, $this->_arViewData); |
|
49
|
|
|
} |
|
50
|
|
|
else{ |
|
51
|
|
|
return abort(404); |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Save all inputs to session |
|
57
|
|
|
* @param $request |
|
58
|
|
|
*/ |
|
59
|
|
|
protected function _saveSessionFields($request){ |
|
60
|
|
|
|
|
61
|
|
|
foreach ($request->all() as $key=>$value){ |
|
62
|
|
|
$arData[$key] = $value; |
|
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
$request->session()->put('frontend_fields', $arData); |
|
|
|
|
|
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Reset all session fields |
|
70
|
|
|
*/ |
|
71
|
|
|
protected function _resetSessionFields($request){ |
|
72
|
|
|
|
|
73
|
|
|
$request->session()->forget('frontend_fields'); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Calculate price |
|
78
|
|
|
* |
|
79
|
|
|
* @param $request |
|
80
|
|
|
*/ |
|
81
|
|
|
protected function _calculatePrice($request){ |
|
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
return 0; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Get frontend fields |
|
88
|
|
|
* |
|
89
|
|
|
* @param $request |
|
90
|
|
|
* @return mixed |
|
91
|
|
|
*/ |
|
92
|
|
|
protected function _getSessionFields($request){ |
|
93
|
|
|
|
|
94
|
|
|
$fields = $request->session()->get('frontend_fields'); |
|
95
|
|
|
|
|
96
|
|
|
if(isset($request->id)){ |
|
|
|
|
|
|
97
|
|
|
//$fields['price'] = $this->_calculatePrice($request); |
|
|
|
|
|
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
if(isset($fields['city'])) { |
|
101
|
|
|
$arCityInfo = explode('|', $fields['city']); |
|
102
|
|
|
|
|
103
|
|
|
$fields['citypart'] = @trim($arCityInfo[0]); |
|
104
|
|
|
$fields['citymain'] = @trim($arCityInfo[1]); |
|
105
|
|
|
$fields['county'] = @trim($arCityInfo[2]); |
|
106
|
|
|
$fields['zip'] = @trim($arCityInfo[3]); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
$this->_arViewData['fields'] = $fields; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Load page by URL |
|
114
|
|
|
* |
|
115
|
|
|
* @param $url |
|
116
|
|
|
* @return mixed |
|
117
|
|
|
*/ |
|
118
|
|
|
protected function _loadPageByUrl($url){ |
|
119
|
|
|
|
|
120
|
|
|
return Page::where('url', $url)->firstOrFail(); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* Load page by id |
|
125
|
|
|
* |
|
126
|
|
|
* @param $id |
|
127
|
|
|
* @return mixed |
|
128
|
|
|
*/ |
|
129
|
|
|
protected function _loadPageById($id){ |
|
130
|
|
|
return Page::findOrFail($id); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
protected function _getSettings($id){ |
|
134
|
|
|
|
|
135
|
|
|
$settings = Settings::find($id); |
|
136
|
|
|
|
|
137
|
|
|
if(!empty($settings)){ |
|
138
|
|
|
return $settings['value']; |
|
139
|
|
|
} |
|
140
|
|
|
else{ |
|
141
|
|
|
return NULL; |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* Save transaction |
|
147
|
|
|
* |
|
148
|
|
|
* @param int $typeId |
|
|
|
|
|
|
149
|
|
|
* @param string $text |
|
|
|
|
|
|
150
|
|
|
* @param $userId |
|
151
|
|
|
* @param $amount |
|
152
|
|
|
*/ |
|
153
|
|
View Code Duplication |
protected function _saveTransation($status_id = 1, $user_id, $amount, |
|
|
|
|
|
|
154
|
|
|
$campaign_id = null, $payment_id = null, $recommendation_id = null){ |
|
155
|
|
|
|
|
156
|
|
|
/** |
|
157
|
|
|
* Save transaction |
|
158
|
|
|
*/ |
|
159
|
|
|
$transaction = new Transaction(); |
|
160
|
|
|
$transaction->transactionstatus_id = $status_id; |
|
161
|
|
|
$transaction->user_id = $user_id; |
|
162
|
|
|
$transaction->amount = $amount; |
|
163
|
|
|
$transaction->campaign_id = $campaign_id; |
|
164
|
|
|
$transaction->payment_id = $payment_id; |
|
165
|
|
|
$transaction->recommendation_id = $recommendation_id; |
|
166
|
|
|
$transaction->save(); |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* Update user wallet |
|
170
|
|
|
*/ |
|
171
|
|
|
$user = User::find($user_id); |
|
172
|
|
|
$user->wallet = $user->wallet + $amount; |
|
173
|
|
|
$user->save(); |
|
174
|
|
|
} |
|
175
|
|
|
} |
|
176
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: