<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Http\Requests\MassDestroyEmployeeLanguageRequest;
use App\Http\Requests\StoreEmployeeLanguageRequest;
use App\Http\Requests\UpdateEmployeeLanguageRequest;
use App\Models\Employee;
use App\Models\EmployeeLanguage;
use App\Models\Language;
use Gate;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
use Yajra\DataTables\Facades\DataTables;

class EmployeeLanguagesController extends Controller
{
    public function index(Request $request)
    {
        abort_if(Gate::denies('employee_language_access'), Response::HTTP_FORBIDDEN, '403 Forbidden');

        if ($request->ajax()) {
            $query = EmployeeLanguage::with(['employee', 'languages', 'created_by'])->select(sprintf('%s.*', (new EmployeeLanguage)->table));
            $table = Datatables::of($query);

            $table->addColumn('placeholder', '&nbsp;');
            $table->addColumn('actions', '&nbsp;');

            $table->editColumn('actions', function ($row) {
                $viewGate      = 'employee_language_show';
                $editGate      = 'employee_language_edit';
                $deleteGate    = 'employee_language_delete';
                $crudRoutePart = 'employee-languages';

                return view('partials.datatablesActions', compact(
                    'viewGate',
                    'editGate',
                    'deleteGate',
                    'crudRoutePart',
                    'row'
                ));
            });

            $table->editColumn('id', function ($row) {
                return $row->id? $row->id : "";
            });
            $table->addColumn('employee_employee_number', function ($row) {
                return $row->employee? $row->employee->employee_number : '';
            });

            $table->addColumn('languages_name', function ($row) {
                return $row->languages? $row->languages->name : '';
            });

            $table->editColumn('reading', function ($row) {
                return $row->reading? EmployeeLanguage::READING_SELECT[$row->reading] : '';
            });
            $table->editColumn('speaking', function ($row) {
                return $row->speaking? EmployeeLanguage::SPEAKING_SELECT[$row->speaking] : '';
            });
            $table->editColumn('writing', function ($row) {
                return $row->writing? EmployeeLanguage::WRITING_SELECT[$row->writing] : '';
            });
            $table->editColumn('listening', function ($row) {
                return $row->listening? EmployeeLanguage::LISTENING_SELECT[$row->listening] : '';
            });

            $table->rawColumns(['actions', 'placeholder', 'employee', 'languages']);

            return $table->make(true);
        }

        return view('admin.employeeLanguages.index');
    }

    public function create()
    {
        abort_if(Gate::denies('employee_language_create'), Response::HTTP_FORBIDDEN, '403 Forbidden');

        $employees = Employee::all()->pluck('employee_number', 'id')->prepend(trans('global.pleaseSelect'), '');

        $languages = Language::all()->pluck('name', 'id')->prepend(trans('global.pleaseSelect'), '');

        return view('admin.employeeLanguages.create', compact('employees', 'languages'));
    }

    public function store(StoreEmployeeLanguageRequest $request)
    {
        $employeeLanguage = EmployeeLanguage::create($request->all());

        return redirect()->route('admin.employee-languages.index');
    }

    public function edit(EmployeeLanguage $employeeLanguage)
    {
        abort_if(Gate::denies('employee_language_edit'), Response::HTTP_FORBIDDEN, '403 Forbidden');

        $employees = Employee::all()->pluck('employee_number', 'id')->prepend(trans('global.pleaseSelect'), '');

        $languages = Language::all()->pluck('name', 'id')->prepend(trans('global.pleaseSelect'), '');

        $employeeLanguage->load('employee', 'languages', 'created_by');

        return view('admin.employeeLanguages.edit', compact('employees', 'languages', 'employeeLanguage'));
    }

    public function update(UpdateEmployeeLanguageRequest $request, EmployeeLanguage $employeeLanguage)
    {
        $employeeLanguage->update($request->all());

        return redirect()->route('admin.employee-languages.index');
    }

    public function show(EmployeeLanguage $employeeLanguage)
    {
        abort_if(Gate::denies('employee_language_show'), Response::HTTP_FORBIDDEN, '403 Forbidden');

        $employeeLanguage->load('employee', 'languages', 'created_by');

        return view('admin.employeeLanguages.show', compact('employeeLanguage'));
    }

    public function destroy(EmployeeLanguage $employeeLanguage)
    {
        abort_if(Gate::denies('employee_language_delete'), Response::HTTP_FORBIDDEN, '403 Forbidden');

        $employeeLanguage->delete();

        return back();
    }

    public function massDestroy(MassDestroyEmployeeLanguageRequest $request)
    {
        EmployeeLanguage::whereIn('id', request('ids'))->delete();

        return response(null, Response::HTTP_NO_CONTENT);
    }
}
XHTML, PHP, Validation and Browsers
Posted by Billy | Filed under Apache, Browsers, CSS, PHP, XHTML
Recently for a school project I was working on, I had to develop an XTHML 1.1 Strict validated page and a validated CSS to style the page. This was not a problem in and of itself, however there were several problems that I encountered while trying to serve the pages to different browsers and to the W3C’s validator.
What this post will attempt to do is cover several items that I found necessary to accomplish a page that displayed properly in Internet Explorer 7, Firefox 2, Netscape 9, SeaMonkey, Opera and Safari for Windows. I have not fully tested the resulting pages on the Linux or Mac platforms yet, so I will attempt to do that when time permits. I did however use BrowserCamp to get a screen shot of what it looks like in Safari 2.0.4 and there were some CSS issues (I assume anyway).
The first thing that happened when I attempted to view the page in Firefox was that the body background color did not fill the entire page as it does on IE. The problem, it appears, is caused from the implementation of the Body tag in an XHTML 1.1 doctype. The body tag has been revamped so that it truly is only the content area of the size specified. Thus, I had specified a body of 770 pixels wide, therefore in Firefox, which implements the XHTML standard, showed a body background of 770 pixels wide rather than filling the screen. In IE, the entire body backgorund filled the whitespace. Why? To answer that I have to take you on a journey into mime-types, doctypes and standards compliance browsers…….Let’s go.
The XHTML 1.1 specification denotes that all documents of this type SHOULD be sent with the application/xhtml+xml mime-type. Huh? What that means is the server, whether through the configuration of it (in my case apache), through.htaccess or programatically should send the document as the mime-type of application/xhtml+xml. The problem is, my server was configured to send all documents as text/html if the extension and/or mime-type were not known. No big deal, I added the supporting mime-type in my conf files and specified it for documents with an.xhtml extension only since I host several sites on here that all use.htm,.html or.php extensions. I didn’t want to specify a mime-type for a standard file extension and start sending regular HTML documents as application/xhtml+xml.
So that takes me to the next phase of this project. I found that after I did this, the validator stopped complaining on files with.xhtml extension, but that files with.php were still being sent as text/html. I could not send all my PHP files on my various sites as application/xhtml+xml, so I couldn’t register.php as that mime-type. What I could do though was register PHP files in this current directory that I was serving them out of as application/xhtml+xml via.htaccess. Sounds great right? Sovles the problem right? Wrong. Unfortunately when I enabled this, I found out that it then bypassed the PHP interpreter and the pages would not render any PHP code in them due to that. So,