-
Posts
812 -
Joined
-
Last visited
Everything posted by a-ok
-
Excluding a past event from a PageReference field after it's been chosen
a-ok replied to a-ok's topic in General Support
Thanks for help, Dave. I originally had this but for some reason the date set in the CMS (to today's date) has passed when using strtotime("now") my guess is that the date today starts at midnight whereas now is... well, now so in a sense it has passed (in UNIX time). -
Excluding a past event from a PageReference field after it's been chosen
a-ok replied to a-ok's topic in General Support
There does seem to be one issue when the $next_upcoming date is the same date as today ($today = strtotime("now");) it seems to set it as NULL (setting a date before or after today is fine... just when it is today (which'll obviously inevitable happen). So, the event that is today... this is being included in the original query (obviously) // Set up the original query (to find all events in date) $today = strtotime("now"); $events = $pages->find("template=events-detail, events_detail_dates_sort_date>=today"); But when we go into the foreach and set the $next_upcoming... even though it should be returning it's returning NULL... could it be that the original today (PW's today) is different from $today (set by string to time now)? I changed them both to $today and now there's no errors but it doesn't include the event (even though it should as it should be >= $today). To get this to work I had to set $today to a UNIX timestamp of the date (rather than using time/now). $dateFormat = date('D. j F Y'); $today = strtotime($dateFormat); -
Excluding a past event from a PageReference field after it's been chosen
a-ok replied to a-ok's topic in General Support
Hi Robin, Yes! This all makes sense I have one issue... the line quoted above at my end is returning NULL when dumping out $next_upcoming. The dates in the CMS are in the future... do you think 'get' is the wrong method? EDIT: I hadn't set up $today yet (as was using simply today in the find selector but obviously need to define $today for the get selector). I think this is it working! Could be pretty beneficial to people this... hopefully! Thank you! P.S Also had no idea you could add custom properties like that -
Excluding a past event from a PageReference field after it's been chosen
a-ok replied to a-ok's topic in General Support
Ah right this is part of the hook, sorry, to sort the output (when returning all events). So if I was to go down the route of having a hidden field... that was populated by the latest date that hasn't passed so I could sort by that value then if I had three sets of dates.. on save it would set the hidden field's value to the date that hasn't passed yet but obviously once that date has passed it would need to update it to the next date that hasn't passed (or don't if it doesn't exist). You see it sets the sort date as the second date (as that hasn't passed yet) but when it has it should update the sort date field to the next date but alas this only happens on page save, right? So it wouldn't know to auto update it. $pages->find("template=events-detail, events_detail_dates_sort_date>=today, sort=events_detail_dates_sort_date, sort=name"); function myHook(HookEvent $event) { $page = $event->arguments(0); if ($page->template->name == 'events-detail') { // What's On detail $today = strtotime("now"); $dateRepeater = $page->events_detail_dates; foreach ($dateRepeater as $row) { $row->of(false); if ($row->events_detail_dates_start_date >= $today) { $page->set("events_detail_dates_sort_date", $row->events_detail_dates_start_date); $page->save("events_detail_dates_sort_date"); break; } } } } wire()->addHookAfter('Pages::saveReady', null, 'myHook'); -
Excluding a past event from a PageReference field after it's been chosen
a-ok replied to a-ok's topic in General Support
This is what I ended up with for the hook... $wire->addHookAfter('Pages::saveReady', function($event) { $page = $event->arguments(0); if ($page->template->name == 'events-detail') { // What's On detail $today = strtotime("now"); $dateRepeater = $page->events_detail_dates; foreach ($dateRepeater as $row) { $row->of(false); if ($row->events_detail_dates_start_date >= $today) { $page->set("events_detail_dates_sort_date", $row->events_detail_dates_start_date); $page->save("events_detail_dates_sort_date"); break; } } } }); EDIT: Only issue is that it won't auto update... only when the page is saved whereas obviously it would need to update when the date has passed so maybe it needs to check it every day? Is that mad? Or like you said "automatic sort to the repeater items so that the most distant date is always first". I was thinking of using lazyCron (although the $event arguments only return the seconds...) function myHook(HookEvent $event) { $page = $event->arguments(0); if ($page->template->name == 'events-detail') { // What's On detail $page->message("TEST!"); $today = strtotime("now"); $dateRepeater = $page->events_detail_dates; foreach ($dateRepeater as $row) { $row->of(false); if ($row->events_detail_dates_start_date >= $today) { $page->set("events_detail_dates_sort_date", $row->events_detail_dates_start_date); $page->save("events_detail_dates_sort_date"); break; } } } } wire()->addHook('LazyCron::every30Seconds', null, 'myHook'); wire()->addHookAfter('Pages::saveReady', null, 'myHook'); -
Excluding a past event from a PageReference field after it's been chosen
a-ok replied to a-ok's topic in General Support
Thanks for this, Robin. I wasn't actually aware you could loop through the repeater using find... some some reason. You were dead right re mixing HTML/PHP. Not sure why I wasn't doing that. I used your example but it spat out an error Exception: Unknown Selector operator: '' -- was your selector value properly escaped? field='events_detail_dates_start_date', value='>= 1511108093', selector: 'events_detail_dates_start_date >= 1511108093' (in /Users/rich/Sites/Sites/ofp/wire/core/Selectors.php line 378) but I've ran with this for now... foreach ($articles as $article) { if ($article->template->name == 'events-detail') { foreach ($article->events_detail_dates as $date) { // Loop through the dates if ($date->events_detail_dates_start_date >= $today) include('./inc/events-item.inc'); break; } } else { include('./inc/pick-item.inc'); } if ($count == $random) { include("./inc/cta.inc"); } $count++; } I like this idea a lot. I think what I would try to do is write a saveReady hook that grabs the date that's not been passed yet, add it to a hidden field, and sort by that. That would work for both one date and 2+ dates, right? As long as I can do my check that would work.. and be fairly robust. -
Excluding a past event from a PageReference field after it's been chosen
a-ok replied to a-ok's topic in General Support
I came up with this for the loop check... <?php $today = strtotime("now"); $articles = $page->home_whatson; ?> <?php foreach ($articles as $article) : ?> <?php if ($article->template->name == 'events-detail') : // Event ?> <?php foreach ($article->events_detail_dates as $date) : // Loop through the dates ?> <?php if ($date->events_detail_dates_start_date >= $today) : // If event hasn't passed then continue ?> <?php include('./inc/events-item.inc'); break; // At least one date is upcoming so break after this as it's already been proved successful ?> <?php endif; ?> <?php endforeach; ?> <?php else : // Our Pick ?> <?php include('./inc/pick-item.inc'); ?> <?php endif; ?> <?php endforeach; ?> -
Excluding a past event from a PageReference field after it's been chosen
a-ok replied to a-ok's topic in General Support
This is all really great, Robin. Thanks. That's super interesting to know about the use of foreach loops... for some reason I would've thought it was using a lot of extra power to check the loop with a foreach but sounds like it doesn't. That's all great. One final point... if I am adding my dates within a repeater (to allow for multiple dates) – sometimes there's one date row and sometimes there will be more, per event. Obviously what I want to do is only return the event if at least one of the dates in greater or equal to today. Is it possible to do this within the loop? Would I use a break, of sorts when one is 'in date'? On some of the pages I use this page selector $pages->find("template=events-detail, events_detail_dates.events_detail_dates_start_date>=today, sort=events_detail_dates.events_detail_dates_start_date, sort=name"); I'm assuming this query is doing what I want, right? Or is it only looking at the first repeater row (events_detail_dates) or checking all of them? EDIT: I believe the selector above is checking all the repeater rows (just checked it) but the sort option is still sorting by the date that is passed (whereas it should be sorting by the in date date... if you get me). -
Excluding a past event from a PageReference field after it's been chosen
a-ok replied to a-ok's topic in General Support
I can check each item in the loop... just always strive to resolve everything in the query but maybe not possible in this case. -
Excluding a past event from a PageReference field after it's been chosen
a-ok replied to a-ok's topic in General Support
Thanks for your reply, Robin. This makes a lot of sense and I like your breakdown of this a lot. I don't know too much about the isValidPage() method... can't find too much on the docs about it. Your code snippet line if($modules->FieldtypePage->isValidPage($item, $field, $page)) { What is this doing? isValidPage might be what I'm after but slightly confused by the arguments... Edit: Ah I see (I missed the $field declaration) but unfortunately this is still returning the event that has passed (even though it's now hidden from the PageField). -
Hi folks, I have a PageReference field which is selecting events (that are in date by a date field) and articles with a specific template. My hook in order to allow those pages is as follows: $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if ($event->object->hasField == 'home_whatson') { // Get in date events $events = new PageArray(); foreach ($event->pages->find("template=events-detail, events_detail_dates.events_detail_dates_start_date>=today, sort=events_detail_dates.events_detail_dates_start_date, sort=name") as $e) { $events->add($e); } // Get Our Picks articles $articles = new PageArray(); foreach ($event->pages->find("template=our-picks-detail, sort=sort") as $article) { $articles->add($article); } // Push events into the pages we allowed $events->import($articles); $event->return = $events; } } This works well but if an event has passed (before it is removed from the PageReference field), obviously it doesn't 'remove' it from the list it simply hides it (even though it's still technically 'selected'). I then need to do a check on the front end for this as well so it isn't returning the items that have passed. I thought this would work: $today = strtotime("now"); $articles = $page->home_whatson->filter("events_detail_dates.events_detail_dates_start_date>$today"); But it's obviously now ignoring the articles with the specific template as the filter is removing it from the list (as this should only be applied to events). Is there a way round this? Should I put removing it from the original query (using ->remove()) or is there some other way? Any help is appreciated.
-
Apologies to bring this back up but I'm having a slight issue. This seemed to be working for me before but for some reason has stopped. I am using @Robin S's ConnectPageFields and my selector is template=tags, tagged.template.name=events-detail, tagged.count>0, sort=name It should return all tagged pages which use X template and count is > 0. I swear this was working before but now when I dump out the query it's written as ["selectors"]=> string(66) "template=tags, tagged.id=0, tagged.count>0, sort=name, status<1024" } If I put 'tagged.template=' in the selector (obviously doesn't work but it's returned the same but when I use multiple sub selectors (tagged.template.name=) it seems to change it to tagged.id=0 Any thoughts?
-
Inserting a random $item into pageArray at a random point
a-ok replied to a-ok's topic in General Support
Actually what I ended up doing was this... $random = $articles->getRandom(); if ($article == $random) { ... Seemed to work pretty well. -
Thanks guys. Really appreciate it... so the only way to set the start is to include limit? That's good to know.
-
Hi folks hope all is well. I'm wanting to insert a random repeater row into a page selector loop ($pages->find()) at a random point (after the 1st, after the 5th, after the 2nd – different each reload). I have managed to get a random repeater row and now I need to insert it into my returned pages... $ctas = $pages->get("name=site-settings")->settings_ctas; $cta = $ctas->getRandom(); $events = $pages->find("template=events-detail, events_detail_dates.events_detail_dates_start_date>=today, sort=events_detail_dates.events_detail_dates_start_date, sort=name"); // Return in-date events only I thought about using $a->insertAfter($item, $existingItem) and setting $existingItem to a random integer? Is this is the best way do you reckon? http://cheatsheet.processwire.com/pagearray-wirearray/setting-and-modifying-items/a-insertafter-item-existingitem/
-
Does the "start" selector property still work? http://cheatsheet.processwire.com/selectors/built-in-page-selector-properties/start-n/ I am doing the following but doesn't seem to have any bearing... $articles = $pages->find("template=meet-the-locals-detail, start=3, sort=sort"); I liked modifying the selector query, rather than the results (with slice) as presumably it's a lot more efficient.
-
Done. Thanks everyone.
-
Actually. My host said they updated the max_input_vars but they hadn't... so I just made this amend and seems to work!
-
I think it's definitely to do with the amount of images... I've managed to add a new page alongside it, and make changes to that fine. If I duplicate one of the pages which has a lot of images on it... I can't edit it.
-
Yep... increased as well as other stuff too. I've enabled debugging to true but not returning any messages I can edit other pages... just not these ones I've uploaded the images to via the API.
-
When I click 'Save' I don't get any changed message either. Hmm.
-
I actually can't seem to edit anything on that page... even if I fill out a text field it resorts to whatever it was before.
-
Thanks for your help, @gmclelland – so there's no drawbacks to uploading via the API... it doesn't 'lock' the images or anything. Weird.
-
Hi folks, I have about 250 images in an image field on a page, and there's about 6 pages. As you can imagine this is quite a lot of image data (but they are appropriately sized so each page of images is only about 30mb). The front-end works fine but in the backend when I try to reorder the images, it allows me to reorder them but when I click 'Save' the order goes back to the original order. I had to use the API to upload these images as it was causing a few issues doing it through the interface. Any thoughts or anything I can check?
-
I wonder what is fastest? Two queries like @lokomotivan suggested (which I opted for) or @Robin S's suggestion? Thanks for all your help.