Skip to content

Commit

Permalink
Merge pull request #3 from AuroraWebSoftware/v2-dev
Browse files Browse the repository at this point in the history
V2 dev
  • Loading branch information
emreakay authored Mar 14, 2024
2 parents 98812ea + b7aec8e commit 0c1f995
Show file tree
Hide file tree
Showing 24 changed files with 1,336 additions and 909 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
php-version: '8.2'
coverage: none

- name: Install composer dependencies
Expand Down
28 changes: 25 additions & 3 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,36 @@ jobs:
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.2, 8.1]
os: [ubuntu-latest]
php: [8.2]
laravel: [10.*]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 10.*
testbench: 8.*
testbench: 8.13
carbon: ^2.63

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

services:
mysql:
image: mysql:8.0
ports:
- 3306
env:
MYSQL_ROOT_PASSWORD: acalendar
MYSQL_PASSWORD: acalendar
MYSQL_USER: acalendar
MYSQL_DATABASE: acalendar
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

steps:
- name: Verify Mysql connection
run: |
mysql --version
sudo apt-get install -y mysql-client
mysql --host 127.0.0.1 --port ${{ job.services.mysql.ports['3306'] }} -uacalendar -pacalendar -e "SHOW DATABASES"
- name: Checkout code
uses: actions/checkout@v3

Expand All @@ -49,3 +67,7 @@ jobs:

- name: Execute tests
run: vendor/bin/pest --ci
env:
DB_USERNAME: acalendar
DB_PASSWORD: acalendar
DB_PORT: ${{ job.services.mysql.ports[3306] }}
4 changes: 2 additions & 2 deletions README-development.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
docker-compose up -d
composer test

pint
phpstan
./vendor/bin/pint
./vendor/bin/phpstan analyse
4 changes: 4 additions & 0 deletions README-todo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

