Skip to content

Commit

Permalink
Administration routes fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
veneliniliev committed Dec 7, 2016
1 parent 6f5f16c commit 8d819fd
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 34 deletions.
112 changes: 79 additions & 33 deletions app/Administration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,43 @@
use File;
use Illuminate\Support\Facades\Facade;
use LaravelLocalization;
use Lavary\Menu\Menu;

class Administration extends Facade {

/*
const AS_MODULE_PREFIX = 'provision.administration.module.'; //administration module route prefix

/**
* inited modules container
* @var string
*/
private static $modules;

/*
/**
* Current module name
* @var string
*/
private static $currentModuleTitle = 'Enter module name here!';

/*
/**
* Current module sub name
* @var string
*/
private static $currentModuleSubTitle = '';

/**
* Set current module name for administration titles
* @param $name
* @return string
*/
public static function setTitle($name) {
Administration::$currentModuleTitle = $name;
return $name;
}

/*
/**
* Get current module name
* @return string
*/
public static function getTitle() {
return Administration::$currentModuleTitle;
Expand All @@ -40,27 +49,32 @@ public static function getTitle() {
/**
* Set current module sub name for administration titles
* @param $name
* @return string
*/
public static function setSubTitle($name) {
Administration::$currentModuleSubTitle = $name;
return $name;
}

/*
* Get current module sub name
*/
/**
* Get current module sub name
* @return string
*/
public static function getSubTitle() {
return Administration::$currentModuleSubTitle;
}

/*
* get all language codes
/**
* Get all language codes
* @return array
*/
public static function getLanguages() {
return LaravelLocalization::getSupportedLocales();
}

/*
* get current language code
/**
* Get current language code
* @return string
*/
public static function getLanguage() {
$locale = LaravelLocalization::setLocale();
Expand All @@ -71,19 +85,25 @@ public static function getLanguage() {
}
}

/*
* get static block for blade templates
/**
* Get static block for blade templates
* @param $key
* @return mixed
*/
public static function getStaticBlock($key) {
$block = StaticBlock::where('key', $key)->first();
if ($block) {
return $block->text;
}

\Debugbar::error('static block not found: ' . $key);
return false;
}

/*
/**
* Get module order index
* @param $module
* @return mixed
*/
public static function getModuleOrderIndex($module) {
$module = \Module::where('slug', $module);
Expand All @@ -93,8 +113,9 @@ public static function getModuleOrderIndex($module) {
return $module['order'];
}

/*
* get Administration menu instance
/**
* Get administration menu instance
* @return Menu
*/
public static function getMenuInstance() {
$menu = \Menu::get('ProVisionAdministrationMenu');
Expand All @@ -105,15 +126,16 @@ public static function getMenuInstance() {
}

/**
* Is in
* @return mixed
* Is in maintenance mode
* @return bool
*/
public static function isInMaintenanceMode() {
return File::exists(storage_path('/framework/down-provision-administration'));
}

/*
* check request URL is in administration
/**
* Check request URL is in administration
* @return bool
*/
public static function routeInAdministration() {
//ако се ползва laravellocalization => 'hideDefaultLocaleInURL' => false,
Expand All @@ -130,15 +152,17 @@ public static function routeInAdministration() {
return true;
}

/*
/**
* Web site prefix in route
* @return string
*/
public static function routePrefix() {
return \LaravelLocalization::setLocale();
}

/*
/**
* Administration prefix in route
* @return mixed|string
*/
public static function routeAdministrationPrefix() {
if (!empty(\LaravelLocalization::setLocale())) {
Expand All @@ -149,8 +173,10 @@ public static function routeAdministrationPrefix() {

}

/*
* default middleware for route
/**
* Default middleware for route
* @param array $middleware
* @return array
*/
public static function routeMiddleware($middleware = []) {
$default = [
Expand All @@ -161,26 +187,46 @@ public static function routeMiddleware($middleware = []) {
return array_merge($default, $middleware);
}

/*
/**
* Administration AS in route
* @return string
*/
public static function routeAdministrationAs() {
return \Administration::getLanguage() . '.';
}

/*
/**
* Адреси за администраторските route
* @param $name
* @param array $parameters
* @param bool $absolute
* @return string
*/
public static function route($name, $parameters = [], $absolute = true) {
return route(Administration::routeAdministrationName($name), $parameters, $absolute);
}

/**
* Име на администраторският route
* @param $name
* @return string
*/
public static function routeAdministrationName($name) {
if (!empty(\LaravelLocalization::setLocale())) {
return \LaravelLocalization::setLocale() . '.' . $name;
} else {
return $name;
}
return self::AS_MODULE_PREFIX . $name;
}

/*
* Route is in Administration Dashboard?
/**
* Get route administration name
* @param $name
* @return string
*/
public static function routeName($name) {
return Administration::routeAdministrationName($name);
}

/**
* Check request is in administration dashboard
* @return bool
*/
public static function isDashboard() {
if (!empty(\LaravelLocalization::setLocale())) {
Expand Down
3 changes: 2 additions & 1 deletion app/Providers/AdministrationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use ProVision\Administration\Facades\StaticBlockFacade;

class AdministrationServiceProvider extends ServiceProvider {

/**
* Bootstrap the application services.
*
Expand Down Expand Up @@ -330,7 +331,7 @@ private function modulesBoot() {
if (method_exists($moduleAdminInit, 'routes')) {
\Route::group([
'prefix' => \ProVision\Administration\Administration::routeAdministrationPrefix(),
'as' => \ProVision\Administration\Administration::routeAdministrationAs() . 'admin.',
'as' => Administration::AS_MODULE_PREFIX,
'middleware' => \ProVision\Administration\Administration::routeMiddleware()
], function () use ($moduleAdminInit, $module) {
$moduleAdminInit->routes($module);
Expand Down

0 comments on commit 8d819fd

Please sign in to comment.