forked from symphonists/subsectionmanager
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathextension.driver.php
More file actions
172 lines (152 loc) · 4.85 KB
/
Copy pathextension.driver.php
File metadata and controls
172 lines (152 loc) · 4.85 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php
Class extension_subsectionmanager extends Extension {
/**
* Extension information
*/
public function about() {
return array(
'name' => 'Subsection Manager',
'type' => 'Field, Interface',
'version' => '1.0dev',
'release-date' => false,
'author' => array(
'name' => 'Nils Hörrmann',
'website' => 'http://www.nilshoerrmann.de',
'email' => 'post@nilshoerrmann.de'
),
'description' => 'A subsection management for Symphony.',
'compatibility' => array(
'2.0.7' => true
)
);
}
/**
* Add callback functions to backend delegates
*/
public function getSubscribedDelegates(){
return array(
array(
'page' => '/administration/',
'delegate' => 'AdminPagePreGenerate',
'callback' => '__appendAssets'
),
array(
'page' => '/publish/new/',
'delegate' => 'EntryPostNew',
'callback' => '__saveSortOrder'
),
array(
'page' => '/publish/edit/',
'delegate' => 'EntryPostEdit',
'callback' => '__saveSortOrder'
),
array(
'page' => '/publish/',
'delegate' => 'Delete',
'callback' => '__deleteSortOrder'
)
);
}
/**
* Append assets to the page head
*
* @param object $context
*/
public function __appendAssets($context) {
$callback = Administration::instance()->getPageCallback();
// Append javascript for field settings pane
if ($callback['driver'] == 'blueprintssections' && is_array($callback['context'])){
Administration::instance()->Page->addScriptToHead(URL . '/extensions/subsectionmanager/assets/settings.subsectionmanager.js', 100, false);
}
// Append styles and javascript for mediasection display
if ($callback['driver'] == 'publish' && ($callback['context']['page'] == 'edit' || $callback['context']['page'] == 'new')){
Administration::instance()->Page->addScriptToHead(URL . '/extensions/subsectionmanager/assets/symphony.subsection.js', 100, false);
Administration::instance()->Page->addStylesheetToHead(URL . '/extensions/subsectionmanager/assets/symphony.subsection.css', 'screen', 101, false);
}
}
/**
* Saves sort order of the field
*
* @param object $context
*/
public function __saveSortOrder($context) {
if(!is_null($context['fields']['sort_order'])) {
// delete current sort order
$entry_id = $context['entry']->_fields['id'];
Administration::instance()->Database->query(
"DELETE FROM `tbl_fields_subsectionmanager_sorting` WHERE `entry_id` = '$entry_id'"
);
// add new sort order
foreach($context['fields']['sort_order'] as $field_id => $value) {
$entries = explode(',', $value);
$order = array();
foreach($entries as $entry) {
$order[] = intval($entry);
}
Administration::instance()->Database->query(
"INSERT INTO `tbl_fields_subsectionmanager_sorting` (`entry_id`, `field_id`, `order`) VALUES ('$entry_id', '$field_id', '" . implode(',', $order) . "')"
);
}
}
}
/**
* Delete sort order of the field
*
* @param object $context
*/
public function __deleteSortOrder($context) {
// DELEGATE NOT WORKING:
// http://github.com/symphony/symphony-2/issues#issue/108
}
/**
* Function to be executed on uninstallation
*/
public function uninstall() {
// drop database table
Administration::instance()->Database->query("DROP TABLE `tbl_fields_subsectionmanager`");
Administration::instance()->Database->query("DROP TABLE `tbl_fields_subsectionmanager_sorting`");
}
/**
* Function to be executed if the extension has been updated
*
* @param string $previousVersion - version number of the currently installed extension build
* @return boolean - true on success, false otherwise
*/
public function update($previousVersion) {
// To do: Mediathek import
return true;
}
/**
* Function to be executed on installation.
*
* @return boolean - true on success, false otherwise
*/
public function install() {
// Create database table and fields.
$fields = Administration::instance()->Database->query(
"CREATE TABLE `tbl_fields_subsectionmanager` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`field_id` int(11) unsigned NOT NULL,
`subsection_id` VARCHAR(255) NOT NULL,
`filter_tags` text,
`caption` text,
`included_fields` text,
`allow_multiple_selection` enum('yes','no') NOT NULL default 'yes',
`show_preview` enum('yes','no') NOT NULL default 'yes',
PRIMARY KEY (`id`),
KEY `field_id` (`field_id`)
)"
);
$sorting = Administration::instance()->Database->query(
"CREATE TABLE `tbl_fields_subsectionmanager_sorting` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`entry_id` int(11) NOT NULL,
`field_id` int(11) NOT NULL,
`order` text,
PRIMARY KEY (`id`)
)"
);
if($fields && $sorting) return true;
else return false;
}
}