We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22448
    • 241 Posts
    Hi Bruno,

    here's the schema:

    <?xml version="1.0" encoding="UTF-8"?>
    <model package="migxresourcerelations" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
        <object class="rrResourceRelation" table="rr_resource_relations" extends="xPDOSimpleObject">
            <field key="source_id" dbtype="int" precision="10" phptype="integer" null="false" default="0" index="index" />
            <field key="target_id" dbtype="int" precision="10" phptype="integer" null="false" default="0" index="index" />
            <field key="active" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" index="index" />
            <field key="published" dbtype="tinyint" precision="1" attributes="unsigned" phptype="integer" null="false" default="0" index="index" />
            <field key="pos" dbtype="int" precision="10" phptype="integer" null="false" default="0" index="index" />
            <field key="extended" dbtype="text" phptype="json" null="false" default="" />
            <field key="rel_type" dbtype="int" precision="10"  phptype="integer" null="false" default="0" index="index" />
            <index alias="source_id" name="source_id" primary="false" unique="false" type="BTREE">
                <column key="source_id" length="" collation="A" null="false" />
            </index>
            <index alias="target_id" name="target_id" primary="false" unique="false" type="BTREE">
                <column key="target_id" length="" collation="A" null="false" />
            </index>
            <index alias="rel_type" name="rel_type" primary="false" unique="false" type="BTREE">
                <column key="rel_type" length="" collation="A" null="false" />
            </index>
            <aggregate alias="Source" class="modResource" local="source_id" foreign="id" cardinality="one" owner="foreign" />
            <aggregate alias="Target" class="modResourse" local="target_id" foreign="id" cardinality="one" owner="foreign" />
        </object>
    </model>


    The MIGXdb configuration at this point is what comes with migxResourceRelations since i couldn't figure out how to change it for what's needed. The only change is the migxresourcerelations_source configuration on the parent filter. I set the default value to the id of the root document in a category sub-branch. That worked for the grid but not for the Parent combobox. And even in the grid it only displayed the children of 18, while i need it include grand-children and so on all the way down.

          "MIGX_id":5,
          "name":"source_parent",
          "label":"parent",
          "emptytext":"filter Parent",
          "type":"treecombo",
          "getlistwhere":{
            "parent":"[[+source_parent]]"
          },
          "getcomboprocessor":"gettreenode",
          "combotextfield":"pagetitle",
          "comboidfield":"id",
          "comboparent":"",
          "default":18
        },


    Than you very much.
      • 4172
      • 5,888 Posts
      to get the default-value as the top-parent for the tree-combo, I added this lines to the gettreenode-processor:
      https://github.com/Bruno17/migxResourceRelations/commit/eeb8333d24e64906619021a6c79d738181dcdb20


      3. In the main grid i need to include not only the children of the filter parent but their childrens's children and so on all the way to the bottom of the sub-branch. How would i do that?

      getlistwhere:
      {"id:IN":[ [[getChildIds? &parent=`[[+source_parent]]` &context=`web`]] ]}


      and have a snippet 'getChildIds':

      $parent = $modx->getOption('parent', $scriptProperties, 0);
      $depth = $modx->getOption('depth',$scriptProperties,10);
      $context = $modx->getOption('context',$scriptProperties,$modx->context->get('key'));
      
      $c = $modx->newQuery('modResource');
      $c->select('id');
      $c->where(array('id:IN' => $modx->getChildIds($parent,$depth,array('context'=>$context))));
      $ids = array();
      if ($resources = $modx->getCollection('modResource', $c)) {
          foreach ($resources as $resource) {
              if ($resource->checkPolicy('list')) {
                  $ids[] = $resource->get('id');
              }
          }
         
      }
      
      return implode(',', $ids);
      





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

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 22448
        • 241 Posts
        This is brilliant.
        I didn't realize that a snippet could be used for the getlistwhere parameter. This is super powerful.

        It's working great.
        One more question. Is there a way to use a property of the actual tv that implements migx configuration.
        So for example i created a tv "categories" that uses Input Type = migxdb and Configurations = migxresourcerelations_source. I added a property on this TV called type_root_id = 18, where 18 is the id of the root document in the category branch. Is there a way to use this tv property to set the default filter value? This will allow to use just one configuration for many relationship tvs.
          • 4172
          • 5,888 Posts
          ok, took me a while to figure that out.

          there is a way to have one configuration for many grids.
          The issue is, each grid needs to have a unique grid-id, this is what the unique-migx-id-setting is for.
          And each filter needs to have a unique name, too.
          So we need to find a way, to give each grid this unique values, without having a whole new configuration for each.

          This seems to be successfull:

          give each TV the same configurations(in the input-options of that MIGXdb-TV)
          followed by the type_root_id, seperated by comma
          example configurations:
          migxresourcerelations_source,18
          migxresourcerelations_source,55

          copy the 'filters' part from the configuration migxresourcerelations_source
          remove all db-filters from that configuration, we add them back dynamically with a php-config-file

          and modify the file
          core/components/migxresourcerelations/migxconfigs/migxresourcerelations_source.config.inc.php

          with this code:

          <?php
          
          $this->customconfigs['sortConfig'] = '
          [{"sortby":"Parent.pagetitle","sortdir":"ASC"},{"sortby":"modResource.pagetitle","sortdir":"ASC"}]
          ';
          
          $this->customconfigs['sourceortarget'] = 'source';
          $this->customconfigs['selectfields'] = 'id,pagetitle';
          
          //$configs = explode(',', $this->modx->getOption('configs', $_REQUEST, ''));
          
          if (count($configs) > 1) {
              $type_root_id = $configs[1];
              
              $this->customconfigs['win_id'] = $this->customconfigs['win_id'] . $type_root_id;
              
              $filters = '[
              {
                "MIGX_id":1,
                "name":"source_parent'.$type_root_id.'",
                "label":"parent",
                "emptytext":"filter Parent",
                "type":"treecombo",
                "getlistwhere":"{\"id:IN\":[ [[getChildIds? &parent=`[[+source_parent'.$type_root_id.']]` &context=`web`]] ]}",
                "getcomboprocessor":"gettreenode",
                "combotextfield":"pagetitle",
                "comboidfield":"id",
                "comboparent":"",
                "default":'.$type_root_id.'
              },
              {
                "MIGX_id":2,
                "name":"source_published'.$type_root_id.'",
                "label":"published",
                "emptytext":"filter published",
                "type":"combobox",
                "getlistwhere":{
                  "ResourceRelation.published":"[[+source_published'.$type_root_id.']]"
                },
                "getcomboprocessor":"getyesnocombo",
                "combotextfield":"",
                "comboidfield":"",
                "comboparent":""
              },
              {
                "MIGX_id":3,
                "name":"source_active'.$type_root_id.'",
                "label":"active",
                "emptytext":"filter active",
                "type":"combobox",
                "getlistwhere":{
                  "ResourceRelation.active":"[[+source_active'.$type_root_id.']]"
                },
                "getcomboprocessor":"getyesnocombo",
                "combotextfield":"",
                "comboidfield":"",
                "comboparent":""
              },
              {
                "MIGX_id":4,
                "name":"source_search'.$type_root_id.'",
                "label":"search",
                "emptytext":"Search...",
                "type":"textbox",
                "getlistwhere":{
                  "pagetitle:LIKE":"%[[+source_search'.$type_root_id.']]%",
                  "OR:id:=":"[[+source_search]]"
                },
                "getcomboprocessor":"",
                "combotextfield":"",
                "comboidfield":"",
                "comboparent":""
              }
            ]';
          
              $this->customconfigs['filters'] = $this->modx->fromJson($filters);
              
          }
          
          


          this gives each grid a uniqe footstep (the win_id)
          and each db-filter a unique name
          and sets the default-value for the tree-combo the the type_root_id

          did work for me.




          [ed. note: Bruno17 last edited this post 12 years, 3 months ago.]
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 22448
            • 241 Posts
            Fantastic, worked like a charm.
            Thanks a lot.
            I bought you a beer and will have one as well.

            Prost.
              • 4172
              • 5,888 Posts
              Hey Kiril,
              thanks for the beer!

              Prost!
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 22448
                • 241 Posts
                Hi Bruno,
                so i finally finished importing all of the data. Took a long time to clean it all up.
                It appears that the filters on CMP for the relationships don't work. When i click on Filter Active and Filter Published no rows are being shown. But there are rows with Published and Active set to 1. I did notice that in the columns specification there are 2 instances of the active and published ones. But all of them have the value of 1. The joins code is at the bottom.

                Here are few more findings and questions:
                1. Column sorting doesn't work for any columns
                2. Is there a way to change the width of the filter fields similar to the column width
                3. In the parent filter field currently the parent ID is shown. Instead i'd like to show the parent pagetitle. Possible?
                4. By default the grid shows all rows and then allows to filter by active, published. Is there a way to reverse this behavior and filter by active by default.
                5. When setting the grid to load automatically (auto) instead of by the button i get modx login box and this error:
                Code: 401 Unauthorized
                {"success":false,"message":"Access denied.","total":0,"data":[],"object":{"code":401}}


                When a user clicks on the template variable tab i would like the grid to load automatically instead of requiring anothe click.

                This is a lot of issues, sorry about that. Filtering and sorting are the most critical right now.
                Thanks a lot.

                Here's the export of the configuration.
                {
                  "formtabs":"",
                  "contextmenus":"",
                  "actionbuttons":"",
                  "columnbuttons":"activate||deactivate||publishtarget||unpublishtarget",
                  "filters":"",
                  "extended":{
                    "migx_add":"",
                    "formcaption":"",
                    "update_win_title":"",
                    "win_id":"relations_source",
                    "maxRecords":"",
                    "addNewItemAt":"bottom",
                    "multiple_formtabs":"",
                    "actionbuttonsperrow":4,
                    "winbuttonslist":"",
                    "extrahandlers":"",
                    "filtersperrow":4,
                    "packageName":"migxresourcerelations",
                    "classname":"modResource",
                    "task":"",
                    "getlistsort":"",
                    "getlistsortdir":"",
                    "use_custom_prefix":"0",
                    "prefix":"",
                    "grid":"",
                    "gridload_mode":1,
                    "check_resid":"0",
                    "check_resid_TV":"",
                    "join_alias":"",
                    "has_jointable":"yes",
                    "getlistwhere":"",
                    "joins":[
                      {
                        "alias":"Parent",
                        "selectfields":"id,pagetitle"
                      },
                      {
                        "alias":"ResourceRelation",
                        "classname":"rrResourceRelation",
                        "on":"ResourceRelation.target_id = modResource.id AND ResourceRelation.source_id =[[+resource_id]]"
                      }
                    ],
                    "cmpmaincaption":"",
                    "cmptabcaption":"",
                    "cmptabdescription":"",
                    "cmptabcontroller":"",
                    "winbuttons":"",
                    "onsubmitsuccess":"",
                    "submitparams":""
                  },
                  "columns":[
                    {
                      "MIGX_id":4,
                      "header":"ID",
                      "dataIndex":"id",
                      "renderer":"",
                      "sortable":"false",
                      "show_in_grid":1
                    },
                    {
                      "MIGX_id":3,
                      "header":"Parent",
                      "dataIndex":"Parent_pagetitle",
                      "width":"",
                      "sortable":"false",
                      "show_in_grid":1,
                      "renderer":"",
                      "clickaction":"",
                      "selectorconfig":"",
                      "renderoptions":""
                    },
                    {
                      "MIGX_id":1,
                      "header":"Pagetitle",
                      "dataIndex":"pagetitle",
                      "width":200,
                      "sortable":"false",
                      "show_in_grid":1,
                      "renderer":"this.renderRowActions",
                      "clickaction":"",
                      "selectorconfig":"",
                      "renderchunktpl":"",
                      "renderoptions":""
                    },
                    {
                      "MIGX_id":2,
                      "header":"Active",
                      "dataIndex":"ResourceRelation_active",
                      "width":"",
                      "sortable":"false",
                      "show_in_grid":1,
                      "renderer":"this.renderCrossTick",
                      "clickaction":"",
                      "selectorconfig":"",
                      "renderoptions":""
                    },
                    {
                      "MIGX_id":5,
                      "header":"Published",
                      "dataIndex":"ResourceRelation_published",
                      "width":"",
                      "sortable":"false",
                      "show_in_grid":1,
                      "renderer":"this.renderCrossTick",
                      "clickaction":"",
                      "selectorconfig":"",
                      "renderoptions":""
                    },
                    {
                      "MIGX_id":6,
                      "header":"Active",
                      "dataIndex":"Joined_active",
                      "width":"",
                      "sortable":"false",
                      "show_in_grid":"0",
                      "renderer":"this.renderCrossTick",
                      "clickaction":"",
                      "selectorconfig":"",
                      "renderoptions":""
                    },
                    {
                      "MIGX_id":7,
                      "header":"Published",
                      "dataIndex":"published",
                      "width":"",
                      "sortable":"false",
                      "show_in_grid":"0",
                      "renderer":"this.renderCrossTick",
                      "clickaction":"",
                      "selectorconfig":"",
                      "renderoptions":""
                    },
                    {
                      "MIGX_id":8,
                      "header":"Type",
                      "dataIndex":"ResourceRelation_rel_type",
                      "width":"",
                      "sortable":true,
                      "show_in_grid":1,
                      "renderer":"",
                      "clickaction":"",
                      "selectorconfig":"",
                      "renderchunktpl":"",
                      "renderoptions":""
                    }
                  ]
                }
                


                Here are the joins:

                [{"alias":"Parent","selectfields":"id,pagetitle"},{"alias":"ResourceRelation","classname":"rrResourceRelation","on":"ResourceRelation.target_id = modResource.id AND ResourceRelation.source_id =[[+resource_id]]"}]