Jump to content

celfred

Members
  • Posts

    184
  • Joined

  • Last visited

Everything posted by celfred

  1. Hello, I can't find my way out of this. I'm trying to use the front-end editing capabilities of PW. It works quite well so far, except if the user sets an empty value. Indeed, in such a case my field just disappears until I reload my page. Here's my code : $out .= '<edit informations>'; if ($page->informations != '') { $out .= '<p>'.$page->informations.'</p>'; } else { $out .= '<p>No infos.</p>'; } $out .= '</edit>'; The idea is to have a paragraph showing 'No infos' if field is empty so the user can double-click on it. He/She then gets the inline editor which works perfectly well as lon as he/she sets a value. But let's say he/she decides (or by mistake) to set an empty value and save, then my paragraph disappears completely and the user must reload the page if he/she wants to edit the field again. I wish I could add some kind of default value if field is empty. Maybe I'm misunderstanding something ? If you have an advice, I'd appreciate PS : I've tried all A/B/C/D front-end possibilities and read and re-read docs, but still the same issue...
  2. Another nice 'lesson' from this community. Thank you very much @Robin S.
  3. Hello, Still in my 'teaching game'. Here's my problem : I 'find' all players with a request like $allPlayers = $pages->find("template=player"); [/code Then, I limit to players belonging to the team of the logged in player with [code] $teamPlayers = $allPlayers->find("team=$loggedPlayer->team"); No problem so far. But my scoreboards rely on either : $allPlayers->getItemKey($loggedPlayer); or $teamPlayers->getItemKey($loggedPlayer); to find the logged player's position in the charts. On the 'global' newboard with scoreboards based upon $allPlayers, everything works as expected. BUT on my 'team' newsboard, even though I'm using $teamPlayers, the returned indexes are based upon $allPlayers. Am I clear ? In other words, I have a total of 125 players, and my logged player is 61 out of 125 regarding the number of places he freed. But in his particular team of 25 players, he sould be 15 whereas he's still 61 I'd like to reset my indexes (and start back from 0), but I can't find my way out of this... If someone has a hint to help, I'd appreciate. I have a second part in my worry : I had a way around it by simply making another 'raw' request : $teamPlayers = $pages->find("team=$loggedPlayer->team"); Then my team indexes were right, but I faced another issue : Reordering my wirearray according to the scoreboard I want usually worked fine (simple sort() based upon an integer field, for example, player's coins, player's karma...) and indexes were updated BUT resorting with places.count ('places' field is a pageArray) doesn't update the indexes returned by getItemKey and my logged player is always at the position he was when I first did my initial $pages->find() query So my way around found its limit and that's why I'm posting here, after struggling with this for a couple of hours... Thanks in advance for the help.
  4. It is an integer and I've checked the setting and intentionally set it to 'Yes' because my freeActs field had no value in some pages and I wanted those pages to be returned. In short, a player being level 1 with no previous activity should have access to items having level 1 set, enough Gold Coins (GC) and 0 previous 'free' actions... I guess I'm not clearly understanding this yet. I'll go ahead and try to check 'No' and see what's going on, but later during the day. Thanks for your help @Robin S
  5. Hello to all, This time, I'm stuck on an issue with a 'find' request. I have found a turnaround, but I have no idea what's going on, really, and I wish I could understand. My code is the following : $nbEl = $player->places->count(); $items = $pages->find("template=place|item|equipment, GC<=$player->GC, level<=$player->level, freeActs<=$nbEl")->sort("template, name"); If I explain briefly : the $items should contain the possible elements for a player according to his level and GC (gold coins), and freeActs, i.e. the number of already 'bought' places. If the 1st line $nbEl returns a number higher than 0, it 'works', I get some items. BUT if the player has not bought any place yet and then $nbEl = 0, $items is... empty whereas it should contain all elements being accessible with a 0 'freeAct' field (and there are many). I have tried to hard-code 'freeActs<=0', I get no items. 'freeActs<=1', I get some nice results' AND THEN, 'freeActs=0' and it works as expected So here's my 'workaround' : $nbEl = $player->places->count()+1; $items = $pages->find("template=place|item|equipment, GC<=$player->GC, level<=$player->level, freeActs<$nbEl")->sort("template, name"); Note the 'freeActs<$nbEl' instead of 'freeActs<=$nbEl' and the '+1' for $nbEl so not to start at 0... Then, it works as expected !?!? Does someone have an explanation for this ? Thanks in advance if you do. And don't hesitate asking me for more details/explanations if you need.
  6. @kongondo Sorry for being late on that... Thanks for your reply. Somehow, your answer is comforting since things should work the way I was understanding them. Now I'll try and find out what's going on in my code. Good point about my wrong variable name. I wasn't even aware of that... Shame on me...
  7. Thanks. But is that new in some way ? Or was it always like that but I didn't notice ? Just making sure I'm being understood : the equipment is added to the player's page, BUT it stays in the equipment list even though I reload the page and empty the cache. I thought it wouldn't stay since I didn't save the page.
  8. Hello, Just a simple (I think) question which is in the title of my post. Roughly speaking : here's my code (made-up because my real function is so long... I don't want to post it all here ) function updateScore($player, $task, $real = true) { [...] $player->score = $player->score+$task->score; if ($task->name == 'new-equipment') { $new-eq = $pages->get("name=sword"); $player->equipment->add($new-eq); } if ($real == true) { $player->save(); } } Everything works fine when I call updateScore($player, $task, true), but if I call updateScore($player, $task, false), scores are untouched, but the equipment gets added ! It used to work fine on PW2.7 but my update to PW 3.0.62 seems to have broken this... Is there a simple explanation ? I keep reading my code over and over and this is driving me crazy... Thanks !
  9. Here's what I think : I had an 'old' processwire directory which I downloaded through Git and which I thought was up-to-date with master (not dev branch) so I really imagined I was with 3.0.62. (I'm sure I did a git pull but I guess not...) And today I added PW version in my footer and saw 3.0.36 and imagined I forgot about the version number _ must have been 3.0.32 and they've already made some changes and now it's 3.0.36... Anyway, you see how good I am with Git and some stuff So I'm really sorry about all these issues which shouldn't have happened if I had done things correctly. I'll update for real (!) and see how it goes. Thanks again for your help and time. I appreciated a lot ! And about my Tracy 'theme' : I just use my computer 'negative' mode because I have eyesight problems and I feel better this way. So no leaking, don't worry EDIT : 3.0.62 installed : I can confirm, there is no more a bug with the 2 forms of 'find' statements.
  10. I PMed you the files so as not to 'pollute' this post with unnecessary lines. Edit : I added my Tracy console.
  11. It returns 'NULL'. How does that sound ?
  12. Well, I've checked my localhost version and it gives 5.7.19. Anyway, I've changed my line taking the 'sort' out of my 'find' string and it works (actually, I believe my 'sort' command is not really useful on my page any longer so it's not really an issue for me any longer). I've taken care of most of my errors (I think) and it seems to work fine. I went ahead and made the changes on my live site. It looks ok. I'll test tomorrow when actually saving data 'for real', but on my localhost it works, so that's cool ! I'm running on PW 3.0.36 now Thanks a lot for your help ! If anything still matters to you and you suspect a weird behavior on PW side and you want to dig this a little, don't hesitate asking me for further testing or information.
  13. Hello, I'm back to it and it's not easy 203 PDO queries in my Tracydebugger ! That sounds like a lot to me... I have tried to isolate the 'responsible' one and here it is (I think) : SELECT pages.id,pages.parent_id,pages.templates_id FROM `pages` JOIN field_team AS field_team ON field_team.pages_id=pages.id AND ((((field_team.data='85366') ) )) LEFT JOIN field_group AS _sort_group ON _sort_group.pages_id=pages.id LEFT JOIN pages AS _sort_page_group_name ON _sort_group.data=_sort_page_group_name.id WHERE (pages.templates_id=43) AND (pages.status<1024) GROUP BY pages.id ORDER BY _sort_page_group_name.name This corresponds to the following statement : $allPlayers = $pages->find("template=player, team=$team, sort=group"); Answering your question : the 'group' field is indeed a 'Page' type. It used to be a 'Text' type so I tried and changed my find query replacing 'sort=group' by 'sort=group.name' and the error is still there. Here's the resulting PDO query in Tracydebugger : SELECT pages.id,pages.parent_id,pages.templates_id FROM `pages` JOIN field_team AS field_team ON field_team.pages_id=pages.id AND ((((field_team.data='85366') ) )) LEFT JOIN field_group AS _sort_group_name ON _sort_group_name.pages_id=pages.id LEFT JOIN pages AS _sort_page_group_name ON _sort_group_name.data=_sort_page_group_name.id WHERE (pages.templates_id=43) AND (pages.status<1024) GROUP BY pages.id ORDER BY _sort_page_group_name.name As I said earlier, if I change the syntax to : $allPlayers = $pages->find("template=player, team=$team")->sort("group.name"); The PDO query shows : SELECT pages.id,pages.parent_id,pages.templates_id FROM `pages` JOIN field_team AS field_team ON field_team.pages_id=pages.id AND ((((field_team.data='85366') ) )) WHERE (pages.templates_id=43) AND (pages.status<1024) GROUP BY pages.id and everything works as expected. I've tried my best to be helpful. I hope I've managed to isolate the correct lines and that you can understand something out of it. (and that I'm not responsible for taking this time from you... by responsible, I mean that I did something wrong that caused the problem, which can be a possibility) Sidenote : Trying to isolate the query, I took almost everything out of my page (no more find/get statement except that one, no more head.inc, foot.inc....) and I still have either 41 or 38 (depending on reload) PDO queries on my page). I would imagine that's PW 'doing his job'. Is that so ?
  14. I have the TracyDebugger installed and I'll try to do what you're asking me with pleasure, but I have to stop right now (time to eat at home, daughters hungry... ) I'll do that tomorrow and keep you updated about my progress. And I agree with your advice about installing modules directly from within ProcessWire. It is indeed quite simple
  15. Last thing for the moment while trying to update to PW 3.x : in backend, my modulemanager page tries to read a modulemanager.cache file in files/assets/cache which doesn't exist hence error messages : Warning: fread(): Length parameter must be greater than 0 in /home/celfred/PlanetAlert/site/modules/ModulesManager/ModulesManager.module on line 812 ProcessWire: ModulesManager: cannot read cache file /home/celfred/PlanetAlert/site/assets/cache/ModuleManager.cache (with debug true)
  16. Here's what I did : Restarted mysql to be back with the initial fatal error. Found out that commenting out the line : $allPlayers = $pages->find("template=player, team=$team, sort=group"); got rid of the error Replaced the line with : $allPlayers = $pages->find("template=player, team=$team")->sort("group"); and... It works That's indeed a cleaner solution better than changing my mysql settings. I guess the 'bug' was on my side with the 'sort' command included in my 'find' query. I have to revise the PW doc to see where I saw that syntax or if I made it up without noticing that it never worked (which is possible !). So thanks for pointing this out to me !
  17. EDIT : As a follow-up, still digging on my updating issues : I have found that post : https://stackoverflow.com/questions/23921117/disable-only-full-group-by#36033983 Along with the namespace line on my particular page, it works EDIT #2 : Sorry ! I validated another post instead of editing the first one.
  18. I must admit I'm completely lost on those issues. I have turned off the compiler on my first fatal error that occurred with another module : Pages2Pdf. As I said earlier, I downloaded the last Github version of that module and noticed in the source the FileCompiler=0 line, so I simply did the same in the Service Pages modules Now when trying to get rid of all lines (FileCompiler and namespace) it seems to work as well (?) . Maybe I'm still having a cache somewhere messing up with all my tests, but it seems to work anyway so that's good ! I am now continuing debugging my local site. I have to add the namespace line at some places to get rid of error messages. But all in all, it looks quite correct. One of my pages trigger a 'big' fatal error that is again over my head for the moment : Error: Exception: SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'planetalert._sort_page_group_name.name' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by (in /home/celfred/PlanetAlert/wire/core/PageFinder.php line 384) (The page worked fine with PW 2.8). But that's another problem and it's not on a 'major' page Thanks for your concern @adrian
  19. So cool ! I can't believe it was so... simple... I added this line on my templates files, but didn't think it was needed in modules as well. Now, I'll try and face the other issues by myself, but it went a little further. That's cool ! Thanks a lot for your help !
  20. Hello, I'm desperately trying to update my website to PW 3.0.62 and I'm facing issues to to module compatibility. I was stuck with Pages2Pdf which I managed to solve bu updating the module from Github, but now it's the Pages Web Service module... and this time, I don't know wht to do The Module is found there. But it is quite old and I can't find it in the modules catalogue... and my site is making quite a use of it (I can't think of a way to do otherwise, sorry...) After adding the FileCompiler=0 to the module pages, the error I'm stuck with is : Fatal error: Class 'WireData' not found in /home/celfred/PlanetAlert/site/modules/ServicePages/ServicePages.module on line 22 and I have no idea on what to do... I must admit I'm not a programmer but a middle-school teacher... (for your information, here's the site I'm talking about : http://planetalert.tuxfamily.org ) but I'm struggling hard to solve the different issues I have to face and I'm wlling to understand things. I have just spent many hours trying to make 2.8 work on my localhost (and it seems ok ) but I'd like to switch to 3.x to prepare the future If anyone had the will to spend a few minutes to try and help me, I would greatly appreciate. Thanks in advance ! If you need more information to understand my problem, feel free to ask.
  21. I feel a little dumb once again... Your explanation is perfect and I guess I want the 2nd one. I think I was mistaken on that 'not()' filter. I'll have to check everywhere I've used it. The 'further filtered' was the key in your explanation. Thanks !
  22. The $prevEvents->count() is fine. This part works as expected Your post reminded me of trying to cut down through my page to see where the ALL pages request was (ou could be), and reducing things little by little, I saw my checkStreak() function in which I look over the history of each player ti find if the last 10 consecutive events are positive, in which case the player becomes an 'AMbassador' and here was my code : $lastEvents = $player->get("name=history")->find("template=event, sort=-date")->not("task.name=donated|donation|absent, limit=10"); I bet you can see right through it : the 'limit=10' is misplaced and useless where it is !!! The code should be (I think) : $lastEvents = $player->get("name=history")->find("template=event, sort=-date, limit=10")->not("task.name=donated|donation|absent"); Now my 'loaded page' is reduced to about 480. What a gain ! And this checkStreak() function is called each time I save a new event for a player (to check if he needs to become an ambassador...) So I'll keep digging because I can imagine I have the same sort of mistake at other places, but I am already glad of this improvement. So thanks a lot !
  23. Thanks @kongondo for the 1st tip. I get the difference between children('-date')->first() and child('-date'). Although I've just tried to change this line and nothing changed in my Tracy 'Processwire Debug' panel... still many many loaded pages... I'll dig that later when I have more time. Maybe I have the same kind of error somewhere else... About the date>=$prevDay : this solved an issue I had because of the time appended to the date. Actually in my code, I take the last event, get the date, change the time to 0:0:0 and eventually get the >= to find all those events having the same day, but with a superior time. Maybe (I'm sure actually...) there's a better solution. I remember at the time I implemented this, I was surprised not to be able to retrieve the same day events and this was the only workaround I found
  24. Hello, I've been struggling ALL day on my loading time problem and I'm stuck... As I said somewhere else on the Forum, I'm discovering TracyDebugger module to try and help me (and it does help !), but I'm still in a dead-end. Tracy told me one of my page loads about 4,500 pages and I can't find any way to make it less (and let me tell you that my website is far from having so many users/visitors or whatever, it's just a teacher's website to try to work differently in class). I have a feeling I am mis-understanding some concepts here. The page can be seen there : http://planetalert.tuxfamily.org/players/4d (for example, but the problem is the same for all teams in my site). As you can see, there are many information on this page, but not that much either I guess for a computer, but it takes 20 seconds to load ! It feels like my page loads just about EVERYTHING that resides in the backend, but I just can't understand by looking a tmy code. For example, the little green and red circles next to the player's names show the actions that have been saved on the last day (so usually 3-5 actions at most, except for players doing online exercises who may have 10 actions). My query is : $lastEvent = $player->child("name=history")->children("sort=-date")->first(); // Get all events on same day $prevDay = date("m/d/Y", $lastEvent->date); $prevDate = $prevDay.' 0:0:0'; // Select events for the whole day $prevEvents = $player->child("name='history'")->children("date>=$prevDate"); $trend = ''; foreach ($prevEvents as $event) { $HP = $event->task->HP; $title = $event->task->title; if ($HP < 0) { $trendClass = 'negativeTrend'; } else { $trendClass = 'positiveTrend'; } if ($event->summary !== '') { $summary = ' ('.$event->summary.')'; } else { $summary = ''; } $trend .= '<span class="'.$trendClass.'" data-toggle="tooltip" data-html="true" title="'.strftime("%d/%m", $event->date).': '.$title.$summary.'">&nbsp;</span>'; } But in Tracy pages, I see that the COMPLETE history for EACH player is loaded ! I thought my code was limiting it to the events appearing on the same day as the last saved event. Do you see where I am wrong ? What's more : I feel like I must do the same mistake for the players (they are all in althought I'm limiting to the particular team). I must say though, that I'm caching (supposively) ALL players when Admin is logged in so he can have a faster access in the top menu. More? All places and people that players can free are loaded as well. Why is this? I just want to load the places and people that are actually freed by players and show the names (not complete info). I'm not putting an example of the code here because I have a feeling the problem resides in my way of organising the complete thing... and that's what worries me the most... Maybe it's gonna be hard for one of you to understand (and have the time) my awkward way of organizing things (even though I'm trying hard to be well-organized ). So I'd rather point to the Github repository : https://github.com/celfred/PlanetAlertProfile/tree/master/site/templates The file I'm talking about above is team.inc.php. It is included in list-all.php which includes head.inc and foot.inc as well. Things have changed quite a bit on my local site today, but I'm getting in such a mess that I'd rather not commit to remote. I've corrected some things, but what I have just explained above is still there While I'm at it. Other page, other problem detected : my adminTable.php page which you can a look at at : http://planetalert.tuxfamily.org/players/adminTable/4d (I've just noticed that it should be acess restricted, but nevermind for today, don't submit just in case I forgot other things... _ yes, I'm desperate tonight...) and which submits to submitForms.php. Well, I had to put AJAX request for that because it was running into a timeout because of the loading time. It worked (althought I ended up waiting 30 seconds to record my table !) but today, Tracy and debug ON showed me the 'Maximum 100 nested functions limit fatal error' after hours of research, I endend up... writing this post I know my function updateScore() (in my-functions.php) is difficult, but what?? It just updates the scores depending on the task being recorded then checks the impact on other players and if it does have an impact, it triggers itself back to update the score of that other player. But yes, I know it can be some sort of never-ending story, but how can I do differently ? I wonder if it's ok to have wire('pages') in so many of my functions. But again, how can I do in another way? Well, sorry for such a long post, folks, but as you can understand, I'm facing a wall here and I hope someone around here will find some time to try and find his or her way into my code and give me a hint on where I could improve. I have had so many help from this community in the past and it felt such a relief and a revelation (Ended up telling my wife : "Wow, it looks so simple for these guys ! I've spent so many hours on that and... Of course ! Now I get it !! I'm getting better ! No next time !") Well, today is a 'next time'... Thanks if you've read up to this point and THANKS if you go and have a look at my code ! Fred.
  25. Just as a follow-up in case people wonder, here's a copy of the message I sent to @adrian
×
×
  • Create New...