PHP code example of aurorawebsoftware / acalendar

1. Go to this page and download the library: Download aurorawebsoftware/acalendar library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

aurorawebsoftware / acalendar example snippets


namespace App\Models;

use AuroraWebSoftware\ACalendar\Contracts\EventableModelContract;
use AuroraWebSoftware\ACalendar\Traits\HasEvents;
use Illuminate\Database\Eloquent\Model;

class Task extends Model implements EventableModelContract
{
    use HasEvents;

    protected $fillable = ['name'];

    public static function getModelType(): string
    {
        return self::class;
    }

    public function getModelId(): int
    {
        return $this->id;
    }

    public function getEventTitle(): ?string
    {
        return $this->name;
    }
}


$task = Task::find(1);
$task->updateOrCreateEvent(
    key: 'deadline',
    type: Type::DATE_POINT,
    start: Carbon::tomorrow(),
    title: 'Preparing SRS Docs'
);

$task->updateOrCreateEvent(
    key: 'deadline',
    type: Type::DATE_POINT,
    start: Carbon::tomorrow(),
    title: 'Preparing SRS Docs'
);


$events = $task->eventInstances('deadline', Carbon::now(), Carbon::now()->addMonth(1));

$events = Task::allEventInstances('deadline', Carbon::now(), Carbon::now()->addMonth(1));

$meeting = Meeting::find(1);
$meeting->updateOrCreateEvent(
    key: 'Weekly Review',
    type: Type::DATETIME_POINT,
    start: Carbon::parse('next monday 10:00'),
    repeatFrequency: RepeatFrequency::WEEK,
    repeatPeriod: 1,
    title: 'Weekly Review Meeting'
);


$eventInstances = $meeting->eventInstances(null, Carbon::now(), Carbon::now()->addWeeks(4));
$byDay = $eventInstances->byDay();

foreach ($byDay as $date => $events) {
    echo "Date: $date\n";
    foreach ($events as $event) {
        echo "- {$event->title} at {$event->start->format('H:i')}\n";
    }
}


$conference = Conference::create(['name' => 'Tech Innovators Conference', 'description' => 'A gathering of technology innovators.']);

$conference->updateOrCreateEvent(
    key: 'tech_innovators_2024',
    type: Type::DATE_ALL_DAY,
    start: Carbon::parse('2024-09-10'),
    title: 'Tech Innovators Conference - All Day'
);


$webinar = Webinar::create(['title' => 'Digital Marketing 101', 'host' => 'Marketing Gurus']);

$webinar->updateOrCreateEvent(
    key: 'digital_marketing_101',
    type: Type::DATE_RANGE,
    start: Carbon::parse('2024-10-05'),
    end: Carbon::parse('2024-10-07'),
    title: 'Digital Marketing 101 Webinar'
);


$exhibition = Exhibition::create(['name' => 'Artists of the 21st Century', 'location' => 'City Art Gallery']);

$exhibition->updateOrCreateEvent(
    key: '21st_century_artists',
    type: Type::DATETIME_RANGE,
    start: Carbon::parse('2024-11-20 09:00'),
    end: Carbon::parse('2024-11-20 17:00'),
    title: 'Artists of the 21st Century Exhibition'
);


phpCopy code
$upcomingConferences = Conference::allEventInstances(
    null,
    Carbon::now(),
    Carbon::now()->addYear(1)
);

foreach ($upcomingConferences as $event) {
    echo "Conference: {$event->title} on {$event->start->toDateString()}\n";
}


phpCopy code
$nextMonthWebinars = Webinar::allEventInstances(
    null,
    Carbon::now()->addMonth(),
    Carbon::now()->addMonths(2)
)->byDay();

foreach ($nextMonthWebinars as $date => $webinars) {
    echo "Date: $date\n";
    foreach ($webinars as $webinar) {
        echo "- Webinar: {$webinar->title} from {$webinar->start->toDateString()} to {$webinar->end->toDateString()}\n";
    }
}


phpCopy code
$exhibitionDetails = Exhibition::allEventInstances('21st_century_artists', Carbon::now(), Carbon::now()->addMonth(1));

foreach ($exhibitionDetails as $detail) {
    echo "Exhibition: {$detail->title}, Start: {$detail->start->toDateTimeString()}, End: {$detail->end->toDateTimeString()}\n";
}

bash
php artisan vendor:publish --provider="AuroraWebSoftware\ACalendar\ACalendarServiceProvider"

bash
php artisan migrate