135 lines
2.9 KiB
PHP
135 lines
2.9 KiB
PHP
<?php
|
|
/**
|
|
* Comptabilise le nombre d'entité d'un fichier
|
|
*/
|
|
class Scores_Conso_File
|
|
{
|
|
|
|
protected $login = array();
|
|
|
|
protected $date;
|
|
|
|
protected $item;
|
|
|
|
/**
|
|
* @var Zend_Db_Table_Abstract
|
|
*/
|
|
protected $table;
|
|
|
|
/**
|
|
*
|
|
* @var Zend_Db_Select
|
|
*/
|
|
protected $sql;
|
|
|
|
/**
|
|
*
|
|
* @param Zend_Db_Table_Abstract $table
|
|
*/
|
|
public function __construct(Zend_Db_Table_Abstract $table)
|
|
{
|
|
$this->table = $table;
|
|
$this->sql = $this->table->select();
|
|
}
|
|
|
|
/**
|
|
* Array of login
|
|
* @param array $login
|
|
*/
|
|
public function setLogin($login)
|
|
{
|
|
$this->login = $login;
|
|
}
|
|
|
|
/**
|
|
* Date au format AAAAMM
|
|
* @param string $date
|
|
*/
|
|
public function setDate($date)
|
|
{
|
|
$this->date = $date;
|
|
}
|
|
|
|
/**
|
|
* Code de l'élément à compter
|
|
* @param string $item
|
|
*/
|
|
public function setItem($item)
|
|
{
|
|
$this->item = $item;
|
|
}
|
|
|
|
/**
|
|
* Retourne la requete
|
|
* @return Zend_Db_Select
|
|
*/
|
|
public function getSqlRule()
|
|
{
|
|
$this->addSqlLogin();
|
|
$this->addSqlItem();
|
|
$this->addSqlDate();
|
|
|
|
return $this->sql;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param unknown $name
|
|
* @param unknown $value
|
|
*/
|
|
public function setOption($name, $value)
|
|
{
|
|
if ( null === $this->item ) {
|
|
return new Zend_Exception('Item is not set !');
|
|
}
|
|
|
|
if ($name == 'duplicate') {
|
|
if ( !array_key_exists('duplicate', $this->rules[$this->item]) ) {
|
|
switch ( strtolower($value) ) {
|
|
case 'day':
|
|
case 'jour':
|
|
$this->rules[$this->item]['duplicate'] = 'day';
|
|
break;
|
|
case 'month':
|
|
case 'mois':
|
|
case 'period':
|
|
case 'periode':
|
|
$this->rules[$this->item]['duplicate'] = 'period';
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
*
|
|
*/
|
|
public function addSqlLogin()
|
|
{
|
|
$this->sql->where("login IN ('".join("','", $this->login)."')");
|
|
}
|
|
|
|
public function addSqlDate()
|
|
{
|
|
$formatedDate = substr($this->date,0,4).'-'.substr($this->date,4,2);
|
|
$this->sql->where("dateAjout BETWEEN '".$formatedDate."-01 00:00:00' AND '".$formatedDate."-31 23:59:59'");
|
|
}
|
|
|
|
public function addSqlItem()
|
|
{
|
|
$this->sql->from($this->table, array('COUNT(*) AS NB'));
|
|
|
|
$rule = $this->rules[$this->item];
|
|
|
|
//Apply item parameters
|
|
/*if ( array_key_exists('params', $rule) && count($rule['params'])>0 ) {
|
|
foreach ( $rule['params'] as $param ) {
|
|
$this->sql->where($param);
|
|
}
|
|
}*/
|
|
$this->sql->where('source=?', $this->item);
|
|
|
|
$this->sql->order('dateAjout ASC');
|
|
}
|
|
|
|
} |