1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @package midcom.helper |
4
|
|
|
* @author The Midgard Project, http://www.midgard-project.org |
5
|
|
|
* @copyright The Midgard Project, http://www.midgard-project.org |
6
|
|
|
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* This class is a view toolbar class. |
11
|
|
|
* |
12
|
|
|
* @package midcom.helper |
13
|
|
|
*/ |
14
|
|
|
class midcom_helper_toolbar_view extends midcom_helper_toolbar |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @param string $class_style The class style tag for the UL. |
18
|
|
|
* @param string $id_style The id style tag for the UL. |
19
|
|
|
*/ |
20
|
351 |
|
public function __construct(?string $class_style = null, ?string $id_style = null) |
21
|
|
|
{ |
22
|
351 |
|
$config = midcom::get()->config; |
23
|
351 |
|
$class_style = $class_style ?: $config->get('toolbars_view_style_class'); |
24
|
351 |
|
$id_style = $id_style ?: $config->get('toolbars_view_style_id'); |
25
|
351 |
|
parent::__construct($class_style, $id_style); |
|
|
|
|
26
|
351 |
|
$this->label = midcom::get()->i18n->get_string('page', 'midcom'); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Binds the a toolbar to a DBA object. This will append a number of globally available |
31
|
|
|
* toolbar options. For example, expect Metadata- and Version Control-related options |
32
|
|
|
* to be added. |
33
|
|
|
* |
34
|
|
|
* Repeated bind calls are intercepted, you can only bind a toolbar to a single object. |
35
|
|
|
*/ |
36
|
52 |
|
public function bind_to(midcom_core_dbaobject $object) |
37
|
|
|
{ |
38
|
52 |
|
if (!midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ANCHORPREFIX)) { |
39
|
|
|
debug_add("Toolbar for object {$object->guid} was called before topic prefix was available, skipping global items.", MIDCOM_LOG_WARN); |
40
|
|
|
return; |
41
|
|
|
} |
42
|
52 |
|
if (array_key_exists('midcom_services_toolbars_bound_to_object', $this->customdata)) { |
43
|
|
|
// We already processed this toolbar, skipping further adds. |
44
|
1 |
|
return; |
45
|
|
|
} |
46
|
52 |
|
$this->customdata['midcom_services_toolbars_bound_to_object'] = true; |
47
|
|
|
|
48
|
52 |
|
$reflector = new midcom_helper_reflector($object); |
|
|
|
|
49
|
52 |
|
$this->set_label($reflector->get_class_label()); |
50
|
|
|
|
51
|
52 |
|
$buttons = $this->get_approval_controls($object); |
52
|
|
|
|
53
|
52 |
|
if ($object->can_do('midgard:update')) { |
54
|
49 |
|
$workflow = new midcom\workflow\datamanager; |
55
|
49 |
|
$buttons[] = $workflow->get_button("__ais/folder/metadata/{$object->guid}/", [ |
56
|
49 |
|
MIDCOM_TOOLBAR_LABEL => midcom::get()->i18n->get_string('edit metadata', 'midcom.admin.folder'), |
57
|
49 |
|
MIDCOM_TOOLBAR_GLYPHICON => 'database', |
58
|
49 |
|
MIDCOM_TOOLBAR_ACCESSKEY => 'm', |
59
|
49 |
|
]); |
60
|
49 |
|
$viewer = new midcom\workflow\viewer; |
61
|
49 |
|
$buttons = array_merge($buttons, [ |
62
|
49 |
|
$viewer->get_button("__ais/folder/move/{$object->guid}/", [ |
63
|
49 |
|
MIDCOM_TOOLBAR_LABEL => midcom::get()->i18n->get_string('move', 'midcom.admin.folder'), |
64
|
49 |
|
MIDCOM_TOOLBAR_GLYPHICON => 'arrows', |
65
|
49 |
|
MIDCOM_TOOLBAR_ENABLED => $object instanceof midcom_db_article |
66
|
49 |
|
]), |
67
|
49 |
|
[ |
68
|
49 |
|
MIDCOM_TOOLBAR_URL => midcom_connection::get_url('self') . "__mfa/asgard/object/open/{$object->guid}/", |
69
|
49 |
|
MIDCOM_TOOLBAR_LABEL => midcom::get()->i18n->get_string('manage object', 'midgard.admin.asgard'), |
70
|
49 |
|
MIDCOM_TOOLBAR_GLYPHICON => 'cog', |
71
|
49 |
|
MIDCOM_TOOLBAR_ENABLED => midcom::get()->auth->can_user_do('midgard.admin.asgard:access', class: 'midgard_admin_asgard_plugin') |
72
|
49 |
|
&& midcom::get()->auth->can_user_do('midgard.admin.asgard:manage_objects', class: 'midgard_admin_asgard_plugin'), |
73
|
49 |
|
] |
74
|
49 |
|
]); |
75
|
|
|
} |
76
|
|
|
|
77
|
52 |
|
if ( midcom::get()->config->get('midcom_services_rcs_enable') |
78
|
52 |
|
&& $object->can_do('midgard:update') |
79
|
52 |
|
&& $object->_use_rcs) { |
80
|
48 |
|
$buttons[] = [ |
81
|
48 |
|
MIDCOM_TOOLBAR_URL => "__ais/rcs/{$object->guid}/", |
82
|
48 |
|
MIDCOM_TOOLBAR_LABEL => midcom::get()->i18n->get_string('show history', 'midcom.admin.rcs'), |
83
|
48 |
|
MIDCOM_TOOLBAR_GLYPHICON => 'history', |
84
|
48 |
|
MIDCOM_TOOLBAR_ACCESSKEY => 'v', |
85
|
48 |
|
]; |
86
|
|
|
} |
87
|
52 |
|
$this->add_items($buttons); |
88
|
|
|
} |
89
|
|
|
|
90
|
139 |
|
public function get_approval_controls(midcom_core_dbaobject $object, bool $add_accesskey = false) : array |
91
|
|
|
{ |
92
|
139 |
|
$buttons = []; |
93
|
139 |
|
if (midcom::get()->config->get('metadata_approval')) { |
94
|
|
|
$published = midcom::get()->config->get('show_hidden_objects') || $object->metadata->is_visible(); |
95
|
|
|
if ($object->metadata->is_approved()) { |
96
|
|
|
$action = 'unapprove'; |
97
|
|
|
$helptext = 'approved'; |
98
|
|
|
$accesskey = 'u'; |
99
|
|
|
$icon = $published ? 'check-square-o' : 'calendar-check-o'; |
100
|
|
|
} else { |
101
|
|
|
$action = 'approve'; |
102
|
|
|
$helptext = 'unapproved'; |
103
|
|
|
$accesskey = 'a'; |
104
|
|
|
$icon = $published ? 'times-rectangle-o' : 'calendar-times-o'; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
$buttons[] = [ |
108
|
|
|
MIDCOM_TOOLBAR_URL => "__ais/folder/" . $action . "/", |
109
|
|
|
MIDCOM_TOOLBAR_LABEL => midcom::get()->i18n->get_string($action, 'midcom'), |
110
|
|
|
MIDCOM_TOOLBAR_HELPTEXT => midcom::get()->i18n->get_string($helptext, 'midcom'), |
111
|
|
|
MIDCOM_TOOLBAR_GLYPHICON => $icon, |
112
|
|
|
MIDCOM_TOOLBAR_POST => true, |
113
|
|
|
MIDCOM_TOOLBAR_POST_HIDDENARGS => [ |
114
|
|
|
'guid' => $object->guid, |
115
|
|
|
'return_to' => $_SERVER['REQUEST_URI'], |
116
|
|
|
], |
117
|
|
|
MIDCOM_TOOLBAR_ACCESSKEY => ($add_accesskey) ? $accesskey : null, |
118
|
|
|
MIDCOM_TOOLBAR_ENABLED => $object->can_do('midcom:approve'), |
119
|
|
|
]; |
120
|
|
|
} |
121
|
139 |
|
return $buttons; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|