mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-28 23:19:42 -08:00
168 lines
5.4 KiB
PHP
168 lines
5.4 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Models\Actionlog;
|
|
use App\Models\Asset;
|
|
use App\Models\Company;
|
|
use App\Models\Location;
|
|
use App\Models\User;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
$factory->defineAs(App\Models\Actionlog::class, 'asset-upload', function ($faker) {
|
|
$asset = \App\Models\Asset::factory()->create();
|
|
|
|
return [
|
|
'item_type' => get_class($asset),
|
|
'item_id' => 1,
|
|
'user_id' => 1,
|
|
'filename' => $faker->word,
|
|
'action_type' => 'uploaded',
|
|
];
|
|
});
|
|
|
|
$factory->defineAs(Actionlog::class, 'asset-checkout-user', function (Faker\Generator $faker) {
|
|
$target = User::inRandomOrder()->first();
|
|
$item = Asset::inRandomOrder()->RTD()->first();
|
|
$user_id = rand(1, 2); // keep it simple - make it one of the two superadmins
|
|
$asset = App\Models\Asset::where('id', $item->id)
|
|
->update(
|
|
[
|
|
'assigned_to' => $target->id,
|
|
'assigned_type' => App\Models\User::class,
|
|
'assigned_to' => $target->location_id,
|
|
]
|
|
);
|
|
|
|
return [
|
|
'created_at' => $faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get()),
|
|
'user_id' => $user_id,
|
|
'action_type' => 'checkout',
|
|
'item_id' => $item->id,
|
|
'item_type' => App\Models\Asset::class,
|
|
'target_id' => $target->id,
|
|
'target_type' => get_class($target),
|
|
|
|
];
|
|
});
|
|
|
|
$factory->defineAs(Actionlog::class, 'asset-checkout-location', function (Faker\Generator $faker) {
|
|
$target = Location::inRandomOrder()->first();
|
|
$item = Asset::inRandomOrder()->RTD()->first();
|
|
$user_id = rand(1, 2); // keep it simple - make it one of the two superadmins
|
|
$asset = App\Models\Asset::where('id', $item->id)
|
|
->update(
|
|
[
|
|
'assigned_to' => $target->id,
|
|
'assigned_type' => App\Models\Location::class,
|
|
'assigned_to' => $target->id,
|
|
]
|
|
);
|
|
|
|
return [
|
|
'created_at' => $faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get()),
|
|
'user_id' => $user_id,
|
|
'action_type' => 'checkout',
|
|
'item_id' => $item->id,
|
|
'item_type' => App\Models\Asset::class,
|
|
'target_id' => $target->id,
|
|
'target_type' => get_class($target),
|
|
];
|
|
});
|
|
|
|
// This doesn't work - we need to assign a seat
|
|
|
|
$factory->defineAs(Actionlog::class, 'license-checkout-asset', function (Faker\Generator $faker) {
|
|
$target = Asset::inRandomOrder()->RTD()->first();
|
|
$item = License::inRandomOrder()->first();
|
|
$user_id = rand(1, 2); // keep it simple - make it one of the two superadmins
|
|
|
|
return [
|
|
'user_id' => $user_id,
|
|
'action_type' => 'checkout',
|
|
'item_id' => $item->id,
|
|
'item_type' => get_class($item),
|
|
'target_id' => $target->id,
|
|
'target_type' => get_class($target),
|
|
'created_at' => $faker->dateTime(),
|
|
'note' => $faker->sentence,
|
|
];
|
|
});
|
|
|
|
$factory->defineAs(Actionlog::class, 'accessory-checkout', function (Faker\Generator $faker) {
|
|
$target = Asset::inRandomOrder()->RTD()->first();
|
|
$item = Accessory::inRandomOrder()->first();
|
|
$user_id = rand(1, 2); // keep it simple - make it one of the two superadmins
|
|
|
|
return [
|
|
'user_id' => $user_id,
|
|
'action_type' => 'checkout',
|
|
'item_id' => $item->id,
|
|
'item_type' => get_class($item),
|
|
'target_id' => $target->id,
|
|
'target_type' => get_class($target),
|
|
'created_at' => $faker->dateTime(),
|
|
'note' => $faker->sentence,
|
|
];
|
|
});
|
|
|
|
$factory->defineAs(Actionlog::class, 'consumable-checkout', function (Faker\Generator $faker) {
|
|
$company = \App\Models\Company::factory()->create();
|
|
$user = \App\Models\User::factory()->create(['company_id' => $company->id]);
|
|
$target = \App\Models\User::factory()->create(['company_id' => $company->id]);
|
|
$item = \App\Models\Consumable::factory()->create(['company_id' => $company->id]);
|
|
|
|
return [
|
|
'user_id' => $user->id,
|
|
'action_type' => 'checkout',
|
|
'item_id' => $item->id,
|
|
'item_type' => get_class($item),
|
|
'target_id' => $target->id,
|
|
'target_type' => get_class($target),
|
|
'created_at' => $faker->dateTime(),
|
|
'note' => $faker->sentence,
|
|
'company_id' => $company->id,
|
|
];
|
|
});
|
|
|
|
$factory->defineAs(Actionlog::class, 'component-checkout', function (Faker\Generator $faker) {
|
|
$company = \App\Models\Company::factory()->create();
|
|
$user = \App\Models\User::factory()->create(['company_id' => $company->id]);
|
|
$target = \App\Models\User::factory()->create(['company_id' => $company->id]);
|
|
$item = \App\Models\Component::factory()->create(['company_id' => $company->id]);
|
|
|
|
return [
|
|
'user_id' => $user->id,
|
|
'action_type' => 'checkout',
|
|
'item_id' => $item->id,
|
|
'item_type' => get_class($item),
|
|
'target_id' => $target->id,
|
|
'target_type' => get_class($target),
|
|
'created_at' => $faker->dateTime(),
|
|
'note' => $faker->sentence,
|
|
'company_id' => $company->id,
|
|
];
|
|
});
|
|
|
|
class ActionlogFactory extends Factory
|
|
{
|
|
/**
|
|
* The name of the factory's corresponding model.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $model = Actionlog::class;
|
|
|
|
/**
|
|
* Define the model's default state.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function definition()
|
|
{
|
|
return [
|
|
'note' => 'Sample checkout from DB seeder!',
|
|
];
|
|
}
|
|
}
|