diff --git a/app/Enums/EuPlatescStatus.php b/app/Enums/EuPlatescStatus.php index 6d6b790a..2465ced5 100644 --- a/app/Enums/EuPlatescStatus.php +++ b/app/Enums/EuPlatescStatus.php @@ -5,7 +5,6 @@ namespace App\Enums; use App\Concerns\Enums\Arrayable; -use App\Concerns\Enums\Comparable; use App\Concerns\Enums\HasLabel; enum EuPlatescStatus: string diff --git a/app/Filament/Resources/BCRProjectResource.php b/app/Filament/Resources/BCRProjectResource.php index 784bb825..d7edb3cc 100644 --- a/app/Filament/Resources/BCRProjectResource.php +++ b/app/Filament/Resources/BCRProjectResource.php @@ -53,8 +53,8 @@ public static function form(Form $form): Form { return $form ->schema([ - TextInput::make('title') - ->label(__('bcr-project.labels.title')) + TextInput::make('name') + ->label(__('bcr-project.labels.name')) ->inlineLabel() ->columnSpanFull() ->required(), @@ -152,10 +152,10 @@ public static function table(Table $table): Table ->formatStateUsing(function (BcrProject $record) { return sprintf('#%d', $record->id); }) - ->label(__('volunteer.column.id')) + ->label(__('bcr-project.labels.id')) ->sortable(), - TextColumn::make('title') - ->label(__('bcr-project.labels.title')) + TextColumn::make('name') + ->label(__('bcr-project.labels.name')) ->searchable() ->sortable(), TextColumn::make('start_date') diff --git a/app/Filament/Resources/BCRProjectResource/Pages/CreateBCRProject.php b/app/Filament/Resources/BCRProjectResource/Pages/CreateBCRProject.php index a7e5e555..908c4706 100644 --- a/app/Filament/Resources/BCRProjectResource/Pages/CreateBCRProject.php +++ b/app/Filament/Resources/BCRProjectResource/Pages/CreateBCRProject.php @@ -1,9 +1,10 @@ whereHas('badges')->count(); } - public static function form(Form $form): Form { return $form ->schema([ TextInput::make('title') ->label(__('badge.category.title')) - ->required() + ->required(), ]); } diff --git a/app/Filament/Resources/BadgeCategoryResource/Pages/CreateBadgeCategory.php b/app/Filament/Resources/BadgeCategoryResource/Pages/CreateBadgeCategory.php index aaf3ec64..0c3d9d2b 100644 --- a/app/Filament/Resources/BadgeCategoryResource/Pages/CreateBadgeCategory.php +++ b/app/Filament/Resources/BadgeCategoryResource/Pages/CreateBadgeCategory.php @@ -1,9 +1,10 @@ 'list', + 'categories' => $this->getProjectCategories(), + 'counties' => $this->getCounties(), + 'collection' => new BcrProjectCardCollection( + QueryBuilder::for(BCRProject::class) + ->allowedFilters([ + AllowedFilter::exact('county', 'county_id'), + AllowedFilter::exact('category', 'project_category_id'), + AllowedFilter::custom('date', new BcrProjectDatesFilter), + AllowedFilter::custom('search', new SearchFilter), + ]) + ->allowedSorts([ + AllowedSort::field('publish_date', 'start_date'), + AllowedSort::field('end_date', 'end_date'), + ]) + ->orderBy('id', 'desc') + ->paginate() + ->withQueryString() + ), + ]); + } + + public function show(BCRProject $project) + { + return Inertia::render('Public/Bcr/Show', [ + 'project' => new BcrProjectResource($project), + ]); + } +} diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index bee28a43..5620b4db 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -8,6 +8,7 @@ use App\Http\Resources\BCRProjectCardResource; use App\Http\Resources\ProjectCardResource; use App\Models\Article; +use App\Models\BCRProject; use App\Models\Organization; use App\Models\Project; use Inertia\Inertia; @@ -35,8 +36,8 @@ public function index() ), 'bcr_projects' => BCRProjectCardResource::collection( - Project::whereIsOpen() - // TODO: ->whereOrganizationIsBCR() + BCRProject::query() + ->with('county') ->limit(12) ->get() ), diff --git a/app/Http/Filters/BcrProjectDatesFilter.php b/app/Http/Filters/BcrProjectDatesFilter.php new file mode 100644 index 00000000..2dbf87cb --- /dev/null +++ b/app/Http/Filters/BcrProjectDatesFilter.php @@ -0,0 +1,21 @@ +whereDate('start_date', '>=', $start) + ->whereDate('end_date', '<=', $end); + } +} diff --git a/app/Http/Resources/BCRProjectCardResource.php b/app/Http/Resources/BCRProjectCardResource.php index 139f0473..644607e2 100644 --- a/app/Http/Resources/BCRProjectCardResource.php +++ b/app/Http/Resources/BCRProjectCardResource.php @@ -15,18 +15,20 @@ public function toArray(Request $request): array { return [ 'id' => $this->id, - // 'type' => $this->type, + 'type' => 'bcr_project', 'name' => $this->name, 'slug' => $this->slug, - 'county' => 'Replace me', // $this->county?->name, - 'image' => Vite::asset('resources/images/placeholder.png'), - 'organization' => [ - 'name' => $this->organization->name, - 'id' => $this->organization->id, - ], + 'county' => $this->county?->name, + 'image' => $this->getFirstMediaUrl('preview') ?? Vite::image('placeholder.png'), + 'description' => $this->description, + 'start_date' => $this->start_date, + 'end_date' => $this->end_date, + 'facebook_link' => $this->facebook_link, + 'is_national' => $this->is_national, + 'accepting_comments' => $this->accepting_comments, + 'videos' => $this->videos, + 'external_links' => $this->external_links, - 'is_active' => $this->is_active, - 'is_ending_soon' => $this->is_ending_soon, ]; } } diff --git a/app/Http/Resources/BcrProjectResource.php b/app/Http/Resources/BcrProjectResource.php new file mode 100644 index 00000000..a37ecfe2 --- /dev/null +++ b/app/Http/Resources/BcrProjectResource.php @@ -0,0 +1,51 @@ + $this->id, + 'name' => $this->name, + 'slug' => $this->slug, + 'county' => $this->county->name, + 'image' => $this->getFirstMediaUrl('preview'), + 'gallery' => $this->getMedia('gallery')->map(function ($media) { + return [ + 'id' => $media->id, + 'url' => $media->getFullUrl(), + ]; + })->toArray(), + 'is_national' => \boolval($this->is_national), + 'area' => $this->is_national ? __('bcr-project.labels.national') : $this->county->name, + 'start' => $this->start_date?->format('d.m.Y'), + 'end' => $this->end_date?->format('d.m.Y'), + 'description' => $this->description, + 'accepting_comments' => \boolval($this->accepting_comments), + 'embedded_videos' => $this->embedded_videos, + 'swipe_gallery' => $this->getMedia('gallery')->map(function ($media) { + return [ + 'src' => $media->getFullUrl(), + 'thumbnail' => $media->getFullUrl('preview'), + 'w' => 1200, + 'h' => 800, + ]; + })->toArray(), + 'external_links' => collect($this->external_links)->map(function (array $link) { + $link['source'] = parse_url($link['link'], \PHP_URL_HOST); + + return $link; + }), + 'category' => $this->category->name, + ]; + } +} diff --git a/app/Http/Resources/Collections/BcrProjectCardCollection.php b/app/Http/Resources/Collections/BcrProjectCardCollection.php new file mode 100644 index 00000000..3b5884bd --- /dev/null +++ b/app/Http/Resources/Collections/BcrProjectCardCollection.php @@ -0,0 +1,20 @@ + \boolval($this->is_national), 'beneficiaries' => $this->beneficiaries, - 'start' => $this->start?->format('Y-m-d'), - 'end' => $this->end?->format('Y-m-d'), + 'start' => $this->start?->format('d.m.Y'), + 'end' => $this->end?->format('d.m.Y'), 'description' => $this->description, 'scope' => $this->scope, 'reason_to_donate' => $this->reason_to_donate, diff --git a/app/Http/Resources/ProjectCardResource.php b/app/Http/Resources/ProjectCardResource.php index 303ea5d0..b61c146a 100644 --- a/app/Http/Resources/ProjectCardResource.php +++ b/app/Http/Resources/ProjectCardResource.php @@ -14,7 +14,7 @@ public function toArray(Request $request): array { return [ 'id' => $this->id, - // 'type' => $this->type, + 'type' => 'project', 'name' => $this->name, 'slug' => $this->slug, 'county' => $this->counties->pluck('name')->join(', '), // $this->county?->name, diff --git a/app/Models/BCRProject.php b/app/Models/BCRProject.php index 660b9303..7f0476a1 100644 --- a/app/Models/BCRProject.php +++ b/app/Models/BCRProject.php @@ -5,6 +5,8 @@ namespace App\Models; use App\Concerns\HasLocation; +use Embed\Embed; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -21,7 +23,7 @@ class BCRProject extends Model implements HasMedia use InteractsWithMedia; protected $fillable = [ - 'title', + 'name', 'description', 'start_date', 'end_date', @@ -44,6 +46,10 @@ class BCRProject extends Model implements HasMedia 'is_national' => 'boolean', ]; + protected $with =[ + 'county','category' + ]; + public function registerMediaCollections(): void { $this->addMediaCollection('preview') @@ -69,4 +75,31 @@ public function category(): BelongsTo { return $this->belongsTo(ProjectCategory::class, 'project_category_id'); } + + public function getEmbeddedVideosAttribute(): array + { + $videos = $this->videos; + $embeddedVideos = []; + if (empty($videos)) { + return []; + } + foreach ($videos as $video) { + $embeddedUrl = rescue(fn () => (new Embed())->get($video['link'])->code, null); + $embeddedVideos[] = $embeddedUrl; + } + + return collect($embeddedVideos)->filter(fn ($item) => ! empty($item))->toArray(); + } + + //TODO MOVE IN TRAIT + public function scopeSearch(Builder $query, ?string $search): Builder + { + if (empty($search)) { + return $query; + } + $search = trim($search); + $search = strip_tags($search); + + return $query->where('name', 'like', "%{$search}%"); + } } diff --git a/app/Models/Badge.php b/app/Models/Badge.php index 75e234d7..819fb97a 100644 --- a/app/Models/Badge.php +++ b/app/Models/Badge.php @@ -23,11 +23,11 @@ class Badge extends Model implements HasMedia protected $fillable = [ 'title', 'description', - 'type' + 'type', ]; - protected $casts =[ - 'type' => BadgeType::class + protected $casts = [ + 'type' => BadgeType::class, ]; protected $appends = [ @@ -62,5 +62,4 @@ public function badgeCategory(): BelongsTo { return $this->belongsTo(BadgeCategory::class); } - } diff --git a/app/Models/Donation.php b/app/Models/Donation.php index 72deea53..763eda2b 100644 --- a/app/Models/Donation.php +++ b/app/Models/Donation.php @@ -32,6 +32,7 @@ class Donation extends Model 'charge_date', 'updated_without_correct_e_pid', ]; + protected $casts = [ 'status' => EuPlatescStatus::class, 'updated_without_correct_e_pid' => 'boolean', diff --git a/database/factories/BCRProjectFactory.php b/database/factories/BCRProjectFactory.php index e6d529c5..84b3f371 100644 --- a/database/factories/BCRProjectFactory.php +++ b/database/factories/BCRProjectFactory.php @@ -32,7 +32,7 @@ public function definition(): array $title = $this->faker->sentence(); return [ - 'title' => $title, + 'name' => $title, 'slug' => Str::slug($title), 'description' => $this->faker->paragraph(), 'start_date' => $this->faker->dateTimeBetween('-1 day', 'now'), diff --git a/database/factories/BadgeCategoryFactory.php b/database/factories/BadgeCategoryFactory.php index f185be55..112d5ee7 100644 --- a/database/factories/BadgeCategoryFactory.php +++ b/database/factories/BadgeCategoryFactory.php @@ -19,7 +19,7 @@ class BadgeCategoryFactory extends Factory public function definition(): array { return [ - 'title' => $this->faker->title , + 'title' => $this->faker->title, ]; } } diff --git a/database/factories/DonationFactory.php b/database/factories/DonationFactory.php index 0c0721e3..9097ee95 100644 --- a/database/factories/DonationFactory.php +++ b/database/factories/DonationFactory.php @@ -28,7 +28,6 @@ public function definition(): array fake()->dateTimeBetween('-1 days', 'today') ); - return [ 'organization_id' => Organization::factory(), 'project_id' => Project::factory(), diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 8896a35f..55ebbc4b 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -65,7 +65,7 @@ public function organizationAdmin(): static public function ngoManager(): static { return $this->state(fn (array $attributes) => [ - 'role' => UserRole::MANAGER, + 'role' => UserRole::MANAGER, ]); } diff --git a/database/migrations/2023_07_03_083038_create_badge_categories_table.php b/database/migrations/2023_07_03_083038_create_badge_categories_table.php index fd5a3833..d7f3f050 100644 --- a/database/migrations/2023_07_03_083038_create_badge_categories_table.php +++ b/database/migrations/2023_07_03_083038_create_badge_categories_table.php @@ -1,5 +1,7 @@ nullable() ->constrained() ->cascadeOnDelete(); - $table->string('title'); + $table->string('name'); $table->string('slug')->unique(); $table->text('description'); $table->date('start_date'); diff --git a/lang/ro.json b/lang/ro.json index de98bc53..19296f0b 100644 --- a/lang/ro.json +++ b/lang/ro.json @@ -385,6 +385,7 @@ "currency": "RON", "bcr_for_community": "BCR pentru comunitate", "articles": "Articole", + "project_period" : "Perioada proiect", "donate_to_a_project": "Donează către un proiect", "see_evolution": "Vezi evolutia faptelor bune", "find_projects": "Descoperă proiecte", diff --git a/lang/ro/bcr-project.php b/lang/ro/bcr-project.php index b878ad47..950c4be6 100644 --- a/lang/ro/bcr-project.php +++ b/lang/ro/bcr-project.php @@ -9,7 +9,7 @@ ], 'labels' => [ - 'title' => 'Titlu', + 'name' => 'Titlu', 'description' => 'Descriere', 'category' => 'Categorie', 'start_date' => 'Data de inceput', @@ -18,6 +18,7 @@ 'accepting_comments' => 'Accepta comentarii', 'county' => 'Judet', 'city' => 'Oras', + 'national' => 'National', 'videos' => 'Galerie video', 'external_links' => [ 'title' => 'Titlu', diff --git a/lang/ro/donation.php b/lang/ro/donation.php index e1545422..878117a1 100644 --- a/lang/ro/donation.php +++ b/lang/ro/donation.php @@ -26,7 +26,7 @@ 'created_at' => 'Data donației', 'approved_at' => 'Data aprobării', 'charged_date' => 'Data încasării', - 'in_championship' => "Este înscrisă în Campionat", + 'in_championship' => 'Este înscrisă în Campionat', 'has_user' => 'Este utilizator inregistrat', 'full_name' => 'Donator', 'email' => 'Email', diff --git a/resources/js/Components/Navbar.vue b/resources/js/Components/Navbar.vue index 3b6b9f1b..5489896d 100644 --- a/resources/js/Components/Navbar.vue +++ b/resources/js/Components/Navbar.vue @@ -242,7 +242,7 @@ { name: 'BCR pentru comunitate', description: 'Descoperă proiectele organizate de BCR.', - href: route('bcr.projects'), + href: route('bcr.index'), }, { name: 'Campionatul de Bine', diff --git a/resources/js/Components/cards/ProjectCard.vue b/resources/js/Components/cards/ProjectCard.vue index 9cebf10e..b17020d1 100644 --- a/resources/js/Components/cards/ProjectCard.vue +++ b/resources/js/Components/cards/ProjectCard.vue @@ -1,7 +1,8 @@