We build. You grow.

Get best community software here

Start a social network, a fan-site, an education project with oxwall - free opensource community software

199 dollars tips: Make your single choice options searchable | Forum

Daniel
Daniel Jul 21
Hi guys, you are welcome, here is 199 dollars tips: Make your single choice options searchable, like adding a "Height" to user question and make it searchable.  


Yes, I am still here. How is going with the covid-19 guys?



****** ****** ****** ****** ****** ****** ****** ****** 

Attention! 

you must backup your database before doing this.  

and make sure you know how to roll back the database if there is a problem.  

Please backup all relevance files before this this. 

I do not take any responsibility on your failure.

Please read through this post before doing it.

**** ******** ****** ****** ****** ****** ****** ****** 


relevance database tables

ow_base_question_config  (ow is your table prefix)


relevance database files

ow_system_plugins/admin/classes/add_question_form.php

ow_system_plugins/base/bol/user_dao.php

ow_system_plugins/base/bol/question_service.php

ow_core/form_element.php




Step 0: 

Put your website to maintain mode. This procedure may take 10 minutes. 


Step 1: 

Add an option "fselect"  to the column `questionPresentation` on the table `ow_base_question_config`  by running below SQL query, as this column is a enum type.

By doing this you must make sure you had not do any custom to this table before, other wise you may need to add it manually.

//------------------------------------------------------------

ALTER TABLE `ow_base_question_config` CHANGE `questionPresentation` `questionPresentation` ENUM('text','textarea','select','date','location','checkbox','multicheckbox','radio','url','password','age','birthdate','fselect');//------------------------------------------------------------



Step 2: 

Run below SQL query:

//------------------------------------------------------------

INSERT INTO `ow_base_question_config` (`id``questionPresentation``name``description``presentationClass`VALUES (NULL'fselect''search_type''''Selectbox')

//------------------------------------------------------------

By running the SQL query, please make sure to replace the table prefix.



Step 3:

Insert below code to file ow_system_plugins/admin/classes/add_question_form.php

after line 283

//------------------------------------------------------------

if ($config->name == 'search_type'){                $options = array(                    'single' => $language->text('admin', 'questions_config_' . ($config->name) . 'option_single' . '_label'),                    'range' => $language->text('admin', 'questions_config_' . ($config->name) . 'option_range' . '_label')                );                $qstConfig->setOptions($options);            }

//--------------------------------------------------------------------


It should be look like this





Step 4

delete line 955 on this file  ow_system_plugins/base/bol/user_dao.php

It should be look like this.




Step 5:

insert below to after line 954 on the same file file  ow_system_plugins/base/bol/user_dao.php

//--------------------------------------------------------------------

if ( is_array($value) )                    {                        if(isset($value['from']) && isset($value['to'])){                            $from_ = (int) $value['from'];                            $to_ = (int) $value['to'];                                                        /**                             *                              * missing both values                             */                            if (!$from_ && !$to_){                                break;                            }                            
                            if (!$to_){                                /**                                 *                                  * to value is missing                                 */                                $result = ' `' . $this->dbo->escapeString($prefix) . '`.`intValue` >= ' . $from_ . ' ';                            }else if(!$from_){                                /**                                 *                                  * from value is mission                                 */                                $result = ' `' . $this->dbo->escapeString($prefix) . '`.`intValue` <= ' . $to_ . ' ';                            }else{                                                                /**                                 *                                  * has both values                                 */                                $from = ($from_ > $to_ && $to_) ? $to_ : $from_;                                $to = ($from_ > $to_) ? $from_ : $to_;                                $result = ' `' . $this->dbo->escapeString($prefix) . '`.`intValue` BETWEEN ' . $from . ' AND ' . ($to++) . ' ';                            }                                                    }else{                            $result = ' `' . $this->dbo->escapeString($prefix) . '`.`intValue` IN ( ' . $this->dbo->mergeInClause($value) . ') ';                        }                                            }


//--------------------------------------------------------------------


It should be look like this




Step 6:

delete line 450 on this file ow_system_plugins/base/bol/question_service.php

It should be looks like this.




Step 7:

Insert blow code to the same position as step 6

//--------------------------------------------------------------------

                    $qtConfigs = json_decode($configs, true);                    if (!empty($qtConfigs['search_type']) && $qtConfigs['search_type'] == 'range'){                        $class = new SelectRange($fieldName);                    }else{                        $class = new Selectbox($fieldName);                    }                    break;

//--------------------------------------------------------------------





Last step:

Append below code the bottom of this file ow_core/form_element.php

//------------------------------------------------------------------

class SelectRange extends FormElement{    protected $from;    protected $to;
    /**     * Constructor.     *     * @param string $name     */    public function __construct( $name )    {        parent::__construct($name);        $this->questionService = BOL_QuestionService::getInstance();        $this->from = new Selectbox($name . '[from]');        $this->to = new Selectbox($name . '[to]');
            }        public function setOptions($options){        $this->from->setOptions($options);        $this->to->setOptions($options);    }
    public function setHasInvitation($hasInvitation){        $this->from->setHasInvitation($hasInvitation);        $this->to->setHasInvitation($hasInvitation);    }        public function setInvitation($invitation){        $this->from->setInvitation($invitation);        $this->to->setInvitation($invitation);    }    /**     * Sets form element value.     *     * @param array $value
     * @return FormElement     */    public function setValue( $value )    {        if ( isset($value['from']) && isset($value['to']) )        {            $this->from->setValue($value['from']);            $this->to->setValue($value['to']);        }
        return $this;    }
    public function getValue()    {        $value = array(            'from' => $this->from->getValue(),            'to' => $this->to->getValue()        );
        return $value;    }        public function renderInput( $params = null )    {        parent::renderInput($params);
        $language = OW::getLanguage();
        $result = '<div id="' . $this->getAttribute('id') . '" class="' . $this->getAttribute('name') . '">                       ' . $language->text('base', 'form_element_from') . '  <div class="ow_inline">' . ( $this->from->renderInput() ) . '</div>                       ' . $language->text('base', 'form_element_to') . '                       <div class="ow_inline">' . ( $this->to->renderInput() ) . '</div>                    </div>';
        return $result;    }}


//------------------------------------------------------------------




The last last step, add the text key:

you.domain.com/admin/settings/dev-tools/languages

(click the "ADD NEW TEXT" button)


text 1

key: questions_config_search_typeoption_range_label   

content: Range


text 2

key: questions_config_search_typeoption_single_label

content: Single


text 3

key: questions_config_search_type_label

content: Search type




The last last last step:

Now you can add a "Single Choice - Regular (Slower results, unlimited)" option, and with a Search type option, like below

When you select Range in the "Search type" option, in the search form, it appear a from-to range. if you select single, will appear a single choice selectbox.






The last last last last step:

Add this page to your browser bookmark list as the oxwall may push an update to the core will lost your custom code, then you can easily follow this post to do it over again. 



No thanks you are welcome.


Oh yet. i also add the transcription to the attachment.


Daniel
Daniel Jul 21
Works on skadate? Yes.
dave Team
dave Jul 21
Topic was moved from Custom Oxwall Projects.