We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 13218
    • 134 Posts
    I rewrote that script a little, maybe that could help you.

    First create a new snippet, call it "MIGX_removeOldEntries"
    Paste this code:
    $dateFormat = $modx->getOption('dateFormat', $scriptProperties, 'Y-m-d H:i:s');
    $checkTime = $modx->getOption('checkTime', $scriptProperties, date($dateFormat, time()) );
    $migxResourceId = $modx->getOption('migxResourceId', $scriptProperties, false );
    $migxTVName = $modx->getOption('migxTVName', $scriptProperties, false );
    $migxCheckField = $modx->getOption('migxCheckField', $scriptProperties, false );
    $resourceCheckTV = $modx->getOption('resourceCheckTV', $scriptProperties, false );
    
    if( !$migxResourceId || !$migxTVName || !$migxCheckField ||!$resourceCheckTV ) return '';
    if( !$migxResource = $modx->getObject('modResource', $migxResourceId) ) return '';
    
    // get MIGX data as array
    $migxEntries = $migxResource->getTVValue($migxTVName);
    if( $migxEntries == '' ) return '';
    $migxEntries = json_decode($migxEntries);
     
    // get array with resource ids
    $resource_ids = array();
    foreach( $migxEntries as $entry ) {
        $resource_ids[] = $entry->$migxCheckField;
    }
    // get all resources with these ids
    $q = $modx->newQuery('modResource');
    $q->where( array(
        'id:IN' => $resource_ids
    ));
    $resources = $modx->getCollection('modResource',$q);
     
    // delete old migxEntries
    foreach( $resources as $resource ) {
    	$resourceDate = $resource->getTVValue($resourceCheckTV);
        if( $resourceDate != '' && $resourceDate < $checkTime ) {
            // delete entry with resource's id
            foreach( $migxEntries as $key => $entry ) {
                if( $entry->$migxCheckField == $resource->id ) {
                    array_splice($migxEntries, $key, 1);
                    break;
                }
            }
        }
    }
     
    // store new values in MIGX TV
    $tv = $modx->getObject('modTemplateVar',array('name' => $migxTVName));
    $tv->setValue($migxResourceId, json_encode($migxEntries));
    $tv->save();
    
    return '';



    You call this snippet like this, for example:
    [[ !MIGX_removeOldEntries?
    	&dateFormat = `Y-m-d H:i:s`
    	&checkTime = `2011-03-12 00:00:00`
    	&migxResourceId = `24`
    	&migxTVName = `myMIGXTV`
    	&migxCheckField = `resourceid`
    	&resourceCheckTV = `eventDate`
    ]]

    Obviously you would have to adjust to values to your needs. If you omit checkTime, the current time will be used.

    I guess you would call the snippet like this somewhere right before you use the contents of your MIGX TV. If you don't know where that would be in your case or if there are settings that do not fit your setup i guess we should maybe switch to email or something, so as not to spam this thread.

    (Keep in mind that this is still not tested code, so take precaution using it. I guess at worst it could delete the data in your MIGX TV.)

    Cheers.
      @itWilllBeOK
      • 1331
      • 129 Posts
      I'll try that out and report back
        • 13218
        • 134 Posts
        Hi Bruno,
        do you have any thoughts on that discrepancy of id numbers as mentioned in https://forums.modx.com/thread/41006/migx---multiitemsgridtv-for-modx---revolution?page=19#dis-post-396494?

        I really don't want to bug you too much, i'm trying to understand how it all works. I guess you would know if those ids should be similar or not, and tell me if i'm looking in the right place or save me some time if not.

        Your help is much appreciated.
        Marc
          @itWilllBeOK
          • 4172
          • 5,888 Posts
          if its online, I can have a quick look and try to find out, what goes wrong, when you send me your manager-login infos.
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 8872
            • 41 Posts
            I am new to migx (and generally to modx) and whatever I do to install it, I can not see migx as input type when I try to create new tv, just regular ones (text, image, etc).

            Sorry if this's been asked before. Using modx 2.1.3 and latest migx.
              • 4172
              • 5,888 Posts
              Quote from: encho at Oct 12, 2011, 11:41 AM
              I am new to migx (and generally to modx) and whatever I do to install it, I can not see migx as input type when I try to create new tv, just regular ones (text, image, etc).

              Sorry if this's been asked before. Using modx 2.1.3 and latest migx.

              After installation per package-manager there should be a plugin for migx.
              Is it?
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 8872
                • 41 Posts
                Quote from: Bruno17 at Oct 12, 2011, 11:46 AM
                Quote from: encho at Oct 12, 2011, 11:41 AM
                I am new to migx (and generally to modx) and whatever I do to install it, I can not see migx as input type when I try to create new tv, just regular ones (text, image, etc).

                Sorry if this's been asked before. Using modx 2.1.3 and latest migx.

                After installation per package-manager there should be a plugin for migx.
                Is it?

                Yes there is, something obviously wrong here. It is fresh installation of 2.1.3.
                  • 8830
                  • 98 Posts
                  First: Thanks for a great plugin! Very useful.

                  I have a little problem with using a variable inside the where-json-string.
                  I'm running a MIGX getImageList inside an other MIGX getImageList -template.

                  [[getImageList? 
                  &tvname=`migxProducts` 
                  &where=`{"productGroupName:=":"[[+productGroupName]]","productItemType:=":"product"}` 
                  &tpl=`migxProductsListRowTpl`]]


                  It's seems that it's the [[+productGroupName]] that breaks it all. I need to use that variable in the where string.

                  Any clue of what's wrong or if there's a solution?

                  Thanks in advance.
                    • 23491 ☆ A M B ☆
                    • 1,056 Posts
                    Quote from: Bruno17 at Oct 12, 2011, 11:46 AM

                    After installation per package-manager there should be a plugin for migx.

                    For anyone not seeing the MIGX plugin, check within your other Plugin categories. In my case (using Revo 2.2.0-dev), MIGX plugin seemed hard-coded to category = 2. However, for my install, the "MIGX" category was actually category = 9.

                    It took me looking in the database directly (`modx_site_plugins` table) to see that the plugin was actually created...

                    Also, for MIGX + Revo 2.2 compatibility this patch came in handy: https://gist.github.com/1266540
                      Mike Reid - www.pixelchutes.com
                      MODx Ambassador / Contributor
                      [Module] MultiMedia Manager / [Module] SiteSearch / [Snippet] DocPassword / [Plugin] EditArea / We support FoxyCart
                      ________________________________
                      Where every pixel matters.
                      • 4172
                      • 5,888 Posts
                      Also, for MIGX + Revo 2.2 compatibility this patch came in handy: https://gist.github.com/1266540
                      added this patch with the last github-commit, but didn't test it myself.
                      https://github.com/Bruno17/multiItemsGridTV/commit/e2c41d409732515dfb50a37298129745e559ddad

                      Thanks!
                        -------------------------------

                        you can buy me a beer, if you like MIGX

                        http://webcmsolutions.de/migx.html

                        Thanks!

                      This discussion is closed to further replies. Keep calm and carry on.