Skip to content

Commit 15231fe

Browse files
committed
Restoring old methods.
1 parent b062409 commit 15231fe

3 files changed

Lines changed: 293 additions & 29 deletions

File tree

Manager/GroupManager.php

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,14 +497,77 @@ public function getAll()
497497
}
498498

499499
/**
500-
* @deprecated use getAll() instead
500+
* Serialize a group array.
501+
*
502+
* @param Group[] $groups
503+
*
504+
* @return array
505+
*/
506+
public function convertGroupsToArray(array $groups)
507+
{
508+
$content = array();
509+
$i = 0;
510+
foreach ($groups as $group) {
511+
$content[$i]['id'] = $group->getId();
512+
$content[$i]['name'] = $group->getName();
513+
$rolesString = '';
514+
$roles = $group->getEntityRoles();
515+
$rolesCount = count($roles);
516+
$j = 0;
517+
foreach ($roles as $role) {
518+
$rolesString .= "{$this->translator->trans($role->getTranslationKey(), array(), 'platform')}";
519+
if ($j < $rolesCount - 1) {
520+
$rolesString .= ' ,';
521+
}
522+
$j++;
523+
}
524+
$content[$i]['roles'] = $rolesString;
525+
$i++;
526+
}
527+
return $content;
528+
}
529+
/**
530+
* @param integer $page
531+
* @param int $max
532+
*
533+
* @return \PagerFanta\PagerFanta
534+
*/
535+
public function getAllGroups($page, $max = 50)
536+
{
537+
$query = $this->groupRepo->findAll(false);
538+
return $this->pagerFactory->createPager($query, $page, $max);
539+
}
540+
/**
541+
* @param integer $page
542+
* @param string $search
543+
* @param int $max
544+
*
545+
* @return \PagerFanta\PagerFanta
501546
*/
547+
public function getAllGroupsBySearch($page, $search, $max = 50)
548+
{
549+
$query = $this->groupRepo->findAllGroupsBySearch($search);
550+
return $this->pagerFactory->createPagerFromArray($query, $page, $max);
551+
}
552+
/**
553+
* @param string[] $names
554+
*
555+
* @return Group[]
556+
*/
557+
public function getGroupsByNames(array $names)
558+
{
559+
if (count($names) > 0) {
560+
return $this->groupRepo->findGroupsByNames($names);
561+
}
562+
return array();
563+
}
564+
502565
public function getAllGroupsWithoutPager(
503566
$orderedBy = 'id',
504567
$order = 'ASC',
505568
$executeQuery = true
506569
)
507570
{
508-
return $this->getAll();
571+
return $this->groupRepo->findAllGroups($orderedBy, $order, $executeQuery);
509572
}
510573
}

