|
1
|
|
|
<?php |
|
2
|
|
|
namespace App\Http\Controllers; |
|
3
|
|
|
|
|
4
|
|
|
use App\Category; |
|
5
|
|
|
use App\Condition; |
|
6
|
|
|
use App\Image; |
|
7
|
|
|
use App\Comment; |
|
8
|
|
|
use Illuminate\Http\Response; |
|
9
|
|
|
use Illuminate\Support\Facades\DB; |
|
10
|
|
|
use Illuminate\Http\Request; |
|
11
|
|
|
use Illuminate\Support\Facades\Auth; |
|
12
|
|
|
use Validator; |
|
13
|
|
|
use App\Http\Requests; |
|
14
|
|
|
use App\Project; |
|
15
|
|
|
|
|
16
|
|
|
class ProjectController extends Controller |
|
17
|
|
|
{ |
|
18
|
|
|
public function add_new() |
|
19
|
|
|
{ |
|
20
|
|
|
$categories = Category::all(); |
|
21
|
|
|
|
|
22
|
|
|
if (Auth::user()->isCreator == null) |
|
23
|
|
|
return redirect('/creator'); |
|
24
|
|
|
return view('project.new',compact('categories')); |
|
25
|
|
|
} |
|
26
|
|
|
/** |
|
27
|
|
|
* Display a listing of the resource. |
|
28
|
|
|
* |
|
29
|
|
|
* @return Response |
|
30
|
|
|
*/ |
|
31
|
|
|
public function index() |
|
32
|
|
|
{ |
|
33
|
|
|
//$model = DB::table('projects','categories')->where('projects.category_id','=','categories.id'); |
|
|
|
|
|
|
34
|
|
|
//dd($model->get()); |
|
|
|
|
|
|
35
|
|
|
$data = [ |
|
|
|
|
|
|
36
|
|
|
'active1' => Project::findOrFail(1), |
|
37
|
|
|
'active2' => Project::findOrFail(2), |
|
38
|
|
|
'active3' => Project::findOrFail(3), |
|
39
|
|
|
'categories' => Category::all() |
|
40
|
|
|
]; |
|
41
|
|
|
// return view('index')->with($data); |
|
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
return redirect(url('by_category',0)); |
|
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function ByCategory($id){ |
|
47
|
|
|
$data = [ |
|
48
|
|
|
'active1' => Project::findOrFail(1), |
|
49
|
|
|
'active2' => Project::findOrFail(2), |
|
50
|
|
|
'active3' => Project::findOrFail(3), |
|
51
|
|
|
'categories' => Category::all(), |
|
52
|
|
|
'id' => $id, |
|
53
|
|
|
]; |
|
54
|
|
|
if ($id == 0){ |
|
55
|
|
|
$project = Project::all(); |
|
56
|
|
|
} |
|
57
|
|
|
else |
|
58
|
|
|
$project = Project::where('category_id','=',$id)->get(); |
|
59
|
|
|
return view('project.ByCategory',compact('project'))->with($data); |
|
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* |
|
65
|
|
|
*/ |
|
66
|
|
|
|
|
67
|
|
|
public function random() |
|
68
|
|
|
{ |
|
69
|
|
|
$data = [ |
|
70
|
|
|
|
|
71
|
|
|
'active1' => Project::findOrFail(1), |
|
72
|
|
|
'project' => Project::all()->random(3), |
|
73
|
|
|
]; |
|
74
|
|
|
|
|
75
|
|
|
return view('project.random')->with($data); |
|
|
|
|
|
|
76
|
|
|
|
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Show the form for creating a new resource. |
|
84
|
|
|
* |
|
85
|
|
|
* @return Response |
|
86
|
|
|
*/ |
|
87
|
|
|
public function create(Request $Project) |
|
88
|
|
|
{ |
|
89
|
|
|
|
|
90
|
|
|
//dd($Project); |
|
91
|
|
|
//dd($Project['case_from1']); |
|
|
|
|
|
|
92
|
|
|
$id_user = Auth::user()->id; |
|
93
|
|
|
$id_creator = DB::table('creators')->where('user_id', $id_user)->first(); |
|
94
|
|
|
$id_creator = $id_creator->id; |
|
95
|
|
|
$validator = Validator::make($Project->all(), [ |
|
96
|
|
|
'project_title' => 'required|max:25', |
|
97
|
|
|
'project_video_cover' => 'required', |
|
98
|
|
|
'text_option' => 'required|max:200', |
|
99
|
|
|
'text_option2' => 'required', |
|
100
|
|
|
'inputCover1' => 'required|max:700|mimes:jpeg,bmp,png', |
|
101
|
|
|
'inputCover2' => 'required|max:700|mimes:jpeg,bmp,png', |
|
102
|
|
|
'inputCover3' => 'required|max:700|mimes:jpeg,bmp,png', |
|
103
|
|
|
'case_mesto' => 'required', |
|
104
|
|
|
'pod_razdel' => 'required', |
|
105
|
|
|
]); |
|
106
|
|
|
|
|
107
|
|
|
if ($validator->fails()) { |
|
108
|
|
|
return redirect('/new') |
|
109
|
|
|
->withInput() |
|
110
|
|
|
->withErrors($validator); |
|
111
|
|
|
} |
|
112
|
|
|
if ($Project->hasFile('inputCover1') && $Project->hasFile('inputCover2') |
|
113
|
|
|
&& $Project->hasFile('inputCover3')) |
|
114
|
|
|
{ |
|
115
|
|
|
$new_project = new Project(); |
|
116
|
|
|
$new_project->title = $Project->project_title; |
|
|
|
|
|
|
117
|
|
|
$link = $Project->project_video_cover; |
|
118
|
|
|
$pos = strpos($link,"watch?v="); |
|
119
|
|
|
if ($pos != 0){ |
|
120
|
|
|
$link = substr_replace($link,"embed/",$pos,8); |
|
121
|
|
|
} |
|
122
|
|
|
$new_project->video_link = $link; |
|
|
|
|
|
|
123
|
|
|
$new_project ->option1 = $Project->text_option; |
|
|
|
|
|
|
124
|
|
|
$new_project ->option2 = $Project->text_option2; |
|
|
|
|
|
|
125
|
|
|
$new_project ->mesto = $Project->case_mesto; |
|
|
|
|
|
|
126
|
|
|
$new_project ->teg = $Project->pod_razdel; |
|
|
|
|
|
|
127
|
|
|
$new_project->creator_id = $id_creator ; |
|
|
|
|
|
|
128
|
|
|
$new_project->category_id = $Project->chooseCategory; |
|
|
|
|
|
|
129
|
|
|
$new_project->duration = $Project->date_okanchenie; |
|
|
|
|
|
|
130
|
|
|
$new_project->save(); |
|
131
|
|
|
|
|
132
|
|
|
$id_project = $new_project->id; |
|
|
|
|
|
|
133
|
|
|
|
|
134
|
|
|
$fileType1 = $Project->file('inputCover1')->getClientOriginalExtension(); |
|
135
|
|
|
$fileType2 = $Project->file('inputCover2')->getClientOriginalExtension(); |
|
136
|
|
|
$fileType3 = $Project->file('inputCover2')->getClientOriginalExtension(); |
|
137
|
|
|
$fname = Auth::user()->name.$Project->title; |
|
138
|
|
|
$fileName1 = $fname.rand(11111,99999).'.'.$fileType1; |
|
139
|
|
|
$fileName2 = $fname.rand(11111,99999).'.'.$fileType2; |
|
140
|
|
|
$fileName3 = $fname.rand(11111,99999).'.'.$fileType3; |
|
141
|
|
|
$documentRoot = 'images/'; |
|
142
|
|
|
$Project->file('inputCover1')->move($documentRoot,$fileName1); |
|
143
|
|
|
$Project->file('inputCover2')->move($documentRoot,$fileName2); |
|
144
|
|
|
$Project->file('inputCover3')->move($documentRoot,$fileName3); |
|
145
|
|
|
|
|
146
|
|
|
$image1 = new Image; |
|
147
|
|
|
$image1->image_name = $fileName1; |
|
|
|
|
|
|
148
|
|
|
$image1->project_id = $id_project; |
|
|
|
|
|
|
149
|
|
|
$image1->save(); |
|
150
|
|
|
$image2 = new Image; |
|
151
|
|
|
$image2->image_name = $fileName2; |
|
|
|
|
|
|
152
|
|
|
$image2->project_id = $id_project; |
|
|
|
|
|
|
153
|
|
|
$image2->save(); |
|
154
|
|
|
$image3 = new Image; |
|
155
|
|
|
$image3->image_name = $fileName3; |
|
|
|
|
|
|
156
|
|
|
$image3->project_id = $id_project; |
|
|
|
|
|
|
157
|
|
|
$image3->save(); |
|
158
|
|
|
|
|
159
|
|
|
for ($i = 1; $i <= $Project->number; $i++) { |
|
160
|
|
|
$ob = new Condition(); |
|
161
|
|
|
$ob->startMoney = $Project['case_from'.$i]; |
|
|
|
|
|
|
162
|
|
|
$ob->endMoney = $Project['case_to'.$i]; |
|
|
|
|
|
|
163
|
|
|
$ob->description = $Project['u_text'.$i]; |
|
|
|
|
|
|
164
|
|
|
$ob->number = $Project['predel'.$i]; |
|
|
|
|
|
|
165
|
|
|
$ob->project_id = $id_project; |
|
|
|
|
|
|
166
|
|
|
$ob->save(); |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
return redirect ('/show/'.$id_project); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
return redirect ('/new'); |
|
173
|
|
|
|
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* Store a newly created resource in storage. |
|
178
|
|
|
* |
|
179
|
|
|
* @param \Illuminate\Http\Request $request |
|
180
|
|
|
* @return Response |
|
181
|
|
|
*/ |
|
182
|
|
|
public function store(Request $request) |
|
|
|
|
|
|
183
|
|
|
{ |
|
184
|
|
|
|
|
185
|
|
|
} |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* Display the specified resource. |
|
189
|
|
|
* |
|
190
|
|
|
* @param int $id |
|
191
|
|
|
* @return Response |
|
192
|
|
|
*/ |
|
193
|
|
|
public function show($id) |
|
194
|
|
|
{ |
|
195
|
|
|
$project = Project::findOrFail($id); |
|
196
|
|
|
$bookmark_id = "none"; |
|
197
|
|
|
|
|
198
|
|
|
if(Auth::check()) { |
|
199
|
|
|
$id_user = Auth::user()->id; |
|
200
|
|
|
$results = DB::select('select id from bookmarks where project_id = ? AND user_id = ?', [$project->id,$id_user]); |
|
201
|
|
|
if($results) |
|
202
|
|
|
{ |
|
203
|
|
|
$bookmark_id = $results; |
|
204
|
|
|
} |
|
205
|
|
|
} |
|
206
|
|
|
$data = [ |
|
207
|
|
|
'pr' => Project::findOrFail($id), |
|
208
|
|
|
'image' => $project->image()->get(), |
|
209
|
|
|
'bookmark'=>$bookmark_id, |
|
210
|
|
|
'comments' => Comment::where('project_id','=',$id)->get(), |
|
211
|
|
|
'conditions' => Condition::findOrFail($id), |
|
212
|
|
|
]; |
|
213
|
|
|
// dd(Auth::user()->avatar); |
|
|
|
|
|
|
214
|
|
|
return view('project.info')->with($data); |
|
|
|
|
|
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
public function archive(){ |
|
218
|
|
|
$archive = Project::all(); |
|
219
|
|
|
return view('project.archive',compact('archive')); |
|
220
|
|
|
} |
|
221
|
|
|
|
|
222
|
|
|
/** |
|
223
|
|
|
* Show the form for editing the specified resource. |
|
224
|
|
|
* |
|
225
|
|
|
* @param int $id |
|
226
|
|
|
* @return Response |
|
227
|
|
|
*/ |
|
228
|
|
|
public function edit($id) |
|
|
|
|
|
|
229
|
|
|
{ |
|
230
|
|
|
// |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
/** |
|
234
|
|
|
* Update the specified resource in storage. |
|
235
|
|
|
* @return Response |
|
236
|
|
|
* @internal param Request $request |
|
237
|
|
|
* @internal param int $id |
|
238
|
|
|
*/ |
|
239
|
|
|
public function update() |
|
240
|
|
|
{ |
|
241
|
|
|
// |
|
242
|
|
|
return view('project.update'); |
|
243
|
|
|
} |
|
244
|
|
|
|
|
245
|
|
|
/** |
|
246
|
|
|
* Remove the specified resource from storage. |
|
247
|
|
|
* |
|
248
|
|
|
* @param int $id |
|
249
|
|
|
* @return Response |
|
250
|
|
|
*/ |
|
251
|
|
|
public function destroy($id) |
|
|
|
|
|
|
252
|
|
|
{ |
|
253
|
|
|
// |
|
254
|
|
|
} |
|
255
|
|
|
|
|
256
|
|
|
// public function comment($id){ |
|
|
|
|
|
|
257
|
|
|
// $project = Project::findOrFail($id); |
|
258
|
|
|
// $bookmark_id = "none"; |
|
259
|
|
|
// if(Auth::check()) { |
|
260
|
|
|
// $id_user = Auth::user()->id; |
|
261
|
|
|
// $results = DB::select('select id from bookmarks where project_id = ? AND user_id = ?', [$project->id,$id_user]); |
|
262
|
|
|
// if($results) |
|
263
|
|
|
// { |
|
264
|
|
|
// $bookmark_id = $results; |
|
265
|
|
|
// } |
|
266
|
|
|
// } |
|
267
|
|
|
// $data = ['pr' => Project::findOrFail($id),'image' => $project->image()->get(),'bookmark'=>$bookmark_id]; |
|
268
|
|
|
// return view('project.comment')->with($data); |
|
269
|
|
|
// } |
|
270
|
|
|
public function commentPost($id , Request $request){ |
|
271
|
|
|
$comment = new Comment(); |
|
272
|
|
|
$comment->user_id = Auth::user()->id; |
|
|
|
|
|
|
273
|
|
|
$comment->project_id = $id; |
|
|
|
|
|
|
274
|
|
|
$comment->text = $request['text']; |
|
|
|
|
|
|
275
|
|
|
$comment->save(); |
|
276
|
|
|
return redirect(url('show',$id)); |
|
|
|
|
|
|
277
|
|
|
} |
|
278
|
|
|
|
|
279
|
|
|
|
|
280
|
|
|
} |
|
281
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.