Skip to content

Commit

Permalink
Merge 3401112 into 6947ed3
Browse files Browse the repository at this point in the history
  • Loading branch information
VaShu committed Jun 14, 2017
2 parents 6947ed3 + 3401112 commit 266c1c1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
21 changes: 19 additions & 2 deletions src/AppBundle/Controller/SiteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,30 @@ public function indexAction(Request $request)
$status = $request->query->get('status');
}

// get all projects current user from RedMine
$redMineClientService = $this->container->get('redmine_client');
$uri = '/users/' . $this->getUser()->getId() . '.json?include=memberships';
$listMemberships = $redMineClientService->get($uri)['user']['memberships'];

if (in_array('ROLE_REDMINE_ADMIN', $this->getUser()->getRoles())) {
$arrayIdProjects = [];
} else {
if ($listMemberships) {
$arrayIdProjects = [];
foreach ($listMemberships as $membership) {
$arrayIdProjects[] = $membership['project']['id'];
}
}
}

if ($name || $framework || $status) {
$query = $em->getRepository('AppBundle:Site')->searchQuery($name, $framework, $status);
$query = $em->getRepository('AppBundle:Site')->searchQuery($name, $framework, $status, $arrayIdProjects);
} else {
$query = $em->getRepository('AppBundle:Site')->findBy(['status' => $status]);
}

$entities = $this->get('knp_paginator')->paginate($query, $request->query->getInt('page', 1), 12);

$entities = $this->get('knp_paginator')->paginate($query, $request->query->getInt('page', 1), 100);
$form = $this->createSearchForm(['name' => $name, 'framework' => $framework, 'status' => $status]);

return [
Expand Down
7 changes: 6 additions & 1 deletion src/AppBundle/Entity/SiteRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SiteRepository extends EntityRepository
* @param string $status
* @return Query
*/
public function searchQuery($name = null, $framework = null, $status = null)
public function searchQuery($name = null, $framework = null, $status = null, $projects = [])
{
$qb = $this->createQueryBuilder('s');
if ($name) {
Expand All @@ -27,6 +27,11 @@ public function searchQuery($name = null, $framework = null, $status = null)
->setParameter('framework', $framework);
}

if (count($projects) != 0) {
$qb->andWhere('s.project IN (:projects)')
->setParameter('projects', $projects);
}

if ($status == Site::STATUS_SUPPORTED) {
$qb
->andWhere('s.status = :status')
Expand Down
2 changes: 1 addition & 1 deletion src/AppBundle/Form/SiteType.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'label' => 'Status',
'required' => false,
'choices' => [
'Suppoerted' => Site::STATUS_SUPPORTED,
'Supported' => Site::STATUS_SUPPORTED,
'UnSupported' => Site::STATUS_UNSUPPORTED,
],
'empty_value' => null,
Expand Down

0 comments on commit 266c1c1

Please sign in to comment.