diff --git a/module/CommonBundle/Controller/Admin/RoleController.php b/module/CommonBundle/Controller/Admin/RoleController.php index cd2ed9563b..c069d3fadb 100644 --- a/module/CommonBundle/Controller/Admin/RoleController.php +++ b/module/CommonBundle/Controller/Admin/RoleController.php @@ -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; @@ -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, ) ); } @@ -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 */ diff --git a/module/CommonBundle/Controller/Admin/UnitController.php b/module/CommonBundle/Controller/Admin/UnitController.php index 97d24f952f..ed49983896 100644 --- a/module/CommonBundle/Controller/Admin/UnitController.php +++ b/module/CommonBundle/Controller/Admin/UnitController.php @@ -18,6 +18,7 @@ * UnitController * * @author Pieter Maene + * @author Pedro Devogelaere */ class UnitController extends \CommonBundle\Component\Controller\ActionController\AdminController { @@ -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 */ diff --git a/module/CommonBundle/Form/Admin/Unit/Csv.php b/module/CommonBundle/Form/Admin/Unit/Csv.php new file mode 100644 index 0000000000..a521d16d4f --- /dev/null +++ b/module/CommonBundle/Form/Admin/Unit/Csv.php @@ -0,0 +1,51 @@ + + */ +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'); + } +} \ No newline at end of file diff --git a/module/CommonBundle/Resources/config/install/acl.config.php b/module/CommonBundle/Resources/config/install/acl.config.php index 352a1bca6e..af3ceb7f7b 100644 --- a/module/CommonBundle/Resources/config/install/acl.config.php +++ b/module/CommonBundle/Resources/config/install/acl.config.php @@ -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', diff --git a/module/CommonBundle/Resources/config/install/configuration.config.php b/module/CommonBundle/Resources/config/install/configuration.config.php index cb90e87a23..5552395298 100644 --- a/module/CommonBundle/Resources/config/install/configuration.config.php +++ b/module/CommonBundle/Resources/config/install/configuration.config.php @@ -202,6 +202,11 @@ 'value' => 'it@vtk.be', 'description' => 'The mail address of system administrator', ), + array( + 'key' => 'system_no-reply_mail', + 'value' => 'no-reply@vtk.be', + 'description' => 'The no-reply mail address', + ), array( 'key' => 'fallback_language', 'value' => 'nl', diff --git a/module/CommonBundle/Resources/translations/site.en.php b/module/CommonBundle/Resources/translations/site.en.php index 5fa8359ab9..065b179e00 100644 --- a/module/CommonBundle/Resources/translations/site.en.php +++ b/module/CommonBundle/Resources/translations/site.en.php @@ -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 neucom@vtk.be 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 ', diff --git a/module/CommonBundle/Resources/translations/site.nl.php b/module/CommonBundle/Resources/translations/site.nl.php index 798d23887d..453109ece4 100644 --- a/module/CommonBundle/Resources/translations/site.nl.php +++ b/module/CommonBundle/Resources/translations/site.nl.php @@ -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 neucom@vtk.be 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 ', diff --git a/module/CommonBundle/Resources/views/common/admin/role/manage.twig b/module/CommonBundle/Resources/views/common/admin/role/manage.twig index adafa38821..7f09f704a8 100644 --- a/module/CommonBundle/Resources/views/common/admin/role/manage.twig +++ b/module/CommonBundle/Resources/views/common/admin/role/manage.twig @@ -74,6 +74,30 @@ + + {% if hasAccess('common_admin_role', 'prune') %}