1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-23 03:50:56 +08:00
2020-03-16 15:33:36 +08:00

64 lines
1.1 KiB
PHP

<?php
namespace App\Validators;
use App\Models\Course as CourseModel;
use App\Repos\Category as CategoryRepo;
class CourseQuery extends Validator
{
public function checkCategory($id)
{
$categoryRepo = new CategoryRepo();
$category = $categoryRepo->findById($id);
if (!$category) {
return false;
}
return $category->id;
}
public function checkLevel($level)
{
$types = CourseModel::levelTypes();
if (!isset($types[$level])) {
return $level;
}
return false;
}
public function checkModel($model)
{
$types = CourseModel::levelTypes();
if (!isset($types[$model])) {
return $model;
}
return false;
}
public function checkSort($sort)
{
switch ($sort) {
case 'rating':
$orderBy = 'rating DESC';
break;
case 'score':
$orderBy = 'score DESC';
break;
default:
$orderBy = 'id DESC';
break;
}
return $orderBy;
}
}