-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/LitusProject/Litus into d…
…ev-shop-noshow
- Loading branch information
Showing
35 changed files
with
396 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
* UnitController | ||
* | ||
* @author Pieter Maene <[email protected]> | ||
* @author Pedro Devogelaere <[email protected]> | ||
*/ | ||
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 | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 ', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 ', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.