search for objects with an attribute not set

This commit is contained in:
Uwe Steinmann 2023-04-28 17:13:16 +02:00
parent 693a68261b
commit b6e6b66125

View File

@ -1041,9 +1041,10 @@ $(document).ready(function() {
$this->contentContainerEnd();
$menuitems = [];
if($facets) {
$menuitems = [];
foreach($facets as $facetname=>$values) {
if($values) {
if(substr($facetname, 0, 5) == 'attr_') {
$tmp = explode('_', $facetname);
if($attrdef = $dms->getAttributeDefinition($tmp[1])) {
@ -1135,11 +1136,31 @@ $(document).ready(function() {
}
}
}
}
if($menuitems) {
self::showNavigationListWithBadges($menuitems);
}
}
}
/* Create remove links for query 'notset'. The don't have any facet
* values and will not show up in the lists created above.
* This currently just workѕ for attributes
*/
$allparams = $request->query->all();
foreach($allparams['attributes'] as $an=>$av) {
if(is_string($av) && $av == '__notset__') {
$tmp = explode('_', $an);
if($attrdef = $dms->getAttributeDefinition($tmp[1])) {
$dispname = $attrdef->getName();
unset($allparams['attributes'][$an]);
$newrequest = Symfony\Component\HttpFoundation\Request::create($request->getBaseUrl(), 'GET', $allparams);
$menuitems[] = array('label'=>'<i class="fa fa-remove"></i> '.$dispname.' is not set', 'link'=>$newrequest->getRequestUri(), 'attributes'=>[['title', 'Click to remove']], '_badge'=>'x');
}
}
}
if($menuitems) {
self::showNavigationListWithBadges($menuitems);
}
echo "<p></p>";
$this->formSubmit("<i class=\"fa fa-search\"></i> ".getMLText('search'));
echo "<p></p>";
@ -1162,7 +1183,9 @@ $(document).ready(function() {
if($values && (count($values) > 1 || reset($values) < $total)) {
if(empty($allparams['attributes'][$facetname]['from']) && empty($allparams['attributes'][$facetname]['to'])) {
$tt = array_keys($values);
$content = '<div class="input-group">';
$content = '';
$content = '<p><a href="'.$newrequest->getRequestUri().'&attributes['.$facetname.']=__notset__">Objects without this attribute</a></p>';
$content .= '<div class="input-group">';
$content .= '<span class="input-group-text" style="border-right: 0;"> from </span>';
$content .= '<input type="number" class="form-control" name="attributes['.$facetname.'][from]" value="" placeholder="min is '.min($tt).'" />';
$content .= '<span class="input-group-text" style="border-left: 0; border-right: 0;"> to </span>';
@ -1192,6 +1215,7 @@ $(document).ready(function() {
/* See below on an explaination for the if statement */
if($values && (count($values) > 1 || reset($values) < $total)) {
$menuitems = array();
$menuitems[] = array('label'=>'not set', 'link'=>$newrequest->getRequestUri().'&attributes['.$facetname.']=__notset__');
arsort($values);
foreach($values as $v=>$c) {
switch($attrdef->getType()) {