Skip to content

Commit

Permalink
Version-Toolbar besser platzieren (#3132)
Browse files Browse the repository at this point in the history
  • Loading branch information
gharlan authored and kodiakhq[bot] committed Jan 13, 2020
1 parent ffcc3e3 commit 3fcd241
Showing 1 changed file with 40 additions and 22 deletions.
62 changes: 40 additions & 22 deletions redaxo/src/addons/structure/plugins/version/boot.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,17 @@
});

rex_extension::register('STRUCTURE_CONTENT_HEADER', static function (rex_extension_point $ep) {
if (!in_array($ep->getParam('page'), ['content/edit', 'content/functions'], true)) {
return null;
}

$params = $ep->getParams();
$return = '';

$rex_version_article = rex::getProperty('login')->getSessionVar('rex_version_article');
if (!is_array($rex_version_article)) {
$rex_version_article = [];
}

$working_version_empty = true;
$gw = rex_sql::factory();
$gw->setQuery('select * from ' . rex::getTablePrefix() . 'article_slice where article_id=? and clang_id=? and revision=1 LIMIT 1', [$params['article_id'], $params['clang']]);
if ($gw->getRows() > 0) {
$working_version_empty = false;
}

$revisions = [];
$revisions[0] = rex_i18n::msg('version_liveversion');
$revisions[1] = rex_i18n::msg('version_workingversion');

$version_id = rex_request('rex_set_version', 'int', '-1');

if (0 === $version_id) {
Expand All @@ -63,6 +55,30 @@
$rex_version_article[$params['article_id']] = 1;
}

if (!rex::getUser()->hasPerm('version[live_version]')) {
$rex_version_article[$params['article_id']] = 1;
}

rex::getProperty('login')->setSessionVar('rex_version_article', $rex_version_article);

$params['slice_revision'] = $rex_version_article[$params['article_id']];
});

rex_extension::register('STRUCTURE_CONTENT_BEFORE_SLICES', static function (rex_extension_point $ep) {
if (!in_array($ep->getParam('page'), ['content/edit', 'content/functions'], true)) {
return null;
}

$params = $ep->getParams();
$return = $ep->getSubject();

$working_version_empty = true;
$gw = rex_sql::factory();
$gw->setQuery('select * from ' . rex::getTablePrefix() . 'article_slice where article_id=? and clang_id=? and revision=1 LIMIT 1', [$params['article_id'], $params['clang']]);
if ($gw->getRows() > 0) {
$working_version_empty = false;
}

$func = rex_request('rex_version_func', 'string');
switch ($func) {
case 'copy_work_to_live':
Expand All @@ -85,12 +101,16 @@
break;
}

if (!rex::getUser()->hasPerm('version[live_version]')) {
$rex_version_article[$params['article_id']] = 1;
unset($revisions[0]);
$rex_version_article = rex::getProperty('login')->getSessionVar('rex_version_article');
if (!is_array($rex_version_article)) {
$rex_version_article = [];
}

rex::getProperty('login')->setSessionVar('rex_version_article', $rex_version_article);
$revisions = [];
if (rex::getUser()->hasPerm('version[live_version]')) {
$revisions[0] = rex_i18n::msg('version_liveversion');
}
$revisions[1] = rex_i18n::msg('version_workingversion');

$context = new rex_context([
'page' => $params['page'],
Expand All @@ -100,22 +120,22 @@
]);

$items = [];
$brand = '';
$currentRevision = '';
foreach ($revisions as $version => $revision) {
$item = [];
$item['title'] = $revision;
$item['href'] = $context->getUrl(['rex_set_version' => $version]);
if ($rex_version_article[$params['article_id']] == $version) {
$item['active'] = true;
$brand = $revision;
$currentRevision = $revision;
}
$items[] = $item;
}

$toolbar = '';

$fragment = new rex_fragment();
$fragment->setVar('button_prefix', rex_i18n::msg('version'));
$fragment->setVar('button_prefix', '<b>'.$currentRevision.'</b>', false);
$fragment->setVar('items', $items, false);
$fragment->setVar('toolbar', true);

Expand Down Expand Up @@ -145,9 +165,7 @@
$inverse = 1 == $rex_version_article[$params['article_id']] ? true : false;
$cssClass = 1 == $rex_version_article[$params['article_id']] ? 'rex-state-inprogress' : 'rex-state-live';

$return .= rex_view::toolbar('<ul class="nav navbar-nav">' . $toolbar . '</ul>', $brand, $cssClass, $inverse);

$params['slice_revision'] = $rex_version_article[$params['article_id']];
$return .= rex_view::toolbar('<ul class="nav navbar-nav">' . $toolbar . '</ul>', null, $cssClass, $inverse);

return $return;
});

0 comments on commit 3fcd241

Please sign in to comment.