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
[[getImageList? &tvname=`productDoc` &tpl=`productDoc` &toPlaceholder=`pDoc`]] [[+pDoc:!empty=` <h2>Title</h2> <ul class="file-list"> [[+pDoc]] </ul>`]]
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?
[
{"caption":"Exhibition", "fields": [
{"field":"mtitle","caption":"Title","inputTV":"exh_title"}
]}
]
[
{"header": "Title", "width": "160", "sortable": "true", "dataIndex": "mtitle"}
]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?
// 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();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();
This discussion is closed to further replies. Keep calm and carry on.