Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/LitusProject/Litus into d…
Browse files Browse the repository at this point in the history
…ev-shop-noshow
  • Loading branch information
driesvanspauwen committed Oct 23, 2023
2 parents 08b6e33 + 073999f commit 2a86a4e
Show file tree
Hide file tree
Showing 35 changed files with 396 additions and 74 deletions.
66 changes: 64 additions & 2 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 @@ -270,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
137 changes: 137 additions & 0 deletions module/CommonBundle/Controller/Admin/UnitController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* UnitController
*
* @author Pieter Maene <[email protected]>
* @author Pedro Devogelaere <[email protected]>
*/
class UnitController extends \CommonBundle\Component\Controller\ActionController\AdminController
{
Expand Down Expand Up @@ -410,6 +411,142 @@ public function pruneAction()
return new ViewModel();
}

public function csvUploadAction()
{
$form = $this->getForm('common_unit_csv');

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

if ($this->getRequest()->isPost()) {
$formData = $this->getRequest()->getPost();
$fileData = $this->getRequest()->getFiles();

$fileName = $fileData['file']['tmp_name'];

$membersArray = array();

$open = fopen($fileName, 'r');
if ($open != false) {
$data = fgetcsv($open, 10000, ',');

while ($data !== false) {
$membersArray[] = $data;
$data = fgetcsv($open, 10000, ',');
}
fclose($open);
}

$form->setData($formData);

if ($form->isValid()) {
$count = 0;

array_shift($membersArray); // Remove header
$total = count($membersArray);
foreach ($membersArray as $data) {
if (in_array(null, array_slice($data, 0, 3))) {
error_log('fail');
continue;
}

$name = $data[0];
$academic = $this->getEntityManager()
->getRepository('CommonBundle\Entity\User\Person\Academic')
->findOneByUsername($data[1]);
$unit = $this->getEntityManager()
->getRepository('CommonBundle\Entity\General\Organization\Unit')
->findOneById($data[2]);
$description = $data[3];
$coordinator = $data[4]?:0;

$repositoryCheck = $this->getEntityManager()
->getRepository('CommonBundle\Entity\User\Person\Organization\UnitMap\Academic')
->findOneBy(
array(
'unit' => $unit,
'academic' => $academic,
'academicYear' => $academicYear,
)
);

if ($repositoryCheck === null) {
$member = new UnitMapAcademic($academic, $academicYear, $unit, $coordinator, $description);

$this->getEntityManager()->persist($member);
}

$count += 1;
}
$this->getEntityManager()->flush();

$this->flashMessenger()->success(
'Succes',
$count . '/' . $total . ' members imported'
);

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

return new ViewModel();
}
}

return new ViewModel(
array(
'form' => $form,
)
);
}

public function templateAction()
{
$file = new CsvFile();

$unit = $this->getUnitEntity();

$heading = array(
'name',
'r-number',
'unit id',
'description',
'coordinator (bool)',
);

$results = array();
$results[] = array(
'',
'',
$unit->getId(),
'',
'',
);

$document = new CsvGenerator($heading, $results);
$document->generateDocument($file);

$headers = new Headers();
$headers->addHeaders(
array(
'Content-Disposition' => 'attachment; filename="unit_members_template.csv"',
'Content-Type' => 'text/csv',
)
);
$this->getResponse()->setHeaders($headers);

return new ViewModel(
array(
'data' => $file->getContent(),
)
);
}

/**
* @return Unit|null
*/
Expand Down
51 changes: 51 additions & 0 deletions module/CommonBundle/Form/Admin/Unit/Csv.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace CommonBundle\Form\Admin\Unit;

