-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcontroller.php
133 lines (108 loc) · 5.05 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
123
124
125
126
127
128
129
130
131
132
133
<?php
namespace Concrete\Package\AttributeForms;
use Concrete\Core\Foundation\ModifiedPsr4ClassLoader;
use Concrete\Package\AttributeForms\Form\ActionType\Factory as ActionTypeFactory;
use Concrete\Core\Foundation\Service\ProviderList;
use Concrete\Core\Backup\ContentImporter,
AssetList,
Package,
Route,
Core;
class Controller extends Package
{
protected $pkgHandle = 'attribute_forms';
protected $appVersionRequired = '5.7.5.2';
protected $pkgVersion = '0.9.9.10';
protected $pkgAutoloaderMapCoreExtensions = true;
public function getPackageName()
{
return t('Attribute Form');
}
public function getPackageDescription()
{
return t('A package to create forms using attributes');
}
protected function installXmlContent()
{
$pkg = Package::getByHandle($this->pkgHandle);
$ci = new ContentImporter();
$ci->importContentFile($pkg->getPackagePath() . '/install.xml');
}
public function install()
{
parent::install();
$this->installXmlContent();
}
public function upgrade()
{
parent::upgrade();
$this->installXmlContent();
}
public function on_start()
{
define('DIRNAME_ACTION_TYPE', 'action_types');
$this->registerAutoloaderMapping();
$this->registerAssets();
$list = new ProviderList(Core::getFacadeApplication());
$list->registerProvider('\Concrete\Package\AttributeForms\Service\Provider');
Route::registerMultiple(array(
'/ccm/attribute_forms/tools/captcha/{atFormTypeID}' => array('\Concrete\Package\AttributeForms\Controller\Tools::displayCaptchaPicture'),
'/ccm/attribute_forms/tools/form/action_type/{handle}/{action}' => array('\Concrete\Package\AttributeForms\Controller\Tools::formActionTypeAction'),
'/ccm/attribute_forms/tools/form/action_type/render/{handle}/{view}' => array('\Concrete\Package\AttributeForms\Controller\Tools::renderFormActionType')
));
ActionTypeFactory::getInstance()->registerDefaults();
}
protected function registerAutoloaderMapping()
{
if (file_exists($this->getPackagePath().'/vendor/autoload.php')) {
require_once $this->getPackagePath().'/vendor/autoload.php';
}
if (file_exists(DIR_BASE.'/vendor/autoload.php')) {
require_once DIR_BASE.'/vendor/autoload.php';
}
$namespace = 'Application';
$app_config_path = DIR_APPLICATION.'/config/app.php';
if (file_exists($app_config_path)) {
$app_config = require $app_config_path;
if (isset($app_config['namespace'])) {
$namespace = $app_config['namespace'];
}
}
define('NAMESPACE_APPLICATION', $namespace);
$symfonyLoader = new ModifiedPsr4ClassLoader();
$symfonyLoader->addPrefix($namespace.'\\ActionType', DIR_APPLICATION.'/'.DIRNAME_ACTION_TYPE);
$packages = \Concrete\Core\Package\PackageList::get()->getPackages();
foreach ($packages as $pkg){
$pkgHandle = $pkg->getPackageHandle();
$symfonyLoader->addPrefix(NAMESPACE_SEGMENT_VENDOR.'\\Package\\'.camelcase($pkgHandle).'\\ActionType', DIR_PACKAGES."/{$pkgHandle}/".DIRNAME_ACTION_TYPE);
}
$symfonyLoader->register();
}
protected function registerAssets()
{
$al = AssetList::getInstance();
$al->register('javascript', 'mesch/attribute_form', 'js/attribute.forms.js', array('minify' => true), $this);
$al->register('css', 'mesch/attribute_form/backend', 'css/backend.css', array('minify' => true), $this);
$al->register('javascript', 'mesch/alert', 'js/mesch.alert.dialog.js', array('minify' => true), $this);
$al->registerGroup('mesch/alert', array(
array('javascript', 'jquery'),
array('javascript', 'mesch/alert'),
));
$al->register('css', 'mesch/gridmanagercss', 'css/jquery.gridmanager.css', array('minify' => true), $this);
$al->register('javascript', 'mesch/gridmanager', 'js/jquery.gridmanager.js', array('minify' => true), $this);
}
public function uninstall()
{
parent::uninstall();
$db = \Database::connection();
$platform = $db->getDatabasePlatform();
$db->executeQuery($platform->getDropTableSQL('btAttributeForm'));
$db->executeQuery($platform->getDropTableSQL('btAttributeFormAction'));
$db->executeQuery($platform->getDropTableSQL('AttributeFormsAttributeValues'));
$db->executeQuery($platform->getDropTableSQL('AttributeForms'));
$db->executeQuery($platform->getDropTableSQL('AttributeFormTypes'));
$db->executeQuery($platform->getDropTableSQL('atAttributeSwitcher'));
$db->executeQuery($platform->getDropTableSQL('atAttributeSwitcherSettings'));
$db->executeQuery($platform->getDropTableSQL('AttributeFormsIndexAttributes'));
}
}