Muito obrigado pela sua disponibilidade e ajuda, agora já consegui todas as aulas às quais me posso inscrever dentro daqueles limites, como contribuição, aqui está a forma a funcionar com o Codeigniter 3:
helpers/marcacao_helper.php
function getRecordTime($weekday, $rectime) {
list($hours, $minutes) = explode(':', $rectime);
$time = $hours * 3600 + $minutes * 60;
if (date('N') != $weekday) {
switch ($weekday) {
case 1: $dayname = 'Monday';
break;
case 2: $dayname = 'Tuesday';
break;
case 3: $dayname = 'Wednesday';
break;
case 4: $dayname = 'Thursday';
break;
case 5: $dayname = 'Friday';
break;
case 6: $dayname = 'Saturday';
break;
case 7: $dayname = 'Sunday';
break;
}
$day = strtotime('next ' . $dayname);
} else {
$day = strtotime('today');
}
return $day + $time;
}
function getRecordLimits($time, $rectime) {
list($hours, $minutes) = explode(':', $rectime);
$threshold = $hours > 12 || $hours == 12 && $minutes > 45 ? 6 : 12;
$date = date("Y-m-d H:i:s", $time);
return [strtotime($date . ' - 48 hours'),
strtotime($date . ' - ' . $threshold . ' hours')];
}
No Controller:
public function aulasDisponiveisMarcacao() {
$this->db->select("Horario.id AS ID,
Horario.dia_semana_id AS DIASEMANA,
Horario.hora AS HORA,
Horario.duracao AS DURACAO,
Modalidades.nome AS MODALIDADE,
Clubes.nome AS CLUBE");
$this->db->from('Horario');
$this->db->join('ClubeModalidades', 'Horario.clube_modalidade_id = ClubeModalidades.id', 'inner');
$this->db->join('Modalidades', 'ClubeModalidades.modalidade_id = Modalidades.id', 'inner');
$this->db->join('Clubes', 'ClubeModalidades.clube_id = Clubes.id', 'inner');
$this->db->where('Clubes.id', 2);
$this->db->where('Horario.estado', '1');
$this->db->order_by('Horario.dia_semana_id, HORA', 'asc');
$resultado = $this->db->get()->result();
$this->load->helper('marcacao');
$now = strtotime('now');
foreach ($resultado as $dados) {
list($limit_inf, $limit_sup) = getRecordLimits(getRecordTime($dados->DIASEMANA, $dados->HORA), $dados->HORA);
if ($limit_inf <= $now && $limit_sup >= $now) {
echo 'Pode inscrever-se na aula de: ' . $dados->MODALIDADE . '. na data ' . date('d-m-Y', getRecordTime($dados->DIASEMANA, $dados->HORA)) . ' às ' . $dados->HORA;
echo '<hr>';
}
}
}
↧