-
Notifications
You must be signed in to change notification settings - Fork 458
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #570 from portabilis/portabilis-patch-2019-05-12
Portabilis patch 12/05/2019
- Loading branch information
Showing
205 changed files
with
23,258 additions
and
4,833 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
app/Exceptions/Enrollment/ExistsActiveEnrollmentSameTimeException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.