Advertisement:

Author Topic: SOLVED Why aren't the dateinterval params shown in search-sidebar from url?  (Read 830 times)

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
I tested and if the custom field is dateinterval, after filtering, the values chosen aren't displayed in the sidebar but are present in the url.
Is this a bug of osclass?

I gues the code responsible for that is from oc-includes/osclass/frm/Field.form.class.php

Code: [Select]
                } else if($field['e_type']=="DATEINTERVAL") {
                    if($search) {
                        echo '<h6>'.$field['s_name'].'</h6>';
                    } else {
                        echo '<label for="meta_'.$field['s_slug'].'">'.$field['s_name'].': </label>';
                    }

                    echo __('from'). ' ';
                    echo '<input type="hidden" id="meta_'.$field['s_slug'].'_from" name="meta['.$field['pk_i_id'].'][from]" value="'.$field['s_value']['from'].'" />';
                    echo '<input type="text" id="" class="meta_'.$field['s_slug'].'_from cf_date_interval" value="" />';
                    FieldForm::initDatePicker('meta_'.$field['s_slug'].'_from', osc_date_format(), $field['s_value']['from'], 'from');

                    echo ' ' . __('to'). ' ';
                    echo '<input type="hidden" id="meta_'.$field['s_slug'].'_to" name="meta['.$field['pk_i_id'].'][to]" value="'.$field['s_value']['to'].'" />';
                    echo '<input type="text" id="" class="meta_'.$field['s_slug'].'_to cf_date_interval" value="" />';
                    FieldForm::initDatePicker('meta_'.$field['s_slug'].'_to', osc_date_format(), $field['s_value']['to'], 'to');

And I suspect that
Code: [Select]
                        $temp['from']   = Params::getParam('meta['.$field['pk_i_id'].'][from]');
                        $temp['to']     = Params::getParam('meta['.$field['pk_i_id'].'][to]');

Is not returning nothing when search=true(the results being displyed in search-sidebar.php).

I aded a picture that contains var_dump($temp).

Thank you.
« Last Edit: January 03, 2018, 01:45:10 pm by marius-ciclistu »

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Solution:
EDIT: official solution https://github.com/osclass/Osclass/commit/0d7e451

So in oc-includes/osclass/frm/Field.form.class.php
I put:
Code: [Select]
        static public function meta($field = null, $search = false) {

            if($field!=null) {
                // date interval
                if($field['e_type']=='DATEINTERVAL') {
                   /* $field['s_value'] = array();
                    $field['s_value']['from']   = '';
                    $field['s_value']['to']     = '';*/

                    if(!$search) {
                        $aInterval = Field::newInstance()->getDateIntervalByPrimaryKey($field['fk_i_item_id'], $field['pk_i_id']);

                        if(is_array($aInterval) && !empty($aInterval) ) {
                            $temp['from']       = @$aInterval['from'];
                            $temp['to']         = @$aInterval['to'];
                            $field['s_value']   = $temp;
                        }
                    } /*else {
                        $temp['from']   = Params::getParam('meta['.$field['pk_i_id'].'][from]');
                        $temp['to']     = Params::getParam('meta['.$field['pk_i_id'].'][to]');
                        $field['s_value'] = $temp;
                    }*/
                }
                // end date interval

                if(Session::newInstance()->_getForm('meta_'.$field['pk_i_id']) != ""){
                    $field['s_value'] = Session::newInstance()->_getForm('meta_'.$field['pk_i_id']);
                } else if(!isset($field['s_value']) || $field['s_value']=='') {
                    $s_value = Params::getParam('meta');
                    $field['s_value'] = '';
                    if(isset($s_value[$field['pk_i_id']])) {
                        $field['s_value'] = $s_value[$field['pk_i_id']];
                    }
                }
instead of

Code: [Select]
        static public function meta($field = null, $search = false) {

            if($field!=null) {
                // date interval
                if($field['e_type']=='DATEINTERVAL') {
                    $field['s_value'] = array();
                    $field['s_value']['from']   = '';
                    $field['s_value']['to']     = '';

                    if(!$search) {
                        $aInterval = Field::newInstance()->getDateIntervalByPrimaryKey($field['fk_i_item_id'], $field['pk_i_id']);

                        if(is_array($aInterval) && !empty($aInterval) ) {
                            $temp['from']       = @$aInterval['from'];
                            $temp['to']         = @$aInterval['to'];
                            $field['s_value']   = $temp;
                        }
                    } else {
                        $temp['from']   = Params::getParam('meta['.$field['pk_i_id'].'][from]');
                        $temp['to']     = Params::getParam('meta['.$field['pk_i_id'].'][to]');
                        $field['s_value'] = $temp;
                    }
                }
                // end date interval
                if(Session::newInstance()->_getForm('meta_'.$field['pk_i_id']) != ""){
                    $field['s_value'] = Session::newInstance()->_getForm('meta_'.$field['pk_i_id']);
                } else if(!isset($field['s_value']) || $field['s_value']=='') {
                    $s_value = Params::getParam('meta');
                    $field['s_value'] = '';
                    if(isset($s_value[$field['pk_i_id']])) {
                        $field['s_value'] = $s_value[$field['pk_i_id']];
                    }
                }


The bug was discovered here: https://forums.osclass.org/development/new-type-of-custom-field-suggestion-number-input-and-interval-filter/msg159213/#msg159213
« Last Edit: June 14, 2018, 01:09:15 am by marius-ciclistu »

teseo

  • Hero Member
  • *****
  • Posts: 6169
Yes, it seems like you've found a bug in the core, weird I haven't been this issue reported ever.

I suspect the function Params::getParam isn't ready to manage sub-arrays (Params::getParam("meta[24]['from']")) ???

Your mod seems to work fine as far as I can see, thanks :)

Regards

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
Thank you. You are my teacher in a way;)

I also finished the other mod now(i hope).

EDITED to solve another bug !
And I think there is another bug in dateinterval's regard.

If the user inserts only one date it will not add condition to search querry as

Code: [Select]
                                if( is_array($aux) && (!empty($aux['from']) && !empty($aux['to'])) ) {from
oc-includes/osclass/controller/search.php will not alow it.

So there must be a change from
Code: [Select]
                            case 'DATEINTERVAL':
                                if( is_array($aux) && (!empty($aux['from']) && !empty($aux['to'])) ) {
                                    $from = $aux['from'];
                                    $to   = $aux['to'];
to
Code: [Select]
                            case 'DATEINTERVAL':
                                if( is_array($aux)) {
                                    if(!empty($aux['to']) && empty($aux['from'])) $aux['from'] = '0';
                                    if(!empty($aux['from']) && empty($aux['to']))  $aux['to'] = '253202544000';
                                    $from = $aux['from'];
                                    $to   = $aux['to'];

EDITED AGAIN

And to avoid php warnings
edit
oc-includes/osclass/frm/Field.form.class.php
Put
Code: [Select]
                    echo '<input type="hidden" id="meta_'.$field['s_slug'].'_from" name="meta['.$field['pk_i_id'].'][from]" value="'.@$field['s_value']['from'].'" />';
                    echo '<input type="text" id="" class="meta_'.$field['s_slug'].'_from cf_date_interval" value="" />';
                    FieldForm::initDatePicker('meta_'.$field['s_slug'].'_from', osc_date_format(), $field['s_value']['from'], 'from');

                    echo ' ' . __('to'). ' ';
                    echo '<input type="hidden" id="meta_'.$field['s_slug'].'_to" name="meta['.$field['pk_i_id'].'][to]" value="'.@$field['s_value']['to'].'" />';

instead of

Code: [Select]
                    echo '<input type="hidden" id="meta_'.$field['s_slug'].'_from" name="meta['.$field['pk_i_id'].'][from]" value="'.$field['s_value']['from'].'" />';
                    echo '<input type="text" id="" class="meta_'.$field['s_slug'].'_from cf_date_interval" value="" />';
                    FieldForm::initDatePicker('meta_'.$field['s_slug'].'_from', osc_date_format(), $field['s_value']['from'], 'from');

                    echo ' ' . __('to'). ' ';
                    echo '<input type="hidden" id="meta_'.$field['s_slug'].'_to" name="meta['.$field['pk_i_id'].'][to]" value="'.$field['s_value']['to'].'" />';
« Last Edit: January 03, 2018, 04:00:00 pm by marius-ciclistu »

marius-ciclistu

  • issues
  • Hero Member
  • *
  • Posts: 1652
  • "BE GRATEFUL TO THOSE THAT SUPPORTED YOU"
A push was made for this bug https://github.com/osclass/Osclass/commit/0d7e451


Edit

There is only one place where $search is true in the same file:

FieldForm::meta($field, true);

So I gues that my fix doesn't allow to filter by date interval...
« Last Edit: June 14, 2018, 01:08:33 am by marius-ciclistu »