-
Notifications
You must be signed in to change notification settings - Fork 1
/
extension.driver.php
94 lines (80 loc) · 3.16 KB
/
extension.driver.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
<?php
Class extension_field_tabular extends Extension{
public function about() {
return array(
'name' => 'tabular',
'version' => '0.1',
'release-date' => '2019-04-25',
'author' => array(
'name' => 'Michele Rosa',
),
'description' => 'Editable table field for backend'
);
}
/*-------------------------------------------------------------------------
Installation:
-------------------------------------------------------------------------*/
public function install(){
try {
Symphony::Database()->query("
CREATE TABLE IF NOT EXISTS `tbl_fields_tabular` (
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`field_id` INT(11) UNSIGNED NOT NULL,
`columns` VARCHAR(255) NOT NULL,
`header` TINYINT(1) UNSIGNED NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `field_id` (`field_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
");
}
catch (Exception $ex) {
$extension = $this->about();
Administration::instance()->Page->pageAlert(__('An error occurred while installing %s. %s', array($extension['name'], $ex->getMessage())), Alert::ERROR);
return false;
}
// No common preferences
return true;
}
public function uninstall(){
if(parent::uninstall() == true){
try {
Symphony::Database()->query("DROP TABLE `tbl_fields_tabular`");
return true;
}
catch (Exception $ex) {
$extension = $this->about();
Administration::instance()->Page->pageAlert(__('An error occurred while uninstalling %s. %s', array($extension['name'], $ex->getMessage())), Alert::ERROR);
return false;
}
}
return false;
}
/*-------------------------------------------------------------------------
Delegate
-------------------------------------------------------------------------*/
public function getSubscribedDelegates(){
return array(
array(
'page' => '/backend/',
'delegate' => 'InitaliseAdminPageHead',
'callback' => 'initaliseAdminPageHead'
)
);
}
/*-------------------------------------------------------------------------
Utilities:
-------------------------------------------------------------------------*/
public static function initaliseAdminPageHead() {
$page = Administration::instance()->Page;
// only on publish pages
if(!$page instanceOf contentPublish) return;
// which are showing new/edit form
$callback = Administration::instance()->getPageCallback();
if(!in_array($callback['context']['page'], array('new', 'edit'))) return;
Administration::instance()->Page->addStylesheetToHead(URL . '/extensions/field_tabular/assets/jsgrid.css', 'screen', 200);
Administration::instance()->Page->addStylesheetToHead(URL . '/extensions/field_tabular/assets/jsgrid-theme.css', 'screen', 210);
Administration::instance()->Page->addStylesheetToHead(URL . '/extensions/field_tabular/assets/tabular.publish.css', 'screen', 210);
Administration::instance()->Page->addScriptToHead(URL . '/extensions/field_tabular/assets/jsgrid.js', 200);
Administration::instance()->Page->addScriptToHead(URL . '/extensions/field_tabular/assets/tabular.publish.js', 200);
}
}