public function addListaVip() { $json = NULL; try { $eventosId = Session::read('Form.eventos_id'); $model = new Mobile(); if (empty($_POST['nomes_listas'])) { throw new Exception('A lista deve conter ao menos um nome e telefone!'); } if (empty($_POST['tipos_listas_id'])) { throw new Exception('O tipo da lista é um campo requirido!'); } $newArr = $this->Evento->quebraLinha($_POST['nomes_listas']); if (empty($newArr)) { throw new Exception('Você deve adicionar nomes a lista respeitando a formatação. ex: NOME - FONE'); } foreach ($newArr as $lista) { $model->data = $_POST; if ($model->validates()) { /** * verificar ou listar o cliente */ $registro = $model->setNome($lista['nome'])->setPhone($lista['telefone'])->register(); /** * inserir na lista vip */ $this->Evento->addClientVipList($registro['pessoas_id'], $eventosId, $_POST['tipos_listas_id'], $this->pessoas_id); $json = json_encode(array('message' => 'Operação realizada com sucesso', "style" => 'success', 'time' => 5000, 'size' => 'md', 'callback' => "carregaMinhaLista();carregaResumoFuncionario();", 'before' => "\$('#loading').fadeOut(500);", 'icon' => 'check', 'title' => 'Success!')); } else { $json = json_encode(array('message' => $model->refactoryError(), "style" => 'warning', 'time' => 5000, 'size' => 'md', 'callback' => NULL, 'before' => "\$('#loading').fadeOut(500);", 'icon' => 'check', 'title' => 'Warning!')); } } echo json_encode(array('funcao' => "bootsAlert( {$json} )")); } catch (Exception $ex) { $json = json_encode(array('message' => $ex->getMessage(), "style" => 'danger', 'time' => 5000, 'size' => 'md', 'callback' => NULL, 'before' => "\$('#loading').fadeOut(500);", 'icon' => 'check', 'title' => 'Danger!')); echo json_encode(array('funcao' => "bootsAlert( {$json} )")); } }