Skip to content

Commit

Permalink
split sidebar in 3 different viewHelpers
Browse files Browse the repository at this point in the history
  • Loading branch information
kokspflanze committed Jun 27, 2015
1 parent aba5a55 commit 2268036
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 87 deletions.
2 changes: 2 additions & 0 deletions config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,11 @@
'email/tpl/country' => __DIR__ . '/../view/email/tpl/country.phtml',
'helper/sidebarWidget' => __DIR__ . '/../view/helper/sidebar.phtml',
'helper/sidebarLoggedInWidget' => __DIR__ . '/../view/helper/logged-in.phtml',
'helper/sidebarServerInfoWidget'=> __DIR__ . '/../view/helper/server-info.phtml',
'helper/formWidget' => __DIR__ . '/../view/helper/form.phtml',
'helper/formNoLabelWidget' => __DIR__ . '/../view/helper/form-no-label.phtml',
'helper/newsWidget' => __DIR__ . '/../view/helper/news-widget.phtml',
'helper/sidebarTimerWidget' => __DIR__ . '/../view/helper/timer.phtml',
'zfc-ticket-system/new' => __DIR__ . '/../view/zfc-ticket-system/ticket-system/new.twig',
'zfc-ticket-system/view' => __DIR__ . '/../view/zfc-ticket-system/ticket-system/view.twig',
'zfc-ticket-system/index' => __DIR__ . '/../view/zfc-ticket-system/ticket-system/index.twig',
Expand Down
9 changes: 9 additions & 0 deletions src/PServerCMS/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@ public function getViewHelperConfig()
'newsWidget' => function ( AbstractPluginManager $pluginManager ) {
return new View\Helper\NewsWidget( $pluginManager->getServiceLocator() );
},
'loggedInWidgetPServerCMS' => function ( AbstractPluginManager $pluginManager ) {
return new View\Helper\LoggedInWidget( $pluginManager->getServiceLocator() );
},
'serverInfoWidgetPServerCMS' => function ( AbstractPluginManager $pluginManager ) {
return new View\Helper\ServerInfoWidget( $pluginManager->getServiceLocator() );
},
'timerWidgetPServerCMS' => function ( AbstractPluginManager $pluginManager ) {
return new View\Helper\TimerWidget( $pluginManager->getServiceLocator() );
},
]
];
}
Expand Down
27 changes: 27 additions & 0 deletions src/PServerCMS/View/Helper/LoggedInWidget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php


namespace PServerCMS\View\Helper;

use Zend\View\Model\ViewModel;

class LoggedInWidget extends InvokerBase
{
/**
* @return string
*/
public function __invoke()
{
$template = '';

if ($this->getAuthService()->hasIdentity()) {
$viewModel = new ViewModel([
'user' => $this->getAuthService()->getIdentity()
]);
$viewModel->setTemplate('helper/sidebarLoggedInWidget');
$template = $this->getView()->render($viewModel);
}

return $template;
}
}
22 changes: 22 additions & 0 deletions src/PServerCMS/View/Helper/ServerInfoWidget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php


namespace PServerCMS\View\Helper;

use Zend\View\Model\ViewModel;

class ServerInfoWidget extends InvokerBase
{
/**
* @return string
*/
public function __invoke()
{
$viewModel = new ViewModel(array(
'serverInfo' => $this->getServerInfoService()->getServerInfo()
));
$viewModel->setTemplate('helper/sidebarServerInfoWidget');

return $this->getView()->render($viewModel);
}
}
53 changes: 3 additions & 50 deletions src/PServerCMS/View/Helper/SideBarWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,18 @@

namespace PServerCMS\View\Helper;

use PServerCMS\Helper\Timer;
use Zend\View\Model\ViewModel;

class SideBarWidget extends InvokerBase
{
/** @var array */
protected $timerService;

/**
/**
* @return string
*/
public function __invoke()
{
$template = '';
if($this->getAuthService()->getIdentity()){
$viewModel = new ViewModel(array(
'user' => $this->getAuthService()->getIdentity()
));
$viewModel->setTemplate('helper/sidebarLoggedInWidget');
$template = $this->getView()->render($viewModel);
}
$viewModel = new ViewModel(array(
'timer' => $this->getTimer(),
'serverInfo' => $this->getServerInfoService()->getServerInfo()
));
$viewModel = new ViewModel();
$viewModel->setTemplate('helper/sidebarWidget');
return sprintf('%s%s', $template, $this->getView()->render($viewModel));
}

/**
* @return array
*/
protected function getTimer()
{
if(!$this->timerService){
$config = $this->getConfig();
$timerConfig = isset($config['pserver']['timer'])?$config['pserver']['timer']:array();
foreach($timerConfig as $data){
$time = 0;
$text = '';
if(!isset($data['type'])){
if(isset($data['days'])){
$time = Timer::getNextTimeDay( $data['days'], $data['hour'], $data['min'] );
}else{
$time = Timer::getNextTime( $data['hours'],$data['min'] );
}
}else{
$text = $data['time'];
}
$this->timerService[] = array(
'time' => $time,
'text' => $text,
'name' => $data['name'],
'icon' => $data['icon']
);
}
}

return $this->timerService;
return $this->getView()->render($viewModel);
}

}
61 changes: 61 additions & 0 deletions src/PServerCMS/View/Helper/TimerWidget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php


