2022-04-23 11:32:04 -07:00
|
|
|
<?php
|
|
|
|
|
|
2024-03-09 03:19:55 -08:00
|
|
|
class UserProfilePostSeeder extends Seeder
|
|
|
|
|
{
|
2022-04-23 11:32:04 -07:00
|
|
|
public array $tables = [
|
|
|
|
|
'nl2_user_profile_wall_posts',
|
|
|
|
|
'nl2_user_profile_wall_posts_replies',
|
|
|
|
|
'nl2_user_profile_wall_posts_reactions',
|
|
|
|
|
];
|
|
|
|
|
|
2024-03-09 03:19:55 -08:00
|
|
|
protected function run(DB $db, \Faker\Generator $faker): void
|
|
|
|
|
{
|
2022-04-23 11:32:04 -07:00
|
|
|
$users = $db->get('users', ['id', '<>', 0])->results();
|
|
|
|
|
|
2023-03-07 08:26:53 -08:00
|
|
|
$this->times(PROFILE_POST_COUNT, function () use ($db, $faker, $users) {
|
2022-04-23 11:32:04 -07:00
|
|
|
$user = $faker->randomElement($users);
|
|
|
|
|
$author = $faker->randomElement($users);
|
|
|
|
|
while ($user->id == $author->id) {
|
|
|
|
|
$author = $faker->randomElement($users);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$db->insert('user_profile_wall_posts', [
|
|
|
|
|
'user_id' => $user->id,
|
|
|
|
|
'author_id' => $author->id,
|
|
|
|
|
'time' => $this->since($author->joined, $faker)->format('U'),
|
|
|
|
|
'content' => $faker->text,
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$profile_posts = $db->get('user_profile_wall_posts', ['id', '<>', 0])->results();
|
2023-03-07 08:26:53 -08:00
|
|
|
$this->times(PROFILE_POST_REPLY_COUNT, function () use ($db, $faker, $profile_posts) {
|
2022-04-23 11:32:04 -07:00
|
|
|
$post = $faker->randomElement($profile_posts);
|
|
|
|
|
$author_id = $faker->randomElement($profile_posts)->author_id;
|
|
|
|
|
|
|
|
|
|
$db->insert('user_profile_wall_posts_replies', [
|
|
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'author_id' => $author_id,
|
|
|
|
|
'time' => $this->since($post->time, $faker)->format('U'),
|
|
|
|
|
'content' => $faker->text,
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
|
2023-06-21 10:19:46 -07:00
|
|
|
$reactions = $db->get('reactions', ['id', '<>', 0])->results();
|
|
|
|
|
$this->times(PROFILE_POST_REACTION_COUNT, function () use ($db, $faker, $profile_posts, $reactions) {
|
2022-04-23 11:32:04 -07:00
|
|
|
$post = $faker->randomElement($profile_posts);
|
|
|
|
|
$user_id = $faker->randomElement($profile_posts)->user_id;
|
|
|
|
|
|
|
|
|
|
$db->insert('user_profile_wall_posts_reactions', [
|
|
|
|
|
'user_id' => $user_id,
|
2023-06-21 10:19:46 -07:00
|
|
|
'post_id' => $post->id,
|
|
|
|
|
'reaction_id' => $faker->randomElement($reactions)->id,
|
2022-04-23 11:32:04 -07:00
|
|
|
'time' => $this->since($post->time, $faker)->format('U'),
|
|
|
|
|
]);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|