Skip to content

Commit

Permalink
display both direct and unit members in roles
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrodevog committed Oct 19, 2023
1 parent 4be72bd commit 644888d
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 40 deletions.
97 changes: 64 additions & 33 deletions module/CommonBundle/Controller/Admin/RoleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace CommonBundle\Controller\Admin;

use CommonBundle\Component\Acl\Acl;
use CommonBundle\Component\Util\AcademicYear;
use CommonBundle\Entity\Acl\Action;
use CommonBundle\Entity\Acl\Role;
use CommonBundle\Entity\General\AcademicYear as AcademicYearEntity;
use CommonBundle\Entity\User\Person;
use Laminas\View\Model\ViewModel;

Expand Down Expand Up @@ -80,14 +82,39 @@ public function membersAction()
return new ViewModel();
}

$academicYear = $this->getAcademicYearEntity();
if ($academicYear === null) {
return new ViewModel();
}

$members = $this->getEntityManager()
->getRepository('CommonBundle\Entity\User\Person')
->findAllByRole($role);

$units = $this->getEntityManager()
->getRepository('CommonBundle\Entity\General\Organization\Unit')
->findAll();
$unitMembers = array();
foreach ($units as $unit) {
$unitRoles = $unit->getRoles();
foreach ($unitRoles as $unitRole) {
if ($unitRole == $role) {
$unitMembers = array_unique(array_merge(
$unitMembers,
$this->getEntityManager()
->getRepository('CommonBundle\Entity\User\Person\Organization\UnitMap')
->findBy(array('unit' => $unit, 'academicYear' => $academicYear))
),
SORT_REGULAR);
}
}
}

return new ViewModel(
array(
'role' => $role,
'members' => $members,
'role' => $role,
'members' => $members,
'unitMembers' => $unitMembers,
)
);
}
Expand Down Expand Up @@ -185,37 +212,6 @@ public function deleteMemberAction()
);
}

// This function deletes all members belonging to a role belonging to a unit, like this each year the roles can be
// updated more easily
public function deleteAllMembersAction()
{
$this->initAjax();

$units = $this->getEntityManager()
->getRepository('CommonBundle\Entity\General\Organization\Unit')
->findAll();

foreach ($units as $unit) {
$roles = $unit->getRoles();
foreach ($roles as $role) {
$users = $this->getEntityManager()
->getRepository('CommonBundle\Entity\User\Person')
->findAllByRole($role);
foreach ($users as $user) {
$user->removeRole($role);
}
}
}

$this->getEntityManager()->flush();

return new ViewModel(
array(
'result' => (object) array('status' => 'success'),
)
);
}

public function pruneAction()
{
$roles = $this->getEntityManager()
Expand Down Expand Up @@ -301,6 +297,41 @@ private function getPersonEntity()
return $person;
}

/**
* @return \CommonBundle\Entity\General\AcademicYear|null
*/
private function getAcademicYearEntity()
{
if ($this->getParam('academicyear') === null) {
return $this->getCurrentAcademicYear();
}

$start = AcademicYear::getDateTime($this->getParam('academicyear'));
$start->setTime(0, 0);

$academicYear = $this->getEntityManager()
->getRepository('CommonBundle\Entity\General\AcademicYear')
->findOneByUniversityStart($start);

if (!($academicYear instanceof AcademicYearEntity)) {
$this->flashMessenger()->error(
'Error',
'No academic year was found!'
);

$this->redirect()->toRoute(
'common_admin_unit',
array(
'action' => 'manage',
)
);

return;
}

return $academicYear;
}

/**
* @return null
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
'typeahead',
),
'common_admin_role' => array(
'add', 'edit', 'delete', 'deleteMember', 'deleteAllMembers', 'manage', 'members', 'prune',
'add', 'edit', 'delete', 'deleteMember', 'manage', 'members', 'prune',
),
'common_admin_session' => array(
'expire',
Expand Down

This file was deleted.

17 changes: 15 additions & 2 deletions module/CommonBundle/Resources/views/common/admin/role/members.twig
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
<h1>Role</h1>
<p>Name: <b>{{ role.getName() }}</b></p>

<h1>Members</h1>
<h1>Direct members</h1>

<table class="full_width manage">
<tr>
<th>Name</th>
<th width="90px">Actions</th>
<th style="width: 90px">Actions</th>
</tr>
{% for member in members %}
<tr class="item item-{{ member.getId() }}">
Expand All @@ -40,6 +40,19 @@
</tr>
{% endfor %}
</table>

<h1>Unit members</h1>

<table class="full_width manage">
<tr>
<th>Name</th>
</tr>
{% for member in unitMembers %}
<tr class="item item-{{ member.getId() }}">
<td>{{ member.getFullName() }}</td>
</tr>
{% endfor %}
</table>
</div>

<div class="modal fade" id="removeMember" tabindex="-1">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<li><a {% if 'csv' == getParam('csv') %} class="active" {% endif %} href="{{ url("common_admin_unit", {"action": "csv", "academicyear": activeAcademicYear.getCode()}) }}">CSV</a></li>
{% endif %}
{% if hasAccess('common_admin_unit', 'csvUpload') %}
<li><a {% if 'csv' == getParam('csvUpload') %} class="active" {% endif %} href="{{ url("common_admin_unit", {"action": "csvUpload", "academicyear": activeAcademicYear.getCode()}) }}">CSV Upload Members</a></li>
<li><a {% if 'csv' == getParam('csvUpload') %} class="active" {% endif %} href="{{ url("common_admin_unit", {"action": "csvUpload", "academicyear": activeAcademicYear.getCode()}) }}">Upload Members</a></li>
{% endif %}
{% if hasAccess('common_admin_unit', 'add') %}
<li><a {% if 'add' == getParam('action') %} class="active" {% endif %} href="{{ url("common_admin_unit", {"action": "add"}) }}">Add</a></li>
Expand Down

0 comments on commit 644888d

Please sign in to comment.