mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-10 03:23:19 +00:00
delete set_ordermanager & set_exportorder classes
This commit is contained in:
@@ -1,153 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2012 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class set_exportorder extends set_export
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Int $from_usr_id
|
||||
* @param String $usage
|
||||
* @param String $deadline
|
||||
* @return boolean
|
||||
* @return $order_id
|
||||
*/
|
||||
public function order_available_elements($from_usr_id, $usage, $deadline)
|
||||
{
|
||||
$Core = bootstrap::getCore();
|
||||
|
||||
$lst = $this->get_orderable_lst();
|
||||
|
||||
$conn = connection::getPDOConnection();
|
||||
|
||||
$date = phraseadate::format_mysql(new DateTime($deadline));
|
||||
|
||||
$conn->beginTransaction();
|
||||
|
||||
$usage = p4string::cleanTags($usage);
|
||||
|
||||
try {
|
||||
|
||||
$sql = 'INSERT INTO `order`
|
||||
(`id`, `usr_id`, `created_on`, `usage`, `deadline`)
|
||||
VALUES
|
||||
(null, :from_usr_id, NOW(), :usage, :deadline)';
|
||||
|
||||
$params = array(
|
||||
':from_usr_id' => $from_usr_id
|
||||
, ':usage' => $usage
|
||||
, ':deadline' => $deadline
|
||||
);
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute($params);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$order_id = $conn->lastInsertId();
|
||||
|
||||
$sql = 'INSERT INTO order_elements
|
||||
(id, order_id, base_id, record_id, order_master_id)
|
||||
VALUES
|
||||
(null, :order_id, :base_id, :record_id, null)';
|
||||
$stmt = $conn->prepare($sql);
|
||||
|
||||
foreach ($lst as $basrec) {
|
||||
$basrec = explode('_', $basrec);
|
||||
|
||||
$record = new record_adapter($basrec[0], $basrec[1]);
|
||||
$base_id = $record->get_base_id();
|
||||
$record_id = $basrec[1];
|
||||
|
||||
$params = array(
|
||||
':order_id' => $order_id
|
||||
, ':base_id' => $base_id
|
||||
, ':record_id' => $record_id
|
||||
);
|
||||
$stmt->execute($params);
|
||||
}
|
||||
|
||||
$stmt->closeCursor();
|
||||
$conn->commit();
|
||||
} catch (Exception $e) {
|
||||
$conn->rollBack();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$evt_mngr = eventsmanager_broker::getInstance(appbox::get_instance($Core), $Core);
|
||||
|
||||
$params = array(
|
||||
'order_id' => $order_id,
|
||||
'usr_id' => $from_usr_id
|
||||
);
|
||||
|
||||
$evt_mngr->trigger('__NEW_ORDER__', $params);
|
||||
|
||||
return $order_id;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return Array
|
||||
*/
|
||||
protected function get_orderable_lst()
|
||||
{
|
||||
$ret = array();
|
||||
foreach ($this as $download_element) {
|
||||
foreach ($download_element->get_orderable() as $bool) {
|
||||
if ($bool === true) {
|
||||
$ret[] = $download_element->get_serialize_key();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Int $admins
|
||||
* @param Int $base_id
|
||||
* @return Void
|
||||
*/
|
||||
public static function set_order_admins($admins, $base_id)
|
||||
{
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
$conn = $appbox->get_connection();
|
||||
$conn->beginTransaction();
|
||||
try {
|
||||
$user_query = new User_Query($appbox);
|
||||
$result = $user_query->on_base_ids(array($base_id))
|
||||
->who_have_right(array('order_master'))
|
||||
->execute()->get_results();
|
||||
|
||||
foreach ($result as $user) {
|
||||
$user->ACL()->update_rights_to_base($base_id, array('order_master' => false));
|
||||
}
|
||||
|
||||
foreach ($admins as $admin) {
|
||||
$user = User_Adapter::getInstance($admin, $appbox);
|
||||
$user->ACL()->update_rights_to_base($base_id, array('order_master' => true));
|
||||
}
|
||||
|
||||
$conn->commit();
|
||||
} catch (Exception $e) {
|
||||
$conn->rollBack();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
@@ -9,6 +9,9 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use Alchemy\Phrasea\Controller\RecordsRequest;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
@@ -65,6 +68,138 @@ class set_order extends set_abstract
|
||||
*/
|
||||
protected $ssel_id;
|
||||
|
||||
/**
|
||||
* Create a new order entry
|
||||
*
|
||||
* @param RecordsRequest $recordsRequest
|
||||
* @param integer $orderer
|
||||
* @param string $usage
|
||||
* @param \DateTime $deadline
|
||||
* @return boolean
|
||||
*/
|
||||
public static function create(appbox $appbox, RecordsRequest $records, \User_Adapter $orderer, $usage, \DateTime $deadline = null)
|
||||
{
|
||||
$appbox->get_connection()->beginTransaction();
|
||||
|
||||
try {
|
||||
$sql = 'INSERT INTO `order` (`id`, `usr_id`, `created_on`, `usage`, `deadline`)
|
||||
VALUES (null, :from_usr_id, NOW(), :usage, :deadline)';
|
||||
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
|
||||
$stmt->execute(array(
|
||||
':from_usr_id' => $orderer->get_id(),
|
||||
':usage' => $usage,
|
||||
':deadline' => (null !== $deadline ? phraseadate::format_mysql($deadline) : $deadline)
|
||||
));
|
||||
|
||||
$stmt->closeCursor();
|
||||
|
||||
$orderId = $appbox->get_connection()->lastInsertId();
|
||||
|
||||
$sql = 'INSERT INTO order_elements (id, order_id, base_id, record_id, order_master_id)
|
||||
VALUES (null, :order_id, :base_id, :record_id, null)';
|
||||
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
|
||||
foreach ($records as $record) {
|
||||
$stmt->execute(array(
|
||||
':order_id' => $orderId,
|
||||
':base_id' => $record->get_base_id(),
|
||||
':record_id' => $record->get_record_id()
|
||||
));
|
||||
}
|
||||
|
||||
$stmt->closeCursor();
|
||||
$appbox->get_connection()->commit();
|
||||
} catch (Exception $e) {
|
||||
$appbox->get_connection()->rollBack();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$evt_mngr = eventsmanager_broker::getInstance($appbox, \bootstrap::getCore());
|
||||
|
||||
$evt_mngr->trigger('__NEW_ORDER__', array(
|
||||
'order_id' => $orderId,
|
||||
'usr_id' => $orderer->get_id()
|
||||
));
|
||||
|
||||
return new static($orderId);
|
||||
}
|
||||
|
||||
/**
|
||||
* List orders
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param array $baseIds
|
||||
* @param integer $offsetStart
|
||||
* @param integer $perPage
|
||||
* @return array
|
||||
*/
|
||||
public static function listOrders(appbox $appbox, array $baseIds, $offsetStart = 0, $perPage = 10, $sort = null)
|
||||
{
|
||||
|
||||
$sql = 'SELECT distinct o.id, o.usr_id, created_on, deadline, `usage`
|
||||
FROM (`order_elements` e, `order` o)
|
||||
WHERE e.base_id IN (' . implode(', ', $baseIds) . ')
|
||||
AND e.order_id = o.id
|
||||
GROUP BY o.id
|
||||
ORDER BY o.id DESC
|
||||
LIMIT ' . $offsetStart . ',' . $perPage;
|
||||
|
||||
$elements = array();
|
||||
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute();
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
foreach ($rs as $row) {
|
||||
$id = (int) $row['id'];
|
||||
$elements[$id] = new set_order($id);
|
||||
}
|
||||
|
||||
unset($stmt);
|
||||
|
||||
if ($sort && count($elements) > 0) {
|
||||
if ($sort == 'created_on') {
|
||||
uasort($elements, array(__CLASS__, 'date_orders_sort'));
|
||||
} elseif ($sort == 'user') {
|
||||
uasort($elements, array(__CLASS__, 'user_orders_sort'));
|
||||
} elseif ($sort == 'usage') {
|
||||
uasort($elements, array(__CLASS__, 'usage_orders_sort'));
|
||||
}
|
||||
}
|
||||
|
||||
return $elements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get total orders for selected base ids
|
||||
*
|
||||
* @param appbox $appbox
|
||||
* @param array $baseIds
|
||||
* @return integer
|
||||
*/
|
||||
public static function countTotalOrder(appbox $appbox, array $baseIds = array())
|
||||
{
|
||||
$sql = 'SELECT distinct o.id
|
||||
FROM (`order_elements` e, `order` o)
|
||||
WHERE ' . (count($baseIds > 0 ) ? 'e.base_id IN (' . implode(', ', $baseIds) . ') AND ': '' ).
|
||||
'e.order_id = o.id
|
||||
GROUP BY o.id
|
||||
ORDER BY o.id DESC';
|
||||
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute();
|
||||
$total = $stmt->rowCount();
|
||||
$stmt->closeCursor();
|
||||
unset($stmt);
|
||||
|
||||
return (int) $total;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param int $id
|
||||
@@ -363,4 +498,58 @@ class set_order extends set_abstract
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Order orders by usage
|
||||
*
|
||||
* @param string $a
|
||||
* @param string $b
|
||||
* @return int
|
||||
*/
|
||||
private static function usage_orders_sort($a, $b)
|
||||
{
|
||||
$comp = strcasecmp($a['usage'], $b['usage']);
|
||||
|
||||
if ($comp == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $comp < 0 ? -1 : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Order orders by user
|
||||
*
|
||||
* @param string $a
|
||||
* @param string $b
|
||||
* @return int
|
||||
*/
|
||||
private static function user_orders_sort($a, $b)
|
||||
{
|
||||
$comp = strcasecmp($a['usr_display'], $b['usr_display']);
|
||||
|
||||
if ($comp == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $comp < 0 ? -1 : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Order orders by date
|
||||
*
|
||||
* @param DateTime $a
|
||||
* @param DateTime $b
|
||||
* @return int
|
||||
*/
|
||||
private static function date_orders_sort(DateTime $a, DateTime $b)
|
||||
{
|
||||
$comp = $b->format('U') - $a->format('U');
|
||||
|
||||
if ($comp == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $comp < 0 ? -1 : 1;
|
||||
}
|
||||
}
|
||||
|
@@ -1,179 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2012 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
class set_ordermanager extends set_abstract
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $page;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $total;
|
||||
|
||||
const PER_PAGE = 10;
|
||||
|
||||
/**
|
||||
*
|
||||
* @return set_ordermanager
|
||||
*/
|
||||
public function __construct($sort = false, $page = 1)
|
||||
{
|
||||
$appbox = appbox::get_instance(\bootstrap::getCore());
|
||||
$session = $appbox->get_session();
|
||||
$conn = $appbox->get_connection();
|
||||
|
||||
$page = (int) $page;
|
||||
|
||||
$debut = ($page - 1) * self::PER_PAGE;
|
||||
|
||||
$user = User_Adapter::getInstance($session->get_usr_id(), $appbox);
|
||||
$base_ids = array_keys($user->ACL()->get_granted_base(array('order_master')));
|
||||
$sql = 'SELECT distinct o.id, o.usr_id, created_on, deadline, `usage`
|
||||
FROM (`order_elements` e, `order` o)
|
||||
WHERE e.base_id IN (' . implode(', ', $base_ids) . ')
|
||||
AND e.order_id = o.id
|
||||
GROUP BY o.id
|
||||
ORDER BY o.id DESC
|
||||
LIMIT ' . (int) $debut . ',' . self::PER_PAGE;
|
||||
|
||||
$elements = array();
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute();
|
||||
$rs = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
foreach ($rs as $row) {
|
||||
$elements[] = new set_order($row['id']);
|
||||
}
|
||||
|
||||
if ($sort) {
|
||||
if ($sort == 'created_on')
|
||||
uasort($elements, array('set_ordermanager', 'date_orders_sort'));
|
||||
elseif ($sort == 'user')
|
||||
uasort($elements, array('set_ordermanager', 'user_orders_sort'));
|
||||
elseif ($sort == 'usage')
|
||||
uasort($elements, array('set_ordermanager', 'usage_orders_sort'));
|
||||
}
|
||||
|
||||
$sql = 'SELECT distinct o.id
|
||||
FROM (`order_elements` e, `order` o)
|
||||
WHERE e.base_id IN (' . implode(', ', $base_ids) . ')
|
||||
AND e.order_id = o.id
|
||||
GROUP BY o.id
|
||||
ORDER BY o.id DESC';
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
$stmt->execute(array(':usr_id' => $session->get_usr_id()));
|
||||
$total = $stmt->rowCount();
|
||||
$stmt->closeCursor();
|
||||
|
||||
$this->elements = $elements;
|
||||
$this->page = $page;
|
||||
$this->total = $total;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_page()
|
||||
{
|
||||
return $this->page;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_previous_page()
|
||||
{
|
||||
$p_page = $this->page < 2 ? false : ($this->page - 1);
|
||||
|
||||
return $p_page;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function get_next_page()
|
||||
{
|
||||
$t_page = ceil($this->total / self::PER_PAGE);
|
||||
$n_page = $this->page >= $t_page ? false : $this->page + 1;
|
||||
|
||||
return $n_page;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $a
|
||||
* @param string $b
|
||||
* @return int
|
||||
*/
|
||||
protected static function usage_orders_sort($a, $b)
|
||||
{
|
||||
$comp = strcasecmp($a['usage'], $b['usage']);
|
||||
|
||||
if ($comp == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $comp < 0 ? -1 : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $a
|
||||
* @param string $b
|
||||
* @return int
|
||||
*/
|
||||
protected static function user_orders_sort($a, $b)
|
||||
{
|
||||
$comp = strcasecmp($a['usr_display'], $b['usr_display']);
|
||||
|
||||
if ($comp == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $comp < 0 ? -1 : 1;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param DateTime $a
|
||||
* @param DateTime $b
|
||||
* @return int
|
||||
*/
|
||||
protected static function date_orders_sort(DateTime $a, DateTime $b)
|
||||
{
|
||||
$comp = $b->format('U') - $a->format('U');
|
||||
|
||||
if ($comp == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $comp < 0 ? -1 : 1;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user