Skip to content

Commit

Permalink
remove pk
Browse files Browse the repository at this point in the history
  • Loading branch information
mevdschee committed Jul 6, 2020
1 parent 75109fa commit a5e2be0
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/Tqdev/PhpCrudUi/Record/RecordService.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,19 +213,17 @@ public function delete(string $table, string $action, string $id): TemplateDocum
return new TemplateDocument('layouts/default', 'record/deleted', $variables);
}

private function getArguments(array $types, array $filters): array
private function getArguments(string $primaryKey, array $types, array $filters): array
{
$args = array();
$i = 0;
foreach ($filters as $filter) {
if ($filter['type'] == 'search') {
$j = 0;
foreach ($types as $column => $type) {
switch ($type['type']) {
case 'string':
$args["filter${j}[0]"] = implode(',', array($column, $filter['operator'], $filter['value']));
$j++;
break;
if ($column != $primaryKey) {
$args["filter${j}[0]"] = implode(',', array($column, $filter['operator'], $filter['value']));
$j++;
}
}
} elseif ($filter['type'] == 'value') {
Expand Down Expand Up @@ -289,7 +287,7 @@ public function _list(string $table, string $action, array $params): TemplateDoc
list($pageNumber, $pageSize) = explode(',', $pageParams, 2);

$filters = $this->getFilters($references, $params);
$args = $this->getArguments($types, $filters);
$args = $this->getArguments($primaryKey, $types, $filters);

$args['join'] = array_values(array_filter($references));
$args['page'] = "$pageNumber,$pageSize";
Expand Down Expand Up @@ -356,7 +354,7 @@ public function search(string $table, array $body, array $params)
$otherTable = $references[$body['field']];
$otherKey = $this->definition->getPrimaryKey($otherTable, $action);
$otherTypes = $this->definition->getTypes($otherTable, $action);
$args = $this->getArguments($otherTypes, [['type' => 'search', 'field' => '*any*', 'operator' => 'cs', 'value' => $body['value']]]);
$args = $this->getArguments($otherKey, $otherTypes, [['type' => 'search', 'field' => '*any*', 'operator' => 'cs', 'value' => $body['value']]]);
$args['include'] = $otherKey;
$records = $this->api->listRecords($otherTable, $args);
$values = array_map(function ($a) use ($otherKey) {return $a[$otherKey];}, $records['records']);
Expand Down

0 comments on commit a5e2be0

Please sign in to comment.