Skip to content

Commit

Permalink
Merge pull request #31 from achmadhadikurnia/master
Browse files Browse the repository at this point in the history
Add append, fix edit, and crud button on card-header
  • Loading branch information
andri-sudarmawijaya committed May 3, 2018
2 parents bccaf2e + 7d56da0 commit 83a3cca
Show file tree
Hide file tree
Showing 11 changed files with 1,037 additions and 584 deletions.
17 changes: 9 additions & 8 deletions src/Http/Controllers/JenisSekolahController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function index(Request $request)
if ($request->exists('filter')) {
$query->where(function($q) use($request) {
$value = "%{$request->filter}%";

$q->where('jenis_sekolah', 'like', $value);
});
}
Expand All @@ -76,10 +77,10 @@ public function get()
{
$jenis_sekolahs = $this->jenis_sekolah->with('user')->get();

$response['jenis_sekolahs'] = $jenis_sekolahs;
$response['error'] = false;
$response['message'] = 'Success';
$response['status'] = true;
$response['jenis_sekolahs'] = $jenis_sekolahs;
$response['error'] = false;
$response['message'] = 'Success';
$response['status'] = true;

return response()->json($response);
}
Expand Down Expand Up @@ -154,10 +155,10 @@ public function show($id)
{
$jenis_sekolah = $this->jenis_sekolah->with(['user'])->findOrFail($id);

$response['jenis_sekolah'] = $jenis_sekolah;
$response['error'] = false;
$response['message'] = 'Success';
$response['status'] = true;
$response['jenis_sekolah'] = $jenis_sekolah;
$response['error'] = false;
$response['message'] = 'Success';
$response['status'] = true;

return response()->json($response);
}
Expand Down
95 changes: 67 additions & 28 deletions src/Http/Controllers/ProdiSekolahController.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,21 +125,21 @@ public function create()
$users_standar = $this->user->findOrFail($user_id);
$current_user = Auth::User();

