2015-04-02 23:10:41 +02:00
< ? php
namespace Framadate\Repositories ;
use Framadate\Utils ;
2015-04-02 23:23:34 +02:00
class PollRepository extends AbstractRepository {
2015-04-02 23:10:41 +02:00
2015-04-02 23:23:34 +02:00
function __construct ( FramaDB $connect ) {
parent :: __construct ( $connect );
2015-04-02 23:10:41 +02:00
}
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 )
VALUES ( ? , ? , ? , ? , ? , ? , FROM_UNIXTIME ( ? ), ? , ? , ? , ? ) ' ;
2015-04-02 23:23:34 +02:00
$prepared = $this -> prepare ( $sql );
2015-04-02 23:10:41 +02:00
$prepared -> execute ( array ( $poll_id , $admin_poll_id , $form -> title , $form -> description , $form -> admin_name , $form -> admin_mail , $form -> end_date , $form -> format , $form -> editable , $form -> receiveNewVotes , $form -> receiveNewComments ));
}
2015-04-02 23:23:34 +02:00
function findById ( $poll_id ) {
$prepared = $this -> prepare ( 'SELECT * FROM `' . Utils :: table ( 'poll' ) . '` WHERE id = ?' );
2015-04-02 23:10:41 +02:00
2015-04-02 23:23:34 +02:00
$prepared -> execute ( array ( $poll_id ));
$poll = $prepared -> fetch ();
$prepared -> closeCursor ();
2015-04-02 23:10:41 +02:00
2015-04-02 23:23:34 +02:00
return $poll ;
}
public function existsById ( $poll_id ) {
$prepared = $this -> prepare ( 'SELECT 1 FROM `' . Utils :: table ( 'poll' ) . '` WHERE id = ?' );
$prepared -> execute ( array ( $poll_id ));
return $prepared -> rowCount () > 0 ;
}
2015-04-02 23:10:41 +02:00
2015-04-02 23:23:34 +02:00
function update ( $poll ) {
$prepared = $this -> prepare ( 'UPDATE `' . Utils :: table ( 'poll' ) . '` SET title=?, admin_name=?, admin_mail=?, description=?, end_date=?, active=?, editable=? WHERE id = ?' );
2015-04-02 23:10:41 +02:00
2015-04-02 23:23:34 +02:00
return $prepared -> execute ([ $poll -> title , $poll -> admin_name , $poll -> admin_mail , $poll -> description , $poll -> end_date , $poll -> active , $poll -> editable , $poll -> id ]);
2015-04-02 23:10:41 +02:00
}
}