<?php defined('SYSPATH') or die('No direct script access.');
class Model_Promotion{
// Table name used by this model
protected $_table = 'promotion';
/**
* Adds a new message for a user
*
* @param string user_id
* @param string user's message
* @return Database
*/
public function add($libelle, $date_debut, $date_fin)
{
$values=array($libelle, $date_debut, $date_fin);
$data = array('libelle', 'date_debut', 'date_fin');
return DB::insert($this->_table, $data)
->values($values)
->execute();
}


/**
* Edit one promotion
*
* @return array
* */
public function edit($id,$libelle, $date_debut, $date_fin)
{
return DB::update($this->_table)
->set(array('libelle' => $libelle,'date_debut' => $date_debut,'date_fin'=>$date_fin))
->where('id', '=', $id)
->execute();
} 
/**
* Select one promotion
*
* @return array
* */
public function select($id)
{
return DB::select()
->from($this->_table)
->order_by('id')
->execute()
->as_array();
}

/**
* Gets all messages
*
* @return array
* */
public function get_all()
{
return DB::select()
->from($this->_table)
->order_by('id')
->execute()
->as_array();
}
/**
* Deletes a message from the DB
*
* @param string user_id
* @param string user's message
* @return Database
*/
public function delete($id)
{
return DB::delete($this->_table)
->where('id', '=', $id)
->execute();
}
/**
* Counts all messages
*
* @return int
*/
public function count_all()
{
return DB::select(DB::expr('COUNT(*) AS message_count'))
->from($this->_table)
->execute()
->get('message_count');
}
}