Skip to content

Commit

Permalink
Portfolio: Include user in filter - refs BT#18201
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelFQC committed Mar 2, 2021
1 parent 5ce58f5 commit 06d944b
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions main/inc/lib/PortfolioController.php
Expand Up @@ -562,17 +562,16 @@ public function index(HttpRequest $httpRequest)
$categories = [];

if ($this->course) {
$frmTagList = $this->createFormTagFilter();
$frmTagList = $this->createFormTagFilter($listByUser);
$frmStudentList = $this->createFormStudentFilter($listByUser);
$frmStudentList->setDefaults(['user' => $this->owner->getId()]);
} else {
$categories = $this->getCategoriesForIndex($currentUserId);
}

$items = $this->getItemsForIndex($currentUserId, $listByUser, $frmTagList);
$items = $this->getItemsForIndex($listByUser, $frmTagList);

$template = new Template(null, false, false, false, false, false, false);
$template->assign('list_by_user', $listByUser);
$template->assign('user', $this->owner);
$template->assign('course', $this->course);
$template->assign('session', $this->session);
Expand Down Expand Up @@ -1876,7 +1875,7 @@ private function itemBelongToOwner(Portfolio $item): bool
return true;
}

private function createFormTagFilter(): FormValidator
private function createFormTagFilter(bool $listByUser = false): FormValidator
{
$extraField = new ExtraField('portfolio');
$tagFieldInfo = $extraField->get_handler_field_info_by_tags('tags');
Expand All @@ -1891,7 +1890,7 @@ function (array $tagOption) {
$frmTagList = new FormValidator(
'frm_tag_list',
'get',
$this->baseUrl,
$this->baseUrl.($listByUser ? 'user='.$this->owner->getId() : ''),
'',
[],
FormValidator::LAYOUT_BOX
Expand All @@ -1912,6 +1911,10 @@ function (array $tagOption) {
$frmTagList->addHidden('gidReq', 0);
$frmTagList->addHidden('gradebook', 0);
$frmTagList->addHidden('origin', '');

if ($listByUser) {
$frmTagList->addHidden('user', $this->owner->getId());
}
}

return $frmTagList;
Expand Down Expand Up @@ -1988,10 +1991,11 @@ private function getCategoriesForIndex(int $currentUserId): array
}

private function getItemsForIndex(
int $currentUserId,
bool $listByUser = false,
FormValidator $frmFilterList = null
) {
$currentUserId = api_get_user_id();

if ($this->course) {
$queryBuilder = $this->em->createQueryBuilder();
$queryBuilder
Expand All @@ -2008,11 +2012,6 @@ private function getItemsForIndex(
$queryBuilder->andWhere('pi.session IS NULL');
}

if ($listByUser) {
$queryBuilder->andWhere('pi.user = :user');
$queryBuilder->setParameter('user', $this->owner);
}

if ($frmFilterList && $frmFilterList->validate()) {
$values = $frmFilterList->exportValues();

Expand Down Expand Up @@ -2041,6 +2040,12 @@ private function getItemsForIndex(
}
}

if ($listByUser) {
$queryBuilder
->andWhere('pi.user = :user')
->setParameter('user', $this->owner);
}

$queryBuilder
->andWhere(
$queryBuilder->expr()->orX(
Expand Down

0 comments on commit 06d944b

Please sign in to comment.