Jump to content

celfred

Members
  • Posts

    180
  • Joined

  • Last visited

Everything posted by celfred

  1. Hello, I can't understand how this destructive filter() work. Here's my code (with annotations to explain my issue) : $teamPlayers = $pages->find("parent.name=players, team=$team"); bd($monster->name.':'.$teamPlayers->count()); // There should be 24 players in my team (which is the case on first call) foreach ($teamPlayers as $p) { $result = $p->child("name=tmp")->tmpMonstersActivity->get("monster=$monster, bestTime>0"); if ($result) { $p->bestTime = $result->bestTime; } else { $p->bestTime = 0; } } $teamPlayers->filter("bestTime>0")->sort("bestTime"); // I want to return only the list of players having a best time on this monster return $teamPlayers; My problem is that after several calls (for all monsters) the number of players in the team is not 24 but 1… I guess the $teamPlayers never resets and I can't understand why line 1 doesn't start with 24 again… If I code this for the 2 last lines, it works : $teamMates = $teamPlayers->find("bestTime>0")->sort("bestTime"); return $teamMates; But I would like to understand what's going on with my 1st version (I guess it is the destructive aspect of filter()) 😞 So if someone could take a little time to explain, I would appreciate 🙂
  2. Hey there, I don't know if this might help smeone (and if I did it the right way), but I had an issue as follow : all maps worked on my site except 2 monuments which didn't show any map. I noticed they had a single quote in their name and if I got rid of it the map appeared. I then ended up doing this (in my '$opitions' array) and it worked : 'popupFormatter' => function($page) { $page->title = str_replace('\'', '\\\'', $page->title); // Dirty hack (no map if single quote in title) $out[] = '<strong>'.sprintf(__('In %1$s, in %2$s'), $page->city->title, $page->country->title).'</strong>'; $out[] = "<p class=\"text-center\"><img src=\"{$page->photo->eq(0)->getCrop('thumbnail')->url}\" /></p>"; // ** NB: Use escaped double quotes if HTML attributes needed ** return implode('<br/>', $out); }, Again, it might sound a bit hacky, but it works for me and maybe it can be useful to someone...
  3. Hello, I am still using this module a lot on my site but I would like to avoid the reloadign of the page. Is this possible ? Let me explain : I use edit links as follow : foreach($concernedPages as $p) { echo $p->title.' '.$p->feel(array("text"=>"[Edit]", "fields"=>title,image,summary,level")); } So as you may imagine, I have a list of pages titles accompanied by an 'Edit' link. When I click this edit link, a lightbox opens up and I can edit the page.and this works fine BUT, when I hit the 'save' button, my lightbox closes and I wish the current page (which is not the page I have just fronend edited) would NOT reload as well. Would there be a way to test if the current page is the edited one and reload if true, but prevent reloading if false ? Or simpler, just manually set reloading to false when we want it, resulting in the following code : echo $page->feel(); // THIS WOULD RELOAD CURRENT PAGE AFTER EDITING foreach($concernedPages as $p) { echo $p->title.' '.$p->feel(array("text"=>"[Edit]", "fields"=>title,image,summary,level"), 'reload'=>false); // THIS WOULD PREVENT RELOADING (NOTE THE EXTRA PARAMETER ADDED TO ILLUSTRATE MY POINT } Thanks for helping ! PS : I hesitated on creating a new post but eventually decided on following this thread (I have read the complete thread but couldn't finc anything concerning my question) EDIT : Eventually, I guess I've found it myself (and it wasn't so hard) adding this in my main JS file : var FEEL = { onBeforeReload: function (o) { return false; } };
  4. As a follow-up, @ryan had a look at this and made a patch that somehow tests the Mysql version and does something that makes it work fine (at least on my localhost). Technically speaking, I am unable to explain all this, so I prefer let the pros give details if needed, but just know the issue seems solved. As I said on Github, I am quite glad I have been able to somehow contribute to the community. You all have provided me with so much help since I have discovered PW. THANKS again !
  5. @kongondo Great idea ! I've just tested and it works with other fields : title, summary... No problems (apparently). As soon as I change to "name~=", the error triggers. I'll go ahead and write this as well on the 'bug' report.
  6. @kongondo I'm just noticing that my previous message didn't go through... I was saying that for your information, I had replaced all my ~= operators with either ^=, ~*= or = depending on my use cases. It did the trick although I'm losing the original 'whole words' searching capability... but at least I'm not stuck 😉 I wen tahead and submitted a 'bug' issue as you advised. Not sure this is a real bug since I have a feeling somebody else would reproduce it if it was, but I di dmy best explaining the issue and I hope it can help ! If anybody needs more information about it, just ask. I'll keep an eye on this issue since I would like to understand and solve it in a better way ! But thanks again for your help !
  7. @kongondo Thanks for your reply. Ah... And downgrading MySql doesn't seem possible (at least for my low skills... - https://dev.mysql.com/doc/refman/8.0/en/downgrading.html So I guess I'm gonna be in trouble here...
  8. @kongondo Thanks for your reply. Ah... And downgrading MySql doesn't seem possible (at least for my low skills... - https://dev.mysql.com/doc/refman/8.0/en/downgrading.html So I guess I'm gonna be in trouble here...
  9. So nobody has any clue for me 😞 ? On my localhost, I have : PHP version is 7.4.3. MySQL version is 8.0.21. Maybe this can help... I have a feeling if it was just a configuration problem, all requests should end up with the 'illegal argument to a regular expression' error ? But I can't imagine PW would be the cause (otherwise I vould get some clue from the community, I'm sure 😉)
  10. Maybe this can help. The error points to this file/line. File: .../wire/core/WireDatabasePDOStatement.php:166
  11. Hello, I've just upgraded to 3.0.165 (and updated my Ubuntu version as well) and on my localhost, I am facing a weird issue : all my requests having the ~= selector cause a Mysql error with this message : PDOException #HY000 SQLSTATE[HY000]: General error: 3685 Illegal argument to a regular expression. I have no idea what is going on. If I change my request from $visualizer = $pages->get("name~=visualizer"); // Triggers the error to $visualizer = $pages->get("name=visualizer"); or $visualizer = $pages->get("name~*=visualizer"); My code works fine again. Any idea ? Shall I change all my requests (but from what I understand by reading the documentation, ~= exists and fits my needs : all words in any order [though I do understand that in my example above it may be useless since I have only one word]) Thanks !
  12. Hello, Just a mention that today I have received this newsletter from The Whale : https://thewhale.cc/91 And Processwire is part of it 🙂
  13. That's what I keep telling myself but I often end up having a greater and more difficult challenge 🙂 On my side, front-end editing seemed a good solution because I may have up to 50 textareas to edit and if I have to click on each in back-end, save and go to another, having a rather slow connection, can be troublesome... Here, I can load all the 'alerted' textareas on 1 page and edit them 'right away'. It was then just (!) a matter of automatically detecting who was the last user to modify the text. But nevermind for now, as you said, I still have learned a lot trying to do that ! Thanks a lot for your encouraging message and your help !
  14. Thanks @bernhard for your reply. This helps me feeling more confident about my tests since I often don't know if I'm going in the right direction. I must admit I am not mastering anything there (you can tell !). I was glad to learn about the 'Event interceptor' but it seems like it lead me on a false interpretation 😉 So hooks don't fire when front-end editing ? I don't really understand why since the field is actually saved, isn't it ? So I guess I won't be able to avoid my 'Manually check this box to alert your teacher' way of doing 🙂
  15. Still desperately trying things... I have this in my ready.php : $this->addHookBefore('Fieldtype::savePageField', function (HookEvent $event) { bd('ok'); // Also tried fl(), d()... }); I have nothing anywhere (after front-editing my textarea and clicking 'save' in my CKEditor) aven after reloading the page, whereas if I use the event interceptor, I get the whole list of fields being saved (after reloading the page) and I can see that one of them is the field I have just edited. So I'm stuck 😞
  16. Thanks a lot @Zeka for your reply. I do use TracyDebugger in my usual debugging 'flow', but my problem here is that it never triggers anything, and that is exactly what I don't understand. After trying some more things, I can understand thath Tracy works in hooks by testing this : $this->addHookBefore('Page::render', function(HookEvent $event) { bd('ok'); }); which does give me a result on page load. Eventually, my concern is there : in my initial question, I want to debug in a hook that doesn't completely reload my page. I guess that's why I can't see anything. When I double-click my textarea to front-end edit it and then hit 'Save', the page doesn't reload so my dump bar stays silent. Is there a way to dynamically see what's going on ?
  17. Still digging... I have tried this taken from the docs : $wire->addHookAfter('Pages::saved', function(HookEvent $event) { $page = $event->arguments(0); $event->message("You saved page $page->path"); }); But I see nothing... My logs > messages do not show anything, my Tracy bar doesn't show anything... Does a front-end edition and a hit on the 'Save' button does not trigger the hook ? I have a feeling I was confusing things in my previous post, so all in all, let's sum up my question : how do you debug hooks ? Is a simple bd('ok') suppose to work if the hook is working ?
  18. Hello, Here's what I'm trying to achieve : I have a textarea field that is frontend editable on any page I want to. If a user with a specific role updates it, I want to tick a checkbox field on the parent page where the textarea resides. So I tried to hook as follows in my ready.php file : $this->addHookBefore('Fieldtype::savePageField', function(HookEvent $event) { $page = $event->argument[0]; $field = $event->argument[1]; if($this->user->hasRole('teacher')) { $page->alertBox = 1; } // DEBUG HERE (bd($page), l($field)... ???? }); Of course (!) it doesn't work (yet !) but the thing is I have no idea how to debug this since my bd() never triggers. I've tried the 'Event interceptor' of Tracy debugger which helped me setting up my hook. I guess my $page and $field are correct... but how could I go any further ? The road is long to become a dev (when you're not one 🙂 )... For further information in case someone wonders : I'd like to set up a textarea that is modified by a user (having a 'player' role, ie 'student'). When front-end modified, I wish it would automatically alert me (the teacher) by ticking a box. So when I log in with my teacher role, I get a list of all textareas I have to read over. When I read/correct/update them (front-end), I would like my hook to automatically untick the box to remove it from my list. In other words, the 'textarea' status should go back and forth according to who modified it last. For the time being, I have managed to make it work with a checkbox that the user has to manually tick/untick, but I've noticed many kids forget to tick the box so they edit their text and I don't get a notice 😞 Thanks if anyone takes time to try and help me on that one !
  19. Well, I'm getting there... almost ! I used JS to update timestamp. Everything works as expected, except... (sorry...) : only admin can list users ? The aforementioned code by @bernhard : $pages->find("template=user, meetinghalltimestamp>$nowMinusTenMinutes") only returns result when I'm logged in as admin. Should I set my timestamp field on another template or is there a way to 'open' this and is it a recommended practice ? EDIT : I saw that adding 'include=all' to my request made it. Thanks for all your help !
  20. Thanks @LostKobrakai. I understand the problem and my concern was really a very basic thing, even if some use cases 'pass through'. It is nothing professional 😉 and @bernhard's solution seems to the point for me : if another user loads any page, he or she will get an indicator of how many connected users are online and for those being active on the Meeting Hall, let's say within the last 10 minutes, a 'bell' will be added to show this recent activity. My only left concern now is when people are on the Meeting Hall page for more than 10 minutes, using the collaborative pad (which is embedded from another server), hence having no 'activity' on the page. I should need to update the timestamp. I'll have to see if it's possible to have a 'cron' function while connected on a particular page or simply add a button on which a user can click to update his or her timestamp to say "I'm here !"... Again, much work (for me) for not so much effect... 🙂 But thanks a lot for your help !
  21. Wouah. Thanks a lot for your explanations ! I had thought of the tabs issue, but couldn't think of another possibility 🙂 And your timestamp idea sounds great ! I'll go ahead and try and do that instead, but it'll take ME some time so that's for tomorrow I guess ! But the more I think about it, the more I see how this can be made YOUR way. Thanks !
  22. Hi @bernhard, Thanks for your interest. Actually, it is not a big thing. I have a collaborative pad that I share with my middle-school students that resides on the Meeting Hall page. I have used the database session manager module to get a liist of logged-in users so that when someone is on the homepage, he or she can see if others are connected at the same time. And now, I would like to simply add a 'bell' next to the connected names when they actually are ON the Meeting Hall page so others can know they are there. So my idea was to add a Page field on my meeting-hall template with connected users updating... as they come and go... Maybe that's a lot of 'fuss' for not so much, though...
  23. Hello, I'm struggling with hooks to try and do this : adding user page to a page field when visiting a particular page on my website. In fact, I want to have a list of connected users on a particular page (called meeting-hall). I've tried all kinds of things (which I don't really understand, sorry) but the latest is this : $wire->addHookBefore('Page::render', function($e) { $page = $e->arguments(0); if ($page->is("name=meeting-hall")) { $page->connected->add($user); // connected is a Page field $page->save(); } else { $meeting = wire("pages")->get("name=meeting-hall"); $meeting->connected->remove($user); $meeting->save(); } }); I put this in my _init.php file but nothing works... The best I managed was updating my 'connected' field when the user loads the 'meeting hall' page by having this on the page template : if ($user->isLoggedin()) { $page->connected->add($user); $page->of(false); $page->save(); $page->of(true); } But I wanted to remove the user when he or she leaves the page... hence my thought about using hooks... If you can give me a hint, I'd greatly appreciate !
  24. @MadeMyDay Thanks for your reply. From your comment, I have tried testing my $allEments function (it takes 0.415s on localhost). You can see the code there : https://framagit.org/celfred/planetAlert/blob/master/site/templates/my-functions.inc (function teamFreeWorld() line 1468) BUT I have also tried this : $out .= $map->render($allElements->eq(0), 'map', $options); And the page now loads a lot faster (I can tell the difference even on localhost) ! So maybe it's because I have 56 (or even 96) markers, with a photo... ? What could I do, then ? I hope you (or anybody else) will have other pieces of advice for me 🙂 My site has improved so much over the years thansk to the help of this community (and I have learned so much - you can tell I'm not a pro dev 😉 - I'm a teacher and the website is for motivating my middle-school pupils) EDIT : Well, for the moment, I've just removed the images in my map markers tooltips and it loads faster...
  25. Hello, After spending hours trying to find a solution, I ask the community for help... I have a map showing up on page load. It works fine but it takes quite a while. You can see it in action there : https://planetalert.tuxfamily.org/world/6ef (be patient, loading is terrible) I have already tried caching parts of my page (the different lists) and it's ok, but I can't manage to cache the map. So I would like to load the 2nd tab (when clicking on the faces icon at the top-left corner) by default to get a fast loading page and have my map loading on an ajax call. But all my tests are complete failures 😞 Here's my ajax part of code : [...] // Setting $allElements (for markers) and $options there $map = $modules->get('MarkupLeafletMap'); $out .= $map->getLeafletMapHeaderLines(); $out .= $map->render($allElements, 'map', $options); Eventually, I get my map box, but it stays empty 😞 Any advice, please ?
×
×
  • Create New...