Manager/UserManager.php

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,4 +1549,100 @@ public function getLogger()
15491549
{
15501550
return $this->logger;
15511551
}
1552+
1553+
/**
1554+
* @param integer $page
1555+
* @param integer $max
1556+
* @param string $orderedBy
1557+
* @param string $order
1558+
*
1559+
* @return \Pagerfanta\Pagerfanta;
1560+
*/
1561+
public function getAllUsersExcept($page, $max = 20, $orderedBy = 'id', $order = null, array $users )
1562+
{
1563+
$query = $this->userRepo->findAllExcept($users);
1564+
return $this->pagerFactory->createPagerFromArray($query, $page, $max);
1565+
}
1566+
/**
1567+
* @param string $search
1568+
* @param integer $page
1569+
* @param integer $max
1570+
*
1571+
* @return \Pagerfanta\Pagerfanta;
1572+
*/
1573+
public function getAllUsersBySearch($page, $search, $max = 20)
1574+
{
1575+
$users = $this->userRepo->findAllUserBySearch($search);
1576+
return $this->pagerFactory->createPagerFromArray($users, $page, $max);
1577+
}
1578+
1579+
1580+
/**
1581+
* @param \Claroline\CoreBundle\Entity\Group $group
1582+
*
1583+
* @return User[]
1584+
*/
1585+
public function getUsersByGroupWithoutPager(Group $group)
1586+
{
1587+
return $this->userRepo->findByGroup($group);
1588+
}
1589+
1590+
/**
1591+
* @param Workspace $workspace
1592+
*
1593+
* @return User[]
1594+
*/
1595+
public function getByWorkspaceWithUsersFromGroup(Workspace $workspace)
1596+
{
1597+
return $this->userRepo->findByWorkspaceWithUsersFromGroup($workspace);
1598+
}
1599+
1600+
/**
1601+
* @param \Claroline\CoreBundle\Entity\Workspace\Workspace[] $workspaces
1602+
* @param integer $page
1603+
* @param string $search
1604+
* @param integer $max
1605+
*
1606+
* @return \Pagerfanta\Pagerfanta
1607+
*/
1608+
public function getUsersByWorkspacesAndSearch(
1609+
array $workspaces,
1610+
$page,
1611+
$search,
1612+
$max = 20
1613+
)
1614+
{
1615+
$users = $this->userRepo
1616+
->findUsersByWorkspacesAndSearch($workspaces, $search);
1617+
return $this->pagerFactory->createPagerFromArray($users, $page, $max);
1618+
1619+
}
1620+
1621+
/**
1622+
* @param \Claroline\CoreBundle\Entity\Group $group
1623+
* @param integer $page
1624+
* @param integer $max
1625+
* @param string $orderedBy
1626+
*
1627+
* @return \Pagerfanta\Pagerfanta
1628+
*/
1629+
public function getGroupOutsiders(Group $group, $page, $max = 20, $orderedBy = 'id')
1630+
{
1631+
$query = $this->userRepo->findGroupOutsiders($group, false, $orderedBy);
1632+
return $this->pagerFactory->createPager($query, $page, $max);
1633+
}
1634+
/**
1635+
* @param \Claroline\CoreBundle\Entity\Group $group
1636+
* @param integer $page
1637+
* @param string $search
1638+
* @param integer $max
1639+
* @param string $orderedBy
1640+
*
1641+
* @return \Pagerfanta\Pagerfanta
1642+
*/
1643+
public function getGroupOutsidersByName(Group $group, $page, $search, $max = 20, $orderedBy = 'id')
1644+
{
1645+
$query = $this->userRepo->findGroupOutsidersByName($group, $search, false, $orderedBy);
1646+
return $this->pagerFactory->createPager($query, $page, $max);
1647+
}
15521648
}

Repository/UserRepository.php

Lines changed: 132 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -667,33 +667,6 @@ public function findUserByUsernameOrEmail($username, $email)
667667
return $query->getResult();
668668
}
669669

