Skip to content

Commit

Permalink
Implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
mryan43 committed Oct 23, 2018
1 parent 236318f commit 2821db3
Show file tree
Hide file tree
Showing 26 changed files with 1,161 additions and 109 deletions.
63 changes: 63 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
FROM docker.bank.swissquote.ch/composer:1.7.1 as composer

FROM docker.bank.swissquote.ch/php:7.2.9-apache

# Install composer
ENV COMPOSER_ALLOW_SUPERUSER 1
COPY --from=composer /usr/bin/composer /usr/bin/composer

ARG PHP_TIMEZONE="Europe/Zurich"
ARG PHP_INI_DIR="/usr/local/etc/php"

RUN echo "memory_limit=-1" > $PHP_INI_DIR/conf.d/memory-limit.ini
RUN echo "date.timezone=${PHP_TIMEZONE:-UTC}" > $PHP_INI_DIR/conf.d/date_timezone.ini

# Install dependencies
RUN apt-get update -y
RUN apt-get install -y rsync # Utilities
RUN apt-get install -y libcurl3 libcurl3-dev # curl
RUN apt-get install -y mcrypt libmcrypt-dev # mcrypt
RUN apt-get install -y libxml2 libxml2-dev libxslt1.1 libxslt-dev # xsl
RUN apt-get install -y libldap-common libldap2-dev # ldap
RUN apt-get install -y libedit2 libedit-dev # readline
RUN apt-get install -y zlib1g-dev # zlib
RUN apt-get install -y libbz2-dev libbz2-1.0 # bzip2

# Install PHP Extensions
RUN docker-php-ext-configure ldap --with-libdir=lib/x86_64-linux-gnu
RUN docker-php-ext-install curl bcmath pdo pdo_mysql xsl readline zip bz2 opcache ldap pcntl mbstring

ENV APACHE_DOCUMENT_ROOT /app/public

RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
RUN sed -i 's/80/8080/g' /etc/apache2/sites-available/000-default.conf /etc/apache2/ports.conf

COPY docker/php.ini /usr/local/etc/php/php.ini

RUN a2enmod rewrite

WORKDIR /app

COPY app /app/app
COPY bootstrap /app/bootstrap
COPY config /app/config
COPY database /app/database
COPY public /app/public
COPY resources /app/resources
COPY routes /app/routes
# /app/storage is expected to be mounted as a volume
COPY artisan /app/artisan
COPY composer.json /app/composer.json
COPY composer.lock /app/composer.lock

RUN ls -alh /app/database

RUN composer install --no-dev --optimize-autoloader

# Commented out because some of our configuration is not serializable
#RUN /app/artisan config:cache
#RUN /app/artisan route:cache

# Do not run as root by default
USER www-data
85 changes: 84 additions & 1 deletion app/Http/Controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,18 @@
namespace App\Http\Controllers;


use App\Event;
use Illuminate\Support\Facades\DB;
use League\Csv\Writer;

class AdminController extends Controller
{

public function __construct()
{
$this->middleware('auth');
}

public function index()
{
//
Expand All @@ -20,6 +29,80 @@ public function index()

public function export($id)
{
//

$this->authorize('admin');
$csv = Writer::createFromFileObject(new \SplTempFileObject());

$event = Event::findOrFail($id);
$header = ["Person Name", "Department", "Will you be present at this event ?", "Why not ? (optional)"];
foreach ($event->fields->sortBy('id') as $field) {
array_push($header, $field->label);
}

$fieldsById = $event->fields->mapWithKeys(function ($item) {
return [$item->id => $item];
});

$csv->insertOne($header);

$records = DB::table('registration_values')
->join('event_registrations', 'registration_values.event_registration_id', '=', 'event_registrations.id')
->join('users', 'event_registrations.user_id', '=', 'users.id')
->join('fields', 'fields.id', '=', 'registration_values.field_id')
->select('registration_values.value as value', 'fields.label as fieldname', 'fields.id as fieldid', 'users.name as username',
'users.department as department')
->orderBy('username', 'fieldid')
->where('event_registrations.event_id', $id)->get();

$map = [];

foreach ($records as $record) {
$map[$record->username]['department'] = $record->department;
$map[$record->username][$record->fieldid] = $record->value;
}

// sort by username
ksort($map);
// sort answers by field id
ksort($map[$record->username]);

// hide irrelevant answers (conditional fields)
foreach ($map as $username => $answers) {
foreach ($answers as $fieldid => $value) {
// why not ?
if ($fieldid == 2 && $answers[1] === "Yes") {
$map[$username][$fieldid] = "";
}

if ($fieldid < 3 || $fieldid === "department") {
continue;
}

$condition = $fieldsById[$fieldid]->condition;
if (!empty($condition)) {
$conditionFieldId = preg_split("~:~", $condition)[0];
$conditionValue = preg_split("~:~", $condition)[1];
if ($answers[$conditionFieldId] !== $conditionValue) {
$map[$username][$fieldid] = "";
}
}

// non participating
if ($answers[1] === "No") {
$map[$username][$fieldid] = "";
}

}
}

// insert in CSV
foreach ($map as $username => $answers) {
$row = [$username];
foreach ($answers as $fieldid => $value) {
array_push($row, $value);
}
$csv->insertOne($row);
}
$csv->output($event->name . '.csv');
}
}
14 changes: 14 additions & 0 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Request;

class LoginController extends Controller
{
Expand All @@ -27,6 +29,11 @@ class LoginController extends Controller
*/
protected $redirectTo = '/events';

public function username()
{
return 'login';
}

/**
* Create a new controller instance.
*
Expand All @@ -36,4 +43,11 @@ public function __construct()
{
$this->middleware('guest')->except('logout');
}

public function logout(Request $request)
{
Auth::logout();
return redirect('/login');
}

}
Loading

0 comments on commit 2821db3

Please sign in to comment.