Skip to content

Commit

Permalink
merged on prod
Browse files Browse the repository at this point in the history
  • Loading branch information
ilukac committed Sep 2, 2015
2 parents 378fc55 + 929d482 commit 6ebd7a8
Show file tree
Hide file tree
Showing 10 changed files with 197 additions and 76 deletions.
79 changes: 61 additions & 18 deletions Command/ActivationEmailsCommand.php
Expand Up @@ -13,32 +13,75 @@ class ActivationEmailsCommand extends ContainerAwareCommand
protected function configure()
{
$this
->setName('activation:send')
->setName('email:send')
->setDescription('Send activation emails to all users')
->addOption(
'activation',
null,
InputOption::VALUE_NONE,
'activation'
)
->addOption(
'questions',
null,
InputOption::VALUE_NONE,
'Questionnaire'
)
;
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$users = $this->getContainer()->get('doctrine')->getRepository('LiveVotingBundle:User')->findAll();
$num = 0;
foreach ($users as $user) {
$user_email = $user->getEmail();
$emailHash = md5($this->getContainer()->getParameter('email_hash_prefix') . $user_email);
$message = \Swift_Message::newInstance()
->setSubject('Summer Camp workshop voting')
->setFrom('info@netgen.hr')
->setTo($user_email)
->setBody(
$this->getContainer()->get('templating')->render(
'LiveVotingBundle:Email:login.html.twig',
array('emailHash' => $emailHash)
),
'text/html'
);
$this->getContainer()->get('mailer')->send($message);
$num++;
if ($input->getOption('activation'))
{
foreach ($users as $user) {
$user_email = $user->getEmail();
$emailHash = md5($this->getContainer()->getParameter('email_hash_prefix') . $user_email);

$message = \Swift_Message::newInstance()
->setSubject('Say hello to Summer Camp 2015!')
->setFrom('info@netgen.hr')
->setTo($user_email)
->setBody(
$this->getContainer()->get('templating')->render(
'LiveVotingBundle:Email:login.html.twig',
array('emailHash' => $emailHash)
),
'text/html'
);
$this->getContainer()->get('mailer')->send($message);
$num++;
}
$output->writeln('Activation mails have been sent to '.$num.' users');
}
else if ($input->getOption('questions'))
{
foreach ($users as $user) {
$user_email = $user->getEmail();
$emailHash = md5($this->getContainer()->getParameter('email_hash_prefix') . $user_email);

$message = \Swift_Message::newInstance()
->setSubject('PHP & eZ Publish Summer Camp 2015 - Questionnaire')
->setFrom('info@netgen.hr')
->setTo($user_email)
->setBody(
$this->getContainer()->get('templating')->render(
'LiveVotingBundle:Email:questions.html.twig',
array('emailHash' => $emailHash)
),
'text/html'
);
$this->getContainer()->get('mailer')->send($message);
$num++;
}
$output->writeln('Questionnaire mails have been sent to '.$num.' users');
}
$output->writeln('Activation mail has been sent to '.$num.' users');
else
{
$output->writeln('Must choose one optional argument: --activation or --questions');
}

}
}
6 changes: 3 additions & 3 deletions Controller/PresentationAdminController.php
Expand Up @@ -38,16 +38,16 @@ public function indexAction($event_id)
/**
* @var $client JoindInClient
*/
/*$client = $this->get('live_voting.joind_in_client');
$joindInEvents = $client->obtainUserEvents(27355, true);*/
$client = $this->get('live_voting.joind_in_client');
$joindInEvents = $client->obtainUserEvents(27355, true);
$that = $this;
return $this->render('LiveVotingBundle:Presentation:index.html.twig', array(
'entities' => array_map(
function($ent) use ($that) {
return array($ent, $that->createEnableDisableForm($ent)->createView());
}, $entities),
'event' => $event,
/*'joindInEvents' => $joindInEvents*/
'joindInEvents' => $joindInEvents
));
}

Expand Down
11 changes: 9 additions & 2 deletions Controller/SecurityController.php
Expand Up @@ -23,7 +23,7 @@ class SecurityController extends Controller
* @param Request $request
* @return mixed
*/
public function userLoginAction(Request $request, $activateHash)
public function userLoginAction(Request $request, $activateHash, $typeOf)
{
if($activateHash === null){
return $this->redirect($this->generateUrl('root'));
Expand Down Expand Up @@ -55,7 +55,14 @@ public function userLoginAction(Request $request, $activateHash)
$expires = time() + 60*60*24*183;
$value = $this->generateCookieValue(get_class($user), $user->getUsername(), $expires, $user->getPassword());

$return = $this->redirect($this->generateUrl('user_landing'));
if ($typeOf === '0')
{
$return = $this->redirect($this->generateUrl('user_landing'));
}
else if ($typeOf === '1')
{
$return = $this->redirect($this->generateUrl('question', array('event_id' => '17')));
}
$return->headers->setCookie(new Cookie('userEditEnabled', '1', time()+60*60*24*90));

$presentations = $this->getDoctrine()->getRepository('LiveVotingBundle:Presentation')->findByUser($user);
Expand Down
117 changes: 86 additions & 31 deletions Controller/UserAdminController.php
Expand Up @@ -258,32 +258,59 @@ public function processImportCsvAction(Request $request)
);
}

