Skip to content

Commit ecd4996

Browse files
committed
Merge branch 'dev' into pr/1029
2 parents 14f1c56 + b3dcf1d commit ecd4996

16 files changed

Lines changed: 984 additions & 34 deletions

File tree

app/Http/Controllers/FrontEnd/PageController.php

Lines changed: 162 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,17 @@
3131

3232
namespace App\Http\Controllers\FrontEnd;
3333

34-
use App\Facades\Counter;
35-
use App\Http\Controllers\FrontEndController;
34+
use App\Models\Event;
3635
use App\Models\Artikel;
36+
use App\Facades\Counter;
3737
use App\Models\DataDesa;
38-
use App\Models\Event;
3938
use Illuminate\Http\Request;
39+
use PhpParser\Node\Stmt\Catch_;
4040
use Illuminate\Support\Facades\DB;
41+
use Illuminate\Support\Facades\Session;
4142
use willvincent\Feeds\Facades\FeedsFacade;
43+
use App\Http\Controllers\FrontEndController;
44+
use Jenssegers\Agent\Agent;
4245

4346
class PageController extends FrontEndController
4447
{
@@ -72,7 +75,32 @@ public function beritaDesa()
7275

7376
private function getFeeds()
7477
{
75-
return getFeeds();
78+
$all_desa = DataDesa::websiteUrl()->get()
79+
->map(function ($desa) {
80+
return $desa->website_url_feed;
81+
})->all();
82+
83+
$feeds = [];
84+
foreach ($all_desa as $desa) {
85+
$getFeeds = FeedsFacade::make($desa['website'], 5, true);
86+
foreach ($getFeeds->get_items() as $item) {
87+
$feeds[] = [
88+
'desa_id' => $desa['desa_id'],
89+
'nama_desa' => $desa['nama'],
90+
'feed_link' => $item->get_feed()->get_permalink(),
91+
'feed_title' => $item->get_feed()->get_title(),
92+
'link' => $item->get_link(),
93+
'date' => \Carbon\Carbon::parse($item->get_date('U')),
94+
'author' => $item->get_author()->get_name() ?? 'Administrator',
95+
'title' => $item->get_title(),
96+
'image' => get_tag_image($item->get_description()),
97+
'description' => strip_tags(substr(str_replace(['&', 'nbsp;', '[...]'], '', $item->get_description()), 0, 250) . '[...]'),
98+
'content' => $item->get_content(),
99+
];
100+
}
101+
}
102+
103+
return $feeds ?? null;
76104
}
77105

78106
public function filterFeeds(Request $request)
@@ -142,7 +170,7 @@ public function DesaShow($slug)
142170
// Counter::count('desa.show');
143171

144172
$desa = DataDesa::nama($slug)->firstOrFail();
145-
$page_title = 'Desa '.$desa->nama;
173+
$page_title = 'Desa ' . $desa->nama;
146174
$page_description = 'Data Desa';
147175

148176
return view('pages.desa.desa_show', compact('page_title', 'page_description', 'desa'));
@@ -153,16 +181,141 @@ public function refresh_captcha()
153181
return response()->json(['captcha' => captcha_img('mini')]);
154182
}
155183

