diff --git a/lib/Alchemy/Phrasea/Controller/Prod/RootController.php b/lib/Alchemy/Phrasea/Controller/Prod/RootController.php index 27703da663..0c804b781c 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/RootController.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/RootController.php @@ -131,7 +131,6 @@ class RootController extends Controller 'thesau_languages' => $this->app['locales.available'], ]); } - /** * @return DisplaySettingService */ diff --git a/lib/Alchemy/Phrasea/Helper/Prod.php b/lib/Alchemy/Phrasea/Helper/Prod.php index e4f0f1313b..a6685c3fc2 100644 --- a/lib/Alchemy/Phrasea/Helper/Prod.php +++ b/lib/Alchemy/Phrasea/Helper/Prod.php @@ -53,19 +53,17 @@ class Prod extends Helper $data = array('sbas' => array($sbasId), 'fieldname' => $name, 'type' => $type, 'id' => $id); if ($fieldMeta->get_type() === \databox_field::TYPE_DATE) { - if (isset($dates[$id])) { - $dates[$id]['sbas'][] = $sbasId; - } else { - $dates[$id] = $data; + if (!array_key_exists($name, $dates)) { + $dates[$name] = array('sbas' => array()); } + $dates[$name]['sbas'][] = $sbasId; } if ($fieldMeta->get_type() == \databox_field::TYPE_NUMBER || $fieldMeta->get_type() === \databox_field::TYPE_DATE) { - if (isset($sort[$id])) { - $sort[$id]['sbas'][] = $sbasId; - } else { - $sort[$id] = $data; + if (!array_key_exists($name, $sort)) { + $sort[$name] = array('sbas' => array()); } + $sort[$name]['sbas'][] = $sbasId; } if (isset($fields[$name])) { diff --git a/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php b/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php index 82ff905e90..efafcc1cc8 100644 --- a/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php +++ b/lib/Alchemy/Phrasea/SearchEngine/Elastic/ElasticSearchEngine.php @@ -253,7 +253,9 @@ class ElasticSearchEngine implements SearchEngineInterface $context = $this->createQueryContext($options); /** @var QueryCompiler $query_compiler */ $query_compiler = $this->app['query_compiler']; +file_put_contents("/tmp/phraseanet-log.txt", sprintf("%s (%d)\n%s\n", __FILE__, __LINE__, var_export($string, true)), FILE_APPEND); $recordQuery = $query_compiler->compile($string, $context); +file_put_contents("/tmp/phraseanet-log.txt", sprintf("%s (%d)\n%s\n", __FILE__, __LINE__, var_export($recordQuery, true)), FILE_APPEND); $params = $this->createRecordQueryParams($recordQuery, $options, null); @@ -272,8 +274,10 @@ class ElasticSearchEngine implements SearchEngineInterface if ($aggs = $this->getAggregationQueryParams($options)) { $params['body']['aggs'] = $aggs; } +file_put_contents("/tmp/phraseanet-log.txt", sprintf("%s (%d)\n%s\n", __FILE__, __LINE__, var_export($params, true)), FILE_APPEND); $res = $this->client->search($params); +file_put_contents("/tmp/phraseanet-log.txt", sprintf("%s (%d)\n%s\n", __FILE__, __LINE__, var_export($res, true)), FILE_APPEND); $results = new ArrayCollection(); @@ -289,7 +293,7 @@ class ElasticSearchEngine implements SearchEngineInterface $query['query_main'] = $recordQuery; $query['query'] = $params['body']; $query['query_string'] = json_encode($params['body']); - +file_put_contents("/tmp/phraseanet-log.txt", sprintf("%s (%d)\n%s\n", __FILE__, __LINE__, var_export($query['query_string'], true)), FILE_APPEND); return new SearchEngineResult( $results, // ArrayCollection of results json_encode($query), diff --git a/lib/classes/ACL.php b/lib/classes/ACL.php index fbd87f10ef..556e69bcfe 100644 --- a/lib/classes/ACL.php +++ b/lib/classes/ACL.php @@ -728,11 +728,11 @@ class ACL implements cache_cacheableInterface } /** - * Return an array of sbas_id which are granted, with + * Return an array of databox (key=sbas_id) which are granted, with * optionnal filter by rights * * @param Array $rights - * @return Array + * @return \databox[] */ public function get_granted_sbas($rights = []) { diff --git a/lib/classes/databox/status.php b/lib/classes/databox/status.php index 4882c14cc4..c69d3806a8 100644 --- a/lib/classes/databox/status.php +++ b/lib/classes/databox/status.php @@ -21,25 +21,34 @@ class databox_status { public static function getSearchStatus(Application $app) { - $see_all = $structures = $stats = []; + $structures = $stats = []; foreach ($app->getAclForUser($app->getAuthenticatedUser())->get_granted_sbas() as $databox) { - $see_all[$databox->get_sbas_id()] = false; + $see_all = false; foreach ($databox->get_collections() as $collection) { if ($app->getAclForUser($app->getAuthenticatedUser())->has_right_on_base($collection->get_base_id(), 'chgstatus')) { - $see_all[$databox->get_sbas_id()] = true; + $see_all = true; break; } } - $structures[$databox->get_sbas_id()] = $databox->getStatusStructure(); - } - - foreach ($structures as $databox_id => $structure) { - if (false === $see_all[$databox_id]) { - $structure = array_filter($structure->toArray(), function ($status) { - return (bool) $status['searchable']; + $status = $databox->getStatusStructure()->toArray(); + if (!$see_all) { + $status = array_filter($status, function ($statusbit) { + return (bool)$statusbit['searchable']; }); } + ksort($status); + $structures[$databox->get_sbas_id()] = array( + 'name' => $databox->get_label($app['locale']), + 'status'=>$status + ); + } + ksort($structures); +file_put_contents("/tmp/phraseanet-log.txt", sprintf("%s (%d) %s\n", __FILE__, __LINE__, var_export($structures, true)), FILE_APPEND); + + return $structures; + + foreach ($structures as $databox_id => $structure) { foreach($structure as $bit => $status) { $key = RecordHelper::normalizeFlagKey($status['labelon']); @@ -53,6 +62,96 @@ class databox_status $stats[$key] = $status; } } +file_put_contents("/tmp/phraseanet-log.txt", sprintf("%s (%d) %s\n", __FILE__, __LINE__, var_export($stats, true)), FILE_APPEND); + return $stats; + } + + public static function no_getSearchStatus(Application $app) + { + $see_all = $structures = $stats = []; + foreach ($app->getAclForUser($app->getAuthenticatedUser())->get_granted_sbas() as $databox) { + $see_all[$databox->get_sbas_id()] = false; + foreach ($databox->get_collections() as $collection) { + if ($app->getAclForUser($app->getAuthenticatedUser())->has_right_on_base($collection->get_base_id(), 'chgstatus')) { + $see_all[$databox->get_sbas_id()] = true; + break; + } + } + $structures[$databox->get_sbas_id()] = $databox->getStatusStructure(); + } + + // order the result by bit number, ... + $tbits = []; + foreach ($structures as $databox_id => $structure) { + if (false === $see_all[$databox_id]) { + $structure = array_filter($structure->toArray(), function ($status) { + return (bool)$status['searchable']; + }); + } + foreach($structure as $bit => $status) { + if(!array_key_exists($bit, $tbits)) { + $tbits[$bit] = []; + } + $tbits[$bit][$databox_id] = $status; + } + } + ksort($tbits); +// file_put_contents("/tmp/phraseanet-log.txt", sprintf("%s (%d) %s\n", __FILE__, __LINE__, var_export($tbits, true)), FILE_APPEND); + + // ... but group the status with same name + foreach($tbits as $bit=>$tbas) { + foreach($tbas as $sbas_id=>$status) { + // the group-key is the "labelon" + $key = RecordHelper::normalizeFlagKey($status['labelon']); + if(!array_key_exists($key, $stats)) { + $stats[$key] = $status; + $stats[$key]['sbas'] = []; + // $stats[$key]['tbas'] = []; + } + else { + /* + if($stats[$key]['bit'] != $bit) { + // error : in es, 2 sb with same name MUST be at the same position + throw new UnexpectedValueException( + sprintf("statusbit '%s' found at position %d and position %d" + , $key, $stats[$key]['bit'], $bit + ) + ); + } + */ + } + $stats[$key]['sbas'][] = $sbas_id; + // $stats[$key]['tbas'][$sbas_id] = $status; + } + } + file_put_contents("/tmp/phraseanet-log.txt", sprintf("%s (%d) %s\n", __FILE__, __LINE__, var_export($stats, true)), FILE_APPEND); + return $stats; + + + + foreach ($structures as $databox_id => $structure) { + file_put_contents("/tmp/phraseanet-log.txt", sprintf("%s (%d) %s\n%s\n", __FILE__, __LINE__, var_export($databox_id, true), var_export($structure->toArray(), true)), FILE_APPEND); + if (false === $see_all[$databox_id]) { + $structure = array_filter($structure->toArray(), function ($status) { + return (bool) $status['searchable']; + }); + } + + foreach($structure as $bit => $status) { + $key = RecordHelper::normalizeFlagKey($status['labelon']); + file_put_contents("/tmp/phraseanet-log.txt", sprintf("%s (%d) %d:%s\n", __FILE__, __LINE__, $bit, $key), FILE_APPEND); + + if (isset($stats[$key])) { + $status = $stats[$key]; + } + + $status['sbas'][] = $databox_id; + $status['bit'] = $bit; + + $stats[$key] = $status; + } + } + file_put_contents("/tmp/phraseanet-log.txt", sprintf("%s (%d) %s\n", __FILE__, __LINE__, var_export($stats, true)), FILE_APPEND); return $stats; } diff --git a/templates/web/prod/index.html.twig b/templates/web/prod/index.html.twig index 3666fda0d8..2bfdd369ac 100644 --- a/templates/web/prod/index.html.twig +++ b/templates/web/prod/index.html.twig @@ -3,9 +3,10 @@ {% for base in search_datas['bases'] %} {% set sbas_id = base['sbas_id'] %}
- -
-