Skip to content

Commit

Permalink
Merge branch 'master' of github.com:GEWIS/gewisweb
Browse files Browse the repository at this point in the history
  • Loading branch information
jszanto committed Jan 10, 2017
2 parents 87a9917 + 668415e commit 4ed1efd
Show file tree
Hide file tree
Showing 12 changed files with 349 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## [v1.2](https://github.com/GEWIS/gewisweb/tree/v1.2) (2017-01-09)

* External participants can now be subscribed to activites through the activity admin
* Images on committee/fraternity pages now look normal
* Activities can now be edited :tada: (#594)
* Improved the activity administrator interface (#642)
Expand Down
14 changes: 10 additions & 4 deletions module/Activity/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,14 +148,20 @@ public function getServiceConfig()
$acl->addResource('activity_calendar_option');

$acl->allow('guest', 'activity', 'view');
$acl->allow('guest', 'activitySignup', ['view', 'signup']);

$acl->allow('guest', 'activitySignup', ['view', 'externalSignup']);

$acl->allow('user', 'activity', 'create');
$acl->allow('user', 'activitySignup', ['signup', 'signoff', 'checkUserSignedUp']);

$acl->allow('admin', 'activity', ['update', 'viewDetails']);
$acl->allow('user', 'activity', ['update', 'viewDetails'], new IsCreator());
$acl->allow('active_member', 'activity', ['update', 'viewDetails'], new IsOrganMember());
$acl->allow('admin', 'activity', ['update', 'viewDetails', 'adminSignup']);
$acl->allow('user', 'activity', ['update', 'viewDetails', 'adminSignup'], new IsCreator());
$acl->allow(
'active_member',
'activity',
['update', 'viewDetails', 'adminSignup'],
new IsOrganMember()
);

$acl->allow('sosuser', 'activitySignup', ['signup', 'signoff', 'checkUserSignedUp']);

Expand Down
20 changes: 20 additions & 0 deletions module/Activity/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,26 @@
]
]
],
'adminSignup' => [
'type' => 'Segment',
'options' => [
'route' => '/:id/adminSignup',
'defaults' => [
'controller' => 'admin',
'action' => 'externalSignup',
]
]
],
'externalSignoff' => [
'type' => 'Segment',
'options' => [
'route' => '/:id/externalSignoff',
'defaults' => [
'controller' => 'admin',
'action' => 'externalSignoff',
]
]
],
'exportpdf' => [
'type' => 'Segment',
'options' => [
Expand Down
113 changes: 111 additions & 2 deletions module/Activity/src/Activity/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public function participantsAction()
$queryService = $this->getServiceLocator()->get('activity_service_activityQuery');
$translatorService = $this->getServiceLocator()->get('activity_service_activityTranslator');
$langSession = new SessionContainer('lang');

$translator = $this->getServiceLocator()->get('activity_service_activity')->getTranslator();
$signupRequestSession = new SessionContainer('signupRequest');

/** @var $activity Activity */
$activity = $queryService->getActivityWithDetails($id);
Expand All @@ -40,10 +41,23 @@ public function participantsAction()
return $this->notFoundAction();
}

return [
$signupService = $this->getServiceLocator()->get('activity_service_signup');
$externalSignupForm = $signupService->getExternalForm($activity->getFields());

$result = [
'activity' => $translatedActivity,
'signupData' => $translatorService->getTranslatedSignedUpData($activity, $langSession->lang),
'externalSignupForm' => $externalSignupForm,
'externalSignoffForm' => new RequestForm('activityExternalSignoff', $translator->translate('Remove')),
];
//Retrieve and clear the request status from the session, if it exists.
if (isset($signupRequestSession->success)) {
$result['success'] = $signupRequestSession->success;
unset($signupRequestSession->success);
$result['message'] = $signupRequestSession->message;
unset($signupRequestSession->message);
}
return $result;
}

public function updateAction()
Expand Down Expand Up @@ -105,6 +119,101 @@ public function exportPdfAction()
return $pdf;
}

public function externalSignupAction()
{
$id = (int) $this->params('id');
$activityService = $this->getServiceLocator()->get('activity_service_activity');
$queryService = $this->getServiceLocator()->get('activity_service_activityQuery');
$signupService = $this->getServiceLocator()->get('activity_service_signup');

$activity = $queryService->getActivity($id);

$translator = $activityService->getTranslator();

//Assure the form is used
if (!$this->getRequest()->isPost()) {
$error = $translator->translate('Use the form to subscribe');
$this->redirectSignupRequest($id, false, $error);
return;
}

$form = $signupService->getExternalForm($activity->getFields());
$form->setData($this->getRequest()->getPost());

//Assure the form is valid
if (!$form->isValid()) {
$error = $translator->translate('Invalid form');
$this->redirectSignupRequest($id, false, $error);
return;
}

$formData = $form->getData(\Zend\Form\FormInterface::VALUES_AS_ARRAY);
$fullName = $formData['fullName'];
unset($formData['fullName']);
$email = $formData['email'];
unset($formData['email']);
$signupService->adminSignUp($activity, $fullName, $email, $formData);
$message = $translator->translate('Successfully subscribed external participant');
$this->redirectSignupRequest($id, true, $message);
}

