Skip to content

Commit

Permalink
Merge branch 'Justine/Issue1' into 'develop'
Browse files Browse the repository at this point in the history
Collecting polled users emails

Closes #38

See merge request framasoft/framadate!266
  • Loading branch information
tcitworld committed Apr 19, 2018
2 parents b24cc43 + abec2cb commit 0409256
Show file tree
Hide file tree
Showing 18 changed files with 391 additions and 46 deletions.
4 changes: 4 additions & 0 deletions admin/migration.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
*/

use Framadate\Migration\AddColumn_collect_mail_In_poll;
use Framadate\Migration\AddColumn_hidden_In_poll_For_0_9;
use Framadate\Migration\AddColumn_mail_In_vote;
use Framadate\Migration\AddColumn_receiveNewComments_For_0_9;
use Framadate\Migration\AddColumn_uniqId_In_vote_For_0_9;
use Framadate\Migration\AddColumn_ValueMax_In_poll_For_1_1;
Expand Down Expand Up @@ -53,6 +55,8 @@
new Increase_pollId_size(),
new AddColumn_ValueMax_In_poll_For_1_1(),
new Fix_MySQL_No_Zero_Date(),
new AddColumn_mail_In_vote(),
new AddColumn_collect_mail_In_poll()
];
// ---------------------------------------

Expand Down
47 changes: 44 additions & 3 deletions adminstuds.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@

if ($messagePollCreated) {
$sessionService->remove("Framadate", "messagePollCreated");

$message = new Message('success', __('adminstuds', 'The poll is created.'));
}

Expand Down Expand Up @@ -219,6 +219,11 @@

if (!empty($_POST['save'])) { // Save edition of an old vote
$name = $inputService->filterName($_POST['name']);
if(empty($_POST['mail']) || $inputService->filterMail($_POST['mail'])===false) {
$mail = null;
} else {
$mail = $inputService->filterMail($_POST['mail']);
}
$editedVote = filter_input(INPUT_POST, 'save', FILTER_VALIDATE_INT);
$choices = $inputService->filterArray($_POST['choices'], FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => CHOICE_REGEX]]);
$slots_hash = $inputService->filterMD5($_POST['control']);
Expand All @@ -233,7 +238,7 @@
if ($message === null) {
// Update vote
try {
$result = $pollService->updateVote($poll_id, $editedVote, $name, $choices, $slots_hash);
$result = $pollService->updateVote($poll_id, $editedVote, $name, $choices, $slots_hash, $mail);
if ($result) {
$message = new Message('success', __('adminstuds', 'Vote updated'));
} else {
Expand All @@ -249,6 +254,11 @@
}
} elseif (isset($_POST['save'])) { // Add a new vote
$name = $inputService->filterName($_POST['name']);
if(empty($_POST['mail']) || $inputService->filterMail($_POST['mail'])===false) {
$mail = null;
} else {
$mail = $inputService->filterMail($_POST['mail']);
}
$choices = $inputService->filterArray($_POST['choices'], FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => CHOICE_REGEX]]);
$slots_hash = $inputService->filterMD5($_POST['control']);

