mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-24 02:13:15 +00:00
PHRAS-294 #fix display sort & date fields in advanced search
This commit is contained in:
@@ -21,82 +21,78 @@ class Prod extends Helper
|
|||||||
|
|
||||||
public function get_search_datas()
|
public function get_search_datas()
|
||||||
{
|
{
|
||||||
$search_datas = array(
|
$searchData = array('bases' => array(), 'dates' => array(), 'fields' => array(), 'sort' => array(),);
|
||||||
'bases' => array(),
|
|
||||||
'dates' => array(),
|
|
||||||
'fields' => array()
|
|
||||||
);
|
|
||||||
|
|
||||||
$bases = $fields = $dates = array();
|
$bases = $fields = $dates = $sort = array();
|
||||||
|
|
||||||
if (!$this->app['authentication']->getUser() instanceof \User_Adapter) {
|
if (!$this->app['authentication']->getUser() instanceof \User_Adapter) {
|
||||||
return $search_datas;
|
return $searchData;
|
||||||
}
|
}
|
||||||
|
|
||||||
$searchSet = json_decode($this->app['authentication']->getUser()->getPrefs('search'), true);
|
$searchSet = json_decode($this->app['authentication']->getUser()->getPrefs('search'), true);
|
||||||
$saveSettings = $this->app['authentication']->getUser()->getPrefs('advanced_search_reload');
|
$saveSettings = $this->app['authentication']->getUser()->getPrefs('advanced_search_reload');
|
||||||
|
|
||||||
foreach ($this->app['authentication']->getUser()->ACL()->get_granted_sbas() as $databox) {
|
foreach ($this->app['authentication']->getUser()->ACL()->get_granted_sbas() as $databox) {
|
||||||
$sbas_id = $databox->get_sbas_id();
|
$sbasId = $databox->get_sbas_id();
|
||||||
|
|
||||||
$bases[$sbas_id] = array(
|
$bases[$sbasId] = array('thesaurus' => (trim($databox->get_thesaurus()) !== ""), 'cterms' => false, 'collections' => array(), 'sbas_id' => $sbasId);
|
||||||
'thesaurus' => (trim($databox->get_thesaurus()) != ""),
|
|
||||||
'cterms' => false,
|
|
||||||
'collections' => array(),
|
|
||||||
'sbas_id' => $sbas_id
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach ($this->app['authentication']->getUser()->ACL()->get_granted_base(array(), array($databox->get_sbas_id())) as $coll) {
|
foreach ($this->app['authentication']->getUser()->ACL()->get_granted_base(array(), array($sbasId)) as $coll) {
|
||||||
$selected = $saveSettings ? ((isset($searchSet['bases']) && isset($searchSet['bases'][$sbas_id])) ? (in_array($coll->get_base_id(), $searchSet['bases'][$sbas_id])) : true) : true;
|
$selected = $saveSettings ? ((isset($searchSet['bases']) && isset($searchSet['bases'][$sbasId])) ? (in_array($coll->get_base_id(), $searchSet['bases'][$sbasId])) : true) : true;
|
||||||
$bases[$sbas_id]['collections'][] =
|
$bases[$sbasId]['collections'][] = array('selected' => $selected, 'base_id' => $coll->get_base_id());
|
||||||
array(
|
|
||||||
'selected' => $selected,
|
|
||||||
'base_id' => $coll->get_base_id()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$meta_struct = $databox->get_meta_structure();
|
foreach ($databox->get_meta_structure() as $fieldMeta) {
|
||||||
foreach ($meta_struct as $meta) {
|
if (!$fieldMeta->is_indexable()) {
|
||||||
if ( ! $meta->is_indexable())
|
|
||||||
continue;
|
continue;
|
||||||
$id = $meta->get_id();
|
}
|
||||||
$name = $meta->get_name();
|
$id = $fieldMeta->get_id();
|
||||||
if ($meta->get_type() == 'date') {
|
$name = $fieldMeta->get_name();
|
||||||
if (isset($dates[$id]))
|
$type = $fieldMeta->get_type();
|
||||||
$dates[$id]['sbas'][] = $sbas_id;
|
|
||||||
else
|
$data = array('sbas' => array($sbasId), 'fieldname' => $name, 'type' => $type, 'id' => $id);
|
||||||
$dates[$id] = array('sbas' => array($sbas_id), 'fieldname' => $name);
|
|
||||||
|
if ($fieldMeta->get_type() === \databox_field::TYPE_DATE) {
|
||||||
|
if (isset($dates[$id])) {
|
||||||
|
$dates[$id]['sbas'][] = $sbasId;
|
||||||
|
} else {
|
||||||
|
$dates[$id] = $data;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 (isset($fields[$name])) {
|
if (isset($fields[$name])) {
|
||||||
$fields[$name]['sbas'][] = $sbas_id;
|
$fields[$name]['sbas'][] = $sbasId;
|
||||||
} else {
|
} else {
|
||||||
$fields[$name] = array(
|
$fields[$name] = $data;
|
||||||
'sbas' => array($sbas_id)
|
|
||||||
, 'fieldname' => $name
|
|
||||||
, 'type' => $meta->get_type()
|
|
||||||
, 'id' => $id
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! $bases[$sbas_id]['thesaurus']) {
|
if (!$bases[$sbasId]['thesaurus']) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ( ! $this->app['authentication']->getUser()->ACL()->has_right_on_sbas($sbas_id, 'bas_modif_th')) {
|
if (!$this->app['authentication']->getUser()->ACL()->has_right_on_sbas($sbasId, 'bas_modif_th')) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (false !== simplexml_load_string($databox->get_cterms())) {
|
if (false !== simplexml_load_string($databox->get_cterms())) {
|
||||||
$bases[$sbas_id]['cterms'] = true;
|
$bases[$sbasId]['cterms'] = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$search_datas['fields'] = $fields;
|
$searchData['fields'] = $fields;
|
||||||
$search_datas['dates'] = $dates;
|
$searchData['dates'] = $dates;
|
||||||
$search_datas['bases'] = $bases;
|
$searchData['bases'] = $bases;
|
||||||
|
$searchData['sort'] = $sort;
|
||||||
|
|
||||||
return $search_datas;
|
return $searchData;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRandom()
|
public function getRandom()
|
||||||
|
|||||||
@@ -334,8 +334,8 @@
|
|||||||
|
|
||||||
<span>{% trans 'Trier par ' %}</span>
|
<span>{% trans 'Trier par ' %}</span>
|
||||||
<select name="sort" class="input-small">
|
<select name="sort" class="input-small">
|
||||||
{% for sort, sort_name in app['phraseanet.SE'].getAvailableSort() %}
|
{% for sort in search_datas['sort'] %}
|
||||||
<option value="{{ sort }}" {% if sort == app['phraseanet.SE'].getDefaultSort() %}selected="selected" class="default-selection"{% endif %}>{{ sort_name }}</option>
|
<option value="{{ sort.fieldname }}" {% if sort.fieldname == app['phraseanet.SE'].getDefaultSort() %}selected="selected" class="default-selection"{% endif %}>{{ sort.fieldname }}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
<select name="ord" class="input-medium">
|
<select name="ord" class="input-medium">
|
||||||
@@ -408,11 +408,16 @@
|
|||||||
<td colspan="2">{% trans 'Rechercher dans un champ date' %}</td>
|
<td colspan="2">{% trans 'Rechercher dans un champ date' %}</td>
|
||||||
<td colspan="2">
|
<td colspan="2">
|
||||||
<select name="date_field" class="input-medium">
|
<select name="date_field" class="input-medium">
|
||||||
{% for field in app['phraseanet.SE'].getAvailableDateFields() %}
|
{% for date in search_datas['dates'] %}
|
||||||
<option onchange="checkFilters(true);"
|
<option onchange="checkFilters(true);"
|
||||||
class="" value="{{ field }}">{{ field }}</option>
|
class="" value="{{ date.fieldname }}">{{ date.fieldname }}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<option value="{{ app['phraseanet.SE'].getAvailableDateFields()|join('|') }}" selected="selected">
|
|
||||||
|
{% set date_field_names = [] %}
|
||||||
|
{% for field in search_datas['dates'] %}
|
||||||
|
{% set date_field_names = date_field_names|merge([field.fieldname]) %}
|
||||||
|
{% endfor %}
|
||||||
|
<option value="{{ date_field_names|join('|') }}" selected="selected">
|
||||||
{% trans 'rechercher dans tous les champs' %}
|
{% trans 'rechercher dans tous les champs' %}
|
||||||
</option>
|
</option>
|
||||||
</select>
|
</select>
|
||||||
|
|||||||
Reference in New Issue
Block a user