namespace PServerCMS\View\Helper;

use PServerCMS\Helper\Timer;
use Zend\View\Model\ViewModel;

class TimerWidget extends InvokerBase
{
/** @var array */
protected $timerService;

/**
* @return string
*/
public function __invoke()
{
$viewModel = new ViewModel(array(
'timer' => $this->getTimer(),
));
$viewModel->setTemplate('helper/sidebarTimerWidget');

return $this->getView()->render($viewModel);
}

/**
* @return array
*/
protected function getTimer()
{
if(!$this->timerService){
$config = $this->getConfig();
$timerConfig = isset($config['pserver']['timer'])?$config['pserver']['timer']:array();

if ($timerConfig) {
foreach($timerConfig as $data){
$time = 0;
$text = '';
if(!isset($data['type'])){
if(isset($data['days'])){
$time = Timer::getNextTimeDay( $data['days'], $data['hour'], $data['min'] );
}else{
$time = Timer::getNextTime( $data['hours'],$data['min'] );
}
}else{
$text = $data['time'];
}
$this->timerService[] = array(
'time' => $time,
'text' => $text,
'name' => $data['name'],
'icon' => $data['icon']
);
}
}
}

return $this->timerService;
}
}
17 changes: 17 additions & 0 deletions view/helper/server-info.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<div>
<h3><?= $this->translate('Server Info') ?></h3>
<hr/>
<ul class="list-unstyled">
<li><b><?= $this->translate('PlayerOnline') ?></b> <?= $this->playerHistory() ?></li>
<?php if((bool)$this->serverInfo): ?>
<?php foreach($this->serverInfo as $curInfo): ?>
<?php /** @var \PServerCMS\Entity\ServerInfo $curInfo */ ?>
<li>
<i class="<?= $this->escapeHtml($curInfo->getIcon()) ?>"></i>
<b><?= $this->escapeHtml($curInfo->getLabel()) ?></b>
<?= $this->escapeHtml($curInfo->getMemo()) ?>
</li>
<?php endforeach ?>
<?php endif ?>
</ul>
</div>
40 changes: 3 additions & 37 deletions view/helper/sidebar.phtml
Original file line number Diff line number Diff line change
@@ -1,37 +1,3 @@
<div>
<h3><?= $this->translate('Server Info') ?></h3>
<hr/>
<ul class="list-unstyled">
<li><b><?= $this->translate('PlayerOnline') ?></b> <?= $this->playerHistory() ?></li>
<?php if((bool)$this->serverInfo): ?>
<?php foreach($this->serverInfo as $curInfo): ?>
<?php /** @var \PServerCMS\Entity\ServerInfo $curInfo */ ?>
<li>
<i class="<?= $this->escapeHtml($curInfo->getIcon()) ?>"></i>
<b><?= $this->escapeHtml($curInfo->getLabel()) ?></b>
<?= $this->escapeHtml($curInfo->getMemo()) ?>
</li>
<?php endforeach ?>
<?php endif ?>
</ul>
</div>
<div class="margin-top-30">
<h3><?= $this->translate('Servertime') ?></h3>
<hr/>
<ul class="list-unstyled">
<li><i class="fa fa-clock-o"></i> <?= $this->translate('Timer') ?>: <span id="idTimerClock"><?php echo date('H:i:s') ?></span></li>
<?php $i=0; ?>
<?php if ((bool)$this->timer ): ?>
<?php foreach ($this->timer as $curTimer) : ?>
<li><i class="<?= $this->escapeHtml($curTimer['icon']) ?>"></i>
<?= $curTimer['name'] ?>:
<?php if ($curTimer['time'] > 0) { ?>
<span class="timerCountdown" id="<?php echo 'idTimeCountdown_'.$i++; ?>" data-time="<?= $curTimer['time'] ?>"></span>
<?php } else { ?>
<?= $this->escapeHtml($curTimer['text']) ?>
<?php } ?>
</li>
<?php endforeach ?>
<?php endif ?>
</ul>
</div>
<?= $this->loggedInWidgetPServerCMS() ?>
<?= $this->serverInfoWidgetPServerCMS() ?>
<?= $this->timerWidgetPServerCMS() ?>
20 changes: 20 additions & 0 deletions view/helper/timer.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<div class="margin-top-30">
<h3><?= $this->translate('Servertime') ?></h3>
<hr/>
<ul class="list-unstyled">
<li><i class="fa fa-clock-o"></i> <?= $this->translate('Timer') ?>: <span id="idTimerClock"><?php echo date('H:i:s') ?></span></li>
<?php $i=0; ?>
<?php if ((bool)$this->timer ): ?>
<?php foreach ($this->timer as $curTimer) : ?>
<li><i class="<?= $this->escapeHtml($curTimer['icon']) ?>"></i>
<?= $curTimer['name'] ?>:
<?php if ($curTimer['time'] > 0) { ?>
<span class="timerCountdown" id="<?php echo 'idTimeCountdown_'.$i++; ?>" data-time="<?= $curTimer['time'] ?>"></span>
<?php } else { ?>
<?= $this->escapeHtml($curTimer['text']) ?>
<?php } ?>
</li>
<?php endforeach ?>
<?php endif ?>
</ul>
</div>

0 comments on commit 2268036

Please sign in to comment.