public function loginEmailAction(Request $request)
public function loginEmailAction(Request $request, $typeOf)
{
$users = $this->getDoctrine()->getRepository('LiveVotingBundle:User')->findAll();
foreach ($users as $user) {
$user_email = $user->getEmail();
$emailHash = md5($this->container->getParameter('email_hash_prefix') . $user_email);
$message = \Swift_Message::newInstance()
->setSubject('Summer Camp workshop voting')
->setFrom('info@netgen.hr')
->setTo($user_email)
->setBody(
$this->renderView(
'LiveVotingBundle:Email:login.html.twig',
array('emailHash' => $emailHash)
),
'text/html'
);
if ($typeOf === '0')
{
$message = \Swift_Message::newInstance()
->setSubject('Say hello to Summer Camp 2015!')
->setFrom('info@netgen.hr')
->setTo($user_email)
->setBody(
$this->renderView(
'LiveVotingBundle:Email:login.html.twig',
array('emailHash' => $emailHash)
),
'text/html'
);
}
else if ($typeOf === '1')
{
$message = \Swift_Message::newInstance()
->setSubject('PHP & eZ Publish Summer Camp 2015 - Questionnaire')
->setFrom('info@netgen.hr')
->setTo($user_email)
->setBody(
$this->renderView(
'LiveVotingBundle:Email:questions.html.twig',
array('emailHash' => $emailHash)
),
'text/html'
);
}

$this->get('mailer')->send($message);
}
$request->getSession()->getFlashBag()->add(
'message', 'Emails have been sent to all users.'
);
if ($typeOf === '0')
{
$request->getSession()->getFlashBag()->add(
'message', 'Activations have been sent to all users.'
);
}
else if ($typeOf === '1')
{
$request->getSession()->getFlashBag()->add(
'message', 'Questionnaires have been sent to all users.'
);
}
return $this->redirect($this->generateUrl('admin_user'));
}

public function oneUserLoginEmailAction(Request $request, $id)
public function oneUserLoginEmailAction(Request $request, $id, $typeOf)
{
$em = $this->getDoctrine()->getManager();

Expand All @@ -292,24 +319,52 @@ public function oneUserLoginEmailAction(Request $request, $id)
if (!$user) {
throw $this->createNotFoundException('Unable to find User entity.');
}

$user_email = $user->getEmail();
$emailHash = md5($this->container->getParameter('email_hash_prefix') . $user_email);
$message = \Swift_Message::newInstance()
->setSubject('Summer Camp workshop voting')
->setFrom('info@netgen.hr')
->setTo($user_email)
->setBody(
$this->renderView(
'LiveVotingBundle:Email:login.html.twig',
array('emailHash' => $emailHash)
),
'text/html'
);
if ($typeOf === '0')
{
$message = \Swift_Message::newInstance()
->setSubject('Say hello to Summer Camp 2015!')
->setFrom('info@netgen.hr')
->setTo($user_email)
->setBody(
$this->renderView(
'LiveVotingBundle:Email:login.html.twig',
array('emailHash' => $emailHash)
),
'text/html'
);
}
else if ($typeOf === '1')
{
$message = \Swift_Message::newInstance()
->setSubject('PHP & eZ Publish Summer Camp 2015 - Questionnaire')
->setFrom('info@netgen.hr')
->setTo($user_email)
->setBody(
$this->renderView(
'LiveVotingBundle:Email:questions.html.twig',
array('emailHash' => $emailHash)
),
'text/html'
);
}

$this->get('mailer')->send($message);
$request->getSession()->getFlashBag()->add(
'message', 'Email has been sent to '.$user_email
);
if ($typeOf === '0')
{
$request->getSession()->getFlashBag()->add(
'message', 'Activation has been sent to '.$user_email
);
}
else if ($typeOf === '1')
{
$request->getSession()->getFlashBag()->add(
'message', 'Questionnaire has been sent to '.$user_email
);
}


return $this->redirect($this->generateUrl('admin_user'));
}
}
12 changes: 6 additions & 6 deletions Resources/config/routing.yml
Expand Up @@ -155,8 +155,8 @@ admin_presentation_publish:

#USER LOGIN ROUTING#
user_login:
path: /login/{activateHash}
defaults: { _controller: LiveVotingBundle:Security:userLogin, activateHash: null }
path: /login/{activateHash}/{typeOf}
defaults: { _controller: LiveVotingBundle:Security:userLogin, activateHash: null, typeOf: null }

user_login_check:
path: /login_check
Expand Down Expand Up @@ -194,9 +194,9 @@ email_login:
path: /login/

