Commit 438d53d6 authored by Ασπασία Κατσή's avatar Ασπασία Κατσή

Merge branch 'forms2' into 'master'

Teachers Form -University Form

See merge request !20
parents d4eb5da9 e6ab5c20
......@@ -26,6 +26,9 @@ return [
'module/in_numbers_mm/bootstrap.php',
'module/csv_export/bootstrap.php',
'module/open_data/bootstrap.php',
'module/university_form/bootstrap.php',
'module/teacher_form/bootstrap.php',
],
'cache_config' => 'data/cache/config/settings.php',
];
......@@ -42,6 +42,12 @@ return [
['/in_numbers', ['guest', 'user'], ['get']],
['/export/csv/edulabs_{type}.csv', ['guest', 'user'], ['get']],
['/open-data', ['guest', 'user'], ['get']],
['/university-form', ['guest'], ['get', 'post']],
['/university-form/submit-success',['guest'],['get']],
['/teacher-form', ['guest'], ['get', 'post']],
['/teacher-form/submit-success',['guest'], ['get','post']],
['/teacher-form/mm',['guest'], ['get']],
],
],
],
......
......@@ -59,6 +59,14 @@ return [
'label' => 'Ανοικτά δεδομένα',
'route' => 'open_data',
],
'university_form' => [
'label' => 'Ιδρύματα',
'route' => 'university_form',
],
'teacher_form' => [
'label' => 'Εκπαιδευτικοί',
'route' => 'teacher_form',
],
'about' => [
'label' => 'Σχετικά με τη δράση',
'route' => 'about',
......
<?php
use Slim\App;
use Slim\Http\Request;
use Slim\Http\Response;
/**
* gredu_labs.
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
return function (App $app) {
$container = $app->getContainer();
$events = $container['events'];
$events('on', 'app.autoload', function ($autoloader) {
$autoloader->addPsr4('GrEduLabs\\TeacherForm\\', __DIR__ . '/src/');
});
$events('on', 'app.services', function ($container) {
$container[GrEduLabs\TeacherForm\Service\TeacherFormServiceInterface::class] = function ($c) {
return new GrEduLabs\TeacherForm\Service\TeacherFormService();
};
$container[GrEduLabs\TeacherForm\InputFilter\TeacherForm::class] = function ($c) {
return new GrEduLabs\TeacherForm\InputFilter\TeacherForm();
};
$container[GrEduLabs\TeacherForm\Action\TeacherForm::class] = function ($c) {
return new GrEduLabs\TeacherForm\Action\TeacherForm(
$c->get('view'),
$c->get(GrEduLabs\TeacherForm\Service\TeacherFormServiceInterface::class),
$c->get(GrEduLabs\TeacherForm\InputFilter\TeacherForm::class),
$c->get('router')->pathFor('teacher_form.submit_success'),
$c);
};
$container[GrEduLabs\TeacherForm\Action\SubmitSuccess::class] = function ($c) {
return new GrEduLabs\TeacherForm\Action\SubmitSuccess(
$c->get('view'),
$c->get('router')->pathFor('teacher_form')
);
};
});
$events('on', 'app.bootstrap', function ($app, $container) {
$container['view']->getEnvironment()->getLoader()->prependPath(__DIR__ . '/templates');
$app->group('/teacher-form', function () {
$this->map(['get', 'post'], '', GrEduLabs\TeacherForm\Action\TeacherForm::class)
->add(GrEduLabs\Application\Middleware\AddCsrfToView::class)
->add('csrf')
->setName('teacher_form');
$this->get('/submit-success', GrEduLabs\TeacherForm\Action\SubmitSuccess::class)
->setName('teacher_form.submit_success');
});
$app->get('/teacher-form/mm', function (Request $req, Response $res) use ($container) {
$school_name = $req->getQueryParam('term');
$httpClient = new GuzzleHttp\Client([
'base_uri' => $container['settings']['sch_mm']['public_api_url']
]);
$config = $httpClient->getConfig();
$baseUri = $config['base_uri'];
$url = $baseUri . "?name=" . $school_name;
$response = $httpClient->request('GET', $url);
$responseData = json_decode($response->getBody()->getContents(), true);
if (!isset($responseData['data']) || empty($responseData['data'])) {
return;
}
$cnt = count($responseData['data']);
$school_arr = [];
for ($i=0; $i<$cnt; $i++) {
$school_arr[$i]['mm_id'] = $responseData['data'][$i]['mm_id'];
$school_arr[$i]['value'] = $responseData['data'][$i]['name'];
$school_arr[$i]['tel'] = $responseData['data'][$i]['phone_number'];
}
return $res->withJson($school_arr);
})->setName('teacher_form.mm');
});
};
DROP TABLE IF EXISTS `volunteerteachers`;
-- Table structure for table `volunteerteachers`
--
CREATE TABLE IF NOT EXISTS `volunteerteachers` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`surname` varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`eidikothta` int(11) NOT NULL,
`arithmitroou` int(11) NOT NULL,
`telef` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`email` varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`school` varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`schooltelef` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`comments` text NOT NULL,
PRIMARY KEY (`id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
ALTER TABLE `volunteerteachers`
DROP COLUMN `projectdescription`;
ALTER TABLE `volunteerteachers`
ADD COLUMN `projectdescription` text;
-- Table structure for table `volunteerteachers`
--
DROP TABLE IF EXISTS `volunteerteachers`;
CREATE TABLE IF NOT EXISTS `volunteerteachers` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`surname` varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`eidikothta` int(11) NOT NULL,
`arithmitroou` int(11) NOT NULL,
`telef` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`email` varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`school` varchar(191) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`schooltelef` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`comments` text NOT NULL,
`projecttitle` varchar(255),
`projecturl` varchar(255),
`projectdescription` text,
PRIMARY KEY (`id`)
)ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;;
<?php
/**
* gredu_labs.
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
namespace GrEduLabs\TeacherForm\Action;
use Slim\Http\Request;
use Slim\Http\Response;
use Slim\Views\Twig;
class SubmitSuccess
{
protected $view;
protected $formUrl;
public function __construct(Twig $view, $formUrl)
{
$this->view = $view;
$this->formUrl = $formUrl;
}
public function __invoke(Request $req, Response $res)
{
if (!isset($_SESSION['teacherForm']['tForm'])) {
$res = $res->withRedirect($this->formUrl);
return $res;
}
$tForm = $_SESSION['teacherForm']['tForm'];
$_SESSION['teacherForm']['tForm'] = null;
unset($_SESSION['teacherForm']['tForm']);
return $this->view->render($res, 'teacher_form/submit_success.twig', [
]);
}
}
<?php
/**
* gredu_labs.
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
namespace GrEduLabs\TeacherForm\Action;
use GrEduLabs\TeacherForm\Service\TeacherFormServiceInterface;
use Slim\Http\Request;
use Slim\Http\Response;
use Slim\Views\Twig;
use Zend\Authentication\AuthenticationServiceInterface;
use Zend\InputFilter\InputFilterInterface;
class TeacherForm
{
/**
* @var Twig
*/
protected $view;
/**
*
* @var TeacherFormServiceInterface
*/
protected $TeacherFormService;
/**
*
* @var InputFilterInterface
*/
protected $TeacherFormInputFilter;
/**
*
* @var AuthenticationServiceInterface
*/
protected $authService;
/**
*
* @var type SLIM application container
*/
protected $container;
/**
*
* @var string
*/
protected $successUrl;
public function __construct(
Twig $view, TeacherFormServiceInterface $TeacherFormService, InputFilterInterface $TeacherFormInputFilter, $successUrl, $container
) {
$this->view = $view;
$this->TeacherFormService = $TeacherFormService;
$this->TeacherFormInputFilter = $TeacherFormInputFilter;
$this->successUrl = $successUrl;
$this->container = $container;
}
public function __invoke(Request $req, Response $res)
{
if ($req->isPost()) {
$reqParams = array_map(function($string) use ($link) { return htmlspecialchars($string); }, $req->getParams());
$this->TeacherFormInputFilter->setData($reqParams);
$isValid = $this->TeacherFormInputFilter->isValid();
if ($isValid) {
$data = $this->TeacherFormInputFilter->getValues();
$TeacherForm = $this->TeacherFormService->submit($data, $reqParams);
$_SESSION['teacherForm']['tForm'] = $TeacherForm;
$res = $res->withRedirect($this->successUrl);
return $res;
} else {
$this->view['form'] = [
'is_valid' => $isValid,
'values' => $this->TeacherFormInputFilter->getValues(),
'raw_values' => $this->TeacherFormInputFilter->getRawValues(),
'messages' => $this->TeacherFormInputFilter->getMessages(),
'branches' => array_map(function ($branch) {
return ['value' => $branch['id'], 'label' => $branch['name']];
}, $this->TeacherFormService->getBranches()),
];
$res = $this->view->render($res, 'teacher_form/form.twig', []);
}
} else {
$this->view['form'] = [
'branches' => array_map(function ($branch) {
return ['value' => $branch['id'], 'label' => $branch['name']];
}, $this->TeacherFormService->getBranches()),
];
$res = $this->view->render($res, 'teacher_form/form.twig', []);
}
return $res;
}
}
<?php
/**
* gredu_labs
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
namespace GrEduLabs\UniversityForm\InputFilter;
trait InputFilterTrait
{
private $inputFillter;
public function __invoke(array $data)
{
$this->inputFilter->setData($data);
$isValid = $this->inputFilter->isValid();
return [
'is_valid' => $isValid,
'values' => $isValid ? $this->inputFilter->getValues() : [],
'messages' => $this->inputFilter->getMessages(),
];
}
}
<?php
/**
* gredu_labs
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
namespace GrEduLabs\TeacherForm\InputFilter;
use GrEduLabs\TeacherForm\Service;
use Zend\Filter;
use Zend\InputFilter\Input;
use Zend\InputFilter\InputFilter;
use Zend\Validator;
class TeacherForm extends InputFilter
{
public function __construct()
{
$name = new Input('name');
$name->setRequired(true)
->getFilterChain()
->attach(new Filter\StringTrim());
$name->getValidatorChain()
->attach(new Validator\NotEmpty())
->attach(new Validator\StringLength(['min' => 3]));
$surname = new Input('surname');
$surname->setRequired(true)
->getFilterChain()
->attach(new Filter\StringTrim());
$surname->getValidatorChain()
->attach(new Validator\NotEmpty())
->attach(new Validator\StringLength(['min' => 3]));
$eidikothta = new Input('eidikothta');
$eidikothta->getValidatorChain()
->attach(new Validator\NotEmpty())
->attach(new Validator\Digits());
$arithmitroou = new Input('arithmitroou');
$arithmitroou->setRequired(true)
->getFilterChain()
->attach(new Filter\ToInt());
$arithmitroou->getValidatorChain()
->attach(new Validator\NotEmpty())
->attach(new Validator\GreaterThan([
'min' => 0,
'inclusive' => false,
]));
$email = new Input('email');
$email->setRequired(true)
->getValidatorChain()
->attach(new Validator\NotEmpty())
->attach(new Validator\EmailAddress([
'useDomainCheck' => false,
]));
$telef = new Input('telef');
$telef->setRequired(true)
->getFilterChain()
->attach(new Filter\Digits());
$telef->getValidatorChain()
->attach(new Validator\NotEmpty())
->attach(new Validator\StringLength(['min' => 10]))
->attach(new Validator\StringLength(['max' => 13]));
$school = new Input('school');
$school->setRequired(false)
->getFilterChain()
->attach(new Filter\StringTrim());
$schooltelef = new Input('schooltelef');
$schooltelef->setRequired(false)
->getFilterChain()
->attach(new Filter\Digits());
$schooltelef->getValidatorChain()
->attach(new Validator\NotEmpty())
->attach(new Validator\StringLength(['min' => 10]))
->attach(new Validator\StringLength(['max' => 13]));
$projectdescription = new Input('projectdescription');
$projectdescription->setRequired(false)
->getFilterChain()
->attach(new Filter\StringTrim());
$comments = new Input('comments');
$comments->setRequired(false)
->getFilterChain()
->attach(new Filter\StringTrim());
$this->add($name)
->add($surname)
->add($eidikothta)
->add($arithmitroou)
->add($email)
->add($telef)
->add($schooltelef)
->add($school)
->add($projectdescription)
->add($comments);
}
}
<?php
/**
* gredu_labs.
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
namespace GrEduLabs\TeacherForm\Service;
use RedBeanPHP\OODBBean;
use RedBeanPHP\R;
class TeacherFormService implements TeacherFormServiceInterface
{
public function submit(array $data)
{
$appForm = R::dispense('volunteerteachers');
// $appForm->id = $data['id'];
$appForm->name = $data['name'];
$appForm->surname = $data['surname'];
$appForm->eidikothta = $data['eidikothta'];
$appForm->arithmitroou = $data['arithmitroou'];
$appForm->email = $data['email'];
$appForm->telef = trim($data['telef']);
$appForm->school = $data['school'];
$appForm->schooltelef = trim($data['schooltelef']);
$appForm->projectdescription = $data['projectdescription'];
$appForm->comments = $data['comments'];
R::store($appForm);
return $appForm;
}
public function getBranches()
{
return array_map(function ($branch) {
return $branch->export();
}, R::findAll('branch', 'ORDER BY name ASC'));
}
}
<?php
/**
* gredu_labs.
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
namespace GrEduLabs\TeacherForm\Service;
interface TeacherFormServiceInterface
{
public function submit(array $data);
public function getBranches();
}
{% extends "layout.twig" %}
{% import "schools/form.twig" as macros %}
{% block content %}
<style>
input[type=text] {
width: 100%;
}
</style>
<div id="app-form">
<h1>
{% block title %}
{% endblock %}
</h1>
<form method="post" action="" data-is-valid="{{ form.is_valid | default(true) ? '1' : '0' }}"
data-messages="{{ form.messages|default({})|json_encode }}">
<input type="hidden" id="mm_id" name="mm_id" value="0">
<div class="form-group">
<p>
<h1>Αίτηση εκδήλωσης ενδιαφέροντος</h1>
<br>
Στην δράση των edulabs μπορούν να συμμετέχουν εκπαιδευτικοί με εμπειρία σε STEAM που θέλουν να συνεργαστούν με τα σχολεία στην αξιοποίηση των 140 edulabs που εγκαθίστανται σε σχολεία σε όλες τις εκπαιδευτικές διευθύνσεις.
<br>
Παρακαλώ συμπληρώστε τα στοιχεία σας και θα επικοινωνήσουμε μαζί σας.
</p>
</div>
<div class="table-responsive">
<fieldset>
<!-- <div id="items-list"> -->
{{ macros.input('name', 'Όνομα', form.values.name)}}
{{ macros.input('surname', 'Επώνυμο', form.values.surname)}}
{{ macros.select('eidikothta', 'Ειδικότητα', form.branches, form.values.eidikothta, {'required': ''}) }}
{{ macros.input('arithmitroou', 'Αριθμός Μητρώου', form.values.arithmitroou)}}
{{ macros.input('telef', 'Τηλέφωνο', form.values.telef)}}
{{ macros.input('email', 'Email', form.values.email)}}
<div class="form-group">
<label class="control-label hidden-xs hidden-sm col-md-3" for="select_school">Αναζήτηση σχολείου</label>
<div class="col-xs-12 col-sm-12 col-md-9">
<input type="text" id="select_school" name="select_school" placeholder="Γράψτε 4 τουλάχιστο χαρακτήρες για αναζήτηση" class="form-control input-sm">
</div>
</div>
{{ macros.input('school', 'Σχολείο που υπηρετείτε', form.values.school, 'text', {'readonly': true})}}
{{ macros.input('schooltelef', 'Τηλέφωνο Σχολείου', form.values.schooltelef, 'text', {'readonly': true})}}
<br>
<br>
<br>
<h3> Δράσεις</h3>
Παρακαλώ περιγράψτε σύντομα δράσεις που έχετε συμμετάσχει.
<div class="input_fields_wrap">
<button style="color:blue" class="add_field_button" "btn btn-lg btn-primary">Προσθήκη Επιπλέον</button>
<div><label for="projects">Σχετική δράση που συμμετείχατε </label><input type="text" name="projects[]" id="projects"></div>
<div><label for="urlproject">URL δράσης που συμμετείχατε</label><input type="text" name="urlproject[]" id="urlproject"></div>
<div><label for "commentproject">Περιγραφή δράσης που συμμετείχατε</label><input type="text" name="commentsproject[]" id="commentproject"></div>
</div>
<input type="hidden" name="projectdescription" id="projectdescription">
<p>
<p>
<!-- </div> -->
{{ macros.text('comments', 'Σχόλια/Παρατηρήσεις', form.values.comments) }}
</fieldset>
</div>
<hr>
<div class="form-group text-center">
<button name="submit" value="submit" type="submit" id ="submit" class="btn btn-lg btn-primary">Υποβολή</button>
</div>
<input type="hidden" name="{{ csrf.name_key }}" value="{{ csrf.name }}">
<input type="hidden" name="{{ csrf.value_key }}" value="{{ csrf.value }}">
</form>
</div>
{% endblock %}
{% block inlinejs %}
{{ parent() }}
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.2.3/backbone-min.js"></script>
<script src="{{ base_url }}/js/jquery-ui.autoc.min.js"></script>
<script src="{{ base_url() }}/js/teacher_form/index.js"></script>
{% endblock %}
<h1 class="no-print">
{% block title %}
Επιτυχής Καταχώρηση.
{% endblock %}
</h1>
<p class="no-print">Η αίτηση σας καταχωρήθηκε επιτυχώς.
<br> Ευχαριστούμε για τη συμμετοχή σας.
</p>
{% extends "layout.twig" %}
{% block content %}
<div id="app-form-success">
{% include 'teacher_form/result.twig' %}
<div class="row no-print">
<div class="col-xs-12 text-center">
</div>
</div>
<br>
</div>
{% endblock %}
<?php
use Slim\App;
use Slim\Container;
use Slim\Http\Request;
use Slim\Http\Response;
/**
* gredu_labs.
*
* @link https://github.com/eellak/gredu_labs for the canonical source repository
*
* @copyright Copyright (c) 2008-2015 Greek Free/Open Source Software Society (https://gfoss.ellak.gr/)
* @license GNU GPLv3 http://www.gnu.org/licenses/gpl-3.0-standalone.html
*/
return function (App $app) {
$container = $app->getContainer();
$events = $container['events'];
$events('on', 'app.autoload', function ($autoloader) {
$autoloader->addPsr4('GrEduLabs\\UniversityForm\\', __DIR__ . '/src/');
});
$events('on', 'app.services', function ($container) {
$container[GrEduLabs\UniversityForm\Service\UniversityFormServiceInterface::class] = function ($c) {
return new GrEduLabs\UniversityForm\Service\UniversityFormService();
};
$container[GrEduLabs\UniversityForm\InputFilter\UniversityForm::class] = function ($c) {
return new GrEduLabs\UniversityForm\InputFilter\UniversityForm();
};
$container[GrEduLabs\UniversityForm\Action\UniversityForm::class] = function ($c) {
return new GrEduLabs\UniversityForm\Action\UniversityForm(
$c->get('view'),
$c->get(GrEduLabs\UniversityForm\Service\UniversityFormServiceInterface::class),
$c->get(GrEduLabs\UniversityForm\InputFilter\UniversityForm::class),
$c->get('router')->pathFor('university_form.submit_success'),
$c);