first commit
This commit is contained in:
10
app/Enums/ActivityType.php
Normal file
10
app/Enums/ActivityType.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum ActivityType: string
|
||||
{
|
||||
case ALL = 'all';
|
||||
case COMMENTS = 'comments';
|
||||
case HISTORY = 'history';
|
||||
}
|
||||
26
app/Enums/AttachmentStatus.php
Normal file
26
app/Enums/AttachmentStatus.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum AttachmentStatus: int
|
||||
{
|
||||
/**
|
||||
* file just uploaded, attachmentable not set yet, not calculating hash
|
||||
*/
|
||||
case NOT_ATTACHED = 0;
|
||||
|
||||
/**
|
||||
* moving file to correct project folder and then calculating hash
|
||||
*/
|
||||
case PROCESSING = 1;
|
||||
|
||||
/**
|
||||
* file hash matched (on cron check and initial upload)
|
||||
*/
|
||||
case GOOD = 2;
|
||||
|
||||
/**
|
||||
* file hash NOT matched (on cron check)
|
||||
*/
|
||||
case BAD = 3;
|
||||
}
|
||||
9
app/Enums/DashboardSortBy.php
Normal file
9
app/Enums/DashboardSortBy.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum DashboardSortBy: string
|
||||
{
|
||||
case USER_NAME = 'user';
|
||||
case WORKED = 'worked';
|
||||
}
|
||||
13
app/Enums/Role.php
Normal file
13
app/Enums/Role.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum Role: int
|
||||
{
|
||||
case ANY = -1;
|
||||
|
||||
case ADMIN = 0;
|
||||
case MANAGER = 1;
|
||||
case USER = 2;
|
||||
case AUDITOR = 3;
|
||||
}
|
||||
75
app/Enums/ScreenshotsState.php
Normal file
75
app/Enums/ScreenshotsState.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use Settings;
|
||||
|
||||
enum ScreenshotsState: int
|
||||
{
|
||||
case ANY = -1;
|
||||
case FORBIDDEN = 0;
|
||||
case REQUIRED = 1;
|
||||
case OPTIONAL = 2;
|
||||
|
||||
public function title(): string
|
||||
{
|
||||
return strtolower($this->name);
|
||||
}
|
||||
|
||||
public function mustBeInherited(): bool
|
||||
{
|
||||
return $this === self::FORBIDDEN || $this === self::REQUIRED;
|
||||
}
|
||||
|
||||
public static function tryFromString(string $value): ?ScreenshotsState
|
||||
{
|
||||
try {
|
||||
return constant(__CLASS__ . "::" . strtoupper($value));
|
||||
} catch (\Throwable $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'value' => $this->value,
|
||||
'name' => $this->title(),
|
||||
];
|
||||
}
|
||||
|
||||
public static function states(): array
|
||||
{
|
||||
return array_map(fn ($case) => $case->toArray(), self::cases());
|
||||
}
|
||||
|
||||
public static function createFrom(null|int|string|ScreenshotsState $value): ?ScreenshotsState
|
||||
{
|
||||
return match (true) {
|
||||
!isset($value) => null,
|
||||
is_numeric($value) => static::tryFrom((int)$value),
|
||||
is_string($value) => static::tryFromString($value),
|
||||
$value instanceof ScreenshotsState => static::tryFrom($value->value),
|
||||
default => static::tryFrom($value),
|
||||
};
|
||||
}
|
||||
|
||||
public static function withGlobalOverrides(null|int|string|ScreenshotsState $value): ?ScreenshotsState
|
||||
{
|
||||
foreach ([
|
||||
ScreenshotsState::createFrom(config('app.screenshots_state')),
|
||||
ScreenshotsState::createFrom(Settings::scope('core')->get('screenshots_state')),
|
||||
] as $globalOverride) {
|
||||
if (isset($globalOverride) && $globalOverride->mustBeInherited()) {
|
||||
return $globalOverride;
|
||||
}
|
||||
}
|
||||
|
||||
return static::createFrom($value);
|
||||
}
|
||||
|
||||
public static function getNormalizedValue(null|int|string|ScreenshotsState $value): ?int
|
||||
{
|
||||
return static::createFrom($value)?->value;
|
||||
}
|
||||
}
|
||||
9
app/Enums/SortDirection.php
Normal file
9
app/Enums/SortDirection.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum SortDirection: string
|
||||
{
|
||||
case ASC = 'asc';
|
||||
case DESC = 'desc';
|
||||
}
|
||||
9
app/Enums/TaskRelationType.php
Normal file
9
app/Enums/TaskRelationType.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum TaskRelationType: string
|
||||
{
|
||||
case FOLLOWS = 'follows';
|
||||
case PRECEDES = 'precedes';
|
||||
}
|
||||
184
app/Enums/UniversalReportBase.php
Normal file
184
app/Enums/UniversalReportBase.php
Normal file
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use App\Models\Project;
|
||||
use App\Models\Task;
|
||||
use App\Models\User;
|
||||
|
||||
enum UniversalReportBase: string
|
||||
{
|
||||
case PROJECT = 'project';
|
||||
case USER = 'user';
|
||||
case TASK = 'task';
|
||||
|
||||
|
||||
public function fields() {
|
||||
return match($this) {
|
||||
self::PROJECT => [
|
||||
'base' => [
|
||||
'name',
|
||||
'created_at',
|
||||
'description',
|
||||
'important',
|
||||
],
|
||||
'tasks' => [
|
||||
'task_name',
|
||||
'priority',
|
||||
'status',
|
||||
'due_date',
|
||||
'estimate',
|
||||
'description',
|
||||
],
|
||||
'users' => [
|
||||
'full_name',
|
||||
'email',
|
||||
],
|
||||
// 'work_time',
|
||||
// 'work_time_user',
|
||||
'calculations' => [
|
||||
'total_spent_time',
|
||||
'total_spent_time_by_user',
|
||||
'total_spent_time_by_day',
|
||||
'total_spent_time_by_day_and_user',
|
||||
],
|
||||
|
||||
],
|
||||
self::USER => [
|
||||
'base' => [
|
||||
'full_name',
|
||||
'email',
|
||||
],
|
||||
'projects' => [
|
||||
'name',
|
||||
'created_at',
|
||||
'description',
|
||||
'important',
|
||||
],
|
||||
'tasks' => [
|
||||
'task_name',
|
||||
'priority',
|
||||
'status',
|
||||
'due_date',
|
||||
'estimate',
|
||||
'description',
|
||||
],
|
||||
'calculations' => [
|
||||
'total_spent_time',
|
||||
'total_spent_time_by_day',
|
||||
]
|
||||
],
|
||||
self::TASK => [
|
||||
'base' => [
|
||||
'task_name',
|
||||
'priority',
|
||||
'status',
|
||||
'due_date',
|
||||
'estimate',
|
||||
'description',
|
||||
// 'workers',
|
||||
],
|
||||
'users' => [
|
||||
'full_name',
|
||||
'email',
|
||||
],
|
||||
'projects' => [
|
||||
'name',
|
||||
'created_at',
|
||||
'description',
|
||||
'important',
|
||||
],
|
||||
'calculations' => [
|
||||
'total_spent_time',
|
||||
'total_spent_time_by_day',
|
||||
'total_spent_time_by_user',
|
||||
'total_spent_time_by_day_and_user'
|
||||
],
|
||||
// 'total_spent_time',
|
||||
// 'user_name',
|
||||
// 'user_time',
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
public function dataObjects()
|
||||
{
|
||||
return match($this) {
|
||||
self::PROJECT => (function() {
|
||||
if(request()->user()->isAdmin()) {
|
||||
return Project::select('id', 'name')->get();
|
||||
}
|
||||
|
||||
return request()->user()->projects()->select('id', 'name')->get();
|
||||
})(),
|
||||
self::USER => (function() {
|
||||
if (request()->user()->isAdmin()) {
|
||||
return User::select('id', 'full_name as name', 'email', 'full_name')->get();
|
||||
}
|
||||
|
||||
return;
|
||||
})(),
|
||||
self::TASK => (function() {
|
||||
if(request()->user()->isAdmin()) {
|
||||
return Task::select('id', 'task_name as name')->get();
|
||||
}
|
||||
|
||||
return request()->user()->tasks()->select('id', 'name')->get();
|
||||
})()
|
||||
};
|
||||
}
|
||||
public function charts() {
|
||||
// [
|
||||
// // Project
|
||||
// "worked_all_users",// "Отработанное время всеми пользователями на проекте за указанный период",
|
||||
// "worked_all_users_separately",// "Отработанное время каждым пользователем на проекте за указанный период",
|
||||
// // Task
|
||||
// 'worked_all_users',// "Отработанное время всеми пользователями на задаче за указанный период",
|
||||
// 'worked_all_users_separately',// "Отработанное время каждым пользователем на задаче за указанный период",
|
||||
// // User
|
||||
// 'total_hours',// "Всего часов за указанный период",
|
||||
// 'hours_tasks',// "Часов на каждой задаче",
|
||||
// 'hours_projects',// "Часов на каждом проекте",
|
||||
|
||||
// ];
|
||||
return match($this) {
|
||||
self::PROJECT => [
|
||||
'total_spent_time_day',
|
||||
'total_spent_time_day_and_users_separately',
|
||||
],
|
||||
self::USER => [
|
||||
'total_spent_time_day',
|
||||
'total_spent_time_day_and_tasks',
|
||||
'total_spent_time_day_and_projects',
|
||||
],
|
||||
self::TASK => [
|
||||
'total_spent_time_day',
|
||||
'total_spent_time_day_users_separately',
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
public static function bases()
|
||||
{
|
||||
return array_map(fn($case) => $case->value, self::cases());
|
||||
}
|
||||
|
||||
public function checkAccess(array $data_objects)
|
||||
{
|
||||
$user = request()->user();
|
||||
return match($this) {
|
||||
self::PROJECT => $user->projects()->select('id')->whereIn('id', $data_objects)->withoutGlobalScopes()->get()->count() === count($data_objects),
|
||||
self::USER => '',
|
||||
self::TASK => $user->tasks()->select('id')->whereIn('id', $data_objects)->withoutGlobalScopes()->get()->count() === count($data_objects),
|
||||
};
|
||||
}
|
||||
|
||||
public function model()
|
||||
{
|
||||
return match($this) {
|
||||
self::PROJECT => new Project(),
|
||||
self::USER => new User(),
|
||||
self::TASK => new Task(),
|
||||
};
|
||||
}
|
||||
}
|
||||
9
app/Enums/UniversalReportType.php
Normal file
9
app/Enums/UniversalReportType.php
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
enum UniversalReportType: string
|
||||
{
|
||||
case COMPANY = 'company';
|
||||
case PERSONAL = 'personal';
|
||||
}
|
||||
Reference in New Issue
Block a user