foreach($program_keahlians as $program_keahlian){
foreach ($program_keahlians as $program_keahlian) {
array_set($program_keahlian, 'label', $program_keahlian->label);
}

$role_check = Auth::User()->hasRole(['superadministrator','administrator']);

if($role_check){
if ($role_check) {
$user_special = true;

foreach($users_special as $user){
foreach ($users_special as $user) {
array_set($user, 'label', $user->name);
}

$users = $users_special;
}else{
} else {
$user_special = false;

array_set($users_standar, 'label', $users_standar->name);
Expand Down Expand Up @@ -175,7 +175,7 @@ public function store(Request $request)
'sekolah_id' => "required|exists:{$this->sekolah->getTable()},id",
'program_keahlian_id' => "required|exists:{$this->program_keahlian->getTable()},id|unique:{$this->prodi_sekolah->getTable()},program_keahlian_id,NULL,id,sekolah_id,{$request->input('sekolah_id')},deleted_at,NULL",
'kuota_siswa' => 'required|numeric|min:0|max:100000',
//'keterangan' => 'max:255',
'keterangan' => 'max:255',
'user_id' => "required|exists:{$this->user->getTable()},id",
]);

Expand All @@ -186,7 +186,7 @@ public function store(Request $request)
$prodi_sekolah->sekolah_id = $request->input('sekolah_id');
$prodi_sekolah->program_keahlian_id = $request->input('program_keahlian_id');
$prodi_sekolah->kuota_siswa = $request->input('kuota_siswa');
//$prodi_sekolah->keterangan = $request->input('keterangan');
$prodi_sekolah->keterangan = $request->input('keterangan');
$prodi_sekolah->user_id = $request->input('user_id');
$prodi_sekolah->save();

Expand Down Expand Up @@ -228,12 +228,50 @@ public function show($id)
*/
public function edit($id)
{
$prodi_sekolah = $this->prodi_sekolah->with(['sekolah', 'program_keahlian', 'user'])->findOrFail($id);
$user_id = isset(Auth::User()->id) ? Auth::User()->id : null;
$prodi_sekolah = $this->prodi_sekolah->with(['sekolah', 'program_keahlian', 'user'])->findOrFail($id);
$program_keahlians = $this->program_keahlian->all();
$users = $this->user->getAttributes();
$users_special = $this->user->all();
$users_standar = $this->user->findOrFail($user_id);
$current_user = Auth::User();

$response['prodi_sekolah'] = $prodi_sekolah;
$response['error'] = false;
$response['message'] = 'Success';
$response['status'] = true;
foreach ($program_keahlians as $program_keahlian) {
array_set($program_keahlian, 'label', $program_keahlian->label);
}

$role_check = Auth::User()->hasRole(['superadministrator','administrator']);

if ($prodi_sekolah->user !== null) {
array_set($prodi_sekolah->user, 'label', $prodi_sekolah->user->name);
}

if ($role_check) {
$user_special = true;

foreach ($users_special as $user) {
array_set($user, 'label', $user->name);
}

$users = $users_special;
} else {
$user_special = false;

array_set($users_standar, 'label', $users_standar->name);

$users = $users_standar;
}

array_set($current_user, 'label', $current_user->name);

$response['prodi_sekolah'] = $prodi_sekolah;
$response['program_keahlians'] = $program_keahlians;
$response['users'] = $users;
$response['user_special'] = $user_special;
$response['current_user'] = $current_user;
$response['error'] = false;
$response['message'] = 'Success';
$response['status'] = true;

return response()->json($response);
}
Expand All @@ -247,34 +285,35 @@ public function edit($id)
*/
public function update(Request $request, $id)
{
$prodi_sekolah = $this->prodi_sekolah->findOrFail($id);
$prodi_sekolah = $this->prodi_sekolah->with(['sekolah', 'program_keahlian', 'user'])->findOrFail($id);

$validator = Validator::make($request->all(), [
'sekolah_id' => 'required',
'user_id' => "required|exists:{$this->user->getTable()},id",
//'keterangan' => 'required',
'kuota_siswa' => 'required',
'program_keahlian_id' => 'required',
]);
$validator = Validator::make($request->all(), [
'sekolah_id' => "required|exists:{$this->sekolah->getTable()},id",
'program_keahlian_id' => "required|exists:{$this->program_keahlian->getTable()},id|unique:{$this->prodi_sekolah->getTable()},program_keahlian_id,{$id},id,sekolah_id,{$request->input('sekolah_id')},deleted_at,NULL",
'kuota_siswa' => 'required|numeric|min:0|max:100000',
'keterangan' => 'max:255',
'user_id' => "required|exists:{$this->user->getTable()},id",
]);

if ($validator->fails()) {
$error = true;
$message = $validator->errors()->first();
} else {
$prodi_sekolah->sekolah_id = $request->input('sekolah_id');
$prodi_sekolah->user_id = $request->input('user_id');
$prodi_sekolah->program_keahlian_id = $request->input('program_keahlian_id');
$prodi_sekolah->keterangan = $request->input('keterangan');
$prodi_sekolah->kuota_siswa = $request->input('kuota_siswa');
$prodi_sekolah->save();
$prodi_sekolah->sekolah_id = $request->input('sekolah_id');
$prodi_sekolah->program_keahlian_id = $request->input('program_keahlian_id');
$prodi_sekolah->kuota_siswa = $request->input('kuota_siswa');
$prodi_sekolah->keterangan = $request->input('keterangan');
$prodi_sekolah->user_id = $request->input('user_id');
$prodi_sekolah->save();

$error = false;
$message = 'Success';
}

$response['error'] = $error;
$response['message'] = $message;
$response['status'] = true;
$response['prodi_sekolah'] = $prodi_sekolah;
$response['error'] = $error;
$response['message'] = $message;
$response['status'] = true;

return response()->json($response);
}
Expand Down
98 changes: 64 additions & 34 deletions src/Http/Controllers/SekolahController.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,43 +116,22 @@ public function create()
$cities = $this->city->getAttributes();
$districts = $this->district->getAttributes();
$villages = $this->village->getAttributes();
$master_zonas = $this->master_zona->all();
$users = $this->user->getAttributes();
$users_special = $this->user->all();
$users_standar = $this->user->findOrFail($user_id);
$current_user = Auth::User();

foreach($provinces as $province){
array_set($province, 'label', $province->name);
}

foreach($cities as $city){
array_set($city, 'label', $city->name);
}

foreach($districts as $district){
array_set($district, 'label', $district->name);
}

foreach($villages as $village){
array_set($village, 'label', $village->name);
}

foreach($master_zonas as $master_zona){
array_set($master_zona, 'label', $master_zona->label);
}

$role_check = Auth::User()->hasRole(['superadministrator','administrator']);

if($role_check){
if ($role_check) {
$user_special = true;

foreach($users_special as $user){
foreach ($users_special as $user) {
array_set($user, 'label', $user->name);
}

$users = $users_special;
}else{
} else {
$user_special = false;

array_set($users_standar, 'label', $users_standar->name);
Expand All @@ -167,7 +146,6 @@ public function create()
$response['cities'] = $cities;
$response['districts'] = $districts;
$response['villages'] = $villages;
$response['master_zonas'] = $master_zonas;
$response['users'] = $users;
$response['user_special'] = $user_special;
$response['current_user'] = $current_user;
Expand Down Expand Up @@ -263,16 +241,68 @@ public function show($id)
*/
public function edit($id)
{
$sekolah = $this->sekolah->with(['jenis_sekolah', 'province', 'city', 'district', 'village', 'master_zona', 'user'])->findOrFail($id);
$user_id = isset(Auth::User()->id) ? Auth::User()->id : null;
$sekolah = $this->sekolah->with(['jenis_sekolah', 'province', 'city', 'district', 'village', 'master_zona', 'user'])->findOrFail($id);
$provinces = $this->province->getAttributes();
$cities = $this->city->getAttributes();
$districts = $this->district->getAttributes();
$villages = $this->village->getAttributes();
$users = $this->user->getAttributes();
$users_special = $this->user->all();
$users_standar = $this->user->findOrFail($user_id);
$current_user = Auth::User();

if ($sekolah->province !== null) {
array_set($sekolah->province, 'label', $sekolah->province->name);
}

if ($sekolah->city !== null) {
array_set($sekolah->city, 'label', $sekolah->city->name);
}

if ($sekolah->district !== null) {
array_set($sekolah->district, 'label', $sekolah->district->name);
}

if ($sekolah->village !== null) {
array_set($sekolah->village, 'label', $sekolah->village->name);
}

$role_check = Auth::User()->hasRole(['superadministrator','administrator']);

if ($sekolah->user !== null) {
array_set($sekolah->user, 'label', $sekolah->user->name);
}

if ($role_check) {
$user_special = true;

foreach($users_special as $user){
array_set($user, 'label', $user->name);
}

$users = $users_special;
} else {
$user_special = false;

array_set($users_standar, 'label', $users_standar->name);

$response['sekolah']['province'] = array_add($sekolah->province, 'label', $sekolah->province->name);
$response['sekolah']['city'] = array_add($sekolah->city, 'label', $sekolah->city->name);
$response['sekolah']['district'] = array_add($sekolah->district, 'label', $sekolah->district->name);
$response['sekolah']['village'] = array_add($sekolah->village, 'label', $sekolah->village->name);
$response['sekolah'] = $sekolah;
$response['error'] = false;
$response['message'] = 'Success';
$response['status'] = true;
$users = $users_standar;
}

array_set($current_user, 'label', $current_user->name);

$response['sekolah'] = $sekolah;
$response['provinces'] = $provinces;
$response['cities'] = $cities;
$response['districts'] = $districts;
$response['villages'] = $villages;
$response['users'] = $users;
$response['user_special'] = $user_special;
$response['current_user'] = $current_user;
$response['error'] = false;
$response['message'] = 'Success';
$response['status'] = true;

return response()->json($response);
}
Expand Down

0 comments on commit 83a3cca

Please sign in to comment.