mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-08 18:44:30 +00:00

Conflicts: lib/Alchemy/Phrasea/Controller/Prod/Lazaret.php lib/classes/API/OAuth2/Adapter.php lib/classes/API/V1/adapter.php lib/classes/Feed/Adapter.php lib/classes/Feed/Collection.php lib/classes/Feed/Entry/Adapter.php lib/classes/Feed/Entry/Item.php lib/classes/Feed/Publisher/Adapter.php lib/classes/User/Adapter.php lib/classes/base.php lib/classes/connection.php lib/classes/databox/cgu.php lib/classes/eventsmanager/notify/autoregister.php lib/classes/eventsmanager/notify/bridgeuploadfail.php lib/classes/eventsmanager/notify/order.php lib/classes/eventsmanager/notify/orderdeliver.php lib/classes/eventsmanager/notify/ordernotdelivered.php lib/classes/eventsmanager/notify/push.php lib/classes/eventsmanager/notify/register.php lib/classes/eventsmanager/notify/validate.php lib/classes/eventsmanager/notify/validationdone.php lib/classes/eventsmanager/notify/validationreminder.php lib/classes/module/console/taskState.php lib/classes/module/console/taskrun.php lib/classes/record/adapter.php lib/classes/registry.php lib/classes/set/order.php lib/classes/task/abstract.php lib/classes/task/appboxAbstract.php lib/classes/task/databoxAbstract.php lib/classes/task/manager.php lib/classes/task/period/RecordMover.php lib/classes/task/period/apibridge.php lib/classes/task/period/archive.php lib/classes/task/period/ftp.php lib/classes/task/period/ftpPull.php templates/web/prod/upload/lazaret.html.twig
159 lines
4.5 KiB
PHP
159 lines
4.5 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Phraseanet
|
|
*
|
|
* (c) 2005-2014 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 Alchemy\Phrasea\Model\Entities\Basket;
|
|
|
|
class set_selection extends set_abstract
|
|
{
|
|
protected $app;
|
|
/**
|
|
*
|
|
* @return set_selection
|
|
*/
|
|
public function __construct(Application $app)
|
|
{
|
|
$this->app = $app;
|
|
$this->elements = [];
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param Basket $Basket
|
|
* @return set_selection
|
|
*/
|
|
public function load_basket(Basket $Basket)
|
|
{
|
|
foreach ($Basket->getElements() as $basket_element) {
|
|
$this->add_element($basket_element->getRecord($this->app));
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param array $rights
|
|
* @param array $sbas_rights
|
|
*
|
|
* @return set_selection
|
|
*/
|
|
public function grep_authorized(Array $rights = [], Array $sbas_rights = [])
|
|
{
|
|
$to_remove = [];
|
|
|
|
foreach ($this->elements as $id => $record) {
|
|
$base_id = $record->get_base_id();
|
|
$sbas_id = $record->get_sbas_id();
|
|
$record_id = $record->get_record_id();
|
|
if (! $rights) {
|
|
if ($this->app['acl']->get($this->app['authentication']->getUser())->has_hd_grant($record)) {
|
|
continue;
|
|
}
|
|
|
|
if ($this->app['acl']->get($this->app['authentication']->getUser())->has_preview_grant($record)) {
|
|
continue;
|
|
}
|
|
if ( ! $this->app['acl']->get($this->app['authentication']->getUser())->has_access_to_base($base_id)) {
|
|
$to_remove[] = $id;
|
|
continue;
|
|
}
|
|
} else {
|
|
foreach ($rights as $right) {
|
|
if ( ! $this->app['acl']->get($this->app['authentication']->getUser())->has_right_on_base($base_id, $right)) {
|
|
$to_remove[] = $id;
|
|
continue;
|
|
}
|
|
}
|
|
foreach ($sbas_rights as $right) {
|
|
if ( ! $this->app['acl']->get($this->app['authentication']->getUser())->has_right_on_sbas($sbas_id, $right)) {
|
|
$to_remove[] = $id;
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
|
|
try {
|
|
$connsbas = $record->get_databox()->get_connection();
|
|
|
|
$sql = 'SELECT record_id
|
|
FROM record
|
|
WHERE ((status ^ ' . $this->app['acl']->get($this->app['authentication']->getUser())->get_mask_xor($base_id) . ')
|
|
& ' . $this->app['acl']->get($this->app['authentication']->getUser())->get_mask_and($base_id) . ')=0
|
|
AND record_id = :record_id';
|
|
|
|
$stmt = $connsbas->prepare($sql);
|
|
$stmt->execute([':record_id' => $record_id]);
|
|
$num_rows = $stmt->rowCount();
|
|
$stmt->closeCursor();
|
|
|
|
if ($num_rows == 0) {
|
|
$to_remove[] = $id;
|
|
}
|
|
} catch (\Exception $e) {
|
|
|
|
}
|
|
}
|
|
foreach ($to_remove as $id) {
|
|
unset($this->elements[$id]);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param array $lst
|
|
* @param Boolean $flatten_groupings
|
|
*
|
|
* @return set_selection
|
|
*/
|
|
public function load_list(Array $lst, $flatten_groupings = false)
|
|
{
|
|
foreach ($lst as $basrec) {
|
|
$basrec = explode('_', $basrec);
|
|
if (count($basrec) == 2) {
|
|
try {
|
|
$record = new record_adapter($this->app, (int) $basrec[0], (int) $basrec[1], count($this->elements));
|
|
} catch (\Exception $e) {
|
|
continue;
|
|
}
|
|
if ($record->is_grouping() && $flatten_groupings === true) {
|
|
foreach ($record->get_children() as $rec) {
|
|
$this->add_element($rec);
|
|
}
|
|
} else {
|
|
$this->add_element($record);
|
|
}
|
|
}
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @return array
|
|
*/
|
|
public function get_distinct_sbas_ids()
|
|
{
|
|
$ret = [];
|
|
foreach ($this->elements as $record) {
|
|
$sbas_id = phrasea::sbasFromBas($this->app, $record->get_base_id());
|
|
$ret[$sbas_id] = $sbas_id;
|
|
}
|
|
|
|
return $ret;
|
|
}
|
|
}
|