2015-04-02 23:23:34 +02:00
|
|
|
|
<?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
|
|
|
|
|
*
|
2018-04-18 16:16:22 +02:00
|
|
|
|
* Authors of STUdS (initial project): Guilhem BORGHESI (borghesi@unistra.fr) and Rapha<EFBFBD>l DROZ
|
2016-08-04 22:26:37 +02:00
|
|
|
|
* Authors of Framadate/OpenSondage: Framasoft (https://github.com/framasoft)
|
2015-04-02 23:23:34 +02:00
|
|
|
|
*
|
|
|
|
|
* =============================
|
|
|
|
|
*
|
2018-04-18 16:16:22 +02:00
|
|
|
|
* Ce logiciel est r<EFBFBD>gi par la licence CeCILL-B. Si une copie de cette licence
|
2015-04-02 23:23:34 +02:00
|
|
|
|
* ne se trouve pas avec ce fichier vous pouvez l'obtenir sur
|
|
|
|
|
* http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.txt
|
|
|
|
|
*
|
2018-04-18 16:16:22 +02:00
|
|
|
|
* Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Rapha<EFBFBD>l DROZ
|
2015-04-02 23:23:34 +02:00
|
|
|
|
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
|
|
|
|
|
*/
|
|
|
|
|
namespace Framadate\Repositories;
|
|
|
|
|
|
2015-04-03 00:11:36 +02:00
|
|
|
|
use Framadate\Utils;
|
|
|
|
|
|
2015-04-02 23:23:34 +02:00
|
|
|
|
class SlotRepository extends AbstractRepository {
|
|
|
|
|
/**
|
|
|
|
|
* Insert a bulk of slots.
|
|
|
|
|
*
|
|
|
|
|
* @param int $poll_id
|
|
|
|
|
* @param array $choices
|
|
|
|
|
*/
|
|
|
|
|
public function insertSlots($poll_id, $choices) {
|
|
|
|
|
foreach ($choices as $choice) {
|
|
|
|
|
// We prepared the slots (joined by comas)
|
2018-04-18 16:16:22 +02:00
|
|
|
|
$joinedSlots = null;
|
2015-04-02 23:23:34 +02:00
|
|
|
|
$first = true;
|
|
|
|
|
foreach ($choice->getSlots() as $slot) {
|
|
|
|
|
if ($first) {
|
|
|
|
|
$joinedSlots = $slot;
|
|
|
|
|
$first = false;
|
|
|
|
|
} else {
|
|
|
|
|
$joinedSlots .= ',' . $slot;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We execute the insertion
|
2018-04-18 16:16:22 +02:00
|
|
|
|
$this->connect->insert(Utils::table('slot'), ['poll_id' => $poll_id, 'title' => $choice->getName(), 'moments' => $joinedSlots]);
|
2015-04-02 23:23:34 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-18 16:16:22 +02:00
|
|
|
|
/**
|
|
|
|
|
* @param $poll_id
|
|
|
|
|
* @throws \Doctrine\DBAL\DBALException
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public function listByPollId($poll_id)
|
|
|
|
|
{
|
|
|
|
|
$prepared = $this->prepare('SELECT * FROM ' . Utils::table('slot') . ' WHERE poll_id = ? ORDER BY id');
|
2018-02-19 00:18:43 +01:00
|
|
|
|
$prepared->execute([$poll_id]);
|
2015-04-02 23:23:34 +02:00
|
|
|
|
|
|
|
|
|
return $prepared->fetchAll();
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-03 00:11:36 +02:00
|
|
|
|
/**
|
|
|
|
|
* Find the slot into poll for a given datetime.
|
|
|
|
|
*
|
|
|
|
|
* @param $poll_id int The ID of the poll
|
|
|
|
|
* @param $datetime int The datetime of the slot
|
2018-04-18 16:16:22 +02:00
|
|
|
|
* @throws \Doctrine\DBAL\DBALException
|
2015-04-03 00:11:36 +02:00
|
|
|
|
* @return mixed Object The slot found, or null
|
|
|
|
|
*/
|
|
|
|
|
function findByPollIdAndDatetime($poll_id, $datetime) {
|
2018-04-18 16:16:22 +02:00
|
|
|
|
$prepared = $this->prepare('SELECT * FROM ' . Utils::table('slot') . ' WHERE poll_id = ? AND SUBSTRING_INDEX(title, \'@\', 1) = ?');
|
2015-04-03 00:11:36 +02:00
|
|
|
|
|
|
|
|
|
$prepared->execute([$poll_id, $datetime]);
|
|
|
|
|
$slot = $prepared->fetch();
|
|
|
|
|
$prepared->closeCursor();
|
|
|
|
|
|
|
|
|
|
return $slot;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Insert a new slot into a given poll.
|
|
|
|
|
*
|
|
|
|
|
* @param $poll_id int The ID of the poll
|
|
|
|
|
* @param $title mixed The title of the slot
|
|
|
|
|
* @param $moments mixed|null The moments joined with ","
|
|
|
|
|
* @return bool true if action succeeded
|
|
|
|
|
*/
|
2018-04-18 16:16:22 +02:00
|
|
|
|
function insert($poll_id, $title, $moments)
|
|
|
|
|
{
|
|
|
|
|
return $this->connect->insert(Utils::table('slot'), ['poll_id' => $poll_id, 'title' => $title, 'moments' => $moments]) > 0;
|
2015-04-03 00:11:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update a slot into a poll.
|
|
|
|
|
*
|
|
|
|
|
* @param $poll_id int The ID of the poll
|
|
|
|
|
* @param $datetime int The datetime of the slot to update
|
|
|
|
|
* @param $newMoments mixed The new moments
|
|
|
|
|
* @return bool|null true if action succeeded.
|
|
|
|
|
*/
|
2018-04-18 16:16:22 +02:00
|
|
|
|
function update($poll_id, $datetime, $newMoments)
|
|
|
|
|
{
|
|
|
|
|
return $this->connect->update(Utils::table('slot'), ['moments' => $newMoments], ['poll_id' => $poll_id, 'title' => $datetime]) > 0;
|
2015-04-03 00:11:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Delete a entire slot from a poll.
|
|
|
|
|
*
|
|
|
|
|
* @param $poll_id int The ID of the poll
|
|
|
|
|
* @param $datetime mixed The datetime of the slot
|
2018-04-18 16:16:22 +02:00
|
|
|
|
* @throws \Doctrine\DBAL\DBALException
|
|
|
|
|
* @return bool
|
2015-04-03 00:11:36 +02:00
|
|
|
|
*/
|
2018-04-18 16:16:22 +02:00
|
|
|
|
public function deleteByDateTime($poll_id, $datetime)
|
|
|
|
|
{
|
|
|
|
|
return $this->connect->delete(Utils::table('slot'), ['poll_id' => $poll_id, 'title' => $datetime]) > 0;
|
2015-04-03 00:11:36 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-18 16:16:22 +02:00
|
|
|
|
/**
|
|
|
|
|
* @param $poll_id
|
|
|
|
|
* @throws \Doctrine\DBAL\DBALException
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public function deleteByPollId($poll_id)
|
|
|
|
|
{
|
|
|
|
|
return $this->connect->delete(Utils::table('slot'), ['poll_id' => $poll_id]) > 0;
|
2015-04-03 00:11:36 +02:00
|
|
|
|
}
|
2015-04-02 23:23:34 +02:00
|
|
|
|
}
|