/**
  * Initializes the component. The backend to use is chosen here. If a 
  * current backend is stored in the session we use that, otherwise we fall 
  * back on whatever backend is set as default.
  */
 public function init()
 {
     $currentBackendId = Yii::app()->session->get(self::SESSION_KEY);
     if ($currentBackendId !== null) {
         $this->_backend = Backend::model()->findByPk($currentBackendId);
     } else {
         $this->_backend = Backend::model()->default()->find();
     }
     parent::init();
 }
Exemplo n.º 2
0
<?php

$leftItems = array(array('label' => Yii::t('Menu', 'Movies'), 'items' => array(array('label' => Yii::t('Menu', 'Browse'), 'url' => array('movie/index'), 'active' => in_array($this->route, array('movie/index', 'movie/details'))), array('label' => Yii::t('Menu', 'Recently added'), 'url' => array('movie/recentlyAdded'))), 'linkOptions' => array('class' => 'fa fa-video-camera')), array('label' => Yii::t('Menu', 'TV Shows'), 'items' => array(array('label' => Yii::t('Menu', 'Browse'), 'url' => array('tvShow/index'), 'active' => in_array($this->route, array('tvShow/index', 'tvShow/details', 'tvShow/season'))), array('label' => Yii::t('Menu', 'Recently added'), 'url' => array('tvShow/recentlyAdded'))), 'linkOptions' => array('class' => 'fa fa-desktop')));
$rightItems = array();
// Add a "Change backend" menu when there's more than one configured backend
$backends = Backend::model()->findAll();
if (count($backends) > 1) {
    $backendItems = array();
    $currentBackend = Yii::app()->backendManager->getCurrent();
    foreach ($backends as $backend) {
        $label = $backend->name;
        if ($currentBackend !== null && $currentBackend->id == $backend->id) {
            $label = TbHtml::icon(TbHtml::ICON_OK) . ' ' . $label;
        }
        $backendItems[] = array('label' => $label, 'url' => array('backend/change', 'id' => $backend->id));
    }
    $rightItems[] = array('label' => Yii::t('Menu', 'Change backend'), 'items' => $backendItems, 'linkOptions' => array('class' => 'fa fa-cloud'));
}
// Add the "Settings" menu for administrators
if (Yii::app()->user->role == User::ROLE_ADMIN) {
    $rightItems[] = array('label' => Yii::t('Menu', 'Settings'), 'items' => array(array('label' => Yii::t('Menu', 'Settings')), array('label' => Yii::t('Menu', 'Manage'), 'url' => array('setting/admin')), array('label' => Yii::t('Menu', 'Backends')), array('label' => Yii::t('Menu', 'Manage'), 'url' => array('backend/admin')), array('label' => Yii::t('Menu', 'Create new'), 'url' => array('backend/create')), array('label' => Yii::t('Menu', 'Users')), array('label' => Yii::t('Menu', 'Manage'), 'url' => array('user/admin')), array('label' => Yii::t('Menu', 'Create new'), 'url' => array('user/create')), array('label' => Yii::t('Menu', 'System log')), array('label' => Yii::t('Menu', 'Browse'), 'url' => array('log/'))), 'linkOptions' => array('class' => 'fa fa-cogs'));
}
// Add the "Actions" menu
$changeLanguageItem = array('label' => Yii::t('Menu', 'Change language'), 'url' => '#', 'linkOptions' => array('data-toggle' => 'modal', 'data-target' => '#change-language-modal'));
$actions = array(array('label' => Yii::t('Menu', 'Interface')), $changeLanguageItem, array('label' => Yii::t('Menu', 'System')));
// Only show "Flush cache" if cacheApiCalls is enabled
if (Setting::getBoolean('cacheApiCalls')) {
    $actions[] = array('label' => Yii::t('Menu', 'Flush cache'), 'url' => array('site/flushCache'), 'linkOptions' => array('confirm' => Yii::t('Misc', 'Are you sure you want to flush the cache?')));
}
$actions[] = array('label' => Yii::t('Menu', 'Update library'), 'url' => array('backend/updateLibrary'), 'linkOptions' => array('confirm' => Yii::t('Misc', "Are you sure you want to update the backend's library?")));
if (Yii::app()->powerOffManager->getAllowedActions()) {
Exemplo n.º 3
0
 /**
  * Checks that there is another backend set as default if the default 
  * checkbox is unchecked for this one
  * @param string $attribute the attribute being validated
  */
 public function requireDefaultBackend($attribute)
 {
     if (!$this->{$attribute}) {
         $error = Yii::t('Backend', 'There must be a default backend');
         // If this backend is currently the default one it must remain so
         if (!$this->isNewRecord) {
             $model = $this->findByPk($this->id);
             if ($model->default) {
                 $this->addError($attribute, $error);
             }
         }
         // If there are no other backends then this must be the default one
         if (count(Backend::model()->findAll()) === 0) {
             $this->addError($attribute, $error);
         }
     }
 }
Exemplo n.º 4
0
<?php

/* @var $this BackendController */
/* @var $model Backend */
$this->pageTitle = $title = Yii::t('Backend', 'Manage backends');
?>

<h2><?php 
echo $title;
?>
</h2>

<?php 
echo FormHelper::helpBlock(Yii::t('Backend', 'This is where you configure your backends. A 
	backend is an instance of XBMC that the application connects to and serves 
	library contents from. If you specify more than one backend, a new item 
	will appear in the main menu, allowing you to easily switch backends.'));
?>

<?php 
echo TbHtml::linkButton(Yii::t('Backend', 'Create new backend'), array('color' => TbHtml::BUTTON_COLOR_PRIMARY, 'url' => array('create')));
?>

<hr />

<?php 
$this->widget('bootstrap.widgets.TbGridView', array('type' => TbHtml::GRID_TYPE_STRIPED, 'dataProvider' => Backend::model()->dataProvider, 'enableSorting' => false, 'template' => '{items}', 'columns' => array('name', 'hostname', 'port', 'tcp_port', array('name' => 'default', 'header' => Yii::t('Backend', 'Default'), 'type' => 'raw', 'value' => function ($data) {
    return $data->default ? TbHtml::icon(TbHtml::ICON_OK) : '';
}), 'macAddress', 'subnetMask', array('class' => 'bootstrap.widgets.TbButtonColumn', 'template' => '{update} {delete}'))));
 /**
  * Creates a new backend, then return to the admin action
  */
 public function actionCreate()
 {
     $model = new Backend();
     if (isset($_POST['Backend'])) {
         $model->attributes = $_POST['Backend'];
         // Check whether this is the first backend ever created, if so we
         // redirect to the settings page
         $firstRun = $this->getCurrent() === null;
         if ($model->save()) {
             $this->log('"%s" created backend "%s"', Yii::app()->user->name, $model->name);
             Yii::app()->user->setFlash('success', Yii::t('Backend', 'Backend created successfully'));
             $this->checkWebSocketConnectivity($model);
             if ($firstRun) {
                 Yii::app()->user->setFlash('info', Yii::t('Settings', 'Before you get started, please have a look at the application settings'));
                 $this->redirect(array('setting/admin'));
             } else {
                 $this->redirect(array('admin'));
             }
         }
     } else {
         $model->hostname = 'localhost';
         $model->port = 8080;
         $model->tcp_port = 9090;
         $model->username = '******';
         $model->password = '******';
         // Check "default" if there are no other backends
         $backends = Backend::model()->findAll();
         if (count($backends) === 0) {
             $model->default = true;
         }
     }
     $this->render('create', array('model' => $model));
 }
<?php

// Only use a cached version if there is just one backend configured, otherwise
// the cache invalidation gets too complicated
if (count(Backend::model()->findAll()) === 1) {
    $cacheDependency = new CFileCacheDependency(realpath(__DIR__ . '/_navbar.php'));
    $cacheDuration = 60 * 60 * 24 * 365;
    if ($this->beginCache('MainMenu', array('dependency' => $cacheDependency, 'duration' => $cacheDuration, 'varyByExpression' => function () {
        return implode('_', array(Yii::app()->user->role, intval(Setting::getBoolean('cacheApiCalls')), intval(Yii::app()->powerOffManager->getAllowedActions()), intval(Yii::app()->backendManager->getCurrent() === null), Yii::app()->language, Yii::app()->baseUrl));
    }))) {
        $this->renderPartial('//layouts/_navbar');
        $this->endCache();
    }
} else {
    $this->renderPartial('//layouts/_navbar');
}