nblgeoweb VIP
Total posts: 178
27 May 2015 17:18

One of the things I wanted to make available for my users is a link representing the current set of filters they have applied. Then they can bookmark it and share it. I wrote a bit of code for my markup template that prints out each filter as a button (usual behaviour from the default template) but also compiles each filter into a url that represents all the filters together. I've got it working for both array values and single values. I haven't added in the ability to properly handle geo and date range fields yet since I'm not using any of those in my project. A bit more work needs to be done to handle those.

Here's the code below. If you add support for geo and date ranges, post and we can come up with a complete solution.

 <?php $filter_link=JRoute::_(JURI::root().'index.php?option=com_cobalt&task=records.filter&section_id='.$this->section->id); ?>
 <?php $filter_count=0; ?>
 <?php if($this->worns):?>
      <?php foreach ($this->worns AS $worn):?>
          <?php
              if(is_array($worn->value)){
                  foreach ($worn->value AS $val){
                      if (count($worn->value)==1) $filter_val.="&filter_val[$filter_count]=$val";
                      else $filter_val.="&filter_val[$filter_count][]=$val";
                  }
              }
              else $filter_val="&filter_val[$filter_count]=$worn->value";  
          ?>
      <?php $filter_link.="&filter_name[$filter_count]=$worn->name$filter_val"; ?>
      <input type="hidden" name="clean[<?php echo $worn->name; ?>]" id="<?php echo $worn->name; ?>" value="">
      <?php $filter_count++; ?>
      <?php endforeach;?>
 <?php endif;?>
 <div style="float:right"><a href="/<?php echo $filter_link; ?>" title="<?php echo $filter_link; ?>">Filter URL</a></div>

Last Modified: 05 Jun 2015



Sergey
Total posts: 13,748
01 Jun 2015 12:36

Perfect!


pepperstreet VIP
Total posts: 3,837
05 Jun 2015 12:04

+1

Powered by Cobalt