Expand All @@ -262,7 +272,7 @@
if ($message === null) {
// Add vote
try {
$result = $pollService->addVote($poll_id, $name, $choices, $slots_hash);
$result = $pollService->addVote($poll_id, $name, $choices, $slots_hash, $mail);
if ($result) {
$message = new Message('success', __('adminstuds', 'Vote added'));
} else {
Expand Down Expand Up @@ -398,6 +408,37 @@
}
}

// -------------------------------
// Collect the mails of a column
// -------------------------------

if (isset($_GET['collect_mail'])) {
$column_str = strval(filter_input(INPUT_GET, 'collect_mail', FILTER_DEFAULT));
$column_str = strval(Utils::base64url_decode($column_str));
$column = intval($column_str);
$votes = $pollService->splitVotes($pollService->allVotesByPollId($poll_id));
$mails_yes = $mails_ifneedbe = $mails_no = [];
foreach ($votes as $vote) {
if (intval($vote->choices[$column]) === 2 && $vote->mail !== NULL) {
$mails_yes[] = $vote->mail;
} elseif (intval($vote->choices[$column]) === 1 && $vote->mail !== NULL) {
$mails_ifneedbe[] = $vote->mail;
} elseif($vote->mail !== NULL) {
$mails_no[] = $vote->mail;
}
}

$smarty->assign('poll_id', $poll_id);
$smarty->assign('admin_poll_id', $admin_poll_id);
$smarty->assign('admin', true);
$smarty->assign('title', __('Generic', 'Poll') . ' - ' . $poll->title . ' - ' . __('adminstuds', 'Collect the emails of the polled users for the choice'));
$smarty->assign('mails_yes', $mails_yes);
$smarty->assign('mails_ifneedbe', $mails_ifneedbe);
$smarty->assign('mails_no', $mails_no);
$smarty->display('display_mails.tpl');
exit;
}

// -------------------------------
// Add a slot
// -------------------------------
Expand Down
6 changes: 6 additions & 0 deletions app/classes/Framadate/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ class Form
*/
public $results_publicly_visible;

/**
* If true, the users can leave an email address while voting in the poll
* @var boolean
*/
public $collect_users_mail;

/**
* List of available choices
*/
Expand Down
70 changes: 70 additions & 0 deletions app/classes/Framadate/Migration/AddColumn_collect_mail_In_poll.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
/**
* This software is governed by the CeCILL-B license. If a copy of this license
* is not distributed with this file, you can obtain one at
* http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.txt
*
* Authors of STUdS (initial project): Guilhem BORGHESI (borghesi@unistra.fr) and Raphaël DROZ
* Authors of Framadate/OpenSondage: Framasoft (https://github.com/framasoft)
*
* =============================
*
* Ce logiciel est régi par la licence CeCILL-B. Si une copie de cette licence
* ne se trouve pas avec ce fichier vous pouvez l'obtenir sur
* http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.txt
*
* Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
*/
namespace Framadate\Migration;

use Framadate\Utils;

/**
* This migration adds the field uniqId on the vote table.
*
* @package Framadate\Migration
* @version 0.9
*/
class AddColumn_collect_mail_In_poll implements Migration {
function __construct() {
}

/**
* This method should describe in english what is the purpose of the migration class.
*
* @return string The description of the migration class
*/
function description() {
return 'Add column collect_users_mail in table poll';
}

/**
* This method could check if the execute method should be called.
* It is called before the execute method.
*
* @param \PDO $pdo The connection to database
* @return bool true is the Migration should be executed.
*/
function preCondition(\PDO $pdo) {
return true;
}

/**
* This method is called only one time in the migration page.
*
* @param \PDO $pdo The connection to database
* @return bool true is the execution succeeded
*/
function execute(\PDO $pdo) {
$this->alterVoteTable($pdo);

return true;
}

private function alterVoteTable(\PDO $pdo) {
$pdo->exec('
ALTER TABLE `' . Utils::table('poll') . '`
ADD `collect_users_mail` TINYINT DEFAULT 0;');
}
}
70 changes: 70 additions & 0 deletions app/classes/Framadate/Migration/AddColumn_mail_In_vote.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php
/**
* This software is governed by the CeCILL-B license. If a copy of this license
* is not distributed with this file, you can obtain one at
* http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.txt
*
* Authors of STUdS (initial project): Guilhem BORGHESI (borghesi@unistra.fr) and Raphaël DROZ
* Authors of Framadate/OpenSondage: Framasoft (https://github.com/framasoft)
*
* =============================
*
* Ce logiciel est régi par la licence CeCILL-B. Si une copie de cette licence
* ne se trouve pas avec ce fichier vous pouvez l'obtenir sur
* http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.txt
*
* Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphaël DROZ
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
*/
namespace Framadate\Migration;

use Framadate\Utils;

/**
* This migration adds the field uniqId on the vote table.
*
* @package Framadate\Migration
* @version 0.9
*/
class AddColumn_mail_In_vote implements Migration {
function __construct() {
}

/**
* This method should describe in english what is the purpose of the migration class.
*
* @return string The description of the migration class
*/
function description() {
return 'Add column mail in table vote';
}

/**
* This method could check if the execute method should be called.
* It is called before the execute method.
*
* @param \PDO $pdo The connection to database
* @return bool true is the Migration should be executed.
*/
function preCondition(\PDO $pdo) {
return true;
}

/**
* This method is called only one time in the migration page.
*
* @param \PDO $pdo The connection to database
* @return bool true is the execution succeeded
*/
function execute(\PDO $pdo) {
$this->alterVoteTable($pdo);

return true;
}

private function alterVoteTable(\PDO $pdo) {
$pdo->exec('
ALTER TABLE `' . Utils::table('vote') . '`
ADD `mail` VARCHAR(320) DEFAULT NULL;');
}
}
6 changes: 3 additions & 3 deletions app/classes/Framadate/Repositories/PollRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ function __construct(FramaDB $connect) {

public function insertPoll($poll_id, $admin_poll_id, $form) {
$sql = 'INSERT INTO `' . Utils::table('poll') . '`
(id, admin_id, title, description, admin_name, admin_mail, end_date, format, editable, receiveNewVotes, receiveNewComments, hidden, password_hash, results_publicly_visible,ValueMax)
VALUES (?,?,?,?,?,?,FROM_UNIXTIME(?),?,?,?,?,?,?,?,?)';
(id, admin_id, title, description, admin_name, admin_mail, end_date, format, editable, receiveNewVotes, receiveNewComments, hidden, password_hash, results_publicly_visible, ValueMax, collect_users_mail)
VALUES (?,?,?,?,?,?,FROM_UNIXTIME(?),?,?,?,?,?,?,?,?,?)';
$prepared = $this->prepare($sql);
$prepared->execute([$poll_id, $admin_poll_id, $form->title, $form->description, $form->admin_name, $form->admin_mail, $form->end_date, $form->format, ($form->editable>=0 && $form->editable<=2) ? $form->editable : 0, $form->receiveNewVotes ? 1 : 0, $form->receiveNewComments ? 1 : 0, $form->hidden ? 1 : 0, $form->password_hash, $form->results_publicly_visible ? 1 : 0,$form->ValueMax]);
$prepared->execute([$poll_id, $admin_poll_id, $form->title, $form->description, $form->admin_name, $form->admin_mail, $form->end_date, $form->format, ($form->editable>=0 && $form->editable<=2) ? $form->editable : 0, $form->receiveNewVotes ? 1 : 0, $form->receiveNewComments ? 1 : 0, $form->hidden ? 1 : 0, $form->password_hash, $form->results_publicly_visible ? 1 : 0, $form->ValueMax, $form->collect_users_mail? 1 : 0]);
}

function findById($poll_id) {
Expand Down
13 changes: 7 additions & 6 deletions app/classes/Framadate/Repositories/VoteRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@ function insertDefault($poll_id, $insert_position) {
return $prepared->execute([$insert_position, $insert_position + 1, $poll_id]);
}

function insert($poll_id, $name, $choices, $token) {
$prepared = $this->prepare('INSERT INTO `' . Utils::table('vote') . '` (poll_id, name, choices, uniqId) VALUES (?,?,?,?)');
$prepared->execute([$poll_id, $name, $choices, $token]);
function insert($poll_id, $name, $choices, $token, $mail) {
$prepared = $this->prepare('INSERT INTO `' . Utils::table('vote') . '` (poll_id, name, choices, uniqId, mail) VALUES (?,?,?,?,?)');
$prepared->execute([$poll_id, $name, $choices, $token, $mail]);

$newVote = new \stdClass();
$newVote->poll_id = $poll_id;
$newVote->id = $this->lastInsertId();
$newVote->name = $name;
$newVote->choices = $choices;
$newVote->uniqId = $token;
$newVote->mail=$mail;

return $newVote;
}
Expand Down Expand Up @@ -73,10 +74,10 @@ function deleteByIndex($poll_id, $index) {
return $prepared->execute([$index, $index + 2, $poll_id]);
}

function update($poll_id, $vote_id, $name, $choices) {
$prepared = $this->prepare('UPDATE `' . Utils::table('vote') . '` SET choices = ?, name = ? WHERE poll_id = ? AND id = ?');
function update($poll_id, $vote_id, $name, $choices, $mail) {
$prepared = $this->prepare('UPDATE `' . Utils::table('vote') . '` SET choices = ?, name = ?, mail = ? WHERE poll_id = ? AND id = ?');

return $prepared->execute([$choices, $name, $poll_id, $vote_id]);
return $prepared->execute([$choices, $name, $mail, $poll_id, $vote_id]);
}

/**
Expand Down

0 comments on commit 0409256

Please sign in to comment.