We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34109
    • 119 Posts
    Hopefully someone can help with this!

    In the old days gettvcombo used to allow you to use a TV to define the criteria you're searching on. Now the combobox filter works really nicely, but I want to customise the values the client sees for a couple of tinyint columns. So instead of 0 & 1, they'd see Unbpublished and Published, for example.

    The filters section of my setup exports like this:

        {
          "MIGX_id":2,
          "name":"published",
          "label":"Published",
          "emptytext":"Published",
          "type":"combobox",
          "getlistwhere":{
            "published":"[[+published]]"
          },
          "getcomboprocessor":"getcombo",
          "combotextfield":"published",
          "comboidfield":"",
          "comboparent":"",
          "default":""
        }
    


    Which filters fine, but how can I change the labels on the combobox?
    Update: should have mentioned, this is on a MIGXDB cmp, in the db-filters panel [ed. note: [email protected] last edited this post 11 years, 9 months ago.]
      Studio Republic
      http://www.studiorepublic.com
      0845 226 3205
      @christodhunter
      • 34109
      • 119 Posts
      ...and while we're at it, another filter I need is to list out values from another table, to be used in a LIKE statement on a column in this table. Any ideas?

      Thanks!
        Studio Republic
        http://www.studiorepublic.com
        0845 226 3205
        @christodhunter
        • 4172
        • 5,888 Posts
        you can create your own getcombo - processors under

        core/components/yourpackage/processors/mgr/default/getpublishedcombo.php

        with something like that:

        <?php
        
        $config = $modx->migx->customconfigs;
        $emtpytext = $config['gridfilters'][$scriptProperties['searchname']]['emptytext'];
        $emtpytext = empty($emtpytext) ? 'all' : $emtpytext;
        $options = array();
        $options[] = array('combo_name' => $emtpytext, 'combo_id' => 'all');
        $options[] = array('combo_name' => 'published', 'combo_id' => '1');
        $options[] = array('combo_name' => 'unpublished', 'combo_id' => '0');
        
        $count = count($options);
        return $this->outputArray($options, $count);


        and set it up like:

        {
          "MIGX_id":2,
          "name":"published",
          "label":"Published",
          "emptytext":"Filter by Published",
          "type":"combobox",
          "getlistwhere":{
            "published":"[[+published]]"
          },
          "getcomboprocessor":"getpublishedcombo",
          "combotextfield":"",
          "comboidfield":"",
          "comboparent":"",
          "default":""
        }



        to get values of another table try something like that:
        core/components/yourpackage/processors/mgr/default/getcategoriescombo.php

        <?php
        
        //if (!$modx->hasPermission('quip.thread_list')) return $modx->error->failure($modx->lexicon('access_denied'));
        
        $config = $modx->migx->customconfigs;
        
        $textfield = $config['gridfilters'][$scriptProperties['searchname']]['combotextfield'];
        $idfield = $config['gridfilters'][$scriptProperties['searchname']]['comboidfield'];
        $idfield = empty($idfield) ? $textfield : $idfield;
        
        $prefix = isset($config['prefix']) && !empty($config['prefix']) ? $config['prefix'] : null;
        if (isset($config['use_custom_prefix']) && !empty($config['use_custom_prefix'])) {
            $prefix = isset($config['prefix']) ? $config['prefix'] : '';
        }
        
        if (!empty($config['packageName'])) {
            $packageNames = explode(',', $config['packageName']);
        
            if (count($packageNames) == '1') {
                //for now connecting also to foreign databases, only with one package by default possible
                $xpdo = $modx->migx->getXpdoInstanceAndAddPackage($config);
            } else {
                //all packages must have the same prefix for now!
                foreach ($packageNames as $packageName) {
                    $packagepath = $modx->getOption('core_path') . 'components/' . $packageName . '/';
                    $modelpath = $packagepath . 'model/';
                    if (is_dir($modelpath)) {
                        $modx->addPackage($packageName, $modelpath, $prefix);
                    }
        
                }
                $xpdo = &$modx;
            }
        } else {
            $xpdo = &$modx;
        }
        
        $classname = 'modCategory';
        
        $sort = $modx->getOption('sort', $scriptProperties, $textfield);
        $dir = $modx->getOption('dir', $scriptProperties, 'ASC');
        
        $c = $xpdo->newQuery($classname);
        //$count = $modx->getCount($classname,$c);
        $c->select($classname . '.id, ' . $idfield . ' as combo_id, ' . $textfield . ' as combo_name');
        
        $c->sortby($sort, $dir);
        $stmt = $c->prepare();
        //echo $c->toSql();
        $stmt->execute();
        $rows = $stmt->fetchAll();
        
        $count = count($rows);
        
        $emtpytext = $config['gridfilters'][$scriptProperties['searchname']]['emptytext'];
        $emtpytext = empty($emtpytext) ? 'all' : $emtpytext;
        
        $rows = array_merge(array(array('combo_id' => 'all', 'combo_name' => $emtpytext)), $rows);
        
        return $this->outputArray($rows, $count);
        


        and set it up like

        {
          "MIGX_id":2,
          "name":"category",
          "label":"category",
          "emptytext":"Select Category",
          "type":"combobox",
          "getlistwhere":{
            "category":"[[+category]]"
          },
          "getcomboprocessor":"getcategoriescombo",
          "combotextfield":"category",
          "comboidfield":"id",
          "comboparent":"",
          "default":""
        }




          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 34109
          • 119 Posts
          Bruno, you're my hero! Thanks so much for your help (again!)
            Studio Republic
            http://www.studiorepublic.com
            0845 226 3205
            @christodhunter