Initial commit

This commit is contained in:
Ronald Huynen
2026-03-23 21:37:59 +01:00
commit 2547717edb
2193 changed files with 972171 additions and 0 deletions

View File

@@ -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');
}
}

View File

@@ -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();
// }
}