mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 15:03:25 +00:00
V 3.5 RC 1
This commit is contained in:
99
lib/classes/appbox/register.class.php
Normal file
99
lib/classes/appbox/register.class.php
Normal file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2010 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
* @package Appbox
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class appbox_register
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @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)
|
||||
{
|
||||
$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;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user