public function dadosAction() { $this->_helper->layout->disableLayout(); $page = $this->_request->getParam("page"); $limit = $this->_request->getParam("rows"); $sord = $this->_request->getParam("sord"); $clientModel = new ClientModel(); $phoneModel = new ClientphonenumberModel(); $client = $clientModel->fetchAll(); $count = count($client); if ($count > 0 && $limit > 0) { $total_pages = ceil($count / $limit); } else { $total_pages = 0; } if ($page > $total_pages) { $page = $total_pages; } if ($this->_request->getParam("_search") == 'true') { $searchString = $this->_request->getParam("searchString"); $searchField = $this->_request->getParam("searchField"); $clientDados = $clientModel->fetchAll($clientModel->getClientSearchGrid($searchField, $searchString, $sord)); } else { $clientDados = $clientModel->fetchAll(null, 'nmclient', $limit, $page * $limit - $limit); } $response = new stdClass(); $response->page = $page; $response->total = $total_pages; $response->records = $count; $i = 0; foreach ($clientDados as $rows) { // TODO: Arrumar telefone de paciente $phoneData = $phoneModel->fetchRow('cdclient = ' . $rows->cdclient); $fgsex = null; switch ($rows->fgsex) { case '1': $fgsex = 'Masculino'; break; case '2': $fgsex = 'Feminino'; break; } switch ($rows->fgvip) { case '1': $fgvip = 'Sim'; break; case '2': $fgvip = 'Não'; break; } if (isset($rows["dtbirth"])) { $date = GslabUtils::dateToLocaleBR($rows["dtbirth"]); } $response->rows[$i]['cell'] = array($rows->cdclient, $rows->nmclient, $fgsex, $date, $fgvip, $phoneData['nrdddphone'] . " " . $phoneData['nrphonenumber']); $i++; } $this->view->dados = $response; }