- Tüm modellerin eventlerini alan bir facade
- config dosyasındaki gereklilik
- dökümantasyon
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,30 @@
{
public function up()
{
Schema::create('acalendar_aevents', function (Blueprint $table) {
Schema::create('acalendar_events', function (Blueprint $table) {
$table->id();
$table->string('event_type')->nullable(false)->index();
$table->string('tag')->nullable(false)->index();
$table->string('repeat_frequency')->nullable()->index();
$table->unsignedInteger('repeat_period')->nullable()->index();
$table->dateTime('repeat_until')->nullable()->index();
$table->string('model_type')->nullable()->index();
$table->unsignedInteger('model_id')->nullable()->index();
$table->string('name')->nullable(false);
$table->boolean('all_day')->default(false);
$table->string('key')->nullable(false)->index();
$table->enum('type',
['date_point', 'datetime_point', 'date_all_day', 'date_range', 'datetime_range']
)->default('date_point')->nullable(false)->index();
$table->string('title')->nullable(false);
$table->date('start_date')->nullable()->index();
$table->date('end_date')->nullable()->index();
$table->dateTime('start_datetime')->nullable()->index();
$table->dateTime('end_datetime')->nullable()->index();

$table->string('repeat_frequency')->nullable()->index();
$table->unsignedInteger('repeat_period')->nullable()->index();
$table->dateTime('repeat_until')->nullable()->index();
$table->timestamps();

$table->unique(['key', 'model_type', 'model_id']);
});
}

public function down()
{
Schema::drop('acalendar_aevents');
Schema::drop('acalendar_events');
}
};
35 changes: 35 additions & 0 deletions src/Collections/EventInstanceDTOCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace AuroraWebSoftware\ACalendar\Collections;

use AuroraWebSoftware\ACalendar\DTOs\EventInstanceDTO;
use Carbon\CarbonPeriod;
use Illuminate\Support\Collection;

class EventInstanceDTOCollection extends Collection
{
/**
* Group and sort by Calendar Day view
*/
public function byDay(): Collection
{
$byDayCollection = collect();

$this->each(function (EventInstanceDTO $eventInstanceDTO) use ($byDayCollection) {

$period = CarbonPeriod::create($eventInstanceDTO->start, $eventInstanceDTO->end ?? $eventInstanceDTO->start);

foreach ($period as $item) {

$key = $item->format('Y-m-d');

if ($byDayCollection->get($key) == null) {
$byDayCollection->put($key, collect());
}
$byDayCollection->get($key)->push($eventInstanceDTO);
}
});

return $byDayCollection;
}
}
7 changes: 0 additions & 7 deletions src/Contracts/ACalendarEventInstanceContract.php

This file was deleted.

39 changes: 0 additions & 39 deletions src/Contracts/AEventContract.php

This file was deleted.

70 changes: 70 additions & 0 deletions src/Contracts/EventableModelContract.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

namespace AuroraWebSoftware\ACalendar\Contracts;

use AuroraWebSoftware\ACalendar\Collections\EventInstanceDTOCollection;
use AuroraWebSoftware\ACalendar\DTOs\EventInstanceDTO;
use AuroraWebSoftware\ACalendar\Enums\RepeatFrequency;
use AuroraWebSoftware\ACalendar\Enums\Type;
use AuroraWebSoftware\ACalendar\Models\Event;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Carbon;

interface EventableModelContract
{
public static function getModelType(): string;

public function getModelId(): int;

public function getEventTitle(): ?string;

public function updateOrCreateEvent(
string $key,
Type $type,
?Carbon $start = null,
?Carbon $end = null,
?RepeatFrequency $repeatFrequency = null,
?int $repeatPeriod = null,
?Carbon $repeatUntil = null,
): Event;

/**
* returns the event with the given key with polymorphic relation
*
* @return Event|Builder<Event>
*/
public function event(string $key): Event|Builder;

/**
* returns the events of the model with the given keys with polymorphic relation
* returns all if $key is null
*
* @return Event|Builder<Event>
*/
public function events(?array $key = null): Event|Builder;

public function deleteEvent(string $key): void;

/**
* gives all events and recurring occurrences between $start and $end and given keys for a model instance with polymorphic relation
*
* @return EventInstanceDTOCollection<EventInstanceDTO>
*/
public function eventInstances(
array|string|null $keyOrKeys,
Carbon $start,
Carbon $end,
): EventInstanceDTOCollection;

/**
* gives all events and recurring occurrences between $start and $end and given keys for a model instance with polymorphic relation
*
* @return EventInstanceDTOCollection<EventInstanceDTO>
*/
public function scopeAllEventInstances(
Builder $query,
array|string|null $keyOrKeys,
Carbon $start,
Carbon $end,
): EventInstanceDTOCollection;
}
52 changes: 0 additions & 52 deletions src/DTOs/AEventInstanceDTO.php

This file was deleted.

61 changes: 61 additions & 0 deletions src/DTOs/EventInstanceDTO.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace AuroraWebSoftware\ACalendar\DTOs;

use AuroraWebSoftware\ACalendar\Enums\Type;
use Carbon\Carbon;

/**
* Represents an Instance of Event
*/
class EventInstanceDTO
{
/**
* Unique code for each event instance
*/
public string $code;

public ?string $modelType;

public ?int $modelId;

public string $key;

public Type $type;

public string $title;

public ?Carbon $start;

public ?Carbon $end;

public function __construct(
string $code,
?string $modelType,
?int $modelId,
string $key,
Type $type,
string $title,
?Carbon $start = null,
?Carbon $end = null
) {
$this->code = $code;
$this->modelType = $modelType;
$this->modelId = $modelId;
$this->key = $key;
$this->type = $type;
$this->title = $title;
$this->start = $start;
$this->end = $end;
}

public function calendarStartDatetimePoint(): Carbon
{
return $this->start;
}

public function calendarEndDatetimePoint(): Carbon
{
return $this->end;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

namespace AuroraWebSoftware\ACalendar\Enums;

/**
* Event Types
*/
enum AEventCollectionBreakdownEnum: string
enum CollectionBreakdown: string
{
case DAY = 'day';
}
Loading

0 comments on commit 0c1f995

Please sign in to comment.