public function externalSignoffAction()
{
$id = (int) $this->params('id');

$activityService = $this->getServiceLocator()->get('activity_service_activity');
$signupService = $this->getServiceLocator()->get('activity_service_signup');
$signupMapper = $this->getServiceLocator()->get('activity_mapper_signup');

$signup = $signupMapper->getSignupById($id);

if (is_null($signup)) {
return $this->notFoundAction();
}
$activity = $signup->getActivity();
$translator = $activityService->getTranslator();

//Assure a form is used
if (!$this->getRequest()->isPost()) {
$message = $translator->translate('Use the form to unsubscribe an external participant');
$this->redirectSignupRequest($activity->getId(), false, $message);
return;
}

$form = new RequestForm('activityExternalSignoff', $translator->translate('Remove'));
$form->setData($this->getRequest()->getPost());

//Assure the form is valid
if (!$form->isValid()) {
$message = $translator->translate('Invalid form');
$this->redirectSignupRequest($activity->getId(), false, $message);
return;
}

$signupService->externalSignOff($signup);
$message = $translator->translate('Successfully removed external participant');
$this->redirectSignupRequest($activity->getId(), true, $message);
}

/**
* Redirects to the view of the activity with the given $id, where the
* $error message can be displayed if the request was unsuccesful (i.e.
* $success was false)
*
* @param int $id
* @param boolean $success Whether the request was successful
* @param string $message
*/
protected function redirectSignupRequest($id, $success, $message)
{
$signupRequestSession = new SessionContainer('signupRequest');
$signupRequestSession->success = $success;
$signupRequestSession->message = $message;
$this->redirect()->toRoute('activity_admin/participants', [
'id' => $id,
]);
}

/**
* Show a list of all activities this user can manage.
*/
Expand Down
24 changes: 21 additions & 3 deletions module/Activity/src/Activity/Form/ActivitySignup.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public function __construct()
$this->setHydrator(new ClassMethodsHydrator(false))
->setObject(new \Activity\Model\UserActivitySignup());

$this->add([
'name' => 'security',
'type' => 'Zend\Form\Element\Csrf'
]);

$this->add([
'name' => 'submit',
'attributes' => [
Expand All @@ -28,18 +33,31 @@ public function __construct()
}

/**
* Initilialise the form, i.e. set the language and the fields
* Initialize the form, i.e. set the language and the fields
* Add every field in $fields to the form.
*
*
* @param ActivityField $fields
*/
public function initialiseForm($fields)
{
foreach($fields as $field){
foreach($fields as $field) {
$this->add($this->createFieldElementArray($field));
}
}

public function initialiseExternalForm($fields)
{
$this->add([
'name' => 'fullName',
'type' => 'Text'
]);
$this->add([
'name' => 'email',
'type' => 'Text'
]);
$this->initialiseForm($fields);
}

/**
* Apparently, validators are automatically added, so this works.
*
Expand Down
2 changes: 1 addition & 1 deletion module/Activity/src/Activity/Form/ModifyRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* Specifies a form that is used to let an user do a modification request that
* does not require any other data, such as signing off for activities or
* approving or dissapproving them.
* approving or disapproving them.
*/
class ModifyRequest extends Form implements InputFilterProviderInterface
{
Expand Down
17 changes: 17 additions & 0 deletions module/Activity/src/Activity/Mapper/Signup.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ public function __construct(EntityManager $em)
$this->em = $em;
}

/**
* @param int $id
* @return \Activity\Model\ActivitySignup
*/
public function getSignupById($id)
{
$qb = $this->em->createQueryBuilder();
$qb->select('a')
->from('Activity\Model\ActivitySignup', 'a')
->where('a.id = :id')
->setParameter('id', $id);
$result = $qb->getQuery()->getResult();

return count($result) > 0 ? $result[0] : null;
}


/**
* Check if a user is signed up for an activity.
*
Expand Down
10 changes: 10 additions & 0 deletions module/Activity/src/Activity/Model/ExternalActivitySignup.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,14 @@ public function getEmail()
{
return $this->email;
}

public function setFullName($fullName)
{
$this->fullName = $fullName;
}

public function setEmail($email)
{
$this->email = $email;
}
}
Loading

0 comments on commit 4ed1efd

Please sign in to comment.