Skip to content

Commit

Permalink
Merge pull request #15 from JamesMcLennan/Development
Browse files Browse the repository at this point in the history
Assignment 1 Code Complete
  • Loading branch information
JamesMcLennan authored Aug 19, 2017
2 parents acecc63 + b168f44 commit e6ec205
Show file tree
Hide file tree
Showing 131 changed files with 23,027 additions and 455 deletions.
19 changes: 19 additions & 0 deletions app/Comments.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Comments extends Model
{
protected $fillable = [
'comment', 'customer_id', 'ticket_id',
];
public function ticket_id() {
return $this->belongsTo('App\CustomerQuery');
}

public function message() {
return $this->belongsTo('App\Customer', 'customer_id','id');
}
}
20 changes: 20 additions & 0 deletions app/Customer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Customer extends Model
{
protected $fillable = [
'name', 'email', 'phoneNum', 'program',
];

public function customer_queries() {
return $this->hasMany('App\CustomerQuery');
}

public function comments() {
return $this->hasMany('App\Comments');
}
}
21 changes: 21 additions & 0 deletions app/CustomerQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class CustomerQuery extends Model
{
protected $fillable = [
'serviceArea', 'workArea', 'problemDescription', 'problemStatus',
'problemSeverity', 'comments', 'hardwareType', 'softwareType',
];

public function customer() {
return $this->belongsTo('App\Customer');
}

public function comments() {
return $this->hasMany('App\Comments');
}
}
8 changes: 8 additions & 0 deletions app/Exceptions/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
use Exception;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Psr\Log\InvalidArgumentException;
use Illuminate\Support\Facades\Log;
use Illuminate\Http\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class Handler extends ExceptionHandler
{
Expand Down Expand Up @@ -44,6 +48,10 @@ public function report(Exception $exception)
*/
public function render($request, Exception $exception)
{
if ($exception instanceof NotFoundHttpException or $exception instanceof \InvalidArgumentException) {
Log::alert('404 Page from attempted path - '.$request->path());
return response()->view('errors.404', [], 404);
}
return parent::render($request, $exception);
}

Expand Down
110 changes: 110 additions & 0 deletions app/Http/Controllers/AdminQueryController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php

namespace App\Http\Controllers;

use App\Customer;
use App\Comments;
use Illuminate\Support\Facades\Log;
use Illuminate\Http\Request;
use App\Http\Requests\CreateQueryRequest;
use App\Http\Requests\UpdateQueryRequest;
use App\Http\Requests\FilterRequest;
use App\CustomerQuery;

class AdminQueryController extends Controller
{
public function index()
{
$tickets = CustomerQuery::all();
return view('pages.admin.adminRequestService.index', compact('tickets'));
}

public function filter(FilterRequest $request)
{
$allRequest = $request->all();
Log::info('ADMIN - Search Request made for: '.$allRequest['emailText']);
$customer = Customer::all()->where('email', $allRequest['emailText'])->first();
if(is_null($customer))
{
Log::info('ADMIN - Search Request Failed: No customer found.');
$tickets = CustomerQuery::all();
return redirect('pages/admin/adminRequestService/')->with('fail', 'User does not exist')->with('tickets', $tickets);
}
$tickets = CustomerQuery::all()->where('customer_id', $customer->id);
Log::info('ADMIN - Search Request Successful: Returning '.$tickets->count().' cases!');
return view('pages/admin/adminRequestService/index')->with('tickets', $tickets);
}

public function show($id) {
$ticket = CustomerQuery::find($id);
//Test DB to check if comments exist in case.
$comments = Comments::all()->where('ticket_id', $ticket->id)->first();

if(is_null($comments))
{
//Comments do not exist for case.
$comments = null;
}
else{
//A comment does exist for case, create query for all comments.
$comments = Comments::all()->where('ticket_id', $ticket->id);
}
return view('pages.admin.adminRequestService.show', compact('ticket', 'comments'));
}

/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
*/
public function edit($id)
{
$ticket = CustomerQuery::find($id);
$comments = Comments::all()->where('ticket_id', $ticket->id);
return view('pages.admin.adminRequestService.edit')->with('ticket', $ticket)->with('comments', $comments);
}
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update($id, UpdateQueryRequest $request)
{
$allRequest = $request->all();

$ticket = CustomerQuery::find($id);
$ticket->problemStatus = $allRequest['problemStatus'];
$ticket->problemSeverity = $allRequest['problemSeverity'];
$ticket->save();

$checkIfResolved = $ticket->problemStatus;
if($checkIfResolved === "Resolved")
{
$comments = new Comments();
$comments->comment = "Hi ".$ticket->customer->name.", our team has marked your case as resolved.
Please review the case and close if you feel we have resolved your query sufficiently.";
$comments->ticket_id = $id;
$comments->adminComment = 'RMITServiceNow';
$comments->save();
Log::info('ADMIN - Update Request Successful: Admin has closed case, ID: '.$ticket->id);
}
$checkIfComment = $allRequest['comments'];
/**
* Check if the comment has been input.
* If yes, add comment to DB and save.
* If no, disregard creating comment.
*/
if(!is_null($checkIfComment)) {
$comments = new Comments();
$comments->comment = $checkIfComment;
$comments->ticket_id = $id;
$comments->adminComment = 'RMITServiceNow';
$comments->save();
Log::info('ADMIN - Update Request Successful: Admin has added comments to case, ID: '.$ticket->id);
}
Log::info('ADMIN - Update Request Successful: Admin has updated case, ID: '.$ticket->id);
return redirect()->back()->with('success','Case has been updated successfully');
}
}
161 changes: 161 additions & 0 deletions app/Http/Controllers/CustomerQueryController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
<?php
namespace App\Http\Controllers;
use App\Customer;
use App\Comments;
use Illuminate\Http\Request;
use App\Http\Requests\CreateQueryRequest;
use App\Http\Requests\UpdateQueryRequest;
use App\Http\Requests\FilterRequest;
use Illuminate\Support\Facades\Log;
use App\CustomerQuery;

class CustomerQueryController extends Controller
{
public function index()
{
$tickets = CustomerQuery::all();
return view('pages.requestService.index', compact('tickets'));
}

public function create()
{
$query = new CustomerQuery;
return view('pages.requestService.create', ['query' => $query ]);
}

public function store(CreateQueryRequest $request)
{
$allRequest = $request->all();

//Check the email to find if user has already submitted query
$email = $allRequest['email'];
$customerExists = Customer::where('email', $email)->first();

$customer = null;

if(!$customerExists)
{
$customer = new Customer();
$customer->name = $allRequest['name'];
$customer->email = $email;
$customer->phoneNum = $allRequest['phoneNum'];
$customer->program = $allRequest['program'];
$customer->save();
}
else {
$customer = $customerExists;
}

$query = new CustomerQuery();
$query->serviceArea = $allRequest['serviceArea'];
$query->workArea = $allRequest['workArea'];
$query->problemDescription = $allRequest['problemDescription'];
$query->hardwareType = $allRequest['hardwareType'];
$query->softwareType = $allRequest['softwareType'];
$query->problemStatus = "Pending";
$query->problemSeverity = "Not Specified";
$query->customer_id = $customer->id;
$query->save();

return redirect('pages/requestService/create')->with('success','Service requested
successfully. Our team will be in touch within 72 hours.');
}

public function show($id) {
$ticket = CustomerQuery::find($id);
//Test DB to check if comments exist in case.
$comments = Comments::all()->where('ticket_id', $ticket->id)->first();
$user = session('email');
Log::info('CUSTOMER - Show Case: '.$user);

if(is_null($comments))
{
//Comments do not exist for case.
$comments = null;
}
else{
//A comment does exist for case, create query for all comments.
$comments = Comments::all()->where('ticket_id', $ticket->id);
}
return view('pages.requestService.show', compact('ticket', 'comments', 'user'));
}

/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
*/
public function edit($id)
{
$ticket = CustomerQuery::find($id);
$comments = Comments::all()->where('ticket_id', $ticket->id);
return view('pages.requestService.edit')->with('ticket', $ticket)->with('comments', $comments);
}
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update($id, UpdateQueryRequest $request)
{
$allRequest = $request->all();

$ticket = CustomerQuery::find($id);
$ticket->serviceArea = $allRequest['serviceArea'];
$ticket->workArea = $allRequest['workArea'];
$ticket->problemDescription = $allRequest['problemDescription'];
$ticket->hardwareType = $allRequest['hardwareType'];
$ticket->softwareType = $allRequest['softwareType'];
$ticket->save();
Log::info('CUSTOMER - Updated details for ID:'.$id);

$checkIfComment = $allRequest['comments'];
/**
* Check if the comment has been input.
* If yes, add comment to DB and save.
* If no, disregard creating comment.
*/
if(!is_null($checkIfComment)) {
$comments = new Comments();
$comments->comment = $checkIfComment;
$comments->ticket_id = $id;
$comments->customer_id = $ticket->customer_id;
$comments->save();
Log::info('CUSTOMER - Comment added for ID:'.$id);
}
return redirect()->back()->with('success','Case has been updated successfully');
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
CustomerQuery::find($id)->delete();
Log::info('CUSTOMER - Delete Request Successful: Customer has closed their case, ID: '.$id);
return view('pages.requestService.destroy');
}

public function getUserQueries(FilterRequest $request)
{
$allRequest = $request->all();

Log::info('CUSTOMER - Attempt to view queries for email: '.$allRequest['emailText']);
$customer = Customer::all()->where('email', $allRequest['emailText'])->first();
if(is_null($customer))
{
Log::info('CUSTOMER - Attempt Failed: No customer found.');
return redirect()->back()->with('fail', 'This account has not submitted a query.');
}
$tickets = CustomerQuery::all()->where('customer_id', $customer->id);
Log::info('SESSION - Added customer variable to "user"');
Log::info('CUSTOMER - Retrieving data for user');
$request->session()->put('email', $customer->email);
$request->session()->put('user', $tickets);
return view('pages.trackProgress.userQueries', compact('tickets'));
}
}
20 changes: 20 additions & 0 deletions app/Http/Controllers/PageController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class PageController extends Controller
{
public function home() {
return view('pages.home');
}

public function adminPage() {
return view('pages.admin.auth');
}

public function trackprogress() {
return view('pages.trackProgress.credentialsCheck');
}
}
Loading

0 comments on commit e6ec205

Please sign in to comment.