feat: add bylaw management features including documents, legal authorities, subject categories, and nodes
This commit is contained in:
@@ -85,7 +85,7 @@ class ArtController extends Controller
|
||||
{
|
||||
$art = Art::select('id', 'title', 'number', 'text', 'law_id')->find($id);
|
||||
|
||||
if (!$art) {
|
||||
if (! $art) {
|
||||
return $this->failed([], 'Art not found');
|
||||
}
|
||||
|
||||
@@ -96,12 +96,12 @@ class ArtController extends Controller
|
||||
}
|
||||
|
||||
$art->is_like = $this->isLiked($art->id);
|
||||
$art->note = Note::select('id', 'note', 'color_code','created_at')->where('user_id', auth()->user()->id)->where('art_id', $id)->get();
|
||||
$art->note = Note::select('id', 'note', 'color_code', 'created_at')->where('user_id', auth()->user()->id)->where('art_id', $id)->get();
|
||||
$art->category = $law?->category?->name;
|
||||
$art->route = array_values($this->route(Art::class, $art));
|
||||
|
||||
$previousArt = Art::select('id', 'title', 'number', 'text', 'law_id')
|
||||
->where('law_id',$art->law_id)
|
||||
->where('law_id', $art->law_id)
|
||||
->where('number', '<', $art->number)
|
||||
->orderBy('number', 'desc')
|
||||
->first();
|
||||
@@ -115,7 +115,7 @@ class ArtController extends Controller
|
||||
}
|
||||
|
||||
$nextArt = Art::select('id', 'title', 'number', 'text', 'law_id')
|
||||
->where('law_id',$art->law_id)
|
||||
->where('law_id', $art->law_id)
|
||||
->where('number', '>', $art->number)
|
||||
->orderBy('number')
|
||||
->first();
|
||||
@@ -155,7 +155,6 @@ class ArtController extends Controller
|
||||
return $this->success(null, 'Success', 'Art liked successfully');
|
||||
}
|
||||
|
||||
|
||||
private function isLiked($art_id): bool
|
||||
{
|
||||
return LikeArt::query()->where('art_id', $art_id)
|
||||
@@ -165,7 +164,7 @@ class ArtController extends Controller
|
||||
|
||||
private function isLockedForCurrentUser(?Law $law): bool
|
||||
{
|
||||
return !auth()->user()->isSubscriber() && (bool) $law?->is_locked;
|
||||
return ! auth()->user()->isSubscriber() && (bool) $law?->is_locked;
|
||||
}
|
||||
|
||||
public function likes()
|
||||
@@ -179,14 +178,13 @@ class ArtController extends Controller
|
||||
return [
|
||||
'id' => $q->art->id,
|
||||
'title' => $q->art->title,
|
||||
'text' => $isLocked ? null : $q->art->text
|
||||
'text' => $isLocked ? null : $q->art->text,
|
||||
];
|
||||
});
|
||||
|
||||
return $this->success($likes);
|
||||
}
|
||||
|
||||
|
||||
public function search(Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
@@ -201,7 +199,7 @@ class ArtController extends Controller
|
||||
'branch_id' => 'nullable|array',
|
||||
'category_id' => 'nullable|int',
|
||||
'per_page' => 'nullable|integer',
|
||||
'search' => 'nullable|string'
|
||||
'search' => 'nullable|string',
|
||||
]);
|
||||
|
||||
$models = [
|
||||
@@ -214,7 +212,7 @@ class ArtController extends Controller
|
||||
Part::class,
|
||||
Gate::class,
|
||||
Branch::class,
|
||||
Art::class
|
||||
Art::class,
|
||||
];
|
||||
|
||||
$results = [];
|
||||
@@ -238,13 +236,13 @@ class ArtController extends Controller
|
||||
'part_id',
|
||||
'gate_id',
|
||||
'chapter_id',
|
||||
'branch_id'
|
||||
'branch_id',
|
||||
];
|
||||
|
||||
$model = new $modelClass;
|
||||
if ($model->getTable() == 'art') {
|
||||
$query->where(function ($query) use ($validated, $filters) {
|
||||
if (!empty($validated['search'])) {
|
||||
if (! empty($validated['search'])) {
|
||||
$query->where(function ($q) use ($validated) {
|
||||
$q->where('title', 'LIKE', "%{$validated['search']}%")
|
||||
->orWhere('text', 'LIKE', "%{$validated['search']}%");
|
||||
@@ -252,14 +250,13 @@ class ArtController extends Controller
|
||||
}
|
||||
|
||||
foreach ($filters as $filter) {
|
||||
if (!empty($validated[$filter])) {
|
||||
if (! empty($validated[$filter])) {
|
||||
$query->whereIn($filter, $validated[$filter]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if (!empty($validated['category_id'])) {
|
||||
if (! empty($validated['category_id'])) {
|
||||
$query->whereIn('law_id', Category::where('type', $this->convertValueTo($validated['category_id']))->get()->pluck('id'));
|
||||
}
|
||||
|
||||
@@ -268,8 +265,8 @@ class ArtController extends Controller
|
||||
return $items->map(function ($item) use ($validated, $modelClass) {
|
||||
$text = $item->text ?? '';
|
||||
$search = preg_quote($validated['search'] ?? '', '/');
|
||||
if (!empty($text) && preg_match('/\b(.{0,50})\b(' . $search . ')\b(.{0,50})\b/i', $text, $matches)) {
|
||||
$context = trim($matches[1] ?? '') . ' ' . $matches[2] . ' ' . trim($matches[3] ?? '');
|
||||
if (! empty($text) && preg_match('/\b(.{0,50})\b('.$search.')\b(.{0,50})\b/i', $text, $matches)) {
|
||||
$context = trim($matches[1] ?? '').' '.$matches[2].' '.trim($matches[3] ?? '');
|
||||
} else {
|
||||
$context = $text;
|
||||
}
|
||||
@@ -289,11 +286,11 @@ class ArtController extends Controller
|
||||
'count_art' => $law->arts->count(),
|
||||
'count_volums' => $law->volums->count(),
|
||||
'price' => $law->price,
|
||||
'image' => $law->image
|
||||
'image' => $law->image,
|
||||
];
|
||||
})->toArray();
|
||||
} else {
|
||||
$query = $query->where('title', 'LIKE', '%' . ($validated['search'] ?? '') . '%');
|
||||
$query = $query->where('title', 'LIKE', '%'.($validated['search'] ?? '').'%');
|
||||
}
|
||||
|
||||
$items = $query->paginate($validated['per_page'] ?? 10);
|
||||
@@ -306,21 +303,21 @@ class ArtController extends Controller
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => (new $modelClass)->getTable(),
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : optional($law)->is_locked,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : optional($law)->is_locked,
|
||||
'route' => array_values($this->route($modelClass, $item)),
|
||||
'category' => optional($law?->category)?->name ?? '',
|
||||
'image' => $law->image
|
||||
'image' => $law->image,
|
||||
];
|
||||
} else if ((new $modelClass)->getTable() == 'art') {
|
||||
} elseif ((new $modelClass)->getTable() == 'art') {
|
||||
return [
|
||||
'id' => $item->id,
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => (new $modelClass)->getTable(),
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : optional($law)->is_locked,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : optional($law)->is_locked,
|
||||
'route' => array_values($this->route($modelClass, $item)),
|
||||
'law' => $law?->title ?? '',
|
||||
'image' => $law->image
|
||||
'image' => $law->image,
|
||||
];
|
||||
} else {
|
||||
return [
|
||||
@@ -328,7 +325,7 @@ class ArtController extends Controller
|
||||
'title' => $item->title,
|
||||
'number' => $item->number,
|
||||
'type' => (new $modelClass)->getTable(),
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : optional($law)->is_locked,
|
||||
'is_locked' => auth()->user()->isSubscriber() !== false ? false : optional($law)->is_locked,
|
||||
'route' => array_values($this->route($modelClass, $item)),
|
||||
'law' => $law?->title ?? '',
|
||||
];
|
||||
@@ -336,8 +333,6 @@ class ArtController extends Controller
|
||||
})->toArray();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function route($modelClass, $query)
|
||||
{
|
||||
if ((new $modelClass)->getTable() == 'art') {
|
||||
@@ -350,12 +345,14 @@ class ArtController extends Controller
|
||||
Chapter::find($query->chapter_id)?->title,
|
||||
Part::find($query->part_id)?->title,
|
||||
Gate::find($query->gate_id)?->title,
|
||||
Branch::find($query->branch_id)?->title
|
||||
Branch::find($query->branch_id)?->title,
|
||||
]);
|
||||
|
||||
$route = array_values($route);
|
||||
|
||||
return $route;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -365,7 +362,7 @@ class ArtController extends Controller
|
||||
|
||||
$models = [
|
||||
Law::class,
|
||||
Art::class
|
||||
Art::class,
|
||||
];
|
||||
|
||||
$results = [];
|
||||
@@ -374,7 +371,6 @@ class ArtController extends Controller
|
||||
$results = array_merge($results, $this->searchModelFastSearch($modelClass, $search));
|
||||
}
|
||||
|
||||
|
||||
$models_other = [
|
||||
Volum::class,
|
||||
Book::class,
|
||||
@@ -388,13 +384,12 @@ class ArtController extends Controller
|
||||
|
||||
$found = false;
|
||||
foreach ($models_other as $modelClass) {
|
||||
if (count($this->searchModelFastSearch($modelClass, $search)) > 0 && !$found) {
|
||||
if (count($this->searchModelFastSearch($modelClass, $search)) > 0 && ! $found) {
|
||||
$results = array_merge($results, $this->searchModelFastSearch($modelClass, $search));
|
||||
$found = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$models = [
|
||||
Law::class,
|
||||
Volum::class,
|
||||
@@ -405,7 +400,7 @@ class ArtController extends Controller
|
||||
Part::class,
|
||||
Gate::class,
|
||||
Branch::class,
|
||||
Art::class
|
||||
Art::class,
|
||||
];
|
||||
|
||||
$count_all = 0;
|
||||
@@ -414,7 +409,6 @@ class ArtController extends Controller
|
||||
$count_all += count($this->searchModel($modelClass, $search));
|
||||
}
|
||||
|
||||
|
||||
return $this->success(['items' => $results, 'count' => $count_all]);
|
||||
}
|
||||
|
||||
@@ -449,7 +443,7 @@ class ArtController extends Controller
|
||||
'title' => $q->title,
|
||||
'type' => $table === 'section' ? 'sections' : $table,
|
||||
'category' => $category,
|
||||
'law' => Law::where('id', $q->law_id)->first()?->title
|
||||
'law' => Law::where('id', $q->law_id)->first()?->title,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -458,7 +452,7 @@ class ArtController extends Controller
|
||||
'title' => $q->title,
|
||||
'type' => $table === 'section' ? 'sections' : $table,
|
||||
'category' => $category,
|
||||
'image' => Law::where('id', $q->id)->first()?->image
|
||||
'image' => Law::where('id', $q->id)->first()?->image,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -474,13 +468,13 @@ class ArtController extends Controller
|
||||
Chapter::find($q->chapter_id)?->title,
|
||||
Part::find($q->part_id)?->title,
|
||||
Gate::find($q->gate_id)?->title,
|
||||
Branch::find($q->branch_id)?->title
|
||||
Branch::find($q->branch_id)?->title,
|
||||
]);
|
||||
|
||||
$text = $q->text;
|
||||
$search = preg_quote($search, '/');
|
||||
if (preg_match('/\b(.{0,50})\b(' . $search . ')\b(.{0,50})\b/i', $text, $matches)) {
|
||||
$context = trim($matches[1]) . ' ' . $matches[2] . ' ' . trim($matches[3]);
|
||||
if (preg_match('/\b(.{0,50})\b('.$search.')\b(.{0,50})\b/i', $text, $matches)) {
|
||||
$context = trim($matches[1]).' '.$matches[2].' '.trim($matches[3]);
|
||||
} else {
|
||||
$context = $text;
|
||||
}
|
||||
@@ -499,7 +493,7 @@ class ArtController extends Controller
|
||||
'count_art' => $law->arts->count(),
|
||||
'count_volum' => $law->volums->count(),
|
||||
'price' => $law->price,
|
||||
'image' => $law->image
|
||||
'image' => $law->image,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user