forked from simoneeconomo/backend_views
/
extension.driver.php
executable file
·96 lines (77 loc) · 2.77 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
95
96
<?php
require_once(TOOLKIT . '/class.datasourcemanager.php');
require_once(TOOLKIT . '/class.widget.php');
Class extension_backend_views extends Extension {
public function about() {
return array(
'name' => 'Backend Views',
'version' => '0.1.2',
'release-date' => '2012-10-08',
'author' => array('name' => 'Simone Economo',
'website' => 'http://www.lineheight.net',
'email' => 'my.ekoes@gmail.com'),
'description' => 'Use Data Sources to filter entries in the Symphony backend.'
);
}
public function getSubscribedDelegates(){
return array(
array(
'page' => '/system/preferences/',
'delegate' => 'AddCustomPreferenceFieldsets',
'callback' => 'addViewsPreferences'
),
array(
'page' => '/system/preferences/',
'delegate' => 'Save',
'callback' => 'saveViews'
)
);
}
public function fetchNavigation(){
$navigation = array(
'location' => 190,
'name' => __('Views'),
'children' => array()
);
$active_views = Symphony::Configuration()->get('active_views', 'backend_views');
$active_views = explode(",", $active_views);
if(!is_array($active_views) || empty($active_views)) return array();
$datasources = DatasourceManager::listAll();
foreach($datasources as $d) {
if (in_array($d['handle'], $active_views)) {
$navigation['children'][] = array(
'link' => '/view/' . $d['handle'],
'name' => $d['name']
);
}
}
return array($navigation);
}
public function addViewsPreferences($context) {
$datasources = DatasourceManager::listAll();
$fieldset = new XMLElement('fieldset', NULL, array('class' => 'settings'));
$fieldset->appendChild(new XMLElement('legend', __('Views')));
$context['wrapper']->appendChild($fieldset);
$active_views = Symphony::Configuration()->get('active_views', 'backend_views');
$active_views = explode(",", $active_views);
$options = array();
foreach($datasources as $d) {
if (substr($d['type'], -3) != 'xml' || $d['type'] == 'navigation')
$options[] = array($d['handle'], @in_array($d['handle'], $active_views), $d['name']);
}
$selectbox = Widget::Select('settings[backend_views][active_views][]', $options, array('multiple' => true));
$label = Widget::Label(__('Active views'), $selectbox);
$fieldset->appendChild($label);
}
public function saveViews($context) {
if (empty($context['settings']['backend_views']['active_views']))
$context['settings']['backend_views']['active_views'] = NULL;
else
$context['settings']['backend_views']['active_views'] = implode(",", $context['settings']['backend_views']['active_views']);
}
public function uninstall() {
Symphony::Configuration()->remove('backend_views');
Administration::instance()->saveConfig();
}
}
?>