Skip to content

Commit

Permalink
Merge pull request #570 from portabilis/portabilis-patch-2019-05-12
Browse files Browse the repository at this point in the history
Portabilis patch 12/05/2019
  • Loading branch information
edersoares authored May 14, 2019
2 parents bb5224b + aa2685f commit 0f06bfa
Show file tree
Hide file tree
Showing 205 changed files with 23,258 additions and 4,833 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace App\Exceptions\Enrollment;

use App\Models\LegacyRegistration;
use RuntimeException;

class ExistsActiveEnrollmentSameTimeException extends RuntimeException
{
/**
* Existe outra enturmação ativa para a turma.
*
* @param LegacyRegistration $registration
*/
public function __construct(LegacyRegistration $registration)
{
$message = 'A matrícula %s já está enturmada em uma turma com esse horário.';

$message = sprintf($message, $registration->id);

parent::__construct($message);
}
}
4 changes: 2 additions & 2 deletions app/Http/Controllers/BatchEnrollmentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function viewCancelEnrollments(
url('intranet/educar_index.php') => 'Escola',
]);

$this->topMenu(659); // Código: ieducar/intranet/educar_matriculas_turma_lst.php
$this->menu(659); // Código: ieducar/intranet/educar_matriculas_turma_lst.php

return view('enrollments.batch.cancel', [
'schoolClass' => $schoolClass,
Expand Down Expand Up @@ -66,7 +66,7 @@ public function viewEnroll(
url('intranet/educar_index.php') => 'Escola',
]);

$this->topMenu(659); // Código: ieducar/intranet/educar_matriculas_turma_lst.php
$this->menu(659); // Código: ieducar/intranet/educar_matriculas_turma_lst.php

return view('enrollments.batch.enroll', [
'schoolClass' => $schoolClass,
Expand Down
27 changes: 19 additions & 8 deletions app/Http/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

namespace App\Http\Controllers;

use App\Menu;
use iEducar\Support\Navigation\Breadcrumb;
use iEducar\Support\Navigation\TopMenu;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\View;

class Controller extends BaseController
{
Expand All @@ -25,17 +27,26 @@ public function breadcrumb($currentPage, $pages = [])
}

/**
* Set the top menu of the action
* Share with view, title, mainmenu and menu links.
*
* @param int $process
*
* @param $currentSubmenuId
* @param null $currentUri
* @return void
*/
public function topMenu($currentSubmenuId, $currentUri = null)
public function menu($process)
{
if (empty($currentUri)) {
$currentUri = request()->getRequestUri();
$user = Auth::user();
$menu = Menu::user($user);

$topmenu = Menu::query()
->where('process', $process)
->first();

if ($topmenu) {
View::share('mainmenu', $topmenu->root()->getKey());
}

app(TopMenu::class)->current($currentSubmenuId, $currentUri);
View::share('menu', $menu);
View::share('title', '');
}
}
16 changes: 16 additions & 0 deletions app/Http/Controllers/LegacyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers;

use Exception;
use Illuminate\Validation\ValidationException;
use Throwable;
use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Http\Exceptions\HttpResponseException;
Expand Down Expand Up @@ -124,6 +125,21 @@ private function loadFileOrAbort($filename)
try {
require_once $filename;
return;
} catch (HttpResponseException $exception) {

// Para evitar encerrar a aplicação com `die` ou `exit`, é lançada
// uma exceção do tipo `HttpResponseException` com uma `Response`
// interna que será a resposta devolvida pela aplicação.

throw $exception;

} catch (ValidationException $exception) {

// Trata as exceções geradas pela validação do Laravel.
// Nesse caso a exception será lançada e o próprio framework fará o redirect
// e tratamento das mensagens de erro

throw $exception;
} catch (Exception $exception) {

// A maioria das vezes será pega a Exception neste catch, apenas
Expand Down
1 change: 0 additions & 1 deletion app/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class Kernel extends HttpKernel
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'ieducar.navigation' => \App\Http\Middleware\Navigation::class,
'ieducar.setlayoutvariables' => \App\Http\Middleware\SetLayoutVariables::class,
'ieducar.menu' => \App\Http\Middleware\Menu::class,
'ieducar.footer' => \App\Http\Middleware\Footer::class,
'ieducar.xssbypass' => \App\Http\Middleware\XssByPass::class,
'ieducar.suspended' => \App\Http\Middleware\Suspended::class,
Expand Down
2 changes: 2 additions & 0 deletions app/Http/Middleware/ChangeAppName.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\DB;

class ChangeAppName
{
Expand All @@ -18,6 +19,7 @@ public function handle($request, Closure $next)
config([
'app.name' => config('legacy.config.ieducar_entity_name'),
'app.nickname' => url('/'),
'app.slug' => DB::getDefaultConnection(),
'app.url' => $request->getBasePath(),
'honeybadger.environment_name' => $request->getHost(),
]);
Expand Down
49 changes: 0 additions & 49 deletions app/Http/Middleware/Menu.php

This file was deleted.

8 changes: 4 additions & 4 deletions app/Http/Middleware/Navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@

use Closure;
use iEducar\Support\Navigation\Breadcrumb;
use iEducar\Support\Navigation\TopMenu;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\View;

class Navigation
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param Request $request
* @param Closure $next
*
* @return mixed
*/
public function handle($request, Closure $next)
{
View::share('topmenu', app(TopMenu::class));
View::share('breadcrumb', app(Breadcrumb::class));

return $next($request);
Expand Down
165 changes: 165 additions & 0 deletions app/Menu.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Menu extends Model
{
/**
* @var array
*/
protected $fillable = [
'parent_id',
'title',
'description',
'link',
'icon',
'order',
'type',
'process',
'active',
];

/**
* Indica se o menu é um link ou tem ao menos um link em seus submenus.
*
* @return bool
*/
public function hasLink()
{
return $this->isLink() || $this->hasLinkInSubmenu();
}

/**
* Indica se o menu é um link.
*
* @return bool
*/
public function isLink()
{
return boolval($this->link);
}

/**
* Indica se o menu tem links em seus submenus.
*
* @return bool
*/
public function hasLinkInSubmenu()
{
foreach ($this->children as $menu) {

if ($menu->isLink()) {
return true;
}

if ($menu->hasLinkInSubmenu()) {
return true;
}
}

return false;
}

/**
* @return HasMany
*/
public function children()
{
return $this->hasMany(Menu::class, 'parent_id');
}

/**
* @return BelongsTo
*/
public function parent()
{
return $this->belongsTo(Menu::class, 'parent_id');
}

/**
* Retorna o menu raiz.
*
* @return Menu
*/
public function root()
{
$root = $this;

while ($root->parent) {
$root = $root->parent;
}

return $root;
}

/**
* Retorna os menus disponíveis para um determinado usuário.
*
* @param User $user
*
* @return Collection
*/
public static function user(User $user)
{
if ($user->isAdmin()) {
return static::query()
->with('children.children.children.children.children')
->whereNull('parent_id')
->orderBy('order')
->get();
}

$ids = $user->menu()->pluck('process')->sortBy('process')->toArray();

return static::query()
->with([
'children' => function ($query) use ($ids) {
/** @var Builder $query */
$query->whereNull('process');
$query->orWhereIn('process', $ids);
$query->orderBy('order');
$query->with([
'children' => function ($query) use ($ids) {
/** @var Builder $query */
$query->whereNull('process');
$query->orWhereIn('process', $ids);
$query->orderBy('order');
$query->with([
'children' => function ($query) use ($ids) {
/** @var Builder $query */
$query->whereNull('process');
$query->orWhereIn('process', $ids);
$query->orderBy('order');
$query->with([
'children' => function ($query) use ($ids) {
/** @var Builder $query */
$query->whereNull('process');
$query->orWhereIn('process', $ids);
$query->orderBy('order');
$query->with([
'children' => function ($query) use ($ids) {
/** @var Builder $query */
$query->whereNull('process');
$query->orWhereIn('process', $ids);
$query->orderBy('order');
}
]);
}
]);
}
]);
}
]);
}
])
->whereNull('parent_id')
->orderBy('order')
->get();
}
}
Loading

0 comments on commit 0f06bfa

Please sign in to comment.