670-
/**
671-
* @param Workspace $workspace
672-
*
673-
* @return array
674-
*/
675-
public function findByWorkspaceWithUsersFromGroup(Workspace $workspace)
676-
{
677-
$dql = '
678-
SELECT u
679-
FROM Claroline\CoreBundle\Entity\User u
680-
JOIN u.roles ur
681-
LEFT JOIN u.groups g
682-
LEFT JOIN g.roles gr
683-
LEFT JOIN gr.workspace grws
684-
LEFT JOIN ur.workspace uws
685-
WHERE (uws.id = :wsId
686-
OR grws.id = :wsId)
687-
AND u.isEnabled = true
688-
';
689-
690-
$query = $this->_em->createQuery($dql);
691-
$query->setParameter('wsId', $workspace->getId());
692-
$res = $query->getResult();
693-
694-
return $res;
695-
}
696-
697670
/**
698671
* @param string $search
699672
*
@@ -1469,4 +1442,136 @@ public function findForApi($data)
14691442

14701443
return $query->getOneOrNullResult();
14711444
}
1445+
1446+
1447+
/**
1448+
* Returns all the users by search.
1449+
*
1450+
* @param string $search
1451+
*
1452+
* @return User[]
1453+
*/
1454+
public function findAllUserBySearch($search)
1455+
{
1456+
$upperSearch = strtoupper(trim($search));
1457+
if ($search !== '') {
1458+
$dql = '
1459+
SELECT u
1460+
FROM Claroline\CoreBundle\Entity\User u
1461+
WHERE UPPER(u.firstName) LIKE :search
1462+
OR UPPER(u.lastName) LIKE :search
1463+
OR UPPER(u.username) LIKE :search
1464+
AND u.isEnabled = true
1465+
';
1466+
$query = $this->_em->createQuery($dql);
1467+
$query->setParameter('search', "%{$upperSearch}%");
1468+
return $query->getResult();
1469+
}
1470+
return parent::findAll();
1471+
}
1472+
1473+
/**
1474+
* Returns the users who are not members of a group.
1475+
*
1476+
* @param Group $group
1477+
* @param boolean $executeQuery
1478+
* @param string $orderedBy
1479+
*
1480+
* @return User[]|Query
1481+
*
1482+
* @todo Find out why the join on profile preferences is necessary
1483+
*/
1484+
public function findGroupOutsiders(Group $group, $executeQuery = true, $orderedBy = 'id')
1485+
{
1486+
$dql = "
1487+
SELECT DISTINCT u FROM Claroline\CoreBundle\Entity\User u
1488+
WHERE u NOT IN (
1489+
SELECT us FROM Claroline\CoreBundle\Entity\User us
1490+
JOIN us.groups gs
1491+
WHERE gs.id = :groupId
1492+
)
1493+
AND u.isEnabled = true
1494+
ORDER BY u.{$orderedBy}
1495+
";
1496+
$query = $this->_em->createQuery($dql);
1497+
$query->setParameter('groupId', $group->getId());
1498+
return $executeQuery ? $query->getResult() : $query;
1499+
}
1500+
/**
1501+
* Returns the users who are not members of a group and whose first name, last
1502+
* name or username match a given search string.
1503+
*
1504+
* @param \Claroline\CoreBundle\Entity\Group $group
1505+
* @param string $search
1506+
* @param boolean $executeQuery
1507+
* @param string $orderedBy
1508+
*
1509+
* @return User[]|Query
1510+
*
1511+
* @todo Find out why the join on profile preferences is necessary
1512+
*/
1513+
public function findGroupOutsidersByName(Group $group, $search, $executeQuery = true, $orderedBy = 'id')
1514+
{
1515+
$dql = "
1516+
SELECT DISTINCT u FROM Claroline\CoreBundle\Entity\User u
1517+
WHERE (
1518+
UPPER(u.lastName) LIKE :search
1519+
OR UPPER(u.firstName) LIKE :search
1520+
OR UPPER(u.lastName) LIKE :search
1521+
)
1522+
AND u NOT IN (
1523+
SELECT us FROM Claroline\CoreBundle\Entity\User us
1524+
JOIN us.groups gr
1525+
WHERE gr.id = :groupId
1526+
)
1527+
AND u.isEnabled = true
1528+
ORDER BY u.{$orderedBy}
1529+
";
1530+
$search = strtoupper($search);
1531+
$query = $this->_em->createQuery($dql);
1532+
$query->setParameter('groupId', $group->getId());
1533+
$query->setParameter('search', "%{$search}%");
1534+
return $executeQuery ? $query->getResult() : $query;
1535+
}
1536+
/**
1537+
* Returns all the users except a given one.
1538+
*
1539+
* @param array $excludedUser
1540+
*
1541+
* @return User[]
1542+
*/
1543+
public function findAllExcept(array $excludedUser)
1544+
{
1545+
$dql = '
1546+
SELECT u FROM Claroline\CoreBundle\Entity\User u
1547+
WHERE u NOT IN (:userIds)
1548+
AND u.isEnabled = true
1549+
';
1550+
$query = $this->_em->createQuery($dql);
1551+
$query->setParameter('userIds', $excludedUser);
1552+
return $query->getResult();
1553+
}
1554+
/**
1555+
* @param Workspace $workspace
1556+
*
1557+
* @return array
1558+
*/
1559+
public function findByWorkspaceWithUsersFromGroup(Workspace $workspace)
1560+
{
1561+
$dql = '
1562+
SELECT u
1563+
FROM Claroline\CoreBundle\Entity\User u
1564+
JOIN u.roles ur
1565+
LEFT JOIN u.groups g
1566+
LEFT JOIN g.roles gr
1567+
LEFT JOIN gr.workspace grws
1568+
LEFT JOIN ur.workspace uws
1569+
WHERE uws.id = :wsId
1570+
OR grws.id = :wsId
1571+
';
1572+
$query = $this->_em->createQuery($dql);
1573+
$query->setParameter('wsId', $workspace->getId());
1574+
$res = $query->getResult();
1575+
return $res;
1576+
}
14721577
}

0 commit comments

Comments
 (0)