Skip to content
Snippets Groups Projects
Commit 0ceb76a6 authored by Stefan Galinski's avatar Stefan Galinski :video_game:
Browse files

[TASK]

parent 0cf3135a
No related branches found
No related tags found
No related merge requests found
......@@ -278,11 +278,7 @@ class JobRepository extends Repository {
// the minimum amount of related jobs, we should try to find before removing constraints
$minRelatedJobs = 2;
$relatedJobs = [];
$query = $this->prepareRelatedJobsQuery($job, 0);
if ($limit > 0) {
$query->setLimit($limit);
}
$query = $this->prepareRelatedJobsQuery($job, 0, $limit);
$resultCount = $query->count();
......@@ -290,13 +286,13 @@ class JobRepository extends Repository {
if ($resultCount < $minRelatedJobs) {
$queryResult = $query->execute()->toArray();
array_push($relatedJobs, ...$queryResult);
$query = $this->prepareRelatedJobsQuery($job, 1);
$query = $this->prepareRelatedJobsQuery($job, 1, $limit);
$queryResult = $query->execute()->toArray();
array_push($relatedJobs, ...$queryResult);
$relatedJobs = array_unique($relatedJobs);
$relatedJobsCount = count($relatedJobs);
if ($relatedJobsCount < $minRelatedJobs) {
$query = $this->prepareRelatedJobsQuery($job, 2);
$query = $this->prepareRelatedJobsQuery($job, 2, $limit);
$queryResult = $query->execute()->toArray();
array_push($relatedJobs, ...$queryResult);
$relatedJobs = array_unique($relatedJobs);
......@@ -313,10 +309,11 @@ class JobRepository extends Repository {
* Returns a query, to be used within findRelated()
*
* @param Job $job
* @param int $iteration
* @param int $iteration used different conditions based on the iteration step
* @param int $limit
* @return QueryInterface
*/
protected function prepareRelatedJobsQuery(Job $job, int $iteration): QueryInterface {
protected function prepareRelatedJobsQuery(Job $job, int $iteration, $limit = 0): QueryInterface {
$query = $this->createQuery();
$constraints = [];
$storagePageIds = $query->getQuerySettings()->getStoragePageIds();
......@@ -327,6 +324,10 @@ class JobRepository extends Repository {
$company = $job->getCompany();
$department = $job->getDepartment();
if ($limit > 0) {
$query->setLimit($limit);
}
// look for jobs, which have the same company AND department
if ($iteration === 0) {
if ($company !== NULL) {
......@@ -336,10 +337,10 @@ class JobRepository extends Repository {
if ($department !== NULL) {
$constraints[] = $query->equals('department', $department->getUid());
}
} else if (($iteration === 1) && $company !== NULL) {
} elseif (($iteration === 1) && $company !== NULL) {
// look for jobs, which have the same company
$constraints[] = $query->equals('company', $company->getUid());
} else if (($iteration === 2) && $department !== NULL) {
} elseif (($iteration === 2) && $department !== NULL) {
// look for jobs, which have the same department
$constraints[] = $query->equals('department', $department->getUid());
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment