This commit is contained in:
Romain Neutron
2012-04-26 00:55:53 +02:00
parent edbfff226e
commit ade22295ad
631 changed files with 92375 additions and 101763 deletions

View File

@@ -17,83 +17,80 @@
*/
class appbox_register
{
/**
*
* @var appbox
*/
protected $appbox;
/**
*
* @var appbox
*/
protected $appbox;
/**
* Construct an Appbox_Register object which will give use infos
* about the current registrations on the provided appbox
*
* @param appbox $appbox
* @return appbox_register
*/
public function __construct(appbox &$appbox)
{
$this->appbox = $appbox;
return $this;
}
/**
* Add a registration request for a user on a collection
*
* @param User_Interface $user
* @param collection $collection
* @return appbox_register
*/
public function add_request(User_Interface $user, collection $collection)
{
$sql = "INSERT INTO demand (date_modif, usr_id, base_id, en_cours, refuser)
VALUES (now(), :usr_id , :base_id, 1, 0)";
$stmt = $this->appbox->get_connection()->prepare($sql);
$stmt->execute(array(':usr_id' => $user->get_id(), ':base_id' => $collection->get_base_id()));
$stmt->closeCursor();
return $this;
}
/**
* Return an array of collection objects where provided
* user is waiting for approbation
*
* @param User_Interface $user
* @return array
*/
public function get_collection_awaiting_for_user(User_Interface $user)
{
$sql = 'SELECT base_id FROM demand WHERE usr_id = :usr_id AND en_cours="1" ';
$stmt = $this->appbox->get_connection()->prepare($sql);
$stmt->execute(array(':usr_id' => $user->get_id()));
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$ret = array();
foreach ($rs as $row)
/**
* Construct an Appbox_Register object which will give use infos
* about the current registrations on the provided appbox
*
* @param appbox $appbox
* @return appbox_register
*/
public function __construct(appbox &$appbox)
{
$ret[] = collection::get_from_base_id($row['base_id']);
$this->appbox = $appbox;
return $this;
}
return $ret;
}
/**
* Add a registration request for a user on a collection
*
* @param User_Interface $user
* @param collection $collection
* @return appbox_register
*/
public function add_request(User_Interface $user, collection $collection)
{
$sql = "INSERT INTO demand (date_modif, usr_id, base_id, en_cours, refuser)
VALUES (now(), :usr_id , :base_id, 1, 0)";
$stmt = $this->appbox->get_connection()->prepare($sql);
$stmt->execute(array(':usr_id' => $user->get_id(), ':base_id' => $collection->get_base_id()));
$stmt->closeCursor();
/**
* Remove all registration older than a month
*
* @param appbox $appbox
* @return appbox_register
*/
public static function clean_old_requests(appbox $appbox)
{
$lastMonth = new DateTime('-1 month');
$sql = "delete from demand where date_modif < :lastMonth";
$stmt = $appbox->get_connection()->prepare($sql);
$stmt->execute(array(':lastMonth' => phraseadate::format_mysql($lastMonth)));
$stmt->closeCursor();
return $this;
}
return;
}
/**
* Return an array of collection objects where provided
* user is waiting for approbation
*
* @param User_Interface $user
* @return array
*/
public function get_collection_awaiting_for_user(User_Interface $user)
{
$sql = 'SELECT base_id FROM demand WHERE usr_id = :usr_id AND en_cours="1" ';
$stmt = $this->appbox->get_connection()->prepare($sql);
$stmt->execute(array(':usr_id' => $user->get_id()));
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->closeCursor();
$ret = array();
foreach ($rs as $row) {
$ret[] = collection::get_from_base_id($row['base_id']);
}
return $ret;
}
/**
* Remove all registration older than a month
*
* @param appbox $appbox
* @return appbox_register
*/
public static function clean_old_requests(appbox $appbox)
{
$lastMonth = new DateTime('-1 month');
$sql = "delete from demand where date_modif < :lastMonth";
$stmt = $appbox->get_connection()->prepare($sql);
$stmt->execute(array(':lastMonth' => phraseadate::format_mysql($lastMonth)));
$stmt->closeCursor();
return;
}
}