2017-06-12 17:39:03 -07:00
|
|
|
<?php
|
|
|
|
|
2021-06-10 13:17:44 -07:00
|
|
|
namespace Database\Factories;
|
|
|
|
|
2017-06-12 17:39:03 -07:00
|
|
|
use App\Models\Actionlog;
|
2021-06-10 13:15:52 -07:00
|
|
|
use App\Models\Asset;
|
2023-03-20 14:18:54 -07:00
|
|
|
use App\Models\License;
|
|
|
|
use App\Models\LicenseSeat;
|
2017-10-07 04:25:35 -07:00
|
|
|
use App\Models\Location;
|
2021-06-10 13:15:52 -07:00
|
|
|
use App\Models\User;
|
2021-06-10 13:19:27 -07:00
|
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
2017-06-12 17:39:03 -07:00
|
|
|
|
2021-06-10 13:17:44 -07:00
|
|
|
class ActionlogFactory extends Factory
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name of the factory's corresponding model.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2023-03-16 15:25:23 -07:00
|
|
|
protected $model = Actionlog::class;
|
2021-06-10 13:17:44 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Define the model's default state.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function definition()
|
|
|
|
{
|
|
|
|
return [
|
2023-03-16 15:25:23 -07:00
|
|
|
'item_id' => Asset::factory(),
|
|
|
|
'item_type' => Asset::class,
|
2023-03-20 11:19:34 -07:00
|
|
|
'user_id' => User::factory()->superuser(),
|
2021-06-11 19:41:20 -07:00
|
|
|
'action_type' => 'uploaded',
|
2021-06-10 13:17:44 -07:00
|
|
|
];
|
|
|
|
}
|
2021-06-11 19:41:20 -07:00
|
|
|
|
|
|
|
public function assetCheckoutToUser()
|
|
|
|
{
|
|
|
|
return $this->state(function () {
|
2023-03-16 15:25:23 -07:00
|
|
|
$target = User::inRandomOrder()->first();
|
2023-10-25 18:56:34 -07:00
|
|
|
$asset = Asset::inRandomOrder()->RTD()->first();
|
2023-03-16 15:25:23 -07:00
|
|
|
|
|
|
|
$asset->update(
|
2021-06-11 19:41:20 -07:00
|
|
|
[
|
|
|
|
'assigned_to' => $target->id,
|
2023-03-16 15:25:23 -07:00
|
|
|
'assigned_type' => User::class,
|
2023-03-06 16:33:40 -08:00
|
|
|
'location_id' => $target->location_id,
|
2021-06-11 19:41:20 -07:00
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
return [
|
|
|
|
'created_at' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get()),
|
|
|
|
'action_type' => 'checkout',
|
2023-03-16 15:25:23 -07:00
|
|
|
'item_id' => $asset->id,
|
|
|
|
'item_type' => Asset::class,
|
2021-06-11 19:41:20 -07:00
|
|
|
'target_id' => $target->id,
|
2023-03-16 15:25:23 -07:00
|
|
|
'target_type' => User::class,
|
2021-06-11 19:41:20 -07:00
|
|
|
];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function assetCheckoutToLocation()
|
|
|
|
{
|
|
|
|
return $this->state(function () {
|
2023-03-16 15:25:23 -07:00
|
|
|
$target = Location::inRandomOrder()->first();
|
|
|
|
$asset = Asset::inRandomOrder()->RTD()->first();
|
|
|
|
|
|
|
|
$asset->update(
|
2021-06-11 19:41:20 -07:00
|
|
|
[
|
|
|
|
'assigned_to' => $target->id,
|
2023-03-16 15:25:23 -07:00
|
|
|
'assigned_type' => Location::class,
|
2023-03-06 16:33:40 -08:00
|
|
|
'location_id' => $target->id,
|
2021-06-11 19:41:20 -07:00
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
return [
|
|
|
|
'created_at' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get()),
|
|
|
|
'action_type' => 'checkout',
|
2023-03-16 15:25:23 -07:00
|
|
|
'item_id' => $asset->id,
|
|
|
|
'item_type' => Asset::class,
|
2021-06-11 19:41:20 -07:00
|
|
|
'target_id' => $target->id,
|
2023-03-16 15:25:23 -07:00
|
|
|
'target_type' => Location::class,
|
2021-06-11 19:41:20 -07:00
|
|
|
];
|
|
|
|
});
|
|
|
|
}
|
2023-03-20 14:18:54 -07:00
|
|
|
|
|
|
|
public function licenseCheckoutToUser()
|
|
|
|
{
|
|
|
|
return $this->state(function () {
|
|
|
|
$target = User::inRandomOrder()->first();
|
|
|
|
$licenseSeat = LicenseSeat::whereNull('assigned_to')->inRandomOrder()->first();
|
|
|
|
|
|
|
|
$licenseSeat->update([
|
|
|
|
'assigned_to' => $target->id,
|
|
|
|
'user_id' => 1, // not ideal but works
|
|
|
|
]);
|
|
|
|
|
|
|
|
return [
|
|
|
|
'created_at' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get()),
|
|
|
|
'action_type' => 'checkout',
|
|
|
|
'item_id' => $licenseSeat->license->id,
|
|
|
|
'item_type' => License::class,
|
|
|
|
'target_id' => $target->id,
|
|
|
|
'target_type' => User::class,
|
|
|
|
];
|
|
|
|
});
|
|
|
|
}
|
2024-07-03 06:30:06 -07:00
|
|
|
|
|
|
|
public function filesUploaded()
|
|
|
|
{
|
|
|
|
return $this->state(function () {
|
|
|
|
|
|
|
|
return [
|
|
|
|
'created_at' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get()),
|
|
|
|
'action_type' => 'uploaded',
|
|
|
|
'item_type' => User::class,
|
|
|
|
'filename' => $this->faker->unixTime('now'),
|
|
|
|
];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function acceptedSignature()
|
|
|
|
{
|
|
|
|
return $this->state(function () {
|
|
|
|
|
|
|
|
$asset = Asset::factory()->create();
|
|
|
|
|
|
|
|
return [
|
|
|
|
'created_at' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get()),
|
|
|
|
'action_type' => 'accepted',
|
|
|
|
'item_id' => $asset->id,
|
|
|
|
'item_type' => Asset::class,
|
|
|
|
'target_type' => User::class,
|
|
|
|
'accept_signature' => $this->faker->unixTime('now'),
|
|
|
|
];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public function acceptedEula()
|
|
|
|
{
|
|
|
|
return $this->state(function () {
|
|
|
|
|
|
|
|
$asset = Asset::factory()->create();
|
|
|
|
|
|
|
|
return [
|
|
|
|
'created_at' => $this->faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get()),
|
|
|
|
'action_type' => 'accepted',
|
|
|
|
'item_id' => $asset->id,
|
|
|
|
'item_type' => Asset::class,
|
|
|
|
'target_type' => User::class,
|
|
|
|
'filename' => $this->faker->unixTime('now'),
|
|
|
|
];
|
|
|
|
});
|
|
|
|
}
|
2021-06-10 13:17:44 -07:00
|
|
|
}
|