Skip to content

Conversation

krulis-martin
Copy link
Member

No description provided.

@krulis-martin krulis-martin requested review from SemaiCZE and Neloop July 17, 2018 23:53
@krulis-martin krulis-martin force-pushed the pagination-improvements branch 2 times, most recently from 478d3bd to 51cc522 Compare July 19, 2018 20:14
@krulis-martin krulis-martin force-pushed the pagination-improvements branch from 51cc522 to 86c19da Compare July 19, 2018 20:20
/**
* Find appropriate MySQL Collation for given locale.
*/
public function getLocaleCollation()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not really sure, if this is a good place for this function...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not happy about it either. But there are very few options. Only other two choices would be to embed it in OrderByCollationInjectionMysqlWalker (which is slightly worse in my opinion) or place it in a separate helper (which is overkill in case of such a tiny function). If you have other alternatives in mind which I have overlooked, feel free to suggest them... :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me, the better place would be the OrderByCollationInjectionMysqlWalker, but I do not insist on it, if you think it would be worse...

], $code);
}
/*
protected function getPagination(int $offset, ?int $limit, string $orderBy = null, array $filters = []): Pagination {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please delete this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooops :)


$expr = $qb->expr()->orX();
foreach (["u.firstName", "u.lastName"] as $column) {
$expr->add($qb->expr()->like($column, $qb->expr()->literal('%' . $search . '%')));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

search parameter is not splitted, this causes that queries like Martin Polanka do not find anything.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, can do.

if (!$collations) {
// First time initialization ...
$collations = [
'cs' => 'utf8_czech_ci'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about en collation? Do you assume that it is default and therefore you do not have to set it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly. But I can add it, if you would like.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, need... just to be sure...

return $this->pipelineAcl->canViewDetail($pipeline);
});
$this->sendPaginationSuccessResponse($pipelines, $pagination, []);
$this->sendPaginationSuccessResponse($pipelines, $pagination, true); // true = slice manually here
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more like automatically... no? :-)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking was: automatically = already done by database, otherwise we need to do it manually in PHP code. Maybe the most clear description would be true = sliced by pagination class

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it would definitely be more clear ;-)

}

// Add order by
if ($pagination->getOrderBy() && !empty(self::$knownOrderBy[$pagination->getOrderBy()])) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I am not mistaken, this piece of code is the same for Users, maybe a helper function would be on point? ... the same goes for detection of search filter?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I will give it a serious thought.

"totalCount" => count($items),
"items" => $sliceItems
? array_slice(array_values($items), $pagination->getOffset(),
$pagination->getLimit() ? $pagination->getLimit() : null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should omit the zero? Or why is this ternary here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zero limit has "give me everything" semantics.

}

return $this->searchHelper($search, function ($search) {
$idsQueryBuilder = $this->em->createQueryBuilder()->addSelect("l.id")->from(LocalizedExercise::class, "l");
Copy link
Member

@Neloop Neloop Jul 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the searchByName function used somewhere else than in the Exercises:default action? Or why it stayed here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is definitely used in tests since it is a convenient way to get a user. I have decided to keep it rather than fixing all the test (plus using pagination just to fetch one user by the name is a bit tedious).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok...

* @param string $instanceId Id of an instance from which the authors are listed.
* @param string|null $groupId A group where the relevant exercises can be seen (assigned).
*/
public function actionAuthors(string $instanceId = null, string $groupId = null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is a purpose of this endpoint? And why don't you use mass endpoint to obtain users based on IDs?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Purpose is to offer authors for selection in pagination filter (since there are too many users, even supervisors, to offer them all). I thought about passing on the user IDs only, but since full user entities are required in all UI scenarios and since the database selects all the users anyway, it is more efficient and practical to pass the users as complete entities.

* @throws Tester\AssertException
* @throws JsonException
*/
public static function preformPresenterRequest($presenter, string $module, string $method = 'GET', array $params = [], $expectedCode = 200)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo... preform

Martin Krulis added 3 commits July 22, 2018 12:42
Neloop
Neloop previously approved these changes Jul 23, 2018
@krulis-martin krulis-martin merged commit 2300c4e into master Jul 23, 2018
@krulis-martin krulis-martin deleted the pagination-improvements branch July 23, 2018 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants