We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4172
    • 5,888 Posts
    Quote from: tomahl at Sep 20, 2011, 02:43 PM
    Hello Bruno and thanks for a great extension!

    I have a small problem that I hope you can help me with. I'm using your MIGX to output product-related document(s). My problem is that I first need to check the TV's value, so that I do not render the surrounding HTML if the value is empty. That does not work properly at the moment.

    The template file looks something like this:

    [[*productDoc:!empty=`
    <h2>Title</h2>
    <ul class="file-list">
    [[getImageList? &tvname=`productDoc` &tpl=`productDoc`]]
    </ul>`]]


    If I remove the document and re-save my resource, the <h2>Title</h2> still renders. First after clearing the manager cache it disappears. Any idea how I can get this to work?

    TIA


    you can try:

    [[getImageList? &tvname=`productDoc` &tpl=`productDoc` &toPlaceholder=`pDoc`]]
    [[+pDoc:!empty=`
    <h2>Title</h2>
    <ul class="file-list">
    [[+pDoc]]
    </ul>`]]



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

      you can buy me a beer, if you like MIGX

      http://webcmsolutions.de/migx.html

      Thanks!
      • 1331
      • 129 Posts
      Quote from: Bruno17 at Oct 07, 2011, 12:36 AM
      create a snippet called 'strftime' :

      <?php
      return strftime($format);


      and use it this way, when your date-field is called 'date' :
      &where=`{ "date:>" : "[[!strftime? &format=`%Y-%m-%d`]]" }`

      In my situation, the date is a TV on the document, and not a part of MIGX. Is it possible to get them to interact somehow?
        • 4172
        • 5,888 Posts
        Quote from: ambaxter at Oct 10, 2011, 07:01 PM


        In my situation, the date is a TV on the document, and not a part of MIGX. Is it possible to get them to interact somehow?

        I'm afraid, not understanding your situation correctly. Can you explain a bit more?
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 13218
          • 134 Posts
          Hi,
          i'm having trouble using migx in a project. I used it several times and got it to work quite easily (thanks so much for this add-on, Bruno!).

          Problem: i have an easy test setup for the migx TV, which actually works in a 2.1.3pl installation:
          [
          	{"caption":"Exhibition", "fields": [
          		{"field":"mtitle","caption":"Title","inputTV":"exh_title"}
          	]}
          ]
          
          
          [
          	{"header": "Title", "width": "160", "sortable": "true", "dataIndex": "mtitle"}
          ]

          But in this other 2.1.3pl installation it also works as expected, but when i create a new entry, the value of mtitle is not transferred from the create-panel into the list, even though an { "mtitle": "" } is created.

          It obviously has to be something specific to this installation, but i don't even know where to start looking - any ideas?

          Much appreciated,
          Marc
            @itWilllBeOK
            • 4172
            • 5,888 Posts
            do you perpaps have the TV 'exh_title' assigned to your template?
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 13218
              • 134 Posts
              Hi Bruno,
              no template is called totally different.

              Maybe this is a hint:
              in migx.tpl > MODx.window.UpdateTvItem > submit:function in line 363 the fields[i].tv_id is different from the tvid in the actual html of the field in the window where i can enter the value.
              In the other installation, where it works, these ids are the same.

              I hope i explained that right...

              [update] I attached a Firebug screenshot where i marked the two places, where the TV numbers are different. I#m trying to understand, how and where these numbers are generated... [ed. note: itWillBeOk last edited this post 14 years, 11 months ago.]
                @itWilllBeOK
                • 13218
                • 134 Posts
                Oops, sorry. Misread.
                No, the exh_title TV is not assigned to any template.
                  @itWilllBeOK
                  • 1331
                  • 129 Posts
                  Quote from: Bruno17 at Oct 10, 2011, 11:39 PM
                  Quote from: ambaxter at Oct 10, 2011, 07:01 PM


                  In my situation, the date is a TV on the document, and not a part of MIGX. Is it possible to get them to interact somehow?

                  I'm afraid, not understanding your situation correctly. Can you explain a bit more?


                  There is a TV in my documents that sets the event date. Then, in a separate document, I'm picking from this list of event documents using a Resource List TV in MIGX.

                  What I'd like to do is have MIGX automatically drop documents whose event dates have passed.
                    • 13218
                    • 134 Posts
                    Hi Mr. Baxter.

                    I don't think MIGX, as it is, can do that on its own.

                    But you could easily do that thing with a small script, i guess. You probably already have script where you get the values stored in the MIGX TV and put together some kind of list for output.
                    So, before you do that
                    - get the MIGX TV values
                    - walk the array, get the resource
                    - if resource has older event date, remove corresponding array from array-list
                    - store the changed array list in MIGX TV

                    This i adapted from smth i have used, it's quick'n'dirty, not tested. But you may get the gist. You could probably do it much more elegantly, feel free to improve.
                    // today's date, you may have to change the format
                    $now = date('Y-m-d H:i:s', time());
                    
                    // get MIGX data as array
                    $entries = json_decode( $modx->resource->getTVValue('your_migx_tv'), true );
                    
                    // get array with resource ids
                    $resource_ids = array();
                    foreach( $entries as $entry ) {
                    	$resource_ids[] = $entry->stored_resource_id;
                    }
                    // get all resources with these ids
                    $q = $modx->newQuery(_modResource');
                    $q->where( array(
                    	'id:IN' => $resource_ids
                    ));
                    $resources = $modx->getCollection('modResource',$q);
                    
                    // delete old entries
                    foreach( $resources as $resource ) {
                    	if( $resource->getTVValue('event_date') < $now ) {
                    		// delete entry with resource's id
                    		foreach( $entries as $key => $entry ) {
                    			if( $entry->stored_resource_id == $resource->id ) {
                    				array_splice($entries, $key, 1);
                    				break;
                    			}
                    		}
                    	}
                    }
                    
                    // store new values in MIGX TV
                    $tv = $modx->getObject('modTemplateVar',array('name'=>'your_migx_tv'));
                    $tv->setValue($modx->resource->id, json_encode($entries));
                    $tv->save();
                      @itWilllBeOK
                      • 1331
                      • 129 Posts
                      Quote from: itWillBeOk at Oct 11, 2011, 11:42 AM
                      Hi Mr. Baxter.

                      I don't think MIGX, as it is, can do that on its own.

                      But you could easily do that thing with a small script, i guess. You probably already have script where you get the values stored in the MIGX TV and put together some kind of list for output.
                      So, before you do that
                      - get the MIGX TV values
                      - walk the array, get the resource
                      - if resource has older event date, remove corresponding array from array-list
                      - store the changed array list in MIGX TV

                      This i adapted from smth i have used, it's quick'n'dirty, not tested. But you may get the gist. You could probably do it much more elegantly, feel free to improve.
                      // today's date, you may have to change the format
                      $now = date('Y-m-d H:i:s', time());
                      
                      // get MIGX data as array
                      $entries = json_decode( $modx->resource->getTVValue('your_migx_tv'), true );
                      
                      // get array with resource ids
                      $resource_ids = array();
                      foreach( $entries as $entry ) {
                      	$resource_ids[] = $entry->stored_resource_id;
                      }
                      // get all resources with these ids
                      $q = $modx->newQuery(_modResource');
                      $q->where( array(
                      	'id:IN' => $resource_ids
                      ));
                      $resources = $modx->getCollection('modResource',$q);
                      
                      // delete old entries
                      foreach( $resources as $resource ) {
                      	if( $resource->getTVValue('event_date') < $now ) {
                      		// delete entry with resource's id
                      		foreach( $entries as $key => $entry ) {
                      			if( $entry->stored_resource_id == $resource->id ) {
                      				array_splice($entries, $key, 1);
                      				break;
                      			}
                      		}
                      	}
                      }
                      
                      // store new values in MIGX TV
                      $tv = $modx->getObject('modTemplateVar',array('name'=>'your_migx_tv'));
                      $tv->setValue($modx->resource->id, json_encode($entries));
                      $tv->save();

                      Thanks for this. Unfortunately, I don't have any script for grabbing the resources. I'm just using the one provided by MODx itself in the form of the standard Resources TV input option.

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