We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 7858
    • 97 Posts
    Hi, say I've got two columns: "Product" and "Parent Product". Table looks about:

    id product parent_product
    1 bananas 0
    2 baby bananas 1

    I'd like to filter columns by parent broducts. So there must be some dropdown list with names of all products, that have children.

    Is it possible, or not? ))

    This question has been answered by Bruno17. See the first response.

    [ed. note: dopeless last edited this post 11 years, 2 months ago.]
      • 4172
      • 5,888 Posts
      possible, for sure!
      can you post your xpdo-schema with that table-definition?
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 7858
        • 97 Posts
        Hi, Bruno, this is the relevent object

        <?xml version="1.0" encoding="UTF-8"?>
        <model package="flyerPricelist" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
            <object class="fplFormats" table="migx_fpl_formats" extends="xPDOSimpleObject" >
                <field key="format" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
                <field key="formatTitle" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
                <field key="formatImage" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
                <field key="formatDescription" dbtype="varchar" precision="0" phptype="string" null="false" default=""/>
                <field key="allowChildren" dbtype="int" precision="1" attributes="unsigned" phptype="integer" null="false" default="0"/>
                <field key="parent" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" default=""/>
                <field key="published" dbtype="int" precision="1" attributes="unsigned" phptype="integer" null="false" default="1"/>
                <field key="pos" dbtype="int" precision="10" phptype="integer" null="false" default="0" />
                
                <aggregate alias="ThisFormatPrices" class="fplPrices" local="id" foreign="formatId" cardinality="many" owner="local" />
                <aggregate alias="Parent" class="fplFormats" local="parent" foreign="id" cardinality="one" owner="foreign"/>
                <aggregate alias="Children" class="fplFormats" local="id" foreign="parent" cardinality="many" owner="local"/>
            </object>
        </model>


        i need to load every entry, where "parent" is not 0. And get values from "format" fields to display them in list.
          • 4172
          • 5,888 Posts
          For the listbox - input-options you can use the @CHUNK - binding for example:

          @CHUNK inputoptions_formats

          and have a chunk with the name 'inputoptions_formats'

          with:

          Select one==||[[migxLoopCollection? 
          &packageName=`flyerPricelist` 
          &classname=`fplFormats`
          &tpl=`@CODE:[[+formatTitle]]==[[+id]]`
          &outputSeparator=`||`
          &where=`{"parent":"0"}`
          ]]


          btw.

          you should name your package all lowercase, not camelcase, like:
          flyerpricelist


          is it that, what you are asking for?
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 7858
            • 97 Posts
            The idea is right, but how I can use it in migxdb configuration with combobox? I need this filter for migx grid in backend. Sorry, I've forgotten to mention it. I was sure, that i've done it.

            p.s. is it critical, that I use camelcase in package name?
              • 4172
              • 5,888 Posts
              migxdb - configuration

              in formtabs, the field 'parent'

              inputTVtype: listbox
              input option values: @CHUNK inputoptions_formats


              I can remember, have seen issues with package - names, other than everything in lowercase and with special characters.
              But can't say exactly, what it was.

              maybe, it had todo with creating/installing packages.
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 7858
                • 97 Posts
                Bruno, but I need it as filter in DB Filters ) I select parent format and see only the rows, where selected parent exists... My fault


                It works fine with camelcase package name. Will leave it as is, sofar it works )


                  • 4172
                  • 5,888 Posts
                  I see, db-filters.

                  you will need your own getcombo.php to list only items, where parent is 0

                  this is the modified getcombo.php
                  put it into

                  core/components/flyerPricelist/processors/default/

                  or better define a special processorspath in MIGXdb - settings and put it there:

                  core/components/flyerPricelist/processors/yourspecialpath/

                  the code:

                  <?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 = $config['classname'];
                  $joins = isset($config['joins']) && !empty($config['joins']) ? $modx->fromJson($config['joins']) : false;
                  
                  if ($this->modx->lexicon) {
                      $this->modx->lexicon->load($packageName . ':default');
                  }
                  
                  $joinalias = isset($config['join_alias']) ? $config['join_alias'] : '';
                  
                  if (!empty($joinalias)) {
                      if ($fkMeta = $xpdo->getFKDefinition($classname, $joinalias)) {
                          $joinclass = $fkMeta['class'];
                      } else {
                          $joinalias = '';
                      }
                  }
                  
                  /* setup default properties */
                  $isLimit = !empty($scriptProperties['limit']);
                  $isCombo = !empty($scriptProperties['combo']);
                  $start = $modx->getOption('start', $scriptProperties, 0);
                  $limit = $modx->getOption('limit', $scriptProperties, 20);
                  $mode = $modx->getOption('searchname', $scriptProperties, 'year');
                  $context = $modx->getOption('context', $scriptProperties, 'alle');
                  
                  $c = $xpdo->newQuery($classname);
                  //$count = $modx->getCount($classname,$c);
                  
                  $execute = true;
                  
                  switch ($mode) {
                      case 'year':
                          $sort = $modx->getOption('sort', $scriptProperties, 'YEAR(`' . $classname . '`.`' . $textfield . '`)');
                          $dir = $modx->getOption('dir', $scriptProperties, 'DESC');
                          $c->select('id,YEAR(' . $textfield . ') as combo_id , YEAR(' . $textfield . ') as combo_name');
                          break;
                      case 'month':
                          if ($scriptProperties['year'] == 'all') {
                              $rows = array();
                              $execute = false;
                          } else {
                              $sort = $modx->getOption('sort', $scriptProperties, 'MONTH(`' . $classname . '`.`' . $textfield . '`)');
                              $dir = $modx->getOption('dir', $scriptProperties, 'ASC');
                              $c->select('id, MONTH(' . $textfield . ') as combo_id, MONTH(' . $textfield . ') as combo_name,YEAR(`' . $classname . '`.`' . $textfield . '`) as year');
                              //$c->where("YEAR(" . $modx->escape($classname) . '.' . $modx->escape('createdon') . ") = " .$scriptProperties['year'], xPDOQuery::SQL_AND);
                          }
                  
                          break;
                      default:
                          $sort = $modx->getOption('sort', $scriptProperties,  $textfield );
                          $dir = $modx->getOption('dir', $scriptProperties, 'ASC');
                          if (!empty($joinalias)) {
                              $c->leftjoin($joinclass, $joinalias);
                              //$c->select($modx->getSelectColumns($joinclass, $joinalias, $joinalias . '_'));
                          }
                          $c->select($classname.'.id, ' . $idfield . ' as combo_id, ' . $textfield . ' as combo_name');
                          break;
                  }
                  
                  if ($joins) {
                      $modx->migx->prepareJoins($classname, $joins, $c);
                  }
                  
                  if ($execute) {
                      
                      $c->where(array('parent'=>'0'));
                  
                      $c->groupby('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);
                  //$c->prepare(); echo $c->toSql();
                  /*
                  $collection = $modx->getCollection($classname, $c);
                  $rows=array();
                  foreach ($collection as $row){
                  $rows[]=$row->toArray();
                  }
                  $count=count($rows);
                  */
                  return $this->outputArray($rows, $count);
                  
                  


                  I added this line to the default processor (line 102):

                  $c->where(array('parent'=>'0'));


                  Think, I should add a new config for that.
                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 7858
                    • 97 Posts
                    I don't get it (((

                    i'm rtying

                    filter Name: parent_id
                    label: Parent
                    Empty Text: --filter by parent--
                    Filter Type: combobox
                    getlist-where: {"parent":"[[+parent_id]]"}
                    getcombo processor: getcombo
                    getcombo textfield: parent

                    and I get empty list...
                      • 4172
                      • 5,888 Posts
                      your getcombo textfield should be 'formatTitle'
                        -------------------------------

                        you can buy me a beer, if you like MIGX

                        http://webcmsolutions.de/migx.html

                        Thanks!