send_email_login:
path: /admin/user/send_email_login
defaults: {_controller: LiveVotingBundle:UserAdmin:loginEmail}
path: /admin/user/send_email_login/{typeOf}
defaults: {_controller: LiveVotingBundle:UserAdmin:loginEmail, typeOf: null}

send_one_email_login:
path: /admin/user/send_one_email_login/{id}
defaults: {_controller: LiveVotingBundle:UserAdmin:oneUserLoginEmail, id: null }
path: /admin/user/send_one_email_login/{typeOf}/{id}
defaults: {_controller: LiveVotingBundle:UserAdmin:oneUserLoginEmail, id: null, typeOf: null }
3 changes: 1 addition & 2 deletions Resources/views/Email/login.html.twig
@@ -1,7 +1,6 @@
<h3>Summer Camp workshop voting</h3><br/><br/>

Please, take your time after each workshop and rate them.
Login via this <a href="{{ url('email_login') }}{{ emailHash }}">link</a>.<br/><br/>
To login, click following <a href="{{ url('email_login') }}{{ emailHash }}/0">link</a>.<br/><br/>

After login you can see the live schedule and vote for sessions. More votes give you more chance to win raffle prizes :)<br/><br/>

Expand Down
12 changes: 12 additions & 0 deletions Resources/views/Email/questions.html.twig
@@ -0,0 +1,12 @@
Dear participant,<br/><br/>

Thank you for being a part of PHP & eZ Publish Summer Camp 2015!<br/><br/>

We want to make the next one even <b>better</b>, and to do that we need <b>YOUR help</b>. On this <a href="{{ url('email_login') }}{{ emailHash }}/1">link</a> you will find <b>19 short questions</b> that you can answer to in a few minutes.<br/><br/>

Please make time to answer the questions - it helps us <b>immensely</b> to make your experience next year <b>the best one yet</b>!<br/><br/>

Also, if you have any other <b>questions or suggestions</b> for the next Summer Camp, send them to <a href="mailto:maja@netgen.hr">maja@netgen.hr</a> - we value your opinion :)<br/><br/><br/>


Thank you for your help!
6 changes: 3 additions & 3 deletions Resources/views/Presentation/index.html.twig
Expand Up @@ -52,9 +52,9 @@
<button type="button" id="publishPresentationButton" onclick="publishPresentations()" data-success-text="Publishing successful" data-loading-text="Publishing..." class="btn" autocomplete="off">Publish presentations</button>
<label>
<select id="joind-events-select" class="form-control">
{#{% for event in joindInEvents %}
<!--<option value="{{ event.joindInId }}">{{ event.name }}</option>-->
{% endfor %}#}
{% for event in joindInEvents %}
<option value="{{ event.joindInId }}">{{ event.name }}</option>
{% endfor %}
</select>
</label>
<div class="clearfix"></div>
Expand Down
9 changes: 7 additions & 2 deletions Resources/views/User/index.html.twig
Expand Up @@ -20,6 +20,7 @@
<th class="text-center">Enabled</th>
<th>Edit</th>
<th>Activation Email</th>
<th>Questionnaire Email</th>
</tr>
</thead>
<tbody>
Expand All @@ -31,7 +32,10 @@
<a href="{{ path('admin_user_edit', { 'id': entity.id }) }}"><button type="button" class="btn">Edit</button></a>
</td>
<td>
<a href="{{ path('send_one_email_login', { 'id': entity.id }) }}"><button type="button" class="btn">Send Activation Email</button></a>
<a href="{{ path('send_one_email_login', { 'id': entity.id, 'typeOf': 0}) }}"><button type="button" class="btn">Send Activation Email</button></a>
</td>
<td>
<a href="{{ path('send_one_email_login', { 'id': entity.id, 'typeOf': 1}) }}"><button type="button" class="btn">Send Questionnaire Email</button></a>
</td>
</tr>
{% endfor %}
Expand All @@ -45,7 +49,8 @@
<a href="{{ path('admin_user_new') }}"><button type="button" class="btn"><i class="fa fa-plus"></i> Add user</button></a>
<a href="{{ path('csv_export') }}"><button type="button" class="btn"><i class="fa fa-sign-out"></i> Export CSV</button></a>
<a href="{{ path('user_csv_import') }}"><button type="button" class="btn"><i class="fa fa-sign-in"></i> Import CSV</button></a>
<a href="{{ path('send_email_login') }}"><button type="button" class="btn"><i class="fa fa-mail-forward"></i> Send activation email to all users</button></a>
<a href="{{ path('send_email_login',{'typeOf': 0}) }}"><button type="button" class="btn"><i class="fa fa-mail-forward"></i> Send activation email to all users</button></a>
<a href="{{ path('send_email_login',{'typeOf': 1}) }}"><button type="button" class="btn"><i class="fa fa-mail-forward"></i> Send questionnaire email to all users</button></a>
</div>
</div>
{% endblock %}

0 comments on commit 6ebd7a8

Please sign in to comment.