156-
public function detailBerita($slug)
184+
public function detailBerita($slug, Request $request)
157185
{
158-
$artikel = Artikel::where('slug', $slug)->status()->firstOrFail();
186+
// Temukan artikel berdasarkan slug
187+
$artikel = Artikel::where('slug', $slug)
188+
->with(['comments' => function ($query) use ($request) {
189+
// Ambil komentar yang di-approve atau yang milik user dari session
190+
$userCommentIds = $request->session()->get('session_user_comments', []);
191+
192+
// Ambil komentar utama (tanpa parent) yang di-approve atau yang dimiliki oleh user
193+
$query->whereNull('comment_id')
194+
->where(function ($query) use ($userCommentIds) {
195+
$query->where('status', 'enable')
196+
->orWhereIn('id', $userCommentIds);
197+
})
198+
->with(['replies' => function ($query) use ($userCommentIds) {
199+
// Ambil balasan yang di-approve atau yang milik user
200+
$query->where(function ($query) use ($userCommentIds) {
201+
$query->where('status', 'enable')
202+
->orWhereIn('id', $userCommentIds);
203+
});
204+
}]);
205+
}])
206+
->firstOrFail();
207+
159208
$page_title = $artikel->judul;
160-
$page_description = substr($artikel->isi, 0, 300).' ...';
209+
$page_description = substr($artikel->isi, 0, 300) . ' ...';
161210
$page_image = $artikel->gambar;
162211

163-
return view('pages.berita.detail', compact('page_title', 'page_description', 'page_image', 'artikel'));
212+
// Ambil komentar utama yang terkait dengan artikel ini
213+
$comments = $artikel->comments;
214+
215+
return view('pages.berita.detail', compact('page_title', 'page_description', 'page_image', 'artikel', 'comments'));
216+
}
217+
218+
219+
public function kirimKomentar(Request $request)
220+
{
221+
222+
// Validasi input
223+
$validated = $request->validate([
224+
'nama' => 'required|string|max:255',
225+
'email' => 'required|email|max:255',
226+
'body' => 'required|string',
227+
'das_artikel_id' => 'required|exists:das_artikel,id',
228+
'captcha_main' => 'required|captcha',
229+
]);
230+
231+
try {
232+
// Mendeteksi IP address
233+
$ipAddress = $request->ip();
234+
235+
// Mendeteksi device menggunakan jenssegers/agent
236+
$agent = new Agent();
237+
$device = $agent->device() ?: 'Desktop';
238+
$platform = $agent->platform() ?: 'Unknown Platform';
239+
$browser = $agent->browser() ?: 'Unknown Browser';
240+
241+
// Format informasi device
242+
$deviceInfo = "{$device} on {$platform} using {$browser}";
243+
244+
// Simpan komentar baru
245+
$comment = \App\Models\Comment::create([
246+
'nama' => $validated['nama'],
247+
'email' => $validated['email'],
248+
'body' => $validated['body'],
249+
'status' => 'disable', // Set status default ke 'disable' untuk moderasi
250+
'das_artikel_id' => $validated['das_artikel_id'],
251+
'comment_id' => $request->input('comment_id', null), // Jika ini adalah balasan
252+
'ip_address' => $ipAddress,
253+
'device' => $deviceInfo,
254+
]);
255+
256+
// Simpan comment_id ke dalam session agar user bisa melihat komentarnya sendiri
257+
$request->session()->push('session_user_comments', $comment->id);
258+
259+
// Redirect dengan pesan sukses
260+
return redirect()->back()->with('success', 'Komentar Anda telah ditambahkan.');
261+
} catch (\Throwable $th) {
262+
// Penanganan kesalahan
263+
return redirect()->back()->withInput($request->all())->withErrors([$th->getMessage()]);
264+
}
265+
}
266+
267+
public function modalKirimBalasan(Request $request)
268+
{
269+
$commentId = $request->input('comment_id');
270+
$artikelId = $request->input('artikel_id');
271+
return view('pages.berita.comment', compact('commentId', 'artikelId'));
272+
}
273+
274+
public function kirimBalasan(Request $request)
275+
{
276+
$request->validate([
277+
'nama' => 'required|string|max:255',
278+
'email' => 'required|email|max:255',
279+
'body' => 'required|string',
280+
'captcha_main' => 'required|captcha',
281+
'das_artikel_id' => 'required|exists:das_artikel,id', // Pastikan artikel terkait ada
282+
'comment_id' => 'required|exists:das_artikel_comment,id', // Pastikan comment_id ada
283+
]);
284+
285+
try {
286+
// Mendeteksi IP address
287+
$ipAddress = $request->ip();
288+
289+
// Mendeteksi device menggunakan jenssegers/agent
290+
$agent = new Agent();
291+
$device = $agent->device() ?: 'Desktop';
292+
$platform = $agent->platform() ?: 'Unknown Platform';
293+
$browser = $agent->browser() ?: 'Unknown Browser';
294+
295+
// Format informasi device
296+
$deviceInfo = "{$device} on {$platform} using {$browser}";
297+
298+
$comment = \App\Models\Comment::create([
299+
'nama' => $request->nama,
300+
'email' => $request->email,
301+
'body' => $request->body,
302+
'status' => 'disable',
303+
'das_artikel_id' => $request->das_artikel_id,
304+
'comment_id' => $request->comment_id,
305+
'ip_address' => $ipAddress,
306+
'device' => $deviceInfo
307+
]);
308+
309+
// Simpan comment_id ke dalam session agar user bisa melihat komentarnya sendiri
310+
$request->session()->push('session_user_comments', $comment->id);
311+
312+
return redirect()->back()->with('success', 'Balasan berhasil dikirim.');
313+
} catch (\Throwable $th) {
314+
return redirect()->back()->withInput($request->all())->withErrors([$th->getMessage()]);
315+
}
164316
}
165317

