Commit 35b8c056 authored by Nicolas Widart's avatar Nicolas Widart

Add core module that cannot be disabled

parent 664f11eb
<?php namespace Modules\Workshop\Http\Controllers; <?php namespace Modules\Workshop\Http\Controllers;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Redirect; use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\View; use Illuminate\Support\Facades\View;
use Laracasts\Flash\Flash; use Laracasts\Flash\Flash;
...@@ -23,14 +24,14 @@ class ModulesController extends AdminBaseController ...@@ -23,14 +24,14 @@ class ModulesController extends AdminBaseController
public function index() public function index()
{ {
$modules = $this->module->all(); $modules = $this->module->all();
$coreModules = $this->getCoreModules();
return View::make('workshop::admin.modules.index', compact('modules')); return View::make('workshop::admin.modules.index', compact('modules', 'coreModules'));
} }
public function store(ModulesRequest $request) public function store(ModulesRequest $request)
{ {
$enabledModules = $this->module->enabled(); $enabledModules = $this->getFlippedEnabledModules();
$enabledModules = array_flip($enabledModules);
$modules = $request->modules; $modules = $request->modules;
foreach ($modules as $module => $value) { foreach ($modules as $module => $value) {
...@@ -40,15 +41,53 @@ class ModulesController extends AdminBaseController ...@@ -40,15 +41,53 @@ class ModulesController extends AdminBaseController
} }
} }
// Disabled not needed modules // Disabled not needed modules
$this->disableModules($enabledModules);
// Enable new modules
$this->enableModules($modules);
Flash::success('Modules configuration saved!');
return Redirect::route('dashboard.modules.index');
}
/**
* @return array
*/
private function getCoreModules()
{
$coreModules = Config::get('core::config.CoreModules');
$coreModules = array_flip($coreModules);
return $coreModules;
}
/**
* @return array
*/
private function getFlippedEnabledModules()
{
$enabledModules = $this->module->enabled();
$enabledModules = array_flip($enabledModules);
return $enabledModules;
}
private function disableModules($enabledModules)
{
$coreModules = $this->getCoreModules();
foreach ($enabledModules as $moduleToDisable => $value) { foreach ($enabledModules as $moduleToDisable => $value) {
if (isset($coreModules[$moduleToDisable])) {
continue;
}
$this->module->disable($moduleToDisable); $this->module->disable($moduleToDisable);
} }
// Enable new modules }
/**
* @param $modules
*/
private function enableModules($modules)
{
foreach ($modules as $moduleToEnable => $value) { foreach ($modules as $moduleToEnable => $value) {
$this->module->enable($moduleToEnable); $this->module->enable($moduleToEnable);
} }
Flash::success('Modules configuration saved!');
return Redirect::route('dashboard.modules.index');
} }
} }
\ No newline at end of file
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
<li> <li>
<div class="checkbox"> <div class="checkbox">
<label for="{{ $module }}"> <label for="{{ $module }}">
<input id="{{ $module }}" name="modules[{{ $module }}]" type="checkbox" class="flat-blue" <?php echo Module::active($module) ? 'checked' : '' ?> value="true" /> {{ $module }} <input id="{{ $module }}" name="modules[{{ $module }}]" type="checkbox" class="flat-blue" <?php echo Module::active($module) ? 'checked' : '' ?> <?php echo isset($coreModules[$module]) ? 'disabled' : ''; ?> value="true" /> {{ $module }}
</label> </label>
</div> </div>
</li> </li>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment