/** * * @param type $horarios * @param type $intervalo */ private function setHorarios($salao_id, $dia_semana, $horario_fechamento, $horario_abertura) { $horarios = ($horario_fechamento - $horario_abertura) * 2; $date = date('Y-m-d') . ' ' . $horario_abertura; $zendDate = new Zend_Date($date); $horario = $zendDate->subMinute(30); for ($i = 0; $i <= $horarios; $i++) { $horario = $zendDate->addMinute(30)->get(Zend_Date::TIME_SHORT); $insertHorario = array('salao_id' => $salao_id, 'salao_horario_dia_semana' => $dia_semana, 'salao_horario' => $horario); $modelSalaoHorario = new Model_DbTable_SalaoHorario(); if (!$modelSalaoHorario->insert($insertHorario)) { throw new Exception("Falha ao cadastrar os horários"); } } }
public function horariosAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(); $salao_id = $this->getRequest()->getParam('salao_id'); $especialidade_id = $this->getRequest()->getParam('especialidade_id'); $profissional_beleza_id = $this->getRequest()->getParam('profissional_beleza_id', null); $agenda_data = App_Helper_Date::getDateDb($this->getRequest()->getParam('agenda_data')); try { /** * Busca os horarios agendados */ $string_horarios = null; $modelAgenda = new Model_DbTable_Agenda(); $horarios = $modelAgenda->getHorariosAgenda($salao_id, $especialidade_id, $agenda_data, $profissional_beleza_id); if ($horarios->count() > 0) { $array_horarios = array(); foreach ($horarios as $horario) { $array_horarios[] = "'" . App_Helper_Date::getTime($horario->agenda_data) . "'"; } $string_horarios = implode(', ', $array_horarios); } /** * Busca os horarios do salao para a data */ $zendDate = new Zend_Date($agenda_data); $dia_semana = $zendDate->get(Zend_Date::WEEKDAY_DIGIT); $modelSalaoHorario = new Model_DbTable_SalaoHorario(); $horariosLivre = $modelSalaoHorario->getHorariosLivreSalao($salao_id, $dia_semana, $string_horarios); if ($horariosLivre->count() > 0) { $livres = array(); foreach ($horariosLivre as $livre) { $livres[] = substr($livre->salao_horario, 0, -3); } echo Zend_Json::encode($livres); } else { echo Zend_Json::encode(array('count' => 0)); } } catch (Exception $ex) { echo Zend_Json::encode(array('error' => 'Houve um problema - ' . $ex->getMessage())); } }