Skip to content
Permalink
Browse files

Make package groups searchable

  • Loading branch information...
pierres committed Mar 17, 2018
1 parent 1814f07 commit 64df8bdf40d444a4974c5f7eca0cdbdf9f3fe6fd
@@ -68,6 +68,12 @@ $(document).ready(function () {
return data
},
'className': 'd-none d-lg-table-cell'
},
{
'data': 'groups',
'orderable': false,
'searchable': true,
'visible': false
}
]
})
@@ -92,12 +92,14 @@ private function queryDatabase(DatatablesRequest $request, PackageRepository $pa
'repository.name' => 'repository.name',
'architecture' => 'repository.architecture'
];
$textSearchableColumns = [
'name' => 'package.name',
'description' => 'package.description',
'groups' => 'package.groups'
];
$searchableColumns = array_merge(
$compareableColumns,
[
'name' => 'package.name',
'description' => 'package.description'
]
$textSearchableColumns
);
$orderableColumns = array_merge(
$compareableColumns,
@@ -122,7 +124,7 @@ private function queryDatabase(DatatablesRequest $request, PackageRepository $pa
}
if ($request->hasSearch() && !$request->getSearch()->isRegex()) {
$queryBuilder->andWhere('(package.name LIKE :search OR package.description LIKE :search)');
$queryBuilder->andWhere($this->createTextSearchQuery($textSearchableColumns));
$queryBuilder->setParameter(':search', '%' . $request->getSearch()->getValue() . '%');
}
@@ -153,4 +155,25 @@ private function queryDatabase(DatatablesRequest $request, PackageRepository $pa
return $response;
}
/**
* @param $textSearchableColumns
* @return string
*/
private function createTextSearchQuery($textSearchableColumns): string
{
$textSearchesArray = iterator_to_array($this->createTextSearchesIterator($textSearchableColumns));
return '(' . implode(' OR ', $textSearchesArray) . ')';
}
/**
* @param $textSearchableColumns
* @return \Iterator
*/
private function createTextSearchesIterator($textSearchableColumns): \Iterator
{
foreach ($textSearchableColumns as $textSearchableColumn) {
yield $textSearchableColumn . ' LIKE :search';
}
}
}
@@ -560,24 +560,6 @@ public function setBase(string $base): Package
return $this;
}
/**
* @return string[]
*/
public function getGroups(): array
{
return $this->groups;
}
/**
* @param array $groups
* @return Package
*/
public function setGroups(array $groups)
{
$this->groups = $groups;
return $this;
}
/**
* @return int
*/
@@ -718,6 +700,7 @@ public function jsonSerialize(): array
'builddate' => !is_null($this->getBuildDate())
? $this->getBuildDate()->format(\DateTime::RFC2822)
: null,
'groups' => $this->getGroups()
];
}
@@ -819,6 +802,24 @@ public function setBuildDate(?\DateTime $buildDate): Package
return $this;
}
/**
* @return string[]
*/
public function getGroups(): array
{
return $this->groups;
}
/**
* @param array $groups
* @return Package
*/
public function setGroups(array $groups)
{
$this->groups = $groups;
return $this;
}
/**
* @return Packager|null
*/
@@ -20,6 +20,7 @@ public function testJsonSerialize()
$package = new Package($repository, 'pacman', '6.0-1', Architecture::X86_64);
$package->setBuildDate(new \DateTime('2018-01-30'));
$package->setDescription('foo bar');
$package->setGroups(['base']);
$json = json_encode($package);
$this->assertJson($json);
@@ -35,6 +36,9 @@ public function testJsonSerialize()
'name' => 'core',
'architecture' => 'x86_64',
'testing' => false
],
'groups' => [
'base'
]
],
$jsonArray

0 comments on commit 64df8bd

Please sign in to comment.
You can’t perform that action at this time.