Jump to content

Social Impact Award - Voting Tool


bernhard
 Share

Recommended Posts

mockup_sia-voting.800x0.png

https://www.baumrock.com/portfolio/event-voting-tool-social-impact-award/

 

Another nice little Showcase of what can quickly be done with Processwire :) I sponsored this voting tool for the Austrian Social Impact Award ceremony (https://socialimpactaward.net/) helping them to pick the winner of the audience voting.

siavoting.gif

The site is based on the default UIKIT theme (obviously) and i basically just placed the logo + changed the colors. The site structure is also very simple, having only one parent to store all teams, one parent to store all votes and one page to show the results (to the admins):

59dcd644d1087_2017-10-1016_16_22-PagesProcessWirevoting.baumrock_com.png.3b59f0735d26d55b52dffc23c5f66941.png

The Projects-Template stores some informations of the project and the vote-count:

59dcd75aee664_2017-10-1016_20_34-EditPage_IAMREFUGEEvoting.baumrock_com.thumb.png.b744e86ce42a93c8cbed4c381142ab13.png

All the votings are single pages as well having only one checkbox, ensuring that every code can only vote once (every visitor got one code at the entrance):

59dcd7b57ee52_2017-10-1016_22_11-EditPage_d6jgvoting.baumrock_com.png.4aa593c8b5295c1d88371750c92157cc.png

Votes are created via Tracy Console as easy as that:

59dcd81391156_2017-10-1016_23_35-EditPage_d6jgvoting.baumrock_com.png.24d743ab5c8831d31c9124e2069dbac0.png

The hook that creates the passwords is also simple:

/**
 * create unique code for voting
 */
$wire->addHookAfter('Pages::saveReady', function($event) {
  $page = $event->arguments(0);
  if($page->template != 'vote') return;

  if(!$page->title) {
    $rand = '';
    while(!$rand OR pages("title=$rand")->count() > 0) $rand = randomPassword();
    $page->title = $page->name = $rand;
  }
});

And finally the check if the vote for this code is already done (inside the vote-template). the whole vote-template is as simple as that (thanks to the awesomeness of markup regions and functionsapi):

<?php namespace ProcessWire;
// handle votes (url segments)
if($id = $sanitizer->int($input->urlSegment1)) {

  // if voting is locked redirect to thankyou message
  if($page->votingdone) $session->redirect($page->url);

  // else set voting
  $team = pages($id);
  if($team->id) {
    // increase voting for this team
    $team->setAndSave('votes', $team->votes+1);

    // lock this votings page
    $page->setAndSave('votingdone', 1);
  }
}
?>

<?php
// if voting is done show thank you and lock page
if($page->votingdone): ?>
  <region id="main">
    <div class="uk-card uk-card-primary uk-card-body uk-width-1-1 uk-margin-small-top uk-text-center uk-border-rounded">
      <h3 class="uk-card-title">Danke für Ihre Teilnahme!</h3>
    </div>
  </region>
  <?php
  return;
endif; ?>

<region id="main">

  <div class="uk-text-center uk-margin-top"><?= $page->parent->body ?></div>

  <?php foreach(pages('template=team, sort=random') as $team): ?>
    <div class="uk-card uk-card-default uk-card-body uk-width-1-1 uk-margin-small-top uk-border-rounded">
      <h3 class="uk-card-title uk-text-center"><?= $team->title ?></h3>

      <ul uk-accordion="collapsible: true">
        <li>
          <p class="uk-accordion-title uk-text-center"><span uk-icon="icon: chevron-down"></span> Beschreibung anzeigen</p>
          <div class="uk-accordion-content">
            <?= $team->body ?>
          </div>
        </li>
      </ul>

      <a href="<?= $team->id ?>" class="uk-button uk-button-large uk-button-primary uk-width-1-1 uk-border-rounded">Für dieses Projekt abstimmen</a>
    </div>
  <?php endforeach; ?>
</region>

I'm still impressed by ProcessWire and how much can be achieved with how little effort :)

  • Like 23
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...