Skip to content

Commit

Permalink
Merge pull request #130 from lageIBUSP/ordering
Browse files Browse the repository at this point in the history
Ordering
  • Loading branch information
andrechalom authored Jul 30, 2024
2 parents eb3478f + 85c1d23 commit 04933b2
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 10 deletions.
4 changes: 2 additions & 2 deletions app/Http/Controllers/ExercicioController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ExercicioController extends Controller
public function index()
{
$topicos = Topico::orderBy('order');
$semTopico = Exercicio::whereDoesntHave('topico')->orderBy('name');
$semTopico = Exercicio::whereDoesntHave('topico');
/** @var \App\Models\User */
$user = Auth::user();
if (optional($user)->isAdmin()) {
Expand All @@ -55,7 +55,7 @@ public function create()
$this->authorize('create', Exercicio::class);
return View('exercicio.create')
->with('pacotesR', $this->getInstalledPackages())
->with('topicos', Topico::orderBy('order'));
->with('topicos', Topico::all());
}

/**
Expand Down
7 changes: 7 additions & 0 deletions app/Models/Exercicio.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Stephenjude\DefaultModelSorting\Traits\DefaultOrderBy;
use Symfony\Component\Yaml\Yaml as Yaml;

class Exercicio extends Model
Expand All @@ -25,6 +26,12 @@ class Exercicio extends Model
'id'
];

/**
* Set a default ordering for this model
*/
use DefaultOrderBy;
protected static $orderByColumn = 'name';

/**
* Scope a query to only include active users.
*
Expand Down
15 changes: 10 additions & 5 deletions app/Models/Prazo.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@
use Illuminate\Database\Eloquent\Relations\Pivot;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Support\Carbon;
use Stephenjude\DefaultModelSorting\Traits\DefaultOrderBy;

class Prazo extends Pivot
{
use HasFactory;
protected $table = 'prazos';

protected $guarded = [];
/**
* Set a default ordering for this model
*/
use DefaultOrderBy;
protected static $orderByColumn = 'prazo';

// relationships
public function turma()
Expand All @@ -24,13 +29,13 @@ public function exercicio()
}

// passado/futuro
public function getPassadoAttribute()
public function getPassadoAttribute()
{
return $this->prazo < now();
return $this->prazo < now();
}
public function getFuturoAttribute()
public function getFuturoAttribute()
{
return !$this->passado;
return !$this->passado;
}

public function scopeFuturos($query) {
Expand Down
7 changes: 7 additions & 0 deletions app/Models/Topico.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Stephenjude\DefaultModelSorting\Traits\DefaultOrderBy;

class Topico extends Model
{
use HasFactory;
protected $table = 'topicos';
protected $guarded = [];

/**
* Set a default ordering for this model
*/
use DefaultOrderBy;
protected static $orderByColumn = 'order';

// relationships
public function exercicios()
{
Expand Down
4 changes: 2 additions & 2 deletions app/Models/Turma.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ public function prazos()

public function prazosOrdered()
{
// THIS WILL ALWAYS BE ORDERED BY EX-NAME
// THIS WILL ALWAYS BE ORDERED BY PRAZO AND EX-NAME
return $this->prazos()
->join('exercicios', 'prazos.exercicio_id', '=', 'exercicios.id')
->select('prazos.*','exercicios.name as exercicio_name')
->orderBy('exercicio_name')
->orderBy('prazo')
->orderBy('exercicio_name')
;
}
}
7 changes: 7 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Hash;
use Stephenjude\DefaultModelSorting\Traits\DefaultOrderBy;

class User extends Authenticatable
{
use HasFactory, Notifiable;

/**
* Set a default ordering for this model
*/
use DefaultOrderBy;
protected static $orderByColumn = 'name';

/**
* Sets a hashed password
*/
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"laravel/framework": "^11.0",
"laravel/tinker": "^2.9",
"neitanod/forceutf8": "~2.0",
"stephenjude/default-model-sorting": "^3.0",
"symfony/yaml": "^6.0"
},
"require-dev": {
Expand Down
66 changes: 65 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 04933b2

Please sign in to comment.