Skip to content

Commit

Permalink
Merge pull request #178 from JuanVqz/manage_schools
Browse files Browse the repository at this point in the history
responsibilities separate schools and academic settings
  • Loading branch information
changeweb authored Jul 26, 2019
2 parents cec56f9 + 2cdfcdb commit b381939
Show file tree
Hide file tree
Showing 27 changed files with 837 additions and 573 deletions.
97 changes: 23 additions & 74 deletions app/Http/Controllers/SchoolController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace App\Http\Controllers;

use App\User;
use App\School;
use App\Myclass;
use App\Section;
use App\User;
use App\Department;
//use App\Http\Resources\SchoolResource;
use Illuminate\Http\Request;
use App\Http\Requests\SchoolRequest;

class SchoolController extends Controller
{
Expand All @@ -17,28 +17,10 @@ class SchoolController extends Controller
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$schools = School::all();
$classes = Myclass::all();
$sections = Section::all();
$teachers = User::join('departments', 'departments.id', '=', 'users.department_id')
->where('role', 'teacher')
->orderBy('name','ASC')
->where('active', 1)
->get();
$departments = Department::bySchool(\Auth::user()->school_id)->get();
return view('school.create-school', compact('schools', 'classes', 'sections', 'teachers', 'departments'));
}
public function index() {
$schools = School::orderBy('created_at', 'desc')->paginate();

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
//
return view('schools.index', compact('schools'));
}

/**
Expand All @@ -47,23 +29,18 @@ public function create()
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
public function store(SchoolRequest $request)
{
$request->validate([
'school_name' => 'required|string|max:255',
'school_medium' => 'required',
'school_about' => 'required',
'school_established' => 'required',
]);
$tb = new School;
$tb->name = $request->school_name;
$tb->established = $request->school_established;
$tb->about = $request->school_about;
$tb->medium = $request->school_medium;
$tb->code = date("y").substr(number_format(time() * mt_rand(),0,'',''),0,6);
$tb->theme = 'flatly';
$tb->save();
return back()->with('status', __('Created'));
School::create([
'name' => $request->name,
'established' => $request->established,
'about' => $request->about,
'medium' => $request->medium,
'code' => date("y").substr(number_format(time() * mt_rand(), 0, '', ''), 0, 6),
'theme' => 'flatly'
]);

return redirect()->route('schools.index')->with('status', __('Created'));
}

/**
Expand All @@ -78,25 +55,16 @@ public function show($school_id)
return view('school.admin-list',compact('admins'));
}

/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit(Request $request, $school_id)
{
$school = School::find($school_id);
if (!$school) {
abort(404);
}
if ($request->isMethod('post')) {
public function edit(School $school) {
return view('schools.edit', compact('school'));
}

public function update(Request $request, School $school) {
$school->name = $request->name;
$school->about = $request->about;
$school->theme = $request->school_theme;
$school->save();
}
return view('school.edit-school',compact('school'));

return redirect()->route('schools.index');
}

public function addDepartment(Request $request){
Expand All @@ -116,25 +84,6 @@ public function changeTheme(Request $request){
$tb->save();
return back();
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$tb = School::find($id);
$tb->name = $request->name;
$tb->about = $request->about;
//$tb->code = $request->code;
return ($tb->save())?response()->json([
'status' => 'success'
]):response()->json([
'status' => 'error'
]);
}

/**
* Remove the specified resource from storage.
Expand Down
27 changes: 27 additions & 0 deletions app/Http/Controllers/SettingController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace App\Http\Controllers;

use App\User;
use App\School;
use App\Myclass;
use App\Section;
use App\Department;
use Illuminate\Http\Request;

class SettingController extends Controller
{
public function index() {
$school = \Auth::user()->school;
$classes = Myclass::all();
$sections = Section::all();
$departments = Department::bySchool(\Auth::user()->school_id)->get();
$teachers = User::join('departments', 'departments.id', '=', 'users.department_id')
->where('role', 'teacher')
->orderBy('name', 'ASC')
->where('active', 1)
->get();

return view('settings.index', compact('school', 'classes', 'sections', 'departments', 'teachers'));
}
}
33 changes: 33 additions & 0 deletions app/Http/Requests/SchoolRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class SchoolRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'required|string|max:255',
'medium' => 'required',
'about' => 'required',
'established' => 'required',
];
}
}
5 changes: 4 additions & 1 deletion app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Providers;

use Laravel\Dusk\DuskServiceProvider;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;
use Illuminate\Http\Resources\Json\Resource;
Expand All @@ -26,6 +27,8 @@ public function boot()
*/
public function register()
{
//
if ($this->app->environment('local', 'testing')) {
$this->app->register(DuskServiceProvider::class);
}
}
}
11 changes: 6 additions & 5 deletions database/factories/SchoolFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@

