From 74ce2341a26f58823e52b80195874aacdec2bc5e Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Tue, 4 Sep 2012 19:45:41 +0200 Subject: [PATCH] delete set_ordermanager & set_exportorder classes --- lib/Alchemy/Phrasea/Application/Prod.php | 2 +- .../Phrasea/Controller/Admin/Collection.php | 8 +- lib/Alchemy/Phrasea/Controller/Prod/Order.php | 99 ++- lib/Alchemy/Phrasea/Controller/Prod/Root.php | 4 +- .../Phrasea/Controller/RecordsRequest.php | 15 +- lib/classes/User/Adapter.class.php | 28 + lib/classes/set/exportorder.class.php | 153 ----- lib/classes/set/order.class.php | 189 ++++++ lib/classes/set/ordermanager.class.php | 179 ------ templates/web/common/dialog_export.html.twig | 589 +++++++++--------- templates/web/prod/orders/order_box.html.twig | 135 ++-- .../web/prod/orders/order_item.html.twig | 178 +++--- .../Phrasea/Controller/Prod/OrderTest.php | 29 +- tests/PhraseanetPHPUnitAbstract.class.inc | 2 +- tests/record/adapterTest.php | 15 +- www/prod/page0.js | 4 +- www/skins/prod/000000/prodcolor.css | 9 + www/skins/prod/959595/prodcolor.css | 10 + 18 files changed, 807 insertions(+), 841 deletions(-) delete mode 100644 lib/classes/set/exportorder.class.php delete mode 100644 lib/classes/set/ordermanager.class.php diff --git a/lib/Alchemy/Phrasea/Application/Prod.php b/lib/Alchemy/Phrasea/Application/Prod.php index 99854892c7..e032dd2e87 100644 --- a/lib/Alchemy/Phrasea/Application/Prod.php +++ b/lib/Alchemy/Phrasea/Application/Prod.php @@ -71,7 +71,7 @@ return call_user_func(function() { $app->error(function (\Exception $e, $code) use ($app) { /* @var $request \Symfony\Component\HttpFoundation\Request */ $request = $app['request']; - + if ($request->getRequestFormat() == 'json') { $datas = array( 'success' => false diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Collection.php b/lib/Alchemy/Phrasea/Controller/Admin/Collection.php index 9449a99361..185fcaad2e 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Collection.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Collection.php @@ -439,14 +439,14 @@ class Collection implements ControllerProviderInterface public function setOrderAdmins(Application $app, Request $request, $bas_id) { if (count($admins = $request->request->get('admins', array())) > 0) { - $new_admins = array(); + $newAdmins = array(); foreach ($admins as $admin) { - $new_admins[] = $admin; + $newAdmins[] = $admin; } - if (count($new_admins) > 0) { - \set_exportorder::set_order_admins(array_filter($admins), $bas_id); + if (count($newAdmins) > 0) { + \User_Adapter::set_order_admins(array_filter($admins), $bas_id); } } diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Order.php b/lib/Alchemy/Phrasea/Controller/Prod/Order.php index 15c8eb6a89..90452f96f4 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Order.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Order.php @@ -11,6 +11,8 @@ namespace Alchemy\Phrasea\Controller\Prod; +use Alchemy\Phrasea\Controller\RecordsRequest; +use Doctrine\Common\Collections\ArrayCollection; use Silex\Application; use Silex\ControllerProviderInterface; use Symfony\Component\HttpFoundation\Request; @@ -48,8 +50,8 @@ class Order implements ControllerProviderInterface */ $controllers->get('/', $this->call('displayOrders')) ->before(function(Request $request) use ($app) { - $app['phraseanet.core']['Firewall']->requireOrdersAdmin($app); - }) + $app['phraseanet.core']['Firewall']->requireOrdersAdmin($app); + }) ->bind('prod_orders'); /** @@ -83,8 +85,8 @@ class Order implements ControllerProviderInterface */ $controllers->get('/{order_id}/', $this->call('displayOneOrder')) ->before(function(Request $request) use ($app) { - $app['phraseanet.core']['Firewall']->requireOrdersAdmin($app); - }) + $app['phraseanet.core']['Firewall']->requireOrdersAdmin($app); + }) ->bind('prod_order') ->assert('order_id', '\d+'); @@ -103,8 +105,8 @@ class Order implements ControllerProviderInterface */ $controllers->post('/{order_id}/send/', $this->call('sendOrder')) ->before(function(Request $request) use ($app) { - $app['phraseanet.core']['Firewall']->requireOrdersAdmin($app); - }) + $app['phraseanet.core']['Firewall']->requireOrdersAdmin($app); + }) ->bind('prod_order_send') ->assert('order_id', '\d+'); @@ -123,8 +125,8 @@ class Order implements ControllerProviderInterface */ $controllers->post('/{order_id}/deny/', $this->call('denyOrder')) ->before(function(Request $request) use ($app) { - $app['phraseanet.core']['Firewall']->requireOrdersAdmin($app); - }) + $app['phraseanet.core']['Firewall']->requireOrdersAdmin($app); + }) ->bind('prod_order_deny') ->assert('order_id', '\d+'); @@ -142,31 +144,65 @@ class Order implements ControllerProviderInterface public function createOrder(Application $app, Request $request) { $success = false; + $collectionHasOrderAdmins = new ArrayCollection(); try { - $order = new \set_exportorder($request->request->get('lst', ''), (int) $request->request->get('ssttid')); + $records = RecordsRequest::fromRequest($app, $request, true, array('cancmd')); + + $query = new \User_Query($app['phraseanet.appbox']); + + foreach ($records as $key => $record) { + if ($collectionHasOrderAdmins->containsKey($record->get_base_id())) { + if ( ! $collectionHasOrderAdmins->get($record->get_base_id())) { + $records->remove($key); + } + } + + $hasOneAdmin = ! ! count($query->on_base_ids(array($record->get_base_id())) + ->who_have_right(array('order_master')) + ->execute()->get_results()); + + $collectionHasOrderAdmins->set($record->get_base_id(), $hasOneAdmin); + + if ( ! $hasOneAdmin) { + $records->remove($key); + } + } + + $noAdmins = $collectionHasOrderAdmins->forAll(function($key, $hasAdmin) { + return false === $hasAdmin; + }); + + if ($noAdmins) { + $msg = _('There is no one to validate orders, please contact an administrator'); + } + + if (count($records) > 0) { + \set_order::create( + $app['phraseanet.appbox'], $records, $app['phraseanet.core']->getAuthenticatedUser(), $request->request->get('use', ''), ( (null !== $deadLine = $request->request->get('deadline')) ? new \DateTime($deadLine) : $deadLine) + ); - if ($order->order_available_elements( - $app['phraseanet.core']->getAuthenticatedUser()->get_id(), $request->request->get('use', ''), $request->request->get('deadline', '') - )) { $success = true; + $msg = _('The records have been properly ordered'); + } else { + $msg = _('There is no record eligible for an order'); } } catch (\Exception $e) { - $msg = $e->getMessage(); + $msg = _('An error occured'); } if ('json' === $app['request']->getRequestFormat()) { return $app->json(array( 'success' => $success, - 'msg' => $success ? _('The records have been properly ordered') : _('An error occured') . ' ' . $msg, + 'msg' => $msg, )); } return $app->redirect($app['url_generator']->generate('prod_orders', array( - 'success' => (int) $success, - 'action' => 'send' - ))); + 'success' => (int) $success, + 'action' => 'send' + ))); } /** @@ -179,8 +215,23 @@ class Order implements ControllerProviderInterface */ public function displayOrders(Application $app, Request $request) { + $page = (int) $request->query->get('page', 1); + $offsetStart = $page - 1; + $perPage = (int) $request->query->get('per-page', 10); + $sort = $request->query->get('sort'); + + $baseIds = array_keys($app['phraseanet.core']->getAuthenticatedUser()->ACL()->get_granted_base(array('order_master'))); + + $ordersList = \set_order::listOrders($app['phraseanet.appbox'], $baseIds, $offsetStart, $perPage, $sort); + $total = \set_order::countTotalOrder($app['phraseanet.appbox'], $baseIds); + return $app['twig']->render('prod/orders/order_box.html.twig', array( - 'ordermanager' => new \set_ordermanager( ! ! $request->query->get('sort', false), (int) $request->query->get('page', 1)) + 'page' => $page, + 'perPage' => $perPage, + 'total' => $total, + 'previousPage' => $page < 2 ? false : ($page - 1), + 'nextPage' => $page >= ceil($total / $perPage) ? false : $page + 1, + 'orders' => new ArrayCollection($ordersList) )); } @@ -240,9 +291,9 @@ class Order implements ControllerProviderInterface } return $app->redirect($app['url_generator']->generate('prod_orders', array( - 'success' => (int) $success, - 'action' => 'send' - ))); + 'success' => (int) $success, + 'action' => 'send' + ))); } /** @@ -280,9 +331,9 @@ class Order implements ControllerProviderInterface } return $app->redirect($app['url_generator']->generate('prod_orders', array( - 'success' => (int) $success, - 'action' => 'send' - ))); + 'success' => (int) $success, + 'action' => 'send' + ))); } /** diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Root.php b/lib/Alchemy/Phrasea/Controller/Prod/Root.php index cbd200ebb2..ac73683bc2 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Root.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Root.php @@ -122,11 +122,11 @@ class Root implements ControllerProviderInterface $controllers->post('/multi-export/', function(Application $app, Request $request) { - $download = new \set_export($request->request->get('lst', ''), (int) $request->request->get('SSTTID'), $request->request->get('story')); + $download = new \set_export($request->request->get('lst', ''), (int) $request->request->get('ssel'), $request->request->get('story')); return $app['twig']->render('common/dialog_export.html.twig', array( 'download' => $download, - 'ssttid' => (int) $request->request->get('SSTTID'), + 'ssttid' => (int) $request->request->get('ssel'), 'lst' => $download->serialize_list(), 'default_export_title' => $app['phraseanet.core']['Registry']->get('GV_default_export_title'), 'choose_export_title' => $app['phraseanet.core']['Registry']->get('GV_choose_export_title') diff --git a/lib/Alchemy/Phrasea/Controller/RecordsRequest.php b/lib/Alchemy/Phrasea/Controller/RecordsRequest.php index 474ff91f72..28e17b5645 100644 --- a/lib/Alchemy/Phrasea/Controller/RecordsRequest.php +++ b/lib/Alchemy/Phrasea/Controller/RecordsRequest.php @@ -67,7 +67,7 @@ class RecordsRequest extends ArrayCollection { return new ArrayCollection( array_filter($this->toArray(), function(\record_adapter $record) { - return $record->is_grouping(); + return $record->is_grouping(); }) ); } @@ -107,12 +107,13 @@ class RecordsRequest extends ArrayCollection } /** + * Create a new RecordRequest from current request * - * @param \Alchemy\Phrasea\Application $app - * @param \Symfony\Component\HttpFoundation\Request $request - * @param type $flattenStories - * @param array $rightsColl - * @param array $rightsDatabox + * @param Application $app + * @param Request $request + * @param boolean $flattenStories + * @param array $rightsColl + * @param array $rightsDatabox * @return RecordsRequest */ public static function fromRequest(Application $app, Request $request, $flattenStories = false, array $rightsColl = array(), array $rightsDatabox = array()) @@ -165,12 +166,14 @@ class RecordsRequest extends ArrayCollection $to_remove[] = $id; continue; } + foreach ($rightsColl as $right) { if ( ! $user->ACL()->has_right_on_base($record->get_base_id(), $right)) { $to_remove[] = $id; continue; } } + foreach ($rightsDatabox as $right) { if ( ! $user->ACL()->has_right_on_sbas($record->get_sbas_id(), $right)) { $to_remove[] = $id; diff --git a/lib/classes/User/Adapter.class.php b/lib/classes/User/Adapter.class.php index b87730171f..0107226502 100644 --- a/lib/classes/User/Adapter.class.php +++ b/lib/classes/User/Adapter.class.php @@ -1650,6 +1650,34 @@ class User_Adapter implements User_Interface, cache_cacheableInterface return; } + 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; + } + public static function get_locale($usr_id) { $locale = 'en_GB'; diff --git a/lib/classes/set/exportorder.class.php b/lib/classes/set/exportorder.class.php deleted file mode 100644 index cae559307c..0000000000 --- a/lib/classes/set/exportorder.class.php +++ /dev/null @@ -1,153 +0,0 @@ -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; - } -} diff --git a/lib/classes/set/order.class.php b/lib/classes/set/order.class.php index 2f01a426f6..65654f24f3 100644 --- a/lib/classes/set/order.class.php +++ b/lib/classes/set/order.class.php @@ -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; + } } diff --git a/lib/classes/set/ordermanager.class.php b/lib/classes/set/ordermanager.class.php deleted file mode 100644 index e17eaac5b2..0000000000 --- a/lib/classes/set/ordermanager.class.php +++ /dev/null @@ -1,179 +0,0 @@ -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; - } -} diff --git a/templates/web/common/dialog_export.html.twig b/templates/web/common/dialog_export.html.twig index 47cfe55e77..c3f3ed3546 100644 --- a/templates/web/common/dialog_export.html.twig +++ b/templates/web/common/dialog_export.html.twig @@ -96,21 +96,87 @@
  • {% trans 'export:: FTP' %}
  • {% endif %} -
    - {% if download.get_total_download() > 0 %} -
    -
    -

    {% trans 'export:: telechargement' %}

    -
    - - + {% if download.get_total_download() > 0 %} +
    +
    +

    {% trans 'export:: telechargement' %}

    + + + + {% for name, values in download.get_display_download() %} + {% if values.available > 0 %} +
    + + {% set title%} + {% trans 'Documents indisponibles' %} + {% endset %} + {% if values.refused|length > 0 %} + + + + {% endif %} +
    + {% endif %} + {% endfor %} + {% if download.has_business_fields_access() %} + + {% endif %} + {{ _self.choose_title('download', choose_export_title, default_export_title) }} +
    + + +
    + +
    +
    +
    +
    +

    {% trans 'export:: envoi par mail' %}

    +
    + + +
    + {% trans 'export::mail: destinataire' %} + + {% set my_email = user.get_email() %} + {% if my_email != '' %} + + {% else %} + + {% endif %} + {% trans 'Entrez plusieurs adresses email en les separant par des points-virgules' %} +
    +
    +

    {% trans 'export::mail: contenu du mail' %}

    + +
    +
    +

    {% trans 'export::mail: fichiers joint' %}

    {% for name, values in download.get_display_download() %} {% if values.available > 0 %}
    -
    -
    -
    -
    -

    {% trans 'export:: envoi par mail' %}

    -
    - - -
    - {% trans 'export::mail: destinataire' %} - - {% set my_email = user.get_email() %} - {% if my_email != '' %} - - {% else %} - - {% endif %} - {% trans 'Entrez plusieurs adresses email en les separant par des points-virgules' %} -
    -
    -

    {% trans 'export::mail: contenu du mail' %}

    - -
    -
    -

    {% trans 'export::mail: fichiers joint' %}

    - {% for name, values in download.get_display_download() %} - {% if values.available > 0 %} -
    - - {% set title%} - {% trans 'Documents indisponibles' %} - {% endset %} - {% if values.refused|length > 0 %} - + - - {% endif %} -
    - {% endif %} - {% endfor %} -
    - {% if download.has_business_fields_access() %} - - {% endif %} - {{ _self.choose_title('sendmail', choose_export_title, default_export_title) }} -
    - - - -
    -
    - -
    -
    - {% endif %} - {% if download.get_total_order() > 0 %} -
    - {% for name, values in download.get_display_orderable() %} - {% if values.available > 0 %} -
    - {% set docs_orderable = values.available %} - {% trans %}{{docs_orderable}} documents commandes{% endtrans %} - {% set docs_not_orderable = values.total - values.available %} - {% if docs_not_orderable > 0%} - {% trans %}{{docs_not_orderable}} documents ne peuvent pas etre commandes{% endtrans %} - {% endif %} - {% set title%} - {% trans 'Documents indisponibles' %} - {% endset %} - {% if values.refused|length > 0 %} - + - - {% endif %} +
    + {% if download.has_business_fields_access() %} + {% endif %} - {% endfor %} -
    -
    - - - -
    - -
    - -
    -
    - -
    - -
    - -
    -
    - -
    - -
    - -
    -
    - -
    - -
    - -
    -
    - -
    - -
    - -
    -
    - -
    - -
    - -
    -
    - -
    - -
    - -
    -
    - -
    - -
    - -
    -
    - -
    - -
    - -
    -
    - -
    - -
    - -
    -
    - -
    - -
    - -
    -
    - -
    - -
    - -
    -
    - -
    - -
    - -
    -
    - -
    - - - -
    -
    + {{ _self.choose_title('sendmail', choose_export_title, default_export_title) }} +
    + + + +
    + +
    - {% endif %} - {% if download.get_total_ftp() > 0 %} -
    -
    -

    {% trans 'export:: FTP' %}

    -
    - - -
    - -
    - -
    -
    -
    -
    - {% for datas in download.get_ftp_datas() %} - {{ _self.print_ftp_form(datas) }} +
    + {% endif %} + {% if download.get_total_order() > 0 %} +
    + {% for name, values in download.get_display_orderable() %} + {% if values.available > 0 %} +
    + {% set docs_orderable = values.available %} + {% trans %}{{docs_orderable}} documents commandes{% endtrans %} + {% set docs_not_orderable = values.total - values.available %} + {% if docs_not_orderable > 0%} + {% trans %}{{docs_not_orderable}} documents ne peuvent pas etre commandes{% endtrans %} + {% endif %} + {% set title%} + {% trans 'Documents indisponibles' %} + {% endset %} + {% if values.refused|length > 0 %} + + + + {% endif %} +
    + {% endif %} + {% endfor %} +
    + + + + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + +
    + +
    +
    + +
    + + + +
    + +
    + {% endif %} + {% if download.get_total_ftp() > 0 %} +
    +
    +

    {% trans 'export:: FTP' %}

    +
    + + +
    + +
    +
    -
    -

    {% trans 'export::mail: fichiers joint' %}

    - {% for name, values in download.get_display_ftp() %} - {% if values.available > 0 %} -
    - - {% set title%} - {% trans 'Documents indisponibles' %} - {% endset %} - {% if values.refused|length > 0 %} - + - - {% endif %} -
    - {% endif %} +
    +
    +
    + {% for datas in download.get_ftp_datas() %} + {{ _self.print_ftp_form(datas) }} {% endfor %}
    - {% if download.has_business_fields_access() %} - - {% endif %} -
    - - - - - +
    +
    +

    {% trans 'export::mail: fichiers joint' %}

    + {% for name, values in download.get_display_ftp() %} + {% if values.available > 0 %} +
    + + {% set title%} + {% trans 'Documents indisponibles' %} + {% endset %} + {% if values.refused|length > 0 %} + + + + {% endif %} +
    + {% endif %} + {% endfor %} +
    + {% if download.has_business_fields_access() %} + - -
    + {% endif %} +
    + + + + + +
    +
    - {% endif %} -
    +
    + {% endif %} +