We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 20093
    • 81 Posts
    I've looked, but I can't find a recommended way to use MIGX values to filter a getResources call. I'm at the point where I am considering using Simplx Widgeteer to parse the JSON and return the value I'm looking for to the getResources call, but this seems like overkill, doesn't it?

    It would be awesome if we could use dot notation, something like &tvFilters=`myMIGXtv.myJSONkey==myJSONvalue` in the getResources call

    Has anyone done this? [ed. note: MokoJumbie last edited this post 14 years, 7 months ago.]
      • 4172
      • 5,888 Posts
      you have concrete example? more details?
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 44234
        • 219 Posts
        Hi Bruno, know this was a long time ago, but is there a away of filtering pdoResources or getResources results by MIGX TV's?
          Find me on Twitter, GitHub or Google+
          • 34109
          • 119 Posts
          For that sort of filtering to work, you'd have to parse the JSON in the TV value for every resource in order to get a list of IDs. If the value is unique in the MIGX TV data then a normal sql like statement would be able to find it, but if you're trying to match a json key and value then I can't see this being possible using mysql alone. Do you have any more info?
            Studio Republic
            http://www.studiorepublic.com
            0845 226 3205
            @christodhunter
            • 44234
            • 219 Posts
            Thanks for getting back to me chris.

            I have around 150 resources using a migx tv (proAwards) to list multiple awards won (per resource). I would like to use pdoResources to list just the resources which won awards in a certain year.

            The problem is I don't know if its possible to reference the specific migx field for filtering. I'd ideally like to compare the year values from the year field in my migx tv and include the resource if it matches. Something like:
            [[pdoResources?
            &parents=`537`
            &limit=`0`
            &showHidden=`0`
            &sortby=`publishedon`
            &sortdir=`DESC`
            &includeTVs=`proAwards`
            &processTVs=`proAwards`
            &tpl=`overviewAwardTpl`
            &tvFilters=`proAwards.year==2015`
            ]]
            

            Example raw output from my migx 'proAwards' tv is:
            [
            {"MIGX_id":"3","status":"Winner","name":"Award Name 1","body":"Award Cermony 1","year":"2015"},
            {"MIGX_id":"4","status":"Winner","name":"Award Name 2","body":"Award Cermony 2","year":"2015"},
            {"MIGX_id":"2","status":"Winner","name":"Award Name 3","body":"Award Cermony 3","year":"2013"},
            {"MIGX_id":"5","status":"Roll of Honour","name":"Award Name 4","body":"Award Cermony 4","year":"2012"}
            ]
            

            Is this possible and if not does anyone have an idea on how to do this?

            Thanks
              Find me on Twitter, GitHub or Google+
              • 4172
              • 5,888 Posts
              you would need a script, which would loop thrue all MIGX-items of all resources.
              That's not the best option and wouldn't scale with a lot of Resources.

              But it would be possible to import all MIGX-items into a custom-table and use a MIGXdb-TV instead of the MIGX-TV to manage them.

              Then it's easy to join and filter Resources together with that items.
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 44234
                • 219 Posts
                Quote from: Bruno17 at Sep 30, 2015, 12:46 PM
                But it would be possible to import all MIGX-items into a custom-table and use a MIGXdb-TV instead of the MIGX-TV to manage them.

                Ok thanks Bruno, I will have a look at this. Could you explain a few things for me as I'm new to MIGX-DB and the docs seem a bit patchy:

                • Would all the awards be stored in a custom table?
                • How would I link them to their respective resource?
                • How would I import all the awards stored in a MIGX TV to a custom table? Is there something built in?
                • Can I manage a resources respective awards using a TV simular to a normal MIGX TV?
                • Would I use 'loopCollection' to display in the frontend and impliment the filter?

                Thanks
                  Find me on Twitter, GitHub or Google+
                  • 4172
                  • 5,888 Posts
                  yes all awards would be in one custom-table.
                  They would be linked by the field 'resource_id'.

                  the setup would be much like that:
                  https://rtfm.modx.com/extras/revo/migxdb/migxdb.tutorials/migxdb.create-a-basic-gallery-management-from-scratch-with-migxdb

                  But your schema would look like that:

                  <?xml version="1.0" encoding="UTF-8"?>
                  <model package="awards" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
                          <object class="awAward" table="aw_awards" extends="xPDOSimpleObject" >
                          <field key="name" dbtype="varchar" precision="255" phptype="string" null="false" default="" index="index" />
                          <field key="status" dbtype="varchar" precision="255" phptype="string" null="false" default="" index="index" /> 
                          <field key="body" dbtype="varchar" precision="255" phptype="string" null="false" default=""  />                  
                          <field key="resource_id" dbtype="int" precision="11" phptype="integer" null="false" default="0" index="index"/>
                          <field key="year" dbtype="int" precision="4" phptype="integer" null="false" default="0" index="index"/>        
                  
                          <aggregate alias="Resource" class="modResource" local="resource_id" foreign="id" cardinality="one" owner="foreign" />
                          </object>
                  </model>
                  


                  the packageName is 'awards' in this case.

                  to import all MIGX-items into your table, create a snippet like that:

                  <?php
                  
                  $parent = $modx->getOption('parent', $scriptProperties, '');
                  
                  $packageName = 'awards';
                  
                  $packagepath = $modx->getOption('core_path') . 'components/' . $packageName . '/';
                  $modelpath = $packagepath . 'model/';
                  if (is_dir($modelpath)) {
                      $modx->addPackage($packageName, $modelpath);
                  
                      $classname = 'awAward';
                  
                      if ($resources = $modx->getCollection('modResource', array('parent' => $parent))) {
                          foreach ($resources as $resource) {
                              $items = $modx->fromJson($resource->getTVValue('proAwards'));
                  
                              if (is_array($items)) {
                                  foreach ($items as $item) {
                                      $object = $modx->newObject($classname);
                                      $object->fromArray($item);
                                      $object->set('resource_id', $resource->get('id'));
                                      $object->save();
                                  }
                              }
                  
                          }
                      }
                  }
                  


                  put it on a (unpublished) resource and call that resource once. Only once, otherwise you would have duplicate entries!

                  Then you can do for example this:

                  [[migxLoopCollection?
                  &packageName=`awards`
                  &classname=`awAward`
                  &where=`{"year":"2015"}`
                  &groupby=`resource_id`
                  &tpl=`@CODE:[[+resource_id]]`
                  &outputSeparator=`,`
                  &toPlaceholder=`resource_ids`
                  ]]
                  
                  [[pdoResources?
                  &parents=`537`
                  &limit=`0`
                  &showHidden=`0`
                  &sortby=`publishedon`
                  &sortdir=`DESC`
                  &tpl=`overviewAwardTpl`
                  &where=`{"id:IN":[ [[+resource_ids]] ]}`
                  ]]
                  



                  [ed. note: Bruno17 last edited this post 11 years ago.]
                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 44234
                    • 219 Posts
                    This is great Bruno, thanks again. I have this almost working how I need but I have a question regarding the TV.

                    I have selected the 'Add Item' action button which allows me to add awards to the custom table but how do I remove them and re-order them? Theres nothing listed for this in the action button tab and the 'Column Buttons' and 'Handler' tabs don't seem to do anything?

                      Find me on Twitter, GitHub or Google+
                      • 4172
                      • 5,888 Posts
                      Select 'remove' under contextmenues or, if you have one column with the renderer 'this.renderRowActions' then under columnbuttons

                      There isn't reordering by drag/drop like with a MIGX - TV,
                      but you can sort by any field at the frontend.

                      &sortConfig=`[{"sortby":"name","ASC"},{"sortby":"status","sortdir":"DESC"}]`
                        -------------------------------

                        you can buy me a beer, if you like MIGX

                        http://webcmsolutions.de/migx.html

                        Thanks!