/
InstallSeedListener.php
96 lines (79 loc) · 2.42 KB
/
InstallSeedListener.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
namespace App\Modules\Adaptbb\Listeners;
use App\Modules\Core\Events\InstallSeedEvent;
use App\Modules\Adaptbb\Models\Forum;
use App\Modules\Adaptbb\Models\ForumCategory;
use App\Modules\Adaptbb\Models\Reply;
use App\Modules\Adaptbb\Models\Topic;
class InstallSeedListener
{
/**
* Handle the event.
*
* @param OrderShipped $event
* @return void
*/
public function handle(InstallSeedEvent $event)
{
// create categories
$categories = [
[
'name' => 'General'
],
[
'name' => 'Random'
]
];
foreach($categories as $index => $category) {
$model = new ForumCategory;
$model->name = $category['name'];
$model->save();
}
// create forums
$forums = [
[
'name' => 'Website',
'description' => 'Talk about anything related to the site.',
'category_id' => 1
],
[
'name' => 'Off-Topic',
'description' => 'Politics, Video games, etc.',
'category_id' => 2
]
];
foreach($forums as $index => $forum) {
$model = new Forum;
$model->name = $forum['name'];
$model->description = $forum['description'];
$model->meta_description = $forum['description'];
$model->category_id = $forum['category_id'];
$model->topics_count = 1;
$model->replies_count = 1;
$model->save();
}
// create topic
$topic = [
'name' => 'Welcome to AdaptBB!',
'message' => 'Hello and welcome to your new forums software, we hope you enjoy it and never hesitate to reach out for help.'
];
$model = new Topic;
$model->name = $topic['name'];
$model->message = $topic['message'];
$model->topic_type = 'normal';
$model->active = 1;
$model->forum_id = 1;
$model->user_id = 1;
$model->replies_count = 1;
$model->save();
// create reply
$model = new Reply;
$model->name = 'Re: ' . $topic['name'];
$model->message = 'This is a test reply.';
$model->active = 1;
$model->topic_id = 1;
$model->forum_id = 1;
$model->user_id = 1;
$model->save();
}
}