/**
* The form used to add multiple members across different units via CSV.
*
* @author Pedro Devogelaere <[email protected]>
*/
class Csv extends \CommonBundle\Component\Form\Admin\Form
{
const FILE_SIZE = '10MB';

protected $hydrator = 'CommonBundle\Hydrator\General\Organization\Academic';

public function init()
{
parent::init();

$this->add(
array(
'type' => 'file',
'name' => 'file',
'label' => 'Members csv',
'attributes' => array(
'data-help' => 'The maximum file size is ' . self::FILE_SIZE . '.',
),
'options' => array(
'input' => array(
'validators' => array(
array(
'name' => 'FileSize',
'options' => array(
'max' => self::FILE_SIZE,
),
),
array(
'name' => 'FileExtension',
'options' => array(
'extension' => 'csv',
),
),
),
),
),
)
);

$this->addSubmit('Add', 'member_csv file_add');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
'expire',
),
'common_admin_unit' => array(
'add', 'delete', 'deleteMember', 'edit', 'manage', 'members', 'prune', 'csv'
'add', 'delete', 'deleteMember', 'edit', 'manage', 'members', 'prune', 'csv', 'csvUpload', 'template',
),
'common_admin_visit' => array(
'manage', 'search',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@
'value' => '[email protected]',
'description' => 'The mail address of system administrator',
),
array(
'key' => 'system_no-reply_mail',
'value' => '[email protected]',
'description' => 'The no-reply mail address',
),
array(
'key' => 'fallback_language',
'value' => 'nl',
Expand Down
3 changes: 1 addition & 2 deletions module/CommonBundle/Resources/translations/site.en.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@
'International Student' => 'International Student',
'I am an international student' => 'I am an international student',

// 'The POC\'ers are elected! You can find your POC\'ers here!' => 'The POC\'ers are elected! You can find your POC\'ers here!',
'The POC\'ers are elected! You can find your POC\'ers here!' => 'Below you can find the candidate POC for this academic year. If you wish to file an objection against one of the candidates, send an email to [email protected] before Monday, October 16, 11:59 PM.',
'The POC\'ers are elected! You can find your POC\'ers here!' => 'The POC\'ers are elected! You can find your POC\'ers here!',
'We could not find any POC\'ers for you, try again later!' => 'We could not find any POC\'ers for you, try again later!',
'Please login to see your POC\'ers!' => 'Please login to see your POC\'ers!',
'Visit the POC page for more ' => 'Visit the POC page for more ',
Expand Down
3 changes: 1 addition & 2 deletions module/CommonBundle/Resources/translations/site.nl.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@
'International Student' => 'Internationale Student',
'I am an international student' => 'Ik ben een internationale student',

// 'The POC\'ers are elected! You can find your POC\'ers here!' => 'De POC\'ers zijn verkozen! Hieronder kan jij jouw POC\'ers vinden! ',
'The POC\'ers are elected! You can find your POC\'ers here!' => 'Hieronder kun je de kandidaat-RiVers voor dit academiejaar terugvinden. Indien je wenst een bezwaar in te dienen tegen een van de kandidaten, stuur je een e-mail naar [email protected] voor maandag 16 oktober 23u59.',
'The POC\'ers are elected! You can find your POC\'ers here!' => 'De POC\'ers zijn verkozen! Hieronder kan jij jouw POC\'ers vinden! ',
'We could not find any POC\'ers for you, try again later!' => 'We konden geen POC\'ers voor jou vinden, probeer later nog eens !',
'Please login to see your POC\'ers!' => 'Login om jouw POC\'ers te bekijken',
'Visit the POC page for more ' => 'Bezoek de POC pagina voor meer ',
Expand Down
24 changes: 24 additions & 0 deletions module/CommonBundle/Resources/views/common/admin/role/manage.twig
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,30 @@
</div>
</div>

<div class="modal hide fade" id="removeMembers" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<span>Litus Admin</span>
/Delete Members
</div>
<div class="modal-body">
<p>
You are about to delete all the members from roles linked to units!
Please note that this operation cannot be undone!
</p>
<p>
Are you sure you want to continue?
</p>
<div class="footer">
<button class="delete">Yes</button>
<button class="cancel" data-dismiss="modal">No</button>
</div>
</div>
</div>
</div>
</div>

{% if hasAccess('common_admin_role', 'prune') %}
<aside>
<div class="sidebox">
Expand Down
Loading

0 comments on commit 2a86a4e

Please sign in to comment.