318+
166319
public function eventDetail($slug)
167320
{
168321
$event = Event::slug($slug)->firstOrFail();

app/Http/Controllers/FrontEnd/SistemKomplainController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ public function kirim()
8585
public function tracking(Request $request)
8686
{
8787
try {
88-
$komplain = Komplain::where('komplain_id', '=', $request->post('q'))->firstOrFail();
89-
88+
$komplain = Komplain::where('komplain_id', '=', $request->post('tracking_id'))->firstOrFail();
9089
return redirect()->route('sistem-komplain.komplain', $komplain->slug);
9190
} catch (\Exception $e) {
9291
report($e);
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
<?php
2+
3+
/*
4+
* File ini bagian dari:
5+
*
6+
* OpenDK
7+
*
8+
* Aplikasi dan source code ini dirilis berdasarkan lisensi GPL V3
9+
*
10+
* Hak Cipta 2017 - 2024 Perkumpulan Desa Digital Terbuka (https://opendesa.id)
11+
*
12+
* Dengan ini diberikan izin, secara gratis, kepada siapa pun yang mendapatkan salinan
13+
* dari perangkat lunak ini dan file dokumentasi terkait ("Aplikasi Ini"), untuk diperlakukan
14+
* tanpa batasan, termasuk hak untuk menggunakan, menyalin, mengubah dan/atau mendistribusikan,
15+
* asal tunduk pada syarat berikut:
16+
*
17+
* Pemberitahuan hak cipta di atas dan pemberitahuan izin ini harus disertakan dalam
18+
* setiap salinan atau bagian penting Aplikasi Ini. Barang siapa yang menghapus atau menghilangkan
19+
* pemberitahuan ini melanggar ketentuan lisensi Aplikasi Ini.
20+
*
21+
* PERANGKAT LUNAK INI DISEDIAKAN "SEBAGAIMANA ADANYA", TANPA JAMINAN APA PUN, BAIK TERSURAT MAUPUN
22+
* TERSIRAT. PENULIS ATAU PEMEGANG HAK CIPTA SAMA SEKALI TIDAK BERTANGGUNG JAWAB ATAS KLAIM, KERUSAKAN ATAU
23+
* KEWAJIBAN APAPUN ATAS PENGGUNAAN ATAU LAINNYA TERKAIT APLIKASI INI.
24+
*
25+
* @package OpenDK
26+
* @author Tim Pengembang OpenDesa
27+
* @copyright Hak Cipta 2017 - 2024 Perkumpulan Desa Digital Terbuka (https://opendesa.id)
28+
* @license http://www.gnu.org/licenses/gpl.html GPL V3
29+
* @link https://github.com/OpenSID/opendk
30+
*/
31+
32+
namespace App\Http\Controllers\Informasi;
33+
34+
use App\Models\Comment;
35+
use App\Http\Controllers\Controller;
36+
use Illuminate\Http\Request;
37+
use Yajra\DataTables\DataTables;
38+
39+
class KomentarArtikelController extends Controller
40+
{
41+
public function index()
42+
{
43+
$page_title = 'Komentar Artikel';
44+
$page_description = 'Daftar Komentar Artikel';
45+
46+
return view('informasi.komentar_artikel.index', compact('page_title', 'page_description'));
47+
}
48+
49+
public function getDataKomentar(Request $request)
50+
{
51+
if ($request->ajax()) {
52+
$comments = Comment::with(['artikel'])->get();
53+
54+
return DataTables::of($comments)
55+
->addIndexColumn()
56+
->addColumn('aksi', function ($row) {
57+
58+
if (!auth()->guest()) {
59+
$data['delete_url'] = route('informasi.komentar-artikel.destroy', $row->id);
60+
}
61+
62+
return view('forms.aksi', $data);
63+
})
64+
->editColumn('user', function ($row) {
65+
$nama = $row->nama ? '<strong>' . $row->nama . '</strong></br>' : 'User tidak ditemukan';
66+
$email = $row->email ? '<a href="mailto:' . $row->email . '">' . $row->email . '</a>' : '';
67+
return $nama . $email;
68+
})
69+
->editColumn('komentar', function ($row) {
70+
return \Illuminate\Support\Str::limit($row->body, 100, '...');
71+
})
72+
->editColumn('artikel', function ($row) {
73+
$artikel = \Illuminate\Support\Str::limit($row->artikel->judul, 30, '...');
74+
$tampil = $artikel . '<br><a target="_blank" href="' . route('berita.detail', $row->artikel->slug) . '">Lihat Artikel</a> ';
75+
return $tampil;
76+
})
77+
->editColumn('status', function ($row) {
78+
$checked = $row->status == 'enable' ? 'checked' : '';
79+
return '<label class="switch">
80+
<input type="checkbox" class="toggle-status" data-id="' . $row->id . '" ' . $checked . '>
81+
<span class="slider"></span>
82+
</label>';
83+
})
84+
->editColumn('created_at', function ($row) {
85+
return format_datetime($row->created_at);
86+
})
87+
->rawColumns(['aksi', 'user', 'artikel', 'status'])
88+
->make(true);
89+
}
90+
}
91+
92+
public function updateStatus(Request $request)
93+
{
94+
$comment = Comment::find($request->id);
95+
$comment->status = $request->status;
96+
$comment->save();
97+
98+
return response()->json(['success' => 'Status updated successfully.']);
99+
}
100+
101+
102+
public function destroy($id)
103+
{
104+
try {
105+
// Temukan komentar berdasarkan ID
106+
$comment = Comment::find($id);
107+
108+
// Jika komentar tidak ditemukan, kembalikan respon error
109+
if (!$comment) {
110+
return redirect()->route('informasi.komentar-artikel.index')
111+
->with('error', 'Komentar tidak ditemukan!');
112+
}
113+
114+
// Hapus komentar
115+
$comment->delete();
116+
117+
// Kembalikan respon sukses
118+
return redirect()->route('informasi.komentar-artikel.index')
119+
->with('success', 'Komentar berhasil dihapus!');
120+
} catch (\Exception $e) {
121+
// Tangani pengecualian
122+
report($e);
123+
124+
// Kembalikan respon error
125+
return redirect()->route('informasi.komentar-artikel.index')
126+
->with('error', 'Komentar gagal dihapus!');
127+
}
128+
}
129+
}

app/Models/Artikel.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,10 @@ public function scopeStatus($query, $value = 1)
7676
{
7777
return $query->where('status', $value);
7878
}
79+
80+
// Relasi dengan model Comment
81+
public function comments()
82+
{
83+
return $this->hasMany(Comment::class, 'das_artikel_id')->orderBy('created_at', 'desc');
84+
}
7985
}

app/Models/Comment.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use Illuminate\Database\Eloquent\Factories\HasFactory;
6+
use Illuminate\Database\Eloquent\Model;
7+
8+
class Comment extends Model
9+
{
10+
use HasFactory;
11+
12+
protected $table = 'das_artikel_comment';
13+
14+
protected $guarded = ['id'];
15+
16+
// Relasi dengan model Artikel
17+
public function artikel()
18+
{
19+
return $this->belongsTo(Artikel::class, 'das_artikel_id');
20+
}
21+
22+
// Relasi untuk komentar yang membalas komentar lain
23+
public function parentComment()
24+
{
25+
return $this->belongsTo(Comment::class, 'comment_id');
26+
}
27+
28+
// Relasi untuk mendapatkan balasan dari komentar
29+
public function replies()
30+
{
31+
return $this->hasMany(Comment::class, 'comment_id');
32+
}
33+
}

0 commit comments

Comments
 (0)