Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 8
CRAP
0.00% covered (danger)
0.00%
0 / 53
OrganisationController
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 8
182
0.00% covered (danger)
0.00%
0 / 53
 index
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 7
 create
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 3
 store
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 8
 show
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 3
 edit
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 3
 update
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 12
 destroy
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 3
 storeImage
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 14
<?php
namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\Admin\Organisation;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Storage;
use Intervention\Image\Facades\Image;
use Session;
use App\Helpers\AttendanceHelper;
class OrganisationController extends Controller
{
       /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        $title = '/Setup/Organisation';
        $backurl = route('home');
        // For Attendance Marking
        $val = AttendanceHelper::getAttendanceMarkValue();
        $valTeam = AttendanceHelper::getAttendanceTeam($request);
        $valUser = AttendanceHelper::getAttendanceUser($request);
        return view('administrationForms.Organisation.OrganisationForm',
        compact('title','backurl','val','valTeam','valUser'))->with('organisation',Organisation::first());
    }
    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        $title = '/Setup/Create Organisation';
        $backurl = route('organisation.index');
        return view('administrationForms.Organisation.organisationForm',compact('title','backurl'));
    }
    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        
        $validator = Validator::make($request->all(), [
               'organisation' => 'required|regex:/^[0-9(),.a-zA-Z ]+$/u|max:255',
               'address' =>  'required|regex:/^[0-9().,a-zA-Z ]+$/u|max:255'
        ]);
        if ($validator->fails())
            {
                return redirect()->route('organisation.index')->withErrors($validator);
            }
            else
            {
                $organisation = Organisation::create($request->only(['organisation','address']));
                $this->storeImage($request,$organisation->id);
                Session::flash('success', 'Add Organisation Successful!');
                return redirect()->route('organisation.index');
            }
        }
    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        $organisations = Organisation::find($id);
        return view('administrationForms.Organisation.OrganisationForm',
        compact($organisations))->with('organisation',Organisation::find($id));
    }
    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $organisations = Organisation::find($id);
        return view('administrationForms.Organisation.OrganisationForm',
        compact($organisations))->with('organisation',Organisation::find($id));
    }
    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        if(auth()->user()->can('Edit organization module')){
            $validator = Validator::make($request->all(), [
                'organisation' => 'required|regex:/^[0-9(),.a-zA-Z ]+$/u|max:255',
               'address' =>  'required|regex:/^[0-9().,a-zA-Z ]+$/u|max:255'
            ]);
            if ($validator->fails())
            {
                return redirect()->route('organisation.index')->withErrors($validator);
            }
            else
            {
                $organisations = Organisation::find($id);
                $organisations->update($request->only(['organisation','address']));
                $this->storeImage($request, $id);
                Session::flash('success', 'Organisation Updated Successfully!');
                return redirect()->route('organisation.index');
            }
        }else{
            Session::flash('warning', 'You do not have the permission to edit it!');
            return redirect()->route('organisation.index');
        }
    }
    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $organisation = Organisation::find($id);
        $organisation->delete();
        return redirect()->route('organisation.index')->with('success','Organisation Deleted Successfully');
    }
    private function storeImage($request,$id)
    {
        if($request->file('image')) //if image uploaded
        {
            $validator = Validator::make($request->all(), [
                'image' => 'sometimes|file|image|max:2048|mimes:jpeg,png,jpg'
            ]);
            if ($validator->fails())
                {
                    return;
                }
                else
                {
                    Storage::putFileAs(('public/orgLogo'),$request->file('image'),'orglogo.png');
                    $path = "orgLogo/orglogo.png";
                    $organisation = Organisation::Where('id',$id)->first();
                    $organisation->image =$path;
                    $organisation->save();
                    // open an image file
                    $img = Image::make('storage/'.$organisation->image);
                    // resize the instance
                    $img->resize(206,32);
                    $img->save();
                }
            }
        }
}