Skip to content

Commit

Permalink
🔨 #118 melhorando selectAll
Browse files Browse the repository at this point in the history
  • Loading branch information
bjverde committed Aug 10, 2022
1 parent 8ca4477 commit 9ecdf69
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
8 changes: 7 additions & 1 deletion controllers/CreateApiControllesFiles.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,14 @@ public function addSelectAll()
$this->addLine();
$this->addLine(ESP.'public static function selectAll(Request $request, Response $response, array $args)');
$this->addLine(ESP.'{');
$this->addLine(ESP.ESP.'$page = TGenericAPI::getSelectNumPage($args);');
$this->addLine(ESP.ESP.'$rowsPerPage = TGenericAPI::getSelectNumRowsPerPage($args);');
$this->addLine(ESP.ESP.'$orderBy = null;');
$this->addLine(ESP.ESP.'$where = array();');
$this->addLine();
$this->addLine(ESP.ESP.'$controller = new \\'.ucfirst( $this->getTableName() ).'();');
$this->addLine(ESP.ESP.'$result = $controller->selectAll();');
$this->addLine(ESP.ESP.'//$result = $controller->selectAll();');
$this->addLine(ESP.ESP.'$result = $controller->selectAllPagination( $orderBy, $where, $page, $rowsPerPage);');
$this->addLine(ESP.ESP.'$result = \ArrayHelper::convertArrayFormDin2Pdo($result);');
$this->addLine(ESP.ESP.'$msg = array( \'qtd\'=> \CountHelper::count($result)');
$this->addLine(ESP.ESP.ESP.ESP.ESP.', \'result\'=>$result');
Expand Down
11 changes: 11 additions & 0 deletions system_skeleton/rest/api/api_controllers/TGenericAPI.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,15 @@ public static function getBodyJson($msg, Response $response)
$response->getBody()->write( $msgJson );
return $response->withHeader('Content-Type', 'application/json');
}
public static function getSelectNumPage($args)
{
$page = \ArrayHelper::get($args,'page');
return $page;
}
public static function getSelectNumRowsPerPage($args)
{
$rowsPerPage = \ArrayHelper::get($args,'rowsPerPage');
$rowsPerPage = empty($page)?ROWS_PER_PAGE:$rowsPerPage;
return $rowsPerPage;
}
}

0 comments on commit 9ecdf69

Please sign in to comment.