64 lines
1.8 KiB
PHP
64 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace lib\Services;
|
|
|
|
use lib\Entities\GearlistEntity as Entity;
|
|
use lib\Models\GearlistModel as Model;
|
|
|
|
class GearlistService extends CommonService
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
final public function getClassName(): string
|
|
{
|
|
return "Gearlist";
|
|
}
|
|
final public function getClassPath(): string
|
|
{
|
|
return $this->getClassName();
|
|
}
|
|
public function getModelClass(): string
|
|
{
|
|
return Model::class;
|
|
}
|
|
public function getEntityClass(): string
|
|
{
|
|
return Entity::class;
|
|
}
|
|
|
|
public function getEntitiesForLineUp(): array
|
|
{
|
|
$this->getModel()->whereNotIn("process", DBMS_GEARLIST_PROCESS_TYPES);
|
|
$this->getModel()->whereNotIn("cpuname", DBMS_GEARLIST_CPU_TYPES);
|
|
$this->getModel()->orderBy(["process" => "ASC", "price" => "ASC", "cpuname" => "asc"]);
|
|
return $this->getEntities();
|
|
}
|
|
|
|
public function getCountByMode(string $mode, string $cpu, ?string $spec = null): int
|
|
{
|
|
switch ($mode) {
|
|
case 'all':
|
|
$this->getModel()->like(["server_cpuname" => "%$cpu%", "server_spec" => "%$spec%"]);
|
|
break;
|
|
case 'use':
|
|
$this->getModel()->where("server_use_status", "n");
|
|
$this->getModel()->like(["server_cpuname" => "%$cpu%", "server_spec" => "%$spec%"]);
|
|
break;
|
|
case 'empty':
|
|
$this->getModel()->where("server_use_status", "y");
|
|
$this->getModel()->like(["server_cpuname" => "%$cpu%", "server_spec" => "%$spec%"]);
|
|
break;
|
|
case 'format':
|
|
$this->getModel()->where("server_use_status", "y");
|
|
$this->getModel()->where("server_fomat_date !='NULL'");
|
|
$this->getModel()->like(["server_cpuname" => "%$cpu%"]);
|
|
break;
|
|
default:
|
|
throw new \InvalidArgumentException("Invalid mode: $mode");
|
|
}
|
|
return $this->getCount();
|
|
}
|
|
}
|