Snapshot of main at 9f39a6e1e (2026-11-02)

This commit is contained in:
Ronald Huynen committed 2026-11-02 10:41:47 +01:00
commit 6ccf1792d7
2580 files changed
+1040202

No files matched your search

@@ -0,0 +1,218 @@
<?php
namespace App\Overrides\Asdh\LaravelFlatpickr\Components;
use Carbon\Carbon;
use Illuminate\Support\Str;
use Illuminate\View\Component;
/**
* Override of vendor/asdh/laravel-flatpickr to fix UTC timezone offset bug.
*
* The original component converts all dates to millisecond timestamps via
* Carbon::getTimestampMs(). Flatpickr receives these as UTC timestamps and
* interprets them in the browser's local timezone. For UTC+ timezones, midnight
* UTC becomes the previous day locally — causing dates to shift -1 day on each
* page load when combined with wire:model.
*
* Fix: pass date strings (Y-m-d) instead of timestamps so flatpickr parses
* them without any timezone conversion.
*/
class Flatpickr extends Component
{
public function __construct(
public array $config = [],
public string|int|null $id = null,
public bool $showTime = false,
public string $dateFormat = 'Y-m-d',
public string $timeFormat = 'H:i',
public ?string $altFormat = null,
public string|Carbon|null $minDate = null,
public string|Carbon|null $maxDate = null,
public string|null $minTime = null,
public string|null $maxTime = null,
public int $firstDayOfWeek = 0,
public array $disable = [],
public bool $disableWeekend = false,
public array $enable = [],
public bool $multiple = false,
public bool $range = false,
public ?int $visibleMonths = null,
public string|array|Carbon|null $value = null,
public bool $inline = false,
public bool $showWeekNumbers = false,
public bool $time24hr = true,
public bool $clearable = false,
public bool $disableMobile = true,
) {
$this->id = $this->id ?: Str::random(16);
if ($this->mode() === 'range' && $this->visibleMonths === null) {
$this->visibleMonths = 2;
}
$this->throwValueExceptions();
}
public function config(): array
{
return collect([
'enableTime' => $this->showTime ?: null,
'dateFormat' => $this->dateFormat(),
'altInput' => true,
'altFormat' => $this->altFormat ?: $this->dateFormat(),
'time_24hr' => $this->time24hr(),
'minDate' => $this->minDate(),
'maxDate' => $this->maxDate(),
'minTime' => $this->minTime,
'maxTime' => $this->maxTime,
'enable' => count($this->enable) > 0 ? $this->enable() : null,
'disable' => $this->disable(),
'mode' => $this->mode(),
'defaultDate' => $this->value(),
'inline' => $this->inline ?: null,
'weekNumbers' => $this->showWeekNumbers ?: null,
'wrap' => $this->clearable ?: null,
'showMonths' => $this->visibleMonths,
'disableMobile' => $this->disableMobile ?: false,
])
->merge($this->config)
->filter(fn ($item) => $item !== null)
->toArray();
}
public function disable(): array
{
return $this->formatDates($this->disable);
}
public function enable(): array
{
return $this->formatDates($this->enable);
}
private function dateFormat(): string
{
return $this->showTime ? "{$this->dateFormat} {$this->timeFormat}" : $this->dateFormat;
}
private function minDate(): ?string
{
return $this->minDate ? Carbon::parse($this->minDate)->format('Y/m/d') : null;
}
private function maxDate(): ?string
{
return $this->maxDate ? Carbon::parse($this->maxDate)->format('Y/m/d') : null;
}
private function mode()
{
if ($this->range) {
return 'range';
}
return $this->multiple ? 'multiple' : null;
}
private function value(): string|array|null
{
if (! $this->value) {
return null;
}
if ($this->multiple) {
return $this->formatDates($this->value);
}
if ($this->range) {
if (is_array($this->value)) {
return $this->formatDates($this->value);
}
return $this->value;
}
return Carbon::parse($this->value)->format('Y/m/d');
}
private function formatDates(array $items): array
{
return collect($items)
->filter()
->map(fn ($item) => Carbon::parse($item)->format('Y/m/d'))
->values()
->toArray();
}
public function containerId(): string
{
return "{$this->id}-container";
}
public function selectorId(): string
{
return $this->clearable ? $this->containerId() : $this->id;
}
private function time24hr(): ?bool
{
if (! $this->showTime) {
return null;
}
return $this->time24hr;
}
public function render()
{
return view('flatpickr::flatpickr.index');
}
public function defaultClearer()
{
return view('flatpickr::flatpickr.clear');
}
private function throwValueExceptions()
{
if (! $this->value) {
return;
}
switch ($this->mode()) {
case 'multiple':
if (! is_array($this->value)) {
throw new \Exception("The value must be array of dates or Carbon instances when multiple is set.");
}
break;
case 'range':
if (is_array($this->value)) {
if (count($this->value) !== 2) {
throw new \Exception("The value must be an array with only 2 dates when range is set.");
}
return;
}
if (! is_string($this->value)) {
throw new \Exception("The value must be string when range is set.");
}
if (! Str::contains($this->value, ' to ')) {
throw new \Exception("The two dates must be string and separated by ' to ' in between.");
}
break;
default:
if (is_array($this->value)) {
throw new \Exception("The value cannot be array. Please provide a date string or Carbon instance.");
}
break;
}
}
}
@@ -0,0 +1,98 @@
<?php
namespace Laravel\Jetstream;
use App\Models\Organization;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Laravel\Jetstream\Features;
trait HasProfilePhoto
{
/**
* Update the user's profile photo.
*
* @param \Illuminate\Http\UploadedFile $photo
* @return void
*/
public function updateProfilePhoto(UploadedFile $photo)
{
tap($this->profile_photo_path, function ($previous) use ($photo) {
$this->forceFill([
'profile_photo_path' => $photo->storePublicly(
'profile-photos',
['disk' => $this->profilePhotoDisk()]
),
])->save();
// Only delete a previous profile-photo, and not a previous default-photo in 'app-images/'
if (str_starts_with($previous, 'profile-photos/')) {
Storage::disk($this->profilePhotoDisk())->delete($previous);
}
});
}
/**
* Delete the user's profile photo.
*
* @return void
*/
public function deleteProfilePhoto()
{
if (! Features::managesProfilePhotos()) {
return;
}
if (is_null($this->profile_photo_path)) {
return;
}
// Only delete a profile-photo, and not a default-photo in 'app-images/'
if (str_starts_with($this->profile_photo_path, 'profile-photos/')) {
Storage::disk($this->profilePhotoDisk())->delete($this->profile_photo_path);
$this->forceFill([
'profile_photo_path' => timebank_config('profiles.user.profile_photo_path_default'),
])->save();
Session(['activeProfilePhoto'=> $this->profile_photo_path ]);
}
}
/**
* Get the URL to the user's profile photo.
*
* @return string
*/
public function getProfilePhotoUrlAttribute()
{
return $this->profile_photo_path && Storage::disk($this->profilePhotoDisk())->exists($this->profile_photo_path)
? Storage::disk($this->profilePhotoDisk())->url($this->profile_photo_path)
: $this->defaultProfilePhotoUrl();
}
/**
* Get the default profile photo URL if no profile photo has been uploaded.
*
* @return string
*/
protected function defaultProfilePhotoUrl()
{
if (session('activeProfileType') == Organization::class) {
return timebank_config('profiles.organization.profile_photo_path_default');
} else {
return timebank_config('profiles.user.profile_photo_path_default');
}
}
/**
* Get the disk that profile photos should be stored on.
*
* @return string
*/
protected function profilePhotoDisk()
{
return isset($_ENV['VAPOR_ARTIFACT_NAME']) ? 's3' : config('jetstream.profile_photo_disk', 'public');
}
}
@@ -0,0 +1,118 @@
<?php
namespace App\Overrides\Matchish\ScoutElasticSearch\ElasticSearch;
use Illuminate\Database\Eloquent\Model;
use IteratorAggregate;
use Laravel\Scout\Builder;
use Laravel\Scout\Searchable;
use Traversable;
/**
* @internal
*/
final class EloquentHitsIteratorAggregate implements IteratorAggregate
{
/**
* @var array
*/
private $results;
/**
* @var callable|null
*/
private $callback;
/**
* @param array $results
* @param callable|null $callback
*/
public function __construct(array $results, callable $callback = null)
{
$this->results = $results;
$this->callback = $callback;
}
/**
* Retrieve an external iterator.
*
* @link https://php.net/manual/en/iteratoraggregate.getiterator.php
*
* @return Traversable An instance of an object implementing <b>Iterator</b> or
* <b>Traversable</b>
*
* @since 5.0.0
*/
public function getIterator(): Traversable
{
$hits = collect();
if ($this->results['hits']['total']) {
$raw = collect($this->results['hits']['hits']);
$models = $this->collectModels($raw);
$eloquentHits = $this->getEloquentHits($raw, $models);
$hits = $this->mergeHighlightsIntoModels($eloquentHits, $raw);
// $hits2 = $this->mergeCustomFieldsIntoModels($eloquentHits, $raw);
}
return new \ArrayIterator($hits);
}
private function collectModels($rawHits)
{
return collect($rawHits)->groupBy('_source.__class_name')
->map(function ($results, $class) {
$model = new $class();
$builder = new Builder($model, '');
if (! empty($this->callback)) {
$builder->query($this->callback);
}
/* @var Searchable $model */
return $models = $model->getScoutModelsByIds(
$builder,
$results->pluck('_id')->all()
);
})
->flatten()->keyBy(function ($model) {
return get_class($model).'::'.$model->getScoutKey();
});
}
private function getEloquentHits($hits, $models)
{
return collect($hits)->map(function ($hit) use ($models) {
$key = $hit['_source']['__class_name'].'::'.$hit['_id'];
return isset($models[$key]) ? $models[$key] : null;
})->filter()->all();
}
private function mergeHighlightsIntoModels($eloquentHits, $raw)
{
return collect($eloquentHits)->map(function (Model $eloquentHit) use ($raw) {
$raw = collect($raw)
->where('_source.__class_name', get_class($eloquentHit))
->where('_source.id', $eloquentHit->id)
->first();
foreach($raw['highlight'] ?? [] as $key => $highlight) {
$eloquentHit->setAttribute($key, $highlight[0]);
}
return $eloquentHit;
})->all();
}
// private function mergeCustomFieldsIntoModels($eloquentHits, $raw){
// return collect($eloquentHits)->map(function(Model $eloquentHit) use($raw){
// $raw = collect($raw)
// ->where('_source.__class_name', get_class($eloquentHit))
// ->where('_source.id', $eloquentHit->id)
// ->first()['_source'];
// $source = collect($raw);
// $eloquentHit->setAttribute('published_from', $source->get('published_from'));
// $eloquentHit->setAttribute('published_to', $source->get('published_to'));
// return $eloquentHit;
// })->all();
// }
}