Merge branch 'bug/sondage-avec-smtp-désactivé' into 'develop'

correction : Adresse e-mail d'un sondage avec SMTP désactivé

See merge request framasoft/framadate!270
This commit is contained in:
Thomas Citharel 2018-04-03 09:27:37 +02:00
commit 72de7bff1c

View File

@ -79,7 +79,7 @@ class PollRepository extends AbstractRepository {
} }
/** /**
* Search polls in databse. * Search polls in database.
* *
* @param array $search Array of search : ['id'=>..., 'title'=>..., 'name'=>..., 'mail'=>...] * @param array $search Array of search : ['id'=>..., 'title'=>..., 'name'=>..., 'mail'=>...]
* @param int $start The number of first entry to select * @param int $start The number of first entry to select
@ -88,28 +88,48 @@ class PollRepository extends AbstractRepository {
*/ */
public function findAll($search, $start, $limit) { public function findAll($search, $start, $limit) {
// Polls // Polls
$prepared = $this->prepare('
SELECT p.*, $request = "";
(SELECT count(1) FROM `' . Utils::table('vote') . '` v WHERE p.id=v.poll_id) votes $request .= "SELECT p.*,";
FROM `' . Utils::table('poll') . '` p $request .= " (SELECT count(1) FROM `" . Utils::table('vote') . "` v WHERE p.id=v.poll_id) votes";
WHERE (:id = "" OR p.id LIKE :id) $request .= " FROM `" . Utils::table('poll') . "` p";
AND (:title = "" OR p.title LIKE :title) $request .= " WHERE 1";
AND (:name = "" OR p.admin_name LIKE :name)
AND (:mail = "" OR p.admin_mail LIKE :mail) $values = [];
ORDER BY p.title ASC
LIMIT :start, :limit if (!empty($search["poll"])) {
'); $request .= " AND p.id LIKE :poll";
$values["poll"] = "{$search["poll"]}%";
$poll = $search['poll'] . '%'; }
$title = '%' . $search['title'] . '%';
$name = '%' . $search['name'] . '%'; $fields = [
$mail = '%' . $search['mail'] . '%'; // key of $search => column name
$prepared->bindParam(':id', $poll, PDO::PARAM_STR); "title" => "title",
$prepared->bindParam(':title', $title, PDO::PARAM_STR); "name" => "admin_name",
$prepared->bindParam(':name', $name, PDO::PARAM_STR); "mail" => "admin_mail",
$prepared->bindParam(':mail', $mail, PDO::PARAM_STR); ];
foreach ($fields as $searchKey => $columnName) {
if (empty($search[$searchKey])) {
continue;
}
$request .= " AND p.$columnName LIKE :$searchKey";
$values[$searchKey] = "%{$search[$searchKey]}%";
}
$request .= " ORDER BY p.title ASC";
$request .= " LIMIT :start, :limit";
$prepared = $this->prepare($request);
foreach ($values as $searchKey => $value) {
$prepared->bindParam(":$searchKey", $value, PDO::PARAM_STR);
}
$prepared->bindParam(':start', $start, PDO::PARAM_INT); $prepared->bindParam(':start', $start, PDO::PARAM_INT);
$prepared->bindParam(':limit', $limit, PDO::PARAM_INT); $prepared->bindParam(':limit', $limit, PDO::PARAM_INT);
$prepared->execute(); $prepared->execute();
return $prepared->fetchAll(); return $prepared->fetchAll();