Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • erik09 Friend
    #203955

    Hi,

    I have an extrafield “date” with the format is dd-mm-yyy. I want to be able to filter a range of years (i.e. from 1856 till 2011) with the use of a slider.

    I realise that I will have to hack the script in order to do this. However this task should not be too difficult, as it is easy with PHP to convert a date format into a number.

    Perhaps you can push me in the right direction by telling me where in the script I should start looking in order to make these alterations.

    Thanks & regards,

    Erik

    Luna Garden Moderator
    #560509

    Hi Erik,

    Our developer had a look at your question, pls give him more time to investigate further.

    We will answer you soon with some suggestions.

    Luna Garden Moderator
    #560633

    Hi,

    We have a suggestion like this:
    1. In module, add range slider to date type format. You can choose the value of year maximum and minimum.
    Edit in file: modulesmod_jak2filterelementsk2extrafield.php copy line 270 to 249.
    2. In front-end, when searching, add value to make the number to date format, for example user select a range from 1999 to 2010 we will add it to: from 1-1-1999 to 31-12-2010
    Edit in file: componentscom_jak2filtermodelsitemlist.php from line 1308 to 1318,
    – Check Data type is Date then adding the suffix to minimum value and maximum value.

    eabe Friend
    #903402

    I can only see break; in line 270 and also the same in 249.

    Can you please explain again what exactly needs to be copied and where?

    Thanks

    The Captain Moderator
    #904629

    Hi eabe,

    You can try with my tweak here:

    • In the file modules/mod_jak2filter/elements/k2extrafield.php, +/ Search the snippet of code:

      case 'date':
      $typeOptions[] = JHTML::_('select.option', $prefix.'date', JText::_('FILTER_TYPE_DATE'));
      $typeOptions[] = JHTML::_('select.option', $prefix.'daterange', JText::_('FILTER_TYPE_DATERANGE'));

      Replace by the code:

      case 'date':
      $typeOptions[] = JHTML::_('select.option', $prefix.'date', JText::_('FILTER_TYPE_DATE'));
      $typeOptions[] = JHTML::_('select.option', $prefix.'daterange', JText::_('FILTER_TYPE_DATERANGE'));
      $typeOptions[] = JHTML::_('select.option', $prefix.'rangeslider', JText::_('FILTER_TYPE_RANGE_SLIDER'));
    • In the file components/com_jak2filter/models/itemlist.php, search the snippet of code:

      case 'range':
        list($from, $to) = explode('|', $value);
                 if($from != '') {
                       $from = (int) $from;
                       $searchPattern = $prefix.$this->rgRange($from, 1);
                        $where[] = "(i.extra_fields REGEXP '".$searchPattern."')";
                   }
                   if($to != '') {
                         $to = (int) $to;
                          $searchPattern = $prefix.$this->rgRange($to, 0);
                          $where[] = "(i.extra_fields REGEXP '".$searchPattern."')";
                    }
                    break;

      Replace by the code:

      case 'range':
                                  preg_match_all('/[0-9]+/',$field, $matches);
                                  $fxid = $matches[0][0];
                                  list($from, $to) = explode('|', $value);
                                  if($from != '') {
                                      if($this->isDateFX($fxid))
                                      {
                                          $from = $from.'-01-01';
                                          $searchPattern = $prefix.$this->rgRange($from, 1, 'date');
                                      }else
                                      {
                                          $from = (int) $from;
                                          $searchPattern = $prefix.$this->rgRange($from, 1);
                                      }
                                      $where[] = "(i.extra_fields REGEXP '".$searchPattern."')";
                                  }
                                  if($to != '') {
                                      if($this->isDateFX($fxid))
                                      {
                                          $to = $to.'-12-31';
                                          $searchPattern = $prefix.$this->rgRange($to, 0, 'date');
                                      }else
                                      {
                                          $to = (int) $to;
                                          $searchPattern = $prefix.$this->rgRange($to, 0);
                                      }
                                      $where[] = "(i.extra_fields REGEXP '".$searchPattern."')";
                                  }
                                  break;

      Hope this helps.

Viewing 5 posts - 1 through 5 (of 5 total)

This topic contains 4 replies, has 4 voices, and was last updated by  The Captain 8 years, 1 month ago.

We moved to new unified forum. Please post all new support queries in our New Forum