filtering rows from a repeater field
Started by Rob, Jul 18 2012 10:13 AM
8 replies to this topic
#2
Posted 18 July 2012 - 03:06 PM
I think it's easy if you see the repeaters as pages array
Out of my head this can be done like this:
Out of my head this can be done like this:
$elements = $page->repeater->find("checkboxfield=1");
@somartist | modules created | support me, flattr my work flattr.com
#3
Posted 18 July 2012 - 06:45 PM
Yeah, Soma's right!
You can do it this way:
or this:
You can do it this way:
foreach ($page->myrepeater as $item) {
if ($item->visible) {
echo "<p>$item->title</p>";
//or do something else...
}
}or this:
foreach ($page->myrepeater->find('visible=1') as $item) {
echo "<p>$item->title</p>";
//or do something else...
}
#4
Posted 23 July 2012 - 06:05 AM
Thanks chaps!
I had tried that and thought it wasn't working, but in fact it was. What was happening was that I had pulled an entire page of data, then was trying to "overwrite" one part of it with the filtered version of itself. Trying to overwrite an object with an array = bad news!
I had tried that and thought it wasn't working, but in fact it was. What was happening was that I had pulled an entire page of data, then was trying to "overwrite" one part of it with the filtered version of itself. Trying to overwrite an object with an array = bad news!
#5
Posted 03 December 2012 - 07:32 AM
I can't seem to get repeater selectors work correctly with date fields. I have a repeater with four fields:
Results I am getting are strange:
Show me where I am doing it wrong (I still have a bad gut feeling about doing something very silly here). I have tested this on pretty recent stable version and also latest dev version. I do similar stuff in many places (with events-item template etc), so I do know it should work - but for some reason I don't can get it working with repeaters.
- photo (single image)
- bannerlink (page field)
- startdate (date)
- enddate (date)
Results I am getting are strange:
// Get the current timestamp
$time = time();
// I put my repeater pages into variable
$banners = $page->shop_banners;
// This is where things start to go strange
$less_banners = $banners->find("enddate>0, enddate>$time");
foreach($less_banners as $p) {
echo "START: " . $p->startdate . " < NOW: " . date("j.m.Y H:s", $time) . " < END: " . $p->enddate . "<br>";
}
/*
I have total 6 items, where 4 doesn't have anything on enddate, One has enddate before this moment and another has enddate after this moment.
With that loop I get rows like:
START: 7.8.2012 02:51 < NOW: 3.12.2012 14:42 < END: 4.12.2012 17:48
START: 2.12.2012 00:00 < NOW: 3.12.2012 14:42 < END: 2.12.2012 23:00 // THIS LINE SHOULD NOT BE HERE?
*/
// Then if I put it other way around:
$less_banners = $banners->find("enddate>0, enddate<$time");
foreach($less_banners as $p) {
echo "START: " . $p->startdate . " < NOW: " . date("j.m.Y H:s", $time) . " < END: " . $p->enddate . "<br>";
}
/* I get zero results */
Show me where I am doing it wrong (I still have a bad gut feeling about doing something very silly here). I have tested this on pretty recent stable version and also latest dev version. I do similar stuff in many places (with events-item template etc), so I do know it should work - but for some reason I don't can get it working with repeaters.
#8
Posted 03 December 2012 - 09:38 AM
Antti, it looks like this is a result of output formatting being on, so it's doing a string comparison rather than a time comparison. This is not intended and not a detail people should not have to account for, so I'd consider it a bug. Thanks for tracking it down. The bug is only for in-memory finds on date fields, not database finds, as it's working how it should there already. I've put a fix in the latest commit to the dev branch of you want to try it out. It shows two files updated, but the only one that matters here is /wire/core/Array.php
https://github.com/r...d8436789be2897c
https://github.com/r...d8436789be2897c
#9
Posted 03 December 2012 - 04:36 PM
Thanks Ryan for superfast reply & fix, I'll test this tomorrow.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users













