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;
|
2017-10-07 04:25:35 -07:00
|
|
|
use App\Models\Company;
|
|
|
|
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
|
|
|
|
2017-10-18 04:04:05 -07:00
|
|
|
$factory->defineAs(App\Models\Actionlog::class, 'asset-upload', function ($faker) {
|
2021-06-10 13:17:44 -07:00
|
|
|
$asset = \App\Models\Asset::factory()->create();
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2017-10-18 04:04:05 -07:00
|
|
|
return [
|
|
|
|
'item_type' => get_class($asset),
|
|
|
|
'item_id' => 1,
|
|
|
|
'user_id' => 1,
|
|
|
|
'filename' => $faker->word,
|
2021-06-10 13:15:52 -07:00
|
|
|
'action_type' => 'uploaded',
|
2017-10-18 04:04:05 -07:00
|
|
|
];
|
|
|
|
});
|
|
|
|
|
2017-10-07 04:25:35 -07:00
|
|
|
$factory->defineAs(Actionlog::class, 'asset-checkout-user', function (Faker\Generator $faker) {
|
|
|
|
$target = User::inRandomOrder()->first();
|
2017-10-07 06:16:06 -07:00
|
|
|
$item = Asset::inRandomOrder()->RTD()->first();
|
2021-06-10 13:15:52 -07:00
|
|
|
$user_id = rand(1, 2); // keep it simple - make it one of the two superadmins
|
2017-10-07 04:25:35 -07:00
|
|
|
$asset = App\Models\Asset::where('id', $item->id)
|
|
|
|
->update(
|
|
|
|
[
|
|
|
|
'assigned_to' => $target->id,
|
2017-10-28 05:46:43 -07:00
|
|
|
'assigned_type' => App\Models\User::class,
|
|
|
|
'assigned_to' => $target->location_id,
|
2017-10-07 04:25:35 -07:00
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2017-06-12 17:39:03 -07:00
|
|
|
return [
|
2021-06-10 13:15:52 -07:00
|
|
|
'created_at' => $faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get()),
|
2017-10-07 04:25:35 -07:00
|
|
|
'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();
|
2017-10-07 06:16:06 -07:00
|
|
|
$item = Asset::inRandomOrder()->RTD()->first();
|
2021-06-10 13:15:52 -07:00
|
|
|
$user_id = rand(1, 2); // keep it simple - make it one of the two superadmins
|
2017-10-07 04:25:35 -07:00
|
|
|
$asset = App\Models\Asset::where('id', $item->id)
|
|
|
|
->update(
|
|
|
|
[
|
|
|
|
'assigned_to' => $target->id,
|
2017-10-28 05:46:43 -07:00
|
|
|
'assigned_type' => App\Models\Location::class,
|
|
|
|
'assigned_to' => $target->id,
|
2017-10-07 04:25:35 -07:00
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
return [
|
2021-06-10 13:15:52 -07:00
|
|
|
'created_at' => $faker->dateTimeBetween('-1 years', 'now', date_default_timezone_get()),
|
2017-10-07 04:25:35 -07:00
|
|
|
'user_id' => $user_id,
|
2017-06-12 17:39:03 -07:00
|
|
|
'action_type' => 'checkout',
|
2017-10-01 12:59:55 -07:00
|
|
|
'item_id' => $item->id,
|
2017-06-12 17:39:03 -07:00
|
|
|
'item_type' => App\Models\Asset::class,
|
|
|
|
'target_id' => $target->id,
|
|
|
|
'target_type' => get_class($target),
|
|
|
|
];
|
|
|
|
});
|
|
|
|
|
2017-10-07 04:25:35 -07:00
|
|
|
// This doesn't work - we need to assign a seat
|
2021-06-10 13:17:44 -07:00
|
|
|
|
2017-06-12 17:39:03 -07:00
|
|
|
$factory->defineAs(Actionlog::class, 'license-checkout-asset', function (Faker\Generator $faker) {
|
2017-10-07 06:16:06 -07:00
|
|
|
$target = Asset::inRandomOrder()->RTD()->first();
|
2017-10-07 04:25:35 -07:00
|
|
|
$item = License::inRandomOrder()->first();
|
2021-06-10 13:15:52 -07:00
|
|
|
$user_id = rand(1, 2); // keep it simple - make it one of the two superadmins
|
2017-06-12 17:39:03 -07:00
|
|
|
|
|
|
|
return [
|
2017-10-07 04:25:35 -07:00
|
|
|
'user_id' => $user_id,
|
2017-06-12 17:39:03 -07:00
|
|
|
'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(),
|
2021-06-10 13:15:52 -07:00
|
|
|
'note' => $faker->sentence,
|
2017-06-12 17:39:03 -07:00
|
|
|
];
|
|
|
|
});
|
|
|
|
|
|
|
|
$factory->defineAs(Actionlog::class, 'accessory-checkout', function (Faker\Generator $faker) {
|
2017-10-07 06:16:06 -07:00
|
|
|
$target = Asset::inRandomOrder()->RTD()->first();
|
2017-10-07 04:25:35 -07:00
|
|
|
$item = Accessory::inRandomOrder()->first();
|
2021-06-10 13:15:52 -07:00
|
|
|
$user_id = rand(1, 2); // keep it simple - make it one of the two superadmins
|
2017-06-12 17:39:03 -07:00
|
|
|
|
|
|
|
return [
|
2017-10-07 04:25:35 -07:00
|
|
|
'user_id' => $user_id,
|
2017-06-12 17:39:03 -07:00
|
|
|
'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(),
|
2021-06-10 13:15:52 -07:00
|
|
|
'note' => $faker->sentence,
|
2017-06-12 17:39:03 -07:00
|
|
|
];
|
|
|
|
});
|
|
|
|
|
|
|
|
$factory->defineAs(Actionlog::class, 'consumable-checkout', function (Faker\Generator $faker) {
|
2021-06-10 13:17:44 -07:00
|
|
|
$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]);
|
2017-06-12 17:39:03 -07:00
|
|
|
|
|
|
|
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,
|
2021-06-10 13:15:52 -07:00
|
|
|
'company_id' => $company->id,
|
2017-06-12 17:39:03 -07:00
|
|
|
];
|
|
|
|
});
|
|
|
|
|
|
|
|
$factory->defineAs(Actionlog::class, 'component-checkout', function (Faker\Generator $faker) {
|
2021-06-10 13:17:44 -07:00
|
|
|
$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]);
|
2017-06-12 17:39:03 -07:00
|
|
|
|
|
|
|
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,
|
2021-06-10 13:15:52 -07:00
|
|
|
'company_id' => $company->id,
|
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
|
|
|
|
*/
|
|
|
|
protected $model = Actionlog::class;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Define the model's default state.
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function definition()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'note' => 'Sample checkout from DB seeder!',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|