test
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • Fred Tep Friend
    #904652

    Hi,
    first of all, Thanks for this amazing tool.
    I’m just wondering if there is a way to filter by year. I know I can use the custom range but I’ve been asked if that was possible.
    I’d like to have a dropdown list with all the years of the different items in K2.

    THanks in advance for your answers

    Luna Garden Moderator
    #905381

    Hi,

    We have another custom type for Date time Range to Year range, you could try this code we’ve updated here: https://www.joomlart.com/forums/topic/date-range-slider/

    Fred Tep Friend
    #906625

    Hi,
    Thanks for your answer. I read this topic but it’s no use for me as I don’t have an extrafield with the year.
    I’d like to search in the created date and only pick up the year from there.

    Luna Garden Moderator
    #906966

    Hi,

    Our developer is looking at this, we’ll try to help you out if possible. Please stay tuned.

    Mo0nlight Moderator
    #908860

    Hi Fred,

    You can try with my tweak below:

    • Go to file: /modules/mod_jak2filter/helper.php

    • Add this new code to the end of file:
    function getItemDate() {
        $db = JFactory::getDbo();
        $sql = 'SELECT DISTINCT YEAR(created) FROM #__k2_items';
        $db->setQuery($sql);
        $items = $db->loadColumn();
        $html=array();
        $html[] = JHTML::_('select.option', '', JText::_('SELECT_DATE_RANGE'), 'value', 'text');
        foreach ($items AS $item) {
            $html[] = JHTML::_('select.option', $item, $item, 'value', 'text');
        }
        $input = JFactory::getApplication()->input;
        $current_year = $input->get('jadtrange', '', 'STRING');
        return JHTML::_('select.genericlist', $html, 'jadtrange', array('class'=>'jadtrange'), 'value', 'text', $current_year);
    }

    Edit File : /modules/mod_jak2filter/tmpl/default.php Find for

    <?php echo $filter_by_daterange; ?>

    Around Line : 90 Change To:

    <div style="display:none;" ><?php echo $filter_by_daterange; ?></div>
                    <?php echo getItemDate(); ?>

    Then Find For :

    // multi ordering and sortable order.
        jQuery(document).ready(function () {

    Add new code below:

    jQuery('.jadtrange').change(function(){
                if (jQuery(this).val() == '') {
                    jQuery('#jak2filter<?php echo $module->id;?>').find('#dtrange').val('');
                    jQuery('#jak2filter<?php echo $module->id;?>').find('#sdate_<?php echo $module->id;?>').val('');
                    jQuery('#jak2filter<?php echo $module->id;?>').find('#edate_<?php echo $module->id;?>').val('');
                    return;
                }
                jQuery('#jak2filter<?php echo $module->id;?>').find('#dtrange').val('range');
                jQuery('#jak2filter<?php echo $module->id;?>').find('#sdate_<?php echo $module->id;?>').val(jQuery(this).val()+'-01-01');
                jQuery('#jak2filter<?php echo $module->id;?>').find('#edate_<?php echo $module->id;?>').val(jQuery(this).val()+'-12-31');
            });

    That’s all. Regards.

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

This topic contains 4 replies, has 3 voices, and was last updated by  Mo0nlight 8 years, 8 months ago.

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