Skip to content

Commit d5349ce

Browse files
committed
Added createwithvalues route. Moved $ticket_owner_id to $a_current array
1 parent cc71503 commit d5349ce

3 files changed

Lines changed: 66 additions & 31 deletions

File tree

src/Controllers/TicketsController.php

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -644,9 +644,37 @@ protected function getCacheList($list)
644644
*/
645645
public function create()
646646
{
647-
$data = $this->create_edit_data();
647+
$data = $this->create_edit_data();
648648

649-
$data['ticket_owner_id'] = auth()->user()->id;
649+
$data['categories'] = $this->member->findOrFail(auth()->user()->id)->getNewTicketCategories();
650+
651+
return view('panichd::tickets.createedit', $data);
652+
}
653+
654+
/**
655+
* Open Ticket creation form with one or many parameters pre-setted by URL
656+
*
657+
* @return Response
658+
*/
659+
public function create_with_values($parameters)
660+
{
661+
$data = $this->create_edit_data();
662+
663+
// Get URL parameters and replace a_current array with them
664+
$a_temp = explode('/', $parameters);
665+
$a_parameters = [];
666+
667+
if (count($a_temp) % 2 == 0){
668+
$key = "";
669+
foreach($a_temp as $param){
670+
if ($key == ""){
671+
$key = $param;
672+
}else{
673+
$data['a_current'][$key] = $param;
674+
$key = "";
675+
}
676+
}
677+
}
650678

651679
$data['categories'] = $this->member->findOrFail(auth()->user()->id)->getNewTicketCategories();
652680

@@ -664,8 +692,6 @@ public function edit($id)
664692

665693
$data['ticket'] = $ticket;
666694

667-
$data['ticket_owner_id'] = $data['ticket']->user_id;
668-
669695
$data['categories'] = $this->member->findOrFail(auth()->user()->id)->getEditTicketCategories();
670696

671697
return view('panichd::tickets.createedit', $data);
@@ -700,8 +726,6 @@ public function edit_with_values($id, $parameters)
700726

701727
$data['ticket'] = $ticket;
702728

703-
$data['ticket_owner_id'] = $data['ticket']->user_id;
704-
705729
$data['categories'] = $this->member->findOrFail(auth()->user()->id)->getEditTicketCategories();
706730

707731
return view('panichd::tickets.createedit', $data);
@@ -726,7 +750,9 @@ public function create_edit_data($ticket = false, $a_parameters = false)
726750

727751
if (old('category_id')){
728752
// Form old values
729-
$a_current['complete'] = old('complete');
753+
$a_current['owner_id'] = old('owner_id');
754+
755+
$a_current['complete'] = old('complete');
730756

731757
$a_current['start_date'] = old ('start_date');
732758
$a_current['limit_date'] = old ('limit_date');
@@ -738,7 +764,9 @@ public function create_edit_data($ticket = false, $a_parameters = false)
738764

739765
}elseif($ticket){
740766
// Edition values
741-
$a_current['complete'] = $ticket->isComplete() ? "yes" : "no";
767+
$a_current['owner_id'] = $ticket->owner_id;
768+
769+
$a_current['complete'] = $ticket->isComplete() ? "yes" : "no";
742770
$a_current['status_id'] = $ticket->status_id;
743771

744772
$a_current['start_date'] = $ticket->start_date;
@@ -750,7 +778,9 @@ public function create_edit_data($ticket = false, $a_parameters = false)
750778
$a_current['agent_id'] = $ticket->agent_id;
751779
}else{
752780
// Defaults
753-
$a_current['complete'] = "no";
781+
$a_current['owner_id'] = auth()->user()->id;
782+
783+
$a_current['complete'] = "no";
754784

755785
$a_current['start_date'] = $a_current['limit_date'] = "";
756786

src/Views/tickets/createedit.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
<div class="{{ $u->currentLevel()==1 ? 'col-lg-10' : 'col-lg-9' }} level_class" data-level-1-class="col-lg-10" data-level-2-class="col-lg-9">
5656
<select name="owner_id" class="generate_default_select2 form-control" style="display: none; width: 100%">
5757
@foreach ($a_owners as $owner)
58-
<option value="{{ $owner->id }}" {{ $owner->id == $ticket_owner_id ? 'selected="selected"' : '' }}>{{ $owner->name . ($owner->email == "" ? ' ' . trans('panichd::lang.ticket-owner-no-email') : ' - ' . $owner->email) }}
58+
<option value="{{ $owner->id }}" {{ $owner->id == $a_current['owner_id'] ? 'selected="selected"' : '' }}>{{ $owner->name . ($owner->email == "" ? ' ' . trans('panichd::lang.ticket-owner-no-email') : ' - ' . $owner->email) }}
5959
@if ($setting->grab('departments_notices_feature'))
6060
@if ($owner->ticketit_department == '0')
6161
{{ ' - ' . trans('panichd::lang.create-ticket-notices') . ' ' . trans('panichd::lang.all-depts')}}

src/routes.php

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php
22

33
Route::group(['middleware' => \PanicHD\PanicHD\Helpers\LaravelVersion::authMiddleware()], function () use ($main_route, $main_route_path, $admin_route, $admin_route_path) {
4-
4+
55
//Route::group(['middleware' => '', function () use ($main_route) {
66

77
//Ticket public route
88
Route::get("$main_route_path/complete", 'PanicHD\PanicHD\Controllers\TicketsController@indexComplete')
99
->name("$main_route-complete");
10-
10+
1111
// Get newest tickets list
1212
Route::get("$main_route_path/newest", 'PanicHD\PanicHD\Controllers\TicketsController@indexNewest')
1313
->name("$main_route-newest")
@@ -20,10 +20,10 @@
2020
Route::get("$main_route_path/notices", function(){
2121
return view('panichd::notices.index');
2222
})->name("$main_route.notices");
23-
23+
2424
// Hide or show ticket to user
2525
Route::get("$main_route_path/hide/{value}/{ticket}", 'PanicHD\PanicHD\Controllers\TicketsController@hide')->name("$main_route.hide");
26-
26+
2727
$field_name = last(explode('/', $main_route_path));
2828
Route::resource($main_route_path, 'PanicHD\PanicHD\Controllers\TicketsController', [
2929
'names' => [
@@ -40,15 +40,20 @@
4040
],
4141
]);
4242

43+
// Open Ticket create page with one or more parameters set by URL
44+
Route::get("$main_route_path/createwithvalues/{parameters}", 'PanicHD\PanicHD\Controllers\TicketsController@create_with_values')
45+
->where('parameters', '(.*)')
46+
->name("$main_route.create-with-values");
47+
4348
// Open Ticket edit page with one or more parameters set by URL
4449
Route::get("$main_route_path/{id}/editwithvalues/{parameters}", 'PanicHD\PanicHD\Controllers\TicketsController@edit_with_values')
4550
->where('parameters', '(.*)')
4651
->name("$main_route.edit-with-values");
47-
52+
4853
// Attachment routes
4954
Route::get("$main_route_path/download-attachment/{attachment}", 'PanicHD\PanicHD\Controllers\TicketsController@downloadAttachment')
5055
->name("$main_route.download-attachment");
51-
56+
5257
Route::get("$main_route_path/view-attachment/{attachment}", 'PanicHD\PanicHD\Controllers\TicketsController@viewAttachment')
5358
->name("$main_route.view-attachment");
5459

@@ -78,7 +83,7 @@
7883
Route::get("$main_route_path/{id}/reopen", 'PanicHD\PanicHD\Controllers\TicketsController@reopen')
7984
->name("$main_route.reopen");
8085
//});
81-
86+
8287
// Returns permission_level for category_id
8388
Route::get("$main_route_path/permissionLevel/{category_id?}", [
8489
'as' => $main_route.'-permissionLevel',
@@ -88,7 +93,7 @@
8893
// Ticket list: Change agent for a ticket
8994
Route::patch("$main_route_path-change.agent", 'PanicHD\PanicHD\Controllers\TicketsController@changeAgent')
9095
->name("$main_route-change.agent");
91-
96+
9297
// Ticket list: Change priority for a ticket
9398
Route::patch("$main_route_path-change.priority", 'PanicHD\PanicHD\Controllers\TicketsController@changePriority')
9499
->name("$main_route-change.priority");
@@ -98,20 +103,20 @@
98103
// Send again comment (reply) notification
99104
Route::post("$main_route_path-notification.resend", 'PanicHD\PanicHD\Controllers\NotificationsController@notificationResend')
100105
->name("$main_route-notification.resend");
101-
106+
102107
//API return list of agents in particular category
103108
Route::get("$main_route_path/agents/list/{category_id?}/{ticket_id?}", [
104109
'as' => $main_route.'agentselectlist',
105110
'uses' => 'PanicHD\PanicHD\Controllers\TicketsController@agentSelectList',
106111
]);
107-
112+
108113
// Remove all filters
109114
Route::get("$main_route_path/filter/removeall/{list?}", 'PanicHD\PanicHD\Controllers\FiltersController@removeall')
110115
->name("$main_route-filter-removeall");
111116

112117
// Alter ticket filter
113118
Route::get("$main_route_path/filter/{filter}/{value}", 'PanicHD\PanicHD\Controllers\FiltersController@manage');
114-
119+
115120
// Use single filter in specified list
116121
Route::get("$main_route_path/filteronly/{filter}/{value}/{list}", 'PanicHD\PanicHD\Controllers\FiltersController@only')
117122
->name("$main_route-filteronly");
@@ -151,10 +156,10 @@
151156
'edit' => "$admin_route.priority.edit",
152157
],
153158
]);
154-
159+
155160
Route::post("$admin_route_path/priority/reorder", 'PanicHD\PanicHD\Controllers\PrioritiesController@reorder')
156161
->name("$admin_route.priority.reorder");
157-
162+
158163

159164
//Agents management routes (ex. http://url/panichd/agent)
160165
Route::resource("$admin_route_path/agent", 'PanicHD\PanicHD\Controllers\AgentsController', [
@@ -181,24 +186,24 @@
181186
'edit' => "$admin_route.category.edit",
182187
],
183188
]);
184-
189+
185190
// Members management routes (ex. http://url/panichd/member)
186191
Route::resource("$admin_route_path/member", 'PanicHD\PanicHD\Controllers\MembersController', [
187192
'names' => [
188193
'index' => "$admin_route.member.index",
189-
'store' => "$admin_route.member.store",
190-
'update' => "$admin_route.member.update",
191-
'destroy' => "$admin_route.member.destroy",
194+
'store' => "$admin_route.member.store",
195+
'update' => "$admin_route.member.update",
196+
'destroy' => "$admin_route.member.destroy",
192197
],
193198
]);
194-
199+
195200
//Departments management routes (ex. http://url/panichd/agent)
196201
Route::resource("$admin_route_path/notice", 'PanicHD\PanicHD\Controllers\NoticesController', [
197202
'names' => [
198203
'index' => "$admin_route.notice.index",
199-
'store' => "$admin_route.notice.store",
200-
'update' => "$admin_route.notice.update",
201-
'destroy' => "$admin_route.notice.destroy",
204+
'store' => "$admin_route.notice.store",
205+
'update' => "$admin_route.notice.update",
206+
'destroy' => "$admin_route.notice.destroy",
202207
],
203208
]);
204209

0 commit comments

Comments
 (0)