64 строки
1.6 KiB
PHP
64 строки
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
|
|
class EncuestaModel extends Model
|
|
{
|
|
protected $table = 'survey_set';
|
|
protected $primaryKey = 'id';
|
|
protected $useTimestamps = true;
|
|
|
|
protected $allowedFields = ['title', 'description', 'user_id', 'perfil', 'fecha', 'status'];
|
|
|
|
protected $validationRules = [
|
|
'title' => 'required',
|
|
'user_id' => 'required',
|
|
'perfil' => 'required',
|
|
'fecha' => 'required',
|
|
'status' => 'required',
|
|
];
|
|
|
|
|
|
public function getEncuestas($id = null, $verbose = false)
|
|
{
|
|
if (!$id) {
|
|
return $this->findAll();
|
|
}
|
|
|
|
$encuesta = $this->where('id', $id)->first();
|
|
|
|
if ($verbose && $encuesta) {
|
|
$encuesta['perfil_nombre'] = $encuesta['perfil'] == 1 ? 'Personal de CEJ' : 'Prestador';
|
|
$encuesta['status_nombre'] = $encuesta['status'] == 0 ? 'No publicada' : 'Publicada';
|
|
|
|
switch ($encuesta['fecha']) {
|
|
case 1:
|
|
$encuesta['fecha_nombre'] = 'Inicio de servicio';
|
|
break;
|
|
case 2:
|
|
$encuesta['fecha_nombre'] = '50% de horas o más';
|
|
break;
|
|
case 3:
|
|
$encuesta['fecha_nombre'] = 'Al terminar el servicio';
|
|
break;
|
|
}
|
|
}
|
|
|
|
return $encuesta;
|
|
}
|
|
|
|
public function getPrestadorEncuestas($porcentajeCompletado)
|
|
{
|
|
$fecha = 1 + $porcentajeCompletado * 2;
|
|
|
|
return $this
|
|
->select(['id', 'title'])
|
|
->where('perfil', 2)
|
|
->where('fecha <=', $fecha)
|
|
->findAll();
|
|
}
|
|
}
|