mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-24 02:13:15 +00:00
Fix #1528 : Restrict collection ordering on available collections
This commit is contained in:
@@ -972,7 +972,7 @@ class Databox implements ControllerProviderInterface
|
||||
public function getReorder(Application $app, Request $request, $databox_id)
|
||||
{
|
||||
return $app['twig']->render('admin/collection/reorder.html.twig', array(
|
||||
'databox' => $app['phraseanet.appbox']->get_databox($databox_id),
|
||||
'collections' => $app['authentication']->getUser()->ACL()->get_granted_base(array(), array($databox_id)),
|
||||
));
|
||||
}
|
||||
|
||||
@@ -986,19 +986,14 @@ class Databox implements ControllerProviderInterface
|
||||
*/
|
||||
public function setReorder(Application $app, Request $request, $databox_id)
|
||||
{
|
||||
$success = false;
|
||||
|
||||
try {
|
||||
foreach ($request->request->get('order', array()) as $order => $data) {
|
||||
$baseId = $data['id'];
|
||||
$collection = \collection::get_from_base_id($app, $baseId);
|
||||
$app['phraseanet.appbox']->set_collection_order($collection, $order);
|
||||
unset($collection);
|
||||
foreach ($request->request->get('order', array()) as $data) {
|
||||
$collection = \collection::get_from_base_id($app, $data['id']);
|
||||
$collection->set_ord($data['offset']);
|
||||
}
|
||||
|
||||
$success = true;
|
||||
} catch (\Exception $e) {
|
||||
|
||||
$success = false;
|
||||
}
|
||||
|
||||
if ('json' === $app['request']->getRequestFormat()) {
|
||||
|
||||
@@ -36,6 +36,7 @@ class collection implements cache_cacheableInterface
|
||||
protected $databox;
|
||||
protected $is_active;
|
||||
protected $binary_logo;
|
||||
protected $ord;
|
||||
protected $app;
|
||||
|
||||
const PIC_LOGO = 'minilogos';
|
||||
@@ -63,6 +64,7 @@ class collection implements cache_cacheableInterface
|
||||
$this->available = $datas['available'];
|
||||
$this->pub_wm = $datas['pub_wm'];
|
||||
$this->name = $datas['name'];
|
||||
$this->ord = $datas['ord'];
|
||||
$this->prefs = $datas['prefs'];
|
||||
$this->labels = $datas['labels'];
|
||||
|
||||
@@ -96,7 +98,7 @@ class collection implements cache_cacheableInterface
|
||||
|
||||
$conn = connection::getPDOConnection($this->app);
|
||||
|
||||
$sql = 'SELECT server_coll_id, sbas_id, base_id, active FROM bas
|
||||
$sql = 'SELECT server_coll_id, sbas_id, base_id, active, ord FROM bas
|
||||
WHERE server_coll_id = :coll_id AND sbas_id = :sbas_id';
|
||||
|
||||
$stmt = $conn->prepare($sql);
|
||||
@@ -109,6 +111,7 @@ class collection implements cache_cacheableInterface
|
||||
if ($row) {
|
||||
$this->is_active = ! ! $row['active'];
|
||||
$this->base_id = (int) $row['base_id'];
|
||||
$this->ord = (int) $row['ord'];
|
||||
}
|
||||
|
||||
$stmt->closeCursor();
|
||||
@@ -119,6 +122,7 @@ class collection implements cache_cacheableInterface
|
||||
, 'available' => $this->available
|
||||
, 'pub_wm' => $this->pub_wm
|
||||
, 'name' => $this->name
|
||||
, 'ord' => $this->ord
|
||||
, 'prefs' => $this->prefs
|
||||
, 'labels' => $this->labels
|
||||
);
|
||||
@@ -144,6 +148,20 @@ class collection implements cache_cacheableInterface
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function get_ord()
|
||||
{
|
||||
return $this->ord;
|
||||
}
|
||||
|
||||
public function set_ord($ord)
|
||||
{
|
||||
$this->app['phraseanet.appbox']->set_collection_order($this, $ord);
|
||||
$this->delete_data_from_cache();
|
||||
$this->app['phraseanet.appbox']->delete_data_from_cache(appbox::CACHE_LIST_BASES);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function disable(appbox $appbox)
|
||||
{
|
||||
$sql = 'UPDATE bas SET active=0 WHERE base_id = :base_id';
|
||||
|
||||
90
lib/classes/patch/3819.php
Normal file
90
lib/classes/patch/3819.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?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.
|
||||
*/
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Symfony\Component\Process\ExecutableFinder;
|
||||
|
||||
class patch_3819 implements patchInterface
|
||||
{
|
||||
/** @var string */
|
||||
private $release = '3.8.1';
|
||||
|
||||
/** @var array */
|
||||
private $concern = array(base::APPLICATION_BOX);
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function get_release()
|
||||
{
|
||||
return $this->release;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function require_all_upgrades()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function concern()
|
||||
{
|
||||
return $this->concern;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function apply(base $appbox, Application $app)
|
||||
{
|
||||
$sql = 'SELECT base_id, ord, sbas_id
|
||||
FROM `bas`
|
||||
ORDER BY sbas_id, ord';
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
$stmt->execute();
|
||||
$rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
$stmt->closeCursor();
|
||||
|
||||
$sbasData = array();
|
||||
$sbas_id = null;
|
||||
$reorder = array();
|
||||
foreach ($rs as $row) {
|
||||
$sbasData[$row['sbas_id']][] = array('base_id' => $row['base_id']);
|
||||
if ($sbas_id !== $row['sbas_id']) {
|
||||
$orders = array();
|
||||
}
|
||||
$sbas_id = $row['sbas_id'];
|
||||
if (in_array($row['ord'], $orders, true)) {
|
||||
$reorder[] = $row['sbas_id'];
|
||||
}
|
||||
$orders[] = $row['ord'];
|
||||
}
|
||||
$reorder = array_unique($reorder);
|
||||
|
||||
if (count($reorder) > 0) {
|
||||
$sql = 'UPDATE bas SET ord = :ord WHERE base_id = :base_id';
|
||||
$stmt = $appbox->get_connection()->prepare($sql);
|
||||
foreach ($reorder as $sbas_id) {
|
||||
$i = 1;
|
||||
foreach ($sbasData[$sbas_id] as $data) {
|
||||
$stmt->execute(array('base_id' => $data['base_id'], 'ord' => $i++));
|
||||
}
|
||||
}
|
||||
$stmt->closeCursor();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
<tr>
|
||||
<td valign="center" align="center">
|
||||
<select size=16 name="coll-order" id="coll-order" style="width:140px;">
|
||||
{% for collection in databox.get_collections() %}
|
||||
{% for collection in collections %}
|
||||
<option value="{{ collection.get_base_id() }}"> {{ collection.get_name() }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
@@ -35,6 +35,11 @@
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function(){
|
||||
var offsets = [
|
||||
{% for collection in collections %}
|
||||
{% if not loop.first %},{% endif %} {{ collection.get_ord() }}
|
||||
{% endfor %}
|
||||
];
|
||||
var select = $("#coll-order");
|
||||
var upButton = $('#upbutton');
|
||||
var downButton = $('#downbutton');
|
||||
@@ -63,9 +68,11 @@
|
||||
applyButton.bind('click', function() {
|
||||
var $this = $(this);
|
||||
var order = [];
|
||||
// clone the array
|
||||
var appliedoffsets = offsets.slice(0);
|
||||
|
||||
select.find('option').each(function(i, option){
|
||||
order[i] = {id: $(this).val(), name: $(this).text()};
|
||||
order.push({id: $(this).val(), offset: appliedoffsets.shift()});
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
|
||||
Reference in New Issue
Block a user