tinyqc/app/Models/ControlTestModel.php

33 lines
1023 B
PHP
Raw Normal View History

<?php
namespace App\Models;
use App\Models\BaseModel;
class ControlTestModel extends BaseModel
{
protected $table = 'control_tests';
protected $primaryKey = 'control_test_id';
protected $useAutoIncrement = true;
protected $returnType = 'array';
protected $useSoftDeletes = true;
protected $useTimestamps = true;
protected $allowedFields = ['control_ref_id', 'test_ref_id', 'mean', 'sd'];
public function getByControl($controlId)
{
$builder = $this->db->table('control_tests ct');
$builder->select('ct.*, t.name as test_name, t.unit');
$builder->join('dict_tests t', 't.test_id = ct.test_ref_id');
$builder->where('ct.control_ref_id', $controlId);
return $builder->get()->getResultArray();
}
public function getByControlAndTest($controlId, $testId)
{
return $this->where('control_ref_id', $controlId)
->where('test_ref_id', $testId)
->first();
}
}