Skip to content

Commit

Permalink
Rilis 2411.0.0 (#1074)
Browse files Browse the repository at this point in the history
  • Loading branch information
habibie11 authored Nov 1, 2024
2 parents 63a58de + bd68ba0 commit 1e621a9
Show file tree
Hide file tree
Showing 76 changed files with 5,304 additions and 319 deletions.
46 changes: 11 additions & 35 deletions app/Http/Controllers/Data/PengurusController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,24 @@

namespace App\Http\Controllers\Data;

use App\Enums\JenisJabatan;
use App\Enums\Status;
use App\Http\Controllers\Controller;
use App\Http\Requests\PengurusRequest;
use App\Models\Agama;
use App\Models\Jabatan;
use App\Models\PendidikanKK;
use App\Models\Pengurus;
use App\Enums\JenisJabatan;
use App\Models\PendidikanKK;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Storage;
use Yajra\DataTables\DataTables;
use App\Traits\HandlesFileUpload;
use App\Http\Controllers\Controller;
use App\Http\Requests\PengurusRequest;
use Illuminate\Support\Facades\Storage;

class PengurusController extends Controller
{
use HandlesFileUpload;

/**
* Display a listing of the resource.
*
Expand Down Expand Up @@ -135,13 +138,7 @@ public function store(PengurusRequest $request)
{
try {
$input = $request->all();
if ($request->hasFile('foto')) {
$file = $request->file('foto');
$original_name = strtolower(trim($file->getClientOriginalName()));
$file_name = time().'_'.$original_name;
Storage::putFileAs('public/pengurus', $file, $file_name);
$input['foto'] = $file_name;
}
$this->handleFileUpload($request, $input, 'foto', 'pengurus', false);
Pengurus::create($input);
} catch (\Exception $e) {
report($e);
Expand Down Expand Up @@ -185,18 +182,7 @@ public function update(PengurusRequest $request, $id)

try {
$input = $request->all();

if ($request->hasFile('foto')) {
$file = $request->file('foto');
$original_name = strtolower(trim($file->getClientOriginalName()));
$file_name = time().'_'.$original_name;
Storage::putFileAs('public/pengurus', $file, $file_name);
if ($pengurus->foto) {
Storage::delete('public/pengurus/'.$pengurus->getRawOriginal('foto'));
}
$input['foto'] = $file_name;
}

$this->handleFileUpload($request, $input, 'foto', 'pengurus', false);
$pengurus->update($input);
} catch (\Exception $e) {
report($e);
Expand All @@ -207,19 +193,9 @@ public function update(PengurusRequest $request, $id)
return redirect()->route('data.pengurus.index')->with('success', 'Pengurus berhasil diubah!');
}

/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
public function destroy(Pengurus $pengurus)
{
try {
$pengurus = Pengurus::findOrFail($id);
if ($pengurus->foto) {
Storage::delete('public/pengurus/'.$pengurus->getRawOriginal('foto'));
}
$pengurus->delete();
} catch (\Exception $e) {
report($e);
Expand Down
64 changes: 46 additions & 18 deletions app/Http/Controllers/FrontEnd/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
use Illuminate\Support\Facades\Session;
use willvincent\Feeds\Facades\FeedsFacade;
use App\Http\Controllers\FrontEndController;
use App\Models\Kategori;
use Jenssegers\Agent\Agent;

class PageController extends FrontEndController
Expand All @@ -54,7 +55,7 @@ public function index()
return view('pages.index', [
'page_title' => 'Beranda',
'cari' => null,
'artikel' => Artikel::latest()->status()->paginate(config('setting.artikel_kecamatan_perhalaman') ?? 10),
'artikel' => Artikel::with('kategori')->latest()->status()->paginate(config('setting.artikel_kecamatan_perhalaman') ?? 10),
]);
}

Expand Down Expand Up @@ -181,30 +182,39 @@ public function refresh_captcha()
return response()->json(['captcha' => captcha_img('mini')]);
}

public function kategoriBerita($slug)
{
$kategori = Kategori::where('slug', $slug)->firstOrFail();
$artikel = Artikel::whereRelation('kategori', 'slug', $slug)->paginate(9);
return view('pages.berita.kategori', compact('artikel', 'kategori'));
}

public function detailBerita($slug, Request $request)
{
// Temukan artikel berdasarkan slug
$artikel = Artikel::where('slug', $slug)
->with(['comments' => function ($query) use ($request) {
// Ambil komentar yang di-approve atau yang milik user dari session
$userCommentIds = $request->session()->get('session_user_comments', []);

// Ambil komentar utama (tanpa parent) yang di-approve atau yang dimiliki oleh user
$query->whereNull('comment_id')
->where(function ($query) use ($userCommentIds) {
$artikel = Artikel::with(['kategori', 'comments' => function ($query) use ($request) {
// Ambil komentar yang di-approve atau yang milik user dari session
$userCommentIds = $request->session()->get('session_user_comments', []);

// Ambil komentar utama (tanpa parent) yang di-approve atau yang dimiliki oleh user
$query->whereNull('comment_id')
->where(function ($query) use ($userCommentIds) {
$query->where('status', 'enable')
->orWhereIn('id', $userCommentIds);
})
->with(['replies' => function ($query) use ($userCommentIds) {
// Ambil balasan yang di-approve atau yang milik user
$query->where(function ($query) use ($userCommentIds) {
$query->where('status', 'enable')
->orWhereIn('id', $userCommentIds);
})
->with(['replies' => function ($query) use ($userCommentIds) {
// Ambil balasan yang di-approve atau yang milik user
$query->where(function ($query) use ($userCommentIds) {
$query->where('status', 'enable')
->orWhereIn('id', $userCommentIds);
});
}]);
}])
});
}]);
}])
->where('slug', $slug)
->when(!auth()->check(), fn($query) => $query->status())
->firstOrFail();


$page_title = $artikel->judul;
$page_description = substr($artikel->isi, 0, 300) . ' ...';
$page_image = $artikel->gambar;
Expand Down Expand Up @@ -324,4 +334,22 @@ public function eventDetail($slug)

return view('pages.event.event_detail', compact('page_title', 'page_description', 'event'));
}

public function kategori($slug)
{
// Temukan kategori berdasarkan slug
$kategori = \App\Models\ArtikelKategori::where('slug', $slug)->firstOrFail();

// Ambil semua artikel yang termasuk dalam kategori tersebut
$berita_kategori = Artikel::with('kategori')
->where('id_kategori', $kategori->id_kategori)
->where('status', '1')
->latest()
->paginate(10);

return view('pages.berita.kategori', [
'artikel' => $berita_kategori,
'kategori' => $kategori,
]);
}
}
2 changes: 2 additions & 0 deletions app/Http/Controllers/FrontEndController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
use App\Models\Slide;
use App\Models\Navigation;
use App\Models\MediaSosial;
use App\Models\NavMenu;
use App\Models\SinergiProgram;
use Illuminate\Support\Facades\View;

Expand All @@ -49,6 +50,7 @@ public function __construct()
'events' => Event::getOpenEvents(),
'medsos' => MediaSosial::where('status', 1)->get(),
'navigations' => Navigation::with('childrens')->whereNull('parent_id')->where('status', 1)->orderBy('order', 'asc')->get(),
'navmenus' => NavMenu::with('children')->whereNull('parent_id')->where('is_show', 1)->orderBy('order', 'asc')->get(),
'sinergi' => SinergiProgram::where('status', 1)->orderBy('urutan', 'asc')->get(),
'slides' => Slide::orderBy('created_at', 'DESC')->get(),
]);
Expand Down
51 changes: 26 additions & 25 deletions app/Http/Controllers/Informasi/ArtikelController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,35 @@

namespace App\Http\Controllers\Informasi;

use App\Http\Controllers\Controller;
use App\Http\Requests\ArtikelRequest;
use App\Models\Artikel;
use App\Models\ArtikelKategori;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Yajra\DataTables\DataTables;
use App\Traits\HandlesFileUpload;
use App\Http\Controllers\Controller;
use App\Http\Requests\ArtikelRequest;
use Illuminate\Support\Facades\Storage;

class ArtikelController extends Controller
{
use HandlesFileUpload;

public function index()
{
$page_title = 'Artikel';
$page_description = 'Daftar Artikel';

return view('informasi.artikel.index', compact('page_title', 'page_description'));
$kategori = \App\Models\ArtikelKategori::get();

return view('informasi.artikel.index', compact('page_title', 'page_description','kategori'));
}

public function getDataArtikel(Request $request)
{
if ($request->ajax()) {
return DataTables::of(Artikel::all())
// Mengambil data artikel beserta kategori
$data = Artikel::with('kategori')->get();
return DataTables::of($data)
->addIndexColumn()
->addColumn('aksi', function ($row) {
$data['show_web'] = route('berita.detail', $row->slug);
Expand All @@ -63,6 +71,10 @@ public function getDataArtikel(Request $request)

return view('forms.aksi', $data);
})
->addColumn('kategori', function ($row) {
// Cek apakah artikel memiliki kategori
return $row->kategori ? $row->kategori->nama_kategori : '-';
})
->editColumn('status', function ($row) {
if ($row->status == 0) {
return '<span class="label label-danger">Tidak Aktif</span>';
Expand All @@ -83,19 +95,16 @@ public function create()
$page_title = 'Artikel';
$page_description = 'Tambah Artikel';

return view('informasi.artikel.create', compact('page_title', 'page_description'));
$kategori = ArtikelKategori::where('status', 'Ya')->pluck('nama_kategori', 'id_kategori'); // Mengambil nama kategori dan ID

return view('informasi.artikel.create', compact('page_title', 'page_description', 'kategori'));
}

public function store(ArtikelRequest $request)
{
try {
$input = $request->all();
if ($request->hasFile('gambar')) {
$file = $request->file('gambar');
$path = Storage::putFile('public/artikel', $file);

$input['gambar'] = substr($path, 15);
}
$this->handleFileUpload($request, $input, 'gambar', 'artikel', false);

Artikel::create($input);
} catch (\Exception $e) {
Expand All @@ -112,22 +121,16 @@ public function edit(Artikel $artikel)
$page_title = 'Artikel';
$page_description = 'Ubah Artikel';

return view('informasi.artikel.edit', compact('artikel', 'page_title', 'page_description'));
$kategori = ArtikelKategori::where('status', 'Ya')->pluck('nama_kategori', 'id_kategori'); // Mengambil nama kategori dan ID

return view('informasi.artikel.edit', compact('artikel', 'page_title', 'page_description', 'kategori'));
}

public function update(ArtikelRequest $request, Artikel $artikel)
{
try {
$input = $request->all();

if ($request->hasFile('gambar')) {
$file = $request->file('gambar');
$path = Storage::putFile('public/artikel', $file);

Storage::delete('public/artikel/'.$artikel->getRawOriginal('gambar'));

$input['gambar'] = substr($path, 15);
}
$this->handleFileUpload($request, $input, 'gambar', 'artikel', false);

$artikel->update($input);
} catch (\Exception $e) {
Expand All @@ -142,9 +145,7 @@ public function update(ArtikelRequest $request, Artikel $artikel)
public function destroy(Artikel $artikel)
{
try {
if ($artikel->delete()) {
Storage::delete('public/artikel/'.$artikel->getRawOriginal('gambar'));
}
$artikel->delete();
} catch (\Exception $e) {
report($e);

Expand Down
Loading

0 comments on commit 1e621a9

Please sign in to comment.