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;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\View;
use Laracasts\Flash\Flash;
......@@ -23,14 +24,14 @@ class ModulesController extends AdminBaseController
public function index()
{
$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)
{
$enabledModules = $this->module->enabled();
$enabledModules = array_flip($enabledModules);
$enabledModules = $this->getFlippedEnabledModules();
$modules = $request->modules;
foreach ($modules as $module => $value) {
......@@ -40,15 +41,53 @@ class ModulesController extends AdminBaseController
}
}
// 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) {
if (isset($coreModules[$moduleToDisable])) {
continue;
}
$this->module->disable($moduleToDisable);
}
// Enable new modules
}
/**
* @param $modules
*/
private function enableModules($modules)
{
foreach ($modules as $moduleToEnable => $value) {
$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 @@
<li>
<div class="checkbox">
<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>
</div>
</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