-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.php
129 lines (106 loc) · 2.64 KB
/
init.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
<?php defined('SYSPATH') or die('No direct access allowed.');
if (IS_BACKEND)
{
Route::set('datasources', ADMIN_DIR_NAME . '/<directory>(/<controller>(/<action>(/<id>)))', array(
'directory' => '(datasources|' . implode('|', array_keys(Datasource_Data_Manager::types())) . ')'
))
->defaults(array(
'directory' => 'datasources',
'controller' => 'data',
'action' => 'index',
));
}
Observer::observe('modules::after_load', function() {
if (!IS_BACKEND OR ! Auth::is_logged_in())
{
return;
}
$types = Datasource_Data_Manager::types();
if (empty($types))
{
return;
}
try
{
$ds_section = Model_Navigation::get_section('Datasources');
$ds_section->icon = 'tasks';
$sections_list = Datasource_Data_Manager::get_tree(array_keys($types));
$datasource_is_empty = empty($sections_list);
$folders = Datasource_Folder::get_all();
$root_sections = array();
foreach ($sections_list as $type => $sections)
{
foreach ($sections as $id => $section)
{
if ($section->show_in_root_menu())
{
$root_sections[] = $section;
unset($sections_list[$type][$id]);
continue;
}
if (array_key_exists($section->folder_id(), $folders))
{
$folders[$section->folder_id()]['sections'][] = $section;
unset($sections_list[$type][$id]);
}
}
}
if (!empty($root_sections))
{
foreach ($root_sections as $id => $section)
{
$section->add_to_menu();
}
}
foreach ($folders as $folder_id => $folder)
{
if (empty($folder['sections']))
{
continue;
}
$folder_section = Model_Navigation::get_section($folder['name'], $ds_section);
foreach ($folder['sections'] as $id => $section)
{
$section->add_to_menu($folder_section);
}
}
foreach ($sections_list as $type => $sections)
{
foreach ($sections as $id => $section)
{
$section->add_to_menu($ds_section);
}
}
$_create_section = Model_Navigation::get_section(__('Create section'), $ds_section, 999);
foreach ($types as $id => $type)
{
$_create_section
->add_page(new Model_Navigation_Page(array(
'name' => $type,
'url' => Route::get('datasources')->uri(array(
'controller' => 'section',
'directory' => 'datasources',
'action' => 'create',
'id' => $id
)),
'permissions' => $id.'.section.create'
)));
}
unset($sections_list, $folders, $root_section);
}
catch (Exception $ex)
{
}
});
Observer::observe('update_search_index', function() {
$ds_ids = Datasource_Data_Manager::get_all();
foreach ($ds_ids as $ds_id => $data)
{
$ds = Datasource_Data_Manager::load($ds_id);
if (!$ds->loaded())
{
continue;
}
$ds->update_index();
}
});