$factory->define(School::class, function (Faker $faker) {
return [
'name' => $faker->name,
'about' => $faker->sentences(3, true),
'medium' => $faker->randomElement(['bangla', 'english']),
'code' => date("y").substr(number_format(time() * mt_rand(),0,'',''),0,6),
'theme' => 'flatly',
'name' => $faker->name,
'about' => $faker->sentences(3, true),
'medium' => $faker->randomElement(['bangla', 'english']),
'code' => date("y").substr(number_format(time() * mt_rand(),0,'',''),0,6),
'established' => $faker->name,
'theme' => 'flatly',
];
});
7 changes: 4 additions & 3 deletions resources/lang/es-MX.json
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@
"out of": "de",
"print": "imprimir",
"row No": "fila Num.",
"section": "sección",
"uploaded": "cargado"
}
"section": "Sección",
"uploaded": "Cargado",
"Academic Settings": "Configuración Académica"
}
4 changes: 2 additions & 2 deletions resources/views/auth/register.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<div class="col-md-3" id="side-navbar">
<ul class="nav flex-column">
<li class="nav-item active">
<a class="nav-link" href="{{ url('create-school') }}"><i class="material-icons">gamepad</i> <span class="nav-link-text">@lang('Back to Manage School')</span></a>
<a class="nav-link" href="{{ route('schools.index') }}"><i class="material-icons">gamepad</i> <span class="nav-link-text">@lang('Back to Manage School')</span></a>
</li>
</ul>
</div>
Expand Down Expand Up @@ -547,4 +547,4 @@
$("#registerForm").submit();
});
</script>
@endsection
@endsection
2 changes: 1 addition & 1 deletion resources/views/layouts/leftside-menubar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class="nav-link-text">@lang('Active Exams')</span></a>
</li>
<li class="nav-item" style="border-bottom: 1px solid #dbd8d8;"></li>
<li class="nav-item">
<a class="nav-link" href="{{ url('create-school') }}"><i class="material-icons">settings</i> <span class="nav-link-text">@lang('Academic Settings')</span></a>
<a class="nav-link" href="{{ route('settings.index') }}"><i class="material-icons">settings</i> <span class="nav-link-text">@lang('Academic Settings')</span></a>
</li>
<li class="nav-item dropdown">
<a role="button" href="#" class="nav-link" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i
Expand Down
80 changes: 0 additions & 80 deletions resources/views/layouts/master/create-school-form.blade.php

This file was deleted.

4 changes: 3 additions & 1 deletion resources/views/masters/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
<div class="page-panel-title">@lang('Dashboard')</div>

<div class="panel-body">
<a class="btn btn-danger btn-lg btn-block" href="{{url('create-school')}}" role="button">@lang('Manage Schools')</a>
<a class="btn btn-danger btn-lg btn-block" href="{{ route('schools.index') }}" role="button">
@lang('Manage Schools')
</a>
</div>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions resources/views/school/admin-list.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@endif
<ul class="nav flex-column">
<li class="nav-item">
<a class="nav-link" href="{{url('create-school')}}"><i class="material-icons">gamepad</i> @lang('Manage School')</a>
<a class="nav-link" href="{{ route('schools.index') }}"><i class="material-icons">gamepad</i> @lang('Manage School')</a>
</li>
</ul>
</div>
Expand Down Expand Up @@ -75,4 +75,4 @@
</div>
</div>
</div>
@endsection
@endsection
Loading

0 comments on commit b381939

Please sign in to comment.