Skip to content

Commit

Permalink
Cleaned up messy code in the conference block
Browse files Browse the repository at this point in the history
  • Loading branch information
khfiii committed Oct 11, 2023
1 parent d41fa0f commit 7d68348
Show file tree
Hide file tree
Showing 38 changed files with 664 additions and 1,709 deletions.
36 changes: 36 additions & 0 deletions app/Conference/Blocks/CommitteeBlock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Conference\Blocks;

use App\Livewire\Block;
use App\Models\Participant;

class CommitteeBlock extends Block
{
protected ?string $view = 'conference.blocks.committe-block';

protected ?int $sort = 4;

protected string $name = 'Committee Block';

protected ?string $position = 'right';

public function getViewData(): array
{
$participants = Participant::with('positions')
->whereHas('positions', function ($query) {
// Filter participants to include only those with 'committee' type positions.
$query->where('type', 'committee');
})
->orderBy('order_column') // Order the retrieved data by the 'order_column'.
->take(3) // Limit the query to retrieve only 3 participants.
->get();



return [
// Return the organized data with committee positions as keys and arrays of participants as values.
'participants' => $participants
];
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

namespace App\Website\Blocks;
namespace App\Conference\Blocks;

use App\Livewire\Block;
use App\Models\Conference;

class InformationBlock extends Block
{
protected ?string $view = 'website.blocks.information-block';
protected ?string $view = 'conference.blocks.information-block';

protected ?int $sort = 4;

Expand All @@ -19,4 +19,4 @@ public function getViewData(): array
{
return [];
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

namespace App\Website\Blocks;
namespace App\Conference\Blocks;

use App\Livewire\Block;
use App\Models\UserContent;

class MenuBlock extends Block
{
protected ?string $view = 'website.blocks.menu-block';
protected ?string $view = 'conference.blocks.menu-block';

protected ?int $sort = 2;

Expand Down
25 changes: 25 additions & 0 deletions app/Conference/Blocks/PreviousBlock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace App\Conference\Blocks;

use App\Livewire\Block;
use App\Models\Conference;
use App\Models\Enums\ConferenceStatus;

class PreviousBlock extends Block
{
protected ?string $view = 'conference.blocks.previous-block';

protected ?int $sort = 3;

protected string $name = 'Previous Block';

protected ?string $position = 'left';

public function getViewData(): array
{
return [
'archives' => Conference::where('status', ConferenceStatus::Archived)->get()
];
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

namespace App\Website\Blocks;
namespace App\Conference\Blocks;

use App\Livewire\Block;

class SubmitBlock extends Block
{
protected ?string $view = 'website.blocks.submit-block';
protected ?string $view = 'conference.blocks.submit-block';

protected ?int $sort = 1;

Expand Down
23 changes: 21 additions & 2 deletions app/Conference/Blocks/TimelineBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace App\Conference\Blocks;

use Carbon\Carbon;
use App\Livewire\Block;
use App\Models\Conference;
use App\Models\Timeline;

class TimelineBlock extends Block
Expand All @@ -16,10 +16,29 @@ class TimelineBlock extends Block

protected ?string $position = 'left';


public function getViewData(): array
{
$today = Carbon::now();

$timelines = Timeline::where('conference_id', app()->getCurrentConference()?->getKey())
->where(function ($query) use ($today) {
// 1 day before now (yesterday)
$query->where('date', $today->subDay()->toDateString())
->orWhereBetween('date', [
$today->addDays(1)->toDateString(), // Today
$today->addDays(2)->toDateString(), // 2 days ahead
]);
})
->orWhere(function ($query) {
// If no data matches the above criteria, display only the latest 3 data
$query->latest()->limit(3);
})
->orderBy('date')
->get();

return [
'timelines' => Timeline::where('conference_id', app()->getCurrentConference()?->getKey())->get(),
'timelines' => $timelines,
];
}
}
54 changes: 54 additions & 0 deletions app/Conference/Pages/Committe.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace App\Conference\Pages;

use App\Models\Participant;
use Rahmanramsi\LivewirePageGroup\Pages\Page;

class Committe extends Page
{
protected static string $view = 'conference.pages.committe';

public function mount()
{
//
}

public function getBreadcrumbs(): array
{
return [];
}

protected function getViewData(): array
{
// Retrieve participants with their associated committee positions.
$participants = Participant::with('positions')
->whereHas('positions', function ($query) {
// Filter participants to include only those with 'committee' type positions.
$query->where('type', 'committee');
})
->orderBy('order_column') // Order the retrieved data by the 'order_column'.
->get();

// Initialize an empty associative array to store organized data.
$groupedData = [];

// Iterate through each participant and their associated committee positions.
foreach ($participants as $participant) {
foreach ($participant->positions as $position) {
$positionName = $position->name;
if (!isset($groupedData[$positionName])) {
// Create an array for the committee position if it doesn't exist in $groupedData.
$groupedData[$positionName] = [];
}
// Add the participant to the respective committee position in $groupedData.
$groupedData[$positionName][] = $participant;
}
}

return [
// Return the organized data with committee positions as keys and arrays of participants as values.
'groupedCommittes' => $groupedData
];
}
}
29 changes: 29 additions & 0 deletions app/Conference/Pages/Timeline.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace App\Conference\Pages;

use App\Models\Timeline as ConferenceTimeline;
use Rahmanramsi\LivewirePageGroup\Pages\Page;

class Timeline extends Page
{
protected static string $view = 'conference.pages.timeline';

public function mount()
{
//
}

public function getBreadcrumbs(): array
{
return [];
}

protected function getViewData(): array
{
return [
'events' => ConferenceTimeline::with('conference')
->where('conference_id', app()->getCurrentConference()?->getKey())->get()
];
}
}
18 changes: 17 additions & 1 deletion app/Models/Timeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace App\Models;

use Carbon\Carbon;
use App\Models\Scopes\ConferenceScope;
use Illuminate\Database\Eloquent\Model;
use App\Models\Concerns\BelongsToConference;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Timeline extends Model
{
Expand All @@ -22,4 +24,18 @@ class Timeline extends Model
'roles' => 'array',
'date' => 'datetime'
];

public static function getTimelinesInRange()
{

return self::where('conference_id', app()->getCurrentConference()?->getKey())
->get();
}

// protected static function boot()
// {
// parent::boot();

// static::addGlobalScope(new ConferenceScope);
// }
}
4 changes: 2 additions & 2 deletions app/Models/UserContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ public function user()
public function scopeOrWhereMeta(Builder $q, string $key, $operator, $value = null): void
{
// Shift arguments if no operator is present.
if (! isset($value)) {
if (!isset($value)) {
$value = $operator;
$operator = '=';
}

// Convert value to its serialized version for comparison.
if (! is_string($value)) {
if (!is_string($value)) {
$value = $this->makeMeta($key, $value)->getRawValue();
}

Expand Down
7 changes: 6 additions & 1 deletion app/Panel/Resources/Conferences/ParticipantResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public static function generalFormField(): array
public static function additionalFormField(): array
{
return [
Forms\Components\TagsInput::make('meta.expertise')
->placeholder('')
->columnSpan([
'lg' => 2
]),
Forms\Components\TextInput::make('meta.affiliation')
->prefixIcon('heroicon-s-building-library')
->placeholder('University of Jakarta')
Expand All @@ -61,7 +66,7 @@ public static function additionalFormField(): array
Forms\Components\Select::make('meta.country')
->placeholder('Select a country')
->searchable()
->options(fn () => Country::all()->mapWithKeys(fn ($country) => [$country->id => $country->flag.' '.$country->name]))
->options(fn () => Country::all()->mapWithKeys(fn ($country) => [$country->id => $country->flag . ' ' . $country->name]))
->optionsLimit(250),
Forms\Components\TextInput::make('meta.phone')
->prefixIcon('heroicon-s-phone')
Expand Down
28 changes: 24 additions & 4 deletions app/Providers/ConferenceServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,22 @@

namespace App\Providers;

use App\Facades\Block;
use App\Conference\Pages\Home;
use App\Http\Middleware\IdentifyArchiveConference;
use App\Http\Middleware\IdentifyCurrentConference;
use App\Http\Middleware\SetupDefaultData;
use App\Conference\Blocks\MenuBlock;
use App\Conference\Blocks\TopicBlock;
use Illuminate\Support\Facades\Blade;
use App\Conference\Blocks\SubmitBlock;
use Illuminate\Support\ServiceProvider;
use Rahmanramsi\LivewirePageGroup\Facades\LivewirePageGroup;
use App\Conference\Blocks\CalendarBlock;
use App\Conference\Blocks\CommitteeBlock;
use App\Conference\Blocks\PreviousBlock;
use App\Conference\Blocks\TimelineBlock;
use App\Http\Middleware\SetupDefaultData;
use Rahmanramsi\LivewirePageGroup\PageGroup;
use App\Http\Middleware\IdentifyArchiveConference;
use App\Http\Middleware\IdentifyCurrentConference;
use Rahmanramsi\LivewirePageGroup\Facades\LivewirePageGroup;

class ConferenceServiceProvider extends ServiceProvider
{
Expand Down Expand Up @@ -42,6 +50,18 @@ protected function currentConference(PageGroup $pageGroup): PageGroup
->path('current')
->layout('website.components.layouts.app')
->homePage(Home::class)
->bootUsing(function () {
Block::registerBlocks([
CalendarBlock::class,
TimelineBlock::class,
PreviousBlock::class,
SubmitBlock::class,
TopicBlock::class,
MenuBlock::class,
CommitteeBlock::class
]);
Block::boot();
})
->middleware([
'web',
IdentifyCurrentConference::class,
Expand Down
Loading

0 comments on commit 7d68348

Please sign in to comment.