Skip to content

Commit

Permalink
Merge branch 'main' of github.com:inikoo/wowsbar into main
Browse files Browse the repository at this point in the history
  • Loading branch information
YudhistiraA committed Oct 7, 2023
2 parents cb29ca9 + 565fca1 commit 069afe0
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 48 deletions.
46 changes: 32 additions & 14 deletions app/Actions/HumanResources/JobPosition/HydrateJobPosition.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,32 @@

namespace App\Actions\HumanResources\JobPosition;

use App\Actions\HydrateModel;
use App\Actions\Traits\WithNormalise;
use App\Models\HumanResources\JobPosition;
use Illuminate\Support\Collection;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Lorisleiva\Actions\Concerns\AsAction;

class HydrateJobPosition extends HydrateModel
class HydrateJobPosition
{
use AsAction;
use WithNormalise;

public string $commandSignature = 'hydrate:job-positions {tenants?*} {--i|id=}';

public function handle(JobPosition $jobPosition): void
{
$jobPosition->update(
[
'number_employees' => DB::table('employee_job_position')->where('job_position_id', $jobPosition->id)->count(),
'number_work_time' => DB::table('employee_job_position')->where('job_position_id', $jobPosition->id)->sum('share'),
'number_employees' => DB::table('job_positionables')->where('job_position_id', $jobPosition->id)->count(),
'number_work_time' => DB::table('job_positionables')->where('job_position_id', $jobPosition->id)->sum('share'),
]
);


$this->updateNormalisedJobPositionsShare();
}

private function updateNormalisedJobPositionsShare()
private function updateNormalisedJobPositionsShare(): void
{
foreach ($this->getNormalisedJobPositionsShare() as $id => $share) {
JobPosition::find($id)->update(
Expand All @@ -46,21 +46,39 @@ private function updateNormalisedJobPositionsShare()
private function getNormalisedJobPositionsShare(): array
{
$share = [];
/** @var \App\Models\HumanResources\JobPosition $jobPosition */
foreach (JobPosition::all() as $jobPosition) {
$share[$jobPosition->id] = $jobPosition->number_work_time;
}

return $this->normalise(collect($share));
}

protected function getModel(int $id): JobPosition
{
return JobPosition::findOrFail($id);
}
public string $commandSignature = 'hydrate:job-positions {job-positions?*}';

protected function getAllModels(): Collection
public function asCommand(Command $command): int
{
return JobPosition::all();

if(!$command->argument('job-positions')) {
$jobPositions=JobPosition::all();
} else {
$jobPositions = JobPosition::query()
->when($command->argument('job-positions'), function ($query) use ($command) {
$query->whereIn('slug', $command->argument('job-positions'));
})
->cursor();
}


$exitCode = 0;

foreach ($jobPositions as $jobPosition) {

$this->handle($jobPosition);
$command->line("Jon position $jobPosition->name hydrated 💦");

}

return $exitCode;
}

}
28 changes: 14 additions & 14 deletions app/Actions/Portfolio/Banner/PublishBanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ public function handle(Banner $banner, array $modelData): Banner
$snapshot = StoreBannerSnapshot::run(
$banner,
[
'state' => SnapshotStateEnum::LIVE,
'published_at' => now(),
'layout' => $layout,
'first_commit' => $firstCommit,
'comment' => Arr::get($modelData, 'comment'),
'user_id' => Arr::get($modelData, 'user_id'),
'user_type' => Arr::get($modelData, 'user_type'),
'state' => SnapshotStateEnum::LIVE,
'published_at' => now(),
'layout' => $layout,
'first_commit' => $firstCommit,
'comment' => Arr::get($modelData, 'comment'),
'publisher_id' => Arr::get($modelData, 'publisher_id'),
'publisher_type' => Arr::get($modelData, 'publisher_type'),


],
Expand Down Expand Up @@ -101,20 +101,20 @@ public function authorize(ActionRequest $request): bool
public function rules(): array
{
return [
'layout' => ['required', 'array:delay,common,components'],
'comment' => ['sometimes', 'required', 'string', 'max:1024'],
'user_id' => ['sometimes'],
'user_type' => ['sometimes', 'string'],
'layout' => ['required', 'array:delay,common,components'],
'comment' => ['sometimes', 'required', 'string', 'max:1024'],
'publisher_id' => ['sometimes'],
'publisher_type' => ['sometimes', 'string'],
];
}

public function prepareForValidation(ActionRequest $request): void
{
$request->merge(
[
'layout' => $request->only(['delay', 'common', 'components']),
'user_id' => $request->get('customerUser')->id,
'user_type' => 'CustomerUser'
'layout' => $request->only(['delay', 'common', 'components']),
'publisher_id' => $request->get('customerUser')->id,
'publisher_type' => 'CustomerUser'
]
);
}
Expand Down
25 changes: 19 additions & 6 deletions app/Actions/Web/Webpage/PublishWebpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class PublishWebpage

public function handle(Webpage $webpage, array $modelData): Webpage
{
$firstCommit = false;
if ($webpage->state == WebpageStateEnum::IN_PROCESS or $webpage->state == WebpageStateEnum::READY) {
$firstCommit = true;
}

foreach ($webpage->snapshots()->where('state', SnapshotStateEnum::LIVE)->get() as $liveSnapshot) {
UpdateSnapshot::run($liveSnapshot, [
'state' => SnapshotStateEnum::HISTORIC,
Expand All @@ -40,9 +45,13 @@ public function handle(Webpage $webpage, array $modelData): Webpage
$snapshot = StoreWebpageSnapshot::run(
$webpage,
[
'state' => SnapshotStateEnum::LIVE,
'published_at' => now(),
'layout' => $layout
'state' => SnapshotStateEnum::LIVE,
'published_at' => now(),
'layout' => $layout,
'first_commit' => $firstCommit,
'comment' => Arr::get($modelData, 'comment'),
'publisher_id' => Arr::get($modelData, 'publisher_id'),
'publisher_type' => Arr::get($modelData, 'publisher_type'),
]
);

Expand Down Expand Up @@ -79,16 +88,20 @@ public function authorize(ActionRequest $request): bool
public function rules(): array
{
return [
'layout' => ['required', 'array:delay,common,components'],
'comment' => ['sometimes', 'required', 'string', 'max:1024']
'layout' => ['required', 'array:delay,common,components'],
'comment' => ['sometimes', 'required', 'string', 'max:1024'],
'publisher_id' => ['sometimes'],
'publisher_type' => ['sometimes', 'string'],
];
}

public function prepareForValidation(ActionRequest $request): void
{
$request->merge(
[
'layout' => $request->only(['delay', 'common', 'components']),
'layout' => $request->only(['delay', 'common', 'components']),
'publisher_id' => $request->user()->id,
'publisher_type' => 'OrganisationUser'
]
);
}
Expand Down
34 changes: 26 additions & 8 deletions app/Actions/Web/Website/PublishWebsiteMarginal.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,16 @@ public function handle(Website $website, string $marginal, array $modelData): vo
{
$layout = [];
if ($marginal == 'header') {
$layout=$website->unpublishedHeaderSnapshot->layout;
$layout = $website->unpublishedHeaderSnapshot->layout;
} elseif ($marginal == 'footer') {
$layout = $website->unpublishedFooterSnapshot->layout;
}

$firstCommit = true;


foreach ($website->snapshots()->where('scope', $marginal)->where('state', SnapshotStateEnum::LIVE)->get() as $liveSnapshot) {
$firstCommit = false;
UpdateSnapshot::run($liveSnapshot, [
'state' => SnapshotStateEnum::HISTORIC,
'published_until' => now()
Expand All @@ -45,16 +48,19 @@ public function handle(Website $website, string $marginal, array $modelData): vo
$snapshot = StoreWebsiteSnapshot::run(
$website,
[
'state' => SnapshotStateEnum::LIVE,
'published_at' => now(),
'layout' => $layout,
'scope' => $marginal,
'comment' => Arr::get($modelData, 'comment')
'state' => SnapshotStateEnum::LIVE,
'published_at' => now(),
'layout' => $layout,
'scope' => $marginal,
'first_commit' => $firstCommit,
'comment' => Arr::get($modelData, 'comment'),
'publisher_id' => Arr::get($modelData, 'publisher_id'),
'publisher_type' => Arr::get($modelData, 'publisher_type'),
],
);


$updateData = [
$updateData = [
"live_{$marginal}_snapshot_id" => $snapshot->id,
"compiled_layout->$marginal" => $snapshot->compiledLayout()
];
Expand All @@ -71,10 +77,22 @@ public function authorize(ActionRequest $request): bool
return $request->user()->hasPermissionTo("websites.edit");
}

public function prepareForValidation(ActionRequest $request): void
{
$request->merge(
[
'publisher_id' => $request->user()->id,
'publisher_type' => 'OrganisationUser'
]
);
}

public function rules(): array
{
return [
'comment' => ['sometimes', 'required', 'string', 'max:1024']
'comment' => ['sometimes', 'required', 'string', 'max:1024'],
'publisher_id' => ['sometimes'],
'publisher_type' => ['sometimes', 'string'],
];
}

Expand Down
4 changes: 2 additions & 2 deletions app/Http/Resources/Portfolio/SnapshotResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public function toArray(Request $request): array

$publisher = '';
$publisher_avatar = null;
if ($snapshot->user_id) {
if ($snapshot->publisher_id) {
/** @var CustomerUser $customerUser */
$customerUser = $snapshot->user;
$customerUser = $snapshot->publisher;

$publisher = $customerUser->user->contact_name;
$publisher_avatar = $customerUser->user->avatarImageSources(48, 48);
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Helpers/Snapshot.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function parent(): MorphTo
return $this->morphTo();
}

public function user(): MorphTo
public function publisher(): MorphTo
{
return $this->morphTo();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public function up(): void
Schema::create('snapshots', function (Blueprint $table) {
$table->mediumIncrements('id');
$table->string('slug')->nullable()->collation('und_ns');
$table->string('user_type')->nullable();
$table->unsignedSmallInteger('user_id')->nullable();
$table->string('publisher_type')->nullable();
$table->unsignedSmallInteger('publisher_id')->nullable();
$table->string('parent_type')->nullable();
$table->unsignedInteger('parent_id')->nullable();
$table->unsignedInteger('customer_id')->nullable();
Expand All @@ -33,7 +33,7 @@ public function up(): void
$table->timestampsTz();
$table->index(['parent_type', 'parent_id']);
$table->index(['parent_type', 'parent_id','scope']);
$table->index(['user_id', 'user_type']);
$table->index(['publisher_id', 'publisher_type']);

});

Expand Down

0 comments on commit 069afe0

Please sign in to comment.