-
Notifications
You must be signed in to change notification settings - Fork 1
/
controller.php
122 lines (110 loc) · 2.77 KB
/
controller.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
namespace Concrete\Package\MyBoats;
use Concrete\Core\Backup\ContentImporter;
use Concrete\Core\Package\Package;
use Doctrine\ORM\EntityManager;
use MyBoats\Entity\Boat;
/**
* The package controller.
*
* Manages the package installation, update and start-up.
*/
class Controller extends Package
{
/**
* The minimum concrete5 version.
*
* @var string
*/
protected $appVersionRequired = '8';
/**
* The unique handle that identifies the package.
*
* @var string
*/
protected $pkgHandle = 'my_boats';
/**
* The package version.
*
* @var string
*/
protected $pkgVersion = '1.0.0';
/**
* Map folders to PHP namespaces, for automatic class autoloading.
*
* @var array
*/
protected $pkgAutoloaderRegistries = [
'src' => 'MyBoats',
];
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Package\Package::getPackageName()
*/
public function getPackageName()
{
return t('My Boats');
}
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Package\Package::getPackageDescription()
*/
public function getPackageDescription()
{
return t('Sample package to show the power of ItemLists');
}
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Package\Package::install()
*/
public function install()
{
$pkg = parent::install();
$this->installXml();
$this->addInitialBoats();
}
/**
* {@inheritdoc}
*
* @see \Concrete\Core\Package\Package::upgrade()
*/
public function upgrade()
{
parent::upgrade();
$this->installXml();
}
/**
* Install/update data from install XML file.
*/
private function installXml()
{
$contentImporter = $this->app->make(ContentImporter::class);
$contentImporter->importContentFile($this->getPackagePath() . '/install.xml');
}
/**
* Add some sample boats.
*/
private function addInitialBoats()
{
$em = $this->app->make(EntityManager::class);
/* @var EntityManager $em */
$repo = $em->getRepository(Boat::class);
$r = $repo->createQueryBuilder('b')->select('b.id')->setMaxResults(1)->getQuery()->execute();
if (empty($r)) {
foreach ([
Boat::create('My Boat Of Unknown Length', true),
Boat::create('My Tiny Boat', false, 1.5),
Boat::create('My Medium Boat', true, 5),
Boat::create('My Big Boat', true, 15),
Boat::create('My Huge Boat', false, 100),
Boat::create('Titanic', true, 209),
] as $boat) {
$em->persist($boat);
}
$em->flush();
}
}
}