Jump to content

celfred

Members
  • Posts

    189
  • Joined

  • Last visited

Everything posted by celfred

  1. Hello, My code seems to become quite messy very quickly when I do something... For example : $taskId = $input->post->task[$checked_player]; if ( $taskId != 0) { // Task selected // Get the task bonuses $task = $pages->get($taskId)->title; $new_XP = $pages->get($taskId)->XP; $new_HP = $pages->get($taskId)->HP; $new_GC = $pages->get($taskId)->GC; // Do the math $player->XP = $player->XP + $new_XP; $player->HP = $player->HP + $new_HP; $player->GC = $player->GC + $new_GC; } I feel like I'm using to many 'bridges' variables (I'm not sure this is clear)... Do you think the following would be better? : if ( $input->post->task[$checked_player] != 0) { // Task selected // Get the task bonuses $task = $pages->get($input->post->task[$checked_player])->title; $new_XP = $pages->get($input->post->task[$checked_player])->XP; $new_HP = $pages->get($input->post->task[$checked_player])->HP; $new_GC = $pages->get($input->post->task[$checked_player])->GC; // Do the math $player->XP = $player->XP + $new_XP; $player->HP = $player->HP + $new_HP; $player->GC = $player->GC + $new_GC; } Or even (not tested) : if ( $input->post->task[$checked_player] != 0) { // Task selected $task = $pages->get($input->post->task[$checked_player])->title; // Do the math $player->XP = $player->XP + $pages->get($input->post->task[$checked_player])->XP; $player->HP = $player->HP + $pages->get($input->post->task[$checked_player])->HP; $player->GC = $player->GC + $pages->get($input->post->task[$checked_player])->GC; } Is it just personal preferences or does it have a performance issue to use variables ? It may sound like a 'noob' question, and I know it's not specific to ProcessWire, but I felt like asking, so I know better ;-) Thanks! PS : I've just noticed there was a 'dev forum' for such questions! It should go there... But I guess that's too late... Sorry!
  2. Well that was a quick answer! I trust your experience and follow the advice. If I can handle thousands of events, I guess I'll have more than enough! Thanks a lot!
  3. @apeisa (or others) I've tried doing something with 'event' template for history. It works fine for my purpose right now but I'm still wondering something about scalability. Should I add a new 'event' page (child of 'player' page) each time a player does something or should I have only 1 'events' page and I append to this page? In the first case, I'll end up having like 500 pages by players. Is this a problem? In the 2nd case, I would have only 1 page with either many fields (or 1 big text field, like a log file?) Which would be best? Keep in mind that eventually, I'll try to manage history so I can see how a player does on 1 particular task (let's say, for example, 'No homework' or 'No copybook', useful information for parents' meeting) and for now, I feel like the 1st solution would be better to handle this kind of sorting...
  4. Right about the useless 'All Players'. I got rid of it and displayed the stats on the 'Players' page. Thanks. Great idea about the 'event' template ! I'll dig this a little and keep you informed. And you understood perfectly the need of having freedom and being able to add vustom information ;-) Thanks!
  5. Hi kongondo, Yes, The 'All Players' page pulls the scores from each player's page to display the scores. But then, I think I'll make it possible to edit the scores on the same 'All Players' page because I don't want having to go through each player's page in the Admin Panel to edit individually the scores. I think of checkboxes on the All Players page to be able to select multiple players at once. And by submitting the new All Players page, I would update each player's pages. For the moment, I can't think of another way of managing all theses scores. I'll keep you updated about my progress...
  6. Hi there, Thanks a lot for your answers and your encouraging words! I appreciate a lot. Now, I agree I have to start very small and simple and then build on top of that. That's why I got in touch with you, actually, because I was unable to figure out how to start with PW, and possibly JS to make things more 'dynamic'. From what I see so far, I should forget about JS (or at least not worry about it for the moment) and start digging about my page structure with PW. So far, my first tests lead me to the following simple structure : Home - Players - Player 01 - Player 02 - ... - All Players The 'player' template has the fields : title,team,XP, Lvl, GC, HP. And I filled the values 'by hand' to make an initial state ('title' is the name of the pupil, 'team' is the class, 50 Health Points, 0 Experience, Level 01, 0 Gold Coins). The 'All Players' page allows me to have a list and see the different scores on 1 page. At first, I just thought about being able to update things from this 'All Players' page by checking the names of the players involved and selecting some kind of 'rewards' from a list. Then, I thought it wouldn't be good to display a unique form with about 30 players (1 class) _checkboxes_ with 4 input fields each (like a table) and 1 select to choose the 'task' type which would trigger the score changes. (That's why I started thinking JS...). I just imagined I would have trouble recording things for each player if I have only 1 form. The thing is : - I'd like to keep some kind of freedom about points (manually change something for 1 player) so an input field sounds good. - I could then have a submit button to save all changes (but I guess I would re-save everything since I wouldn't know only 1 field changed). - I thought about updating scores onSelect-ing the rewards (JS) so the kids could see the impact right away, even before submitting the form. [Now I guess I'll bother with that later ;-)] - I imagine the list of tasks could be built in PW Admin interface under a new page 'Tasks'. For example the task 'Homework' could have fields such as 'XP Gain' '3', 'GC Gain' '5'... so I can add different tasks little by little. Writing this, I see another problem : some tasks are positive when done, or negative when not done... Should I make a list like 'Homework', 'No Homework'... But what do I do with 'Class Participation' in which I have 4 levels : Very bad, Bad, Good , Very Good : 4 different tasks? So the 'final' simple structure would be : Home - Players - Player 01 [title(name), XP(0), HP(100), Lvl(1), GC(0), Team(class)] - Player 02 [title(name), XP(0), HP(100), Lvl(1), GC(0), Team(class)] - ... - All Players - Tasks - Homework [title, XP Gain(3), GC Gain(5)] - No Homework [title, HP Loss(5)] - Very Good Class Participation [title, XP Gain(3),GC Gain(3)] - Good Class Participation [title, XP Gain(2),GC Gain(1)] - Bad Class Participation [title, HP Loss(3)] - Very Bad Class Participation [title, HP Loss(5)] - ... My main problem is that I tend to see the final product even though I want to stay very simple at the beginning, but this prevents me from starting because I keep wondering what is best. I'm always scared of heading the wrong direction right from the beginning. (I'd like to keep a history for each player because it's not just a game, it would be useful to analyse the 'Homework' task with the student and the parents... _ but that' would be for LATER, of course) I'd love it to be scalable, but I'm not sure I'm ABLE to think of it as scalable! Anyway, I hope I don't bother you with my long post about how I see my project. Maybe I should just dive in and ask you more specific questions when I'm stuck. But I do think organisation and structure are very important and represent the foundation and you know what happens if you build on sand... So I'll start how I've just described it to you, but please, feel free of interfering and giving advice if you see me heading in a wrong direction ;-) Thanks in advance.
  7. Hello all, I haven't been around for quite a while, but I'm still trying developing stuff for my classrooms (I'm an English teacher) and this time I'm a little stuck even before starting... Let me explain : I've used ProcessWire for my English site (FLEnglish : http://flenglish.tuxfamily.org - if you're curious) and I just loved it (not my site, ProcessWire ;-), and I appreciated the community help a lot) So here I am again with a 'new' project and my questions : I'd like to implement some kind of RPG Game (in the style of HabitRPG) for the language classroom. Actually, it's a lot easier than HabitRPG since I'm interested mainly in managing the score part of the game. I'd like the kids to have a character (no images for the moment, just a name), and scores for Health Points, Experience, Level, Gold Coins) and according to their achievements in class, the scores improve and so on. The idea is that I'd need a tool quite handy to manage because I have many pupils in classes and no time in class to manage all this. Let's see an example : All kids did their homework. They all get +3 experience and 5 gold coins. I don't want to spend 10 minutes going over each pupil's name and adding their numbers... I thought of the Skyscrapers demo site for a start : yes, I could manage students this way, having field for XP, HP, GC and so on (this is what I started doing actually). But then,I can't manage pupils' results 1 by 1 going through the Admin page in PW. So I thought of using Javascript to avoid having to validate a page on which I would have 120 fields to update according to the task succeeded. That's when I started thinking trying to continue learning AngularJS, but I was unable to make it work along with PW... (I get a 403 error when routing to the view template_ I put everything in /site directory, maybe that's not a good way). Anyway, this is quite a mess in my head at this time even though I would like to try and do something this way. If anyone here could give me a possible thought about this to give it a start : could PW be useful for such a task? To be honest, I would love to use PW for this since I would like to be able to merge this score thing with my site already using PW (and why not imagine 'users' being able to log in to see their scores and so on...?) I'm afraid I'm being extremely complicated on that. Let me rephrase it : - Could I have such a system for scores management using PW ? - Could I have a user interface quite handy to update scores easily using PW? In brief, what do you think? I hope reading this was not too much of a burden. Thanks for your help! Celfred.
  8. celfred

    Hit 1000+ likes

    Well, I guess it's just because you really deserve being thanked (and liked) by many people on this forum! I wish I could be more helpful myself but I have to admit I have a long way to go before being close to many of you concerning developping skills. I'm saying this not for my own merit, of course, but just so I could allow people like you focusing on higher skilled matters. Anyway, being around this forum is great and it's just because there are many persons like you, Soma, willing to help the others, quick in answering their problems, and patient enough to repeat some 'beginner' talk to guys like me. So THANKS to you, but also THANKS to many others for your kind help and the way you're involved here. Congratulations!
  9. Waow! That was quick! Well, what can I say except THANKS! Why did you exclude 'guest' role in the list? I guess I can understand that the Login Notifier module's point is to notify the 'guests' login actions, but why not let people decide? i can imagine someone interested in receiving mails only if a paricular role logs in (but not 'guest'). Anyway, that's just a supposition from my side. Your work is just fine for my use as it is so thank you very much. Now that I don't have to try and do that myself (which would have taken me a lot more time, definitely!), I'll look at your code to see what i should have done ;-) Thanks in advance for the lesson !
  10. Hi there, I've just come across this module and it worked as expected. Thanks a lot. I changed a little thing though, for my personal use, and I don't know if this could be of any interest for someone else. (It's the very first time I look inside a module...) Line 72 : if(!$user) return; I changed to : if(!$user || $user->isSuperuser()) return; My point was that I received emails even when I was logging in my site and since it's a very little amateur site with _let's admit_ no traffic (for the moment ;-) ), I kept receiving mails indicating I logged in... Now, with my little tweak, I get emails only when other members log in which is what I wanted ;-) Now here's my thought : I thought some kind of list of roles (or users?) could be added to the settings page of the module so one could only check (or uncheck) some roles to be ignored from keeping a record (either mail or log entries) without actually touching the module code. I don't know if I'm being very clear there... and actually I have no idea if this kind of idea is shared... But if it is, I would be glad to try and see what I can do to include such a feature in the module, even though I'm starting from very low considering my developer skills (but I'm eager to learn and improve). Thanks for letting me know if you think that would be a loss of time ! (Or if I did a mistake changing my little line 72).
  11. celfred

    Happy new year!

    Happy New Year to all of you!
  12. See... Again something I would never have thought about by myself... Thanks !
  13. Well... Thanks again for such a great explanation ;-)
  14. Well, that was a lot more technical than I thought it would be! Anyway, I understand a little better now. I actually didn't even notice my 'Le p'tit' search was not 1 word but 2 words... Looking at the links above was quite helpful and enlightening. In the PW documentation, I didn't see the line concerning %= : Still, I can't understand the $= issue : ie vs. die : 1 result vs. 0 result ? Anyway, this was just a test, I don't need it (now)... Thanks a lot for your help and explanations!
  15. Hello, I've tested some selectors on my site and I'm having a little question here. My 'page tree' look like this : /guests /guests/admin/ /guests/admin/Laurence /guests/admin/Le p'tit /guests/admin/Élodie As you can see, I have names with special characters. I'm trying to retrieve the pages for an autocomplete field on the front-end. So far so good, it worked ok, until I notices I had no result for 'l', that's when I added the 'Laurence' page and it worked. So I thought the problem was due to the apostrophe... Anyway, I used the new 'Selector test' module (thanks to the creator!) and noticed something : parent=/guests/41,title*=l >> returns 1 page found : Laurence (Why not 'Le p'tit' ?) parent=/guests/41,title^=l >> returns 1 page found : Laurence parent=/guests/41,title%=l >> returns 3 pages found : Laurence, Le p'tit, Élodie (no apostrophe problem?) And : parent=/guests/41,title$=ie >> returns 1 page found : Élodie parent=/guests/41,title$=die >> returns 0 pages found ? Why not 'Élodie'? So I don't really know what to think... Am I doing something wrong here? Thanks if anyone has time to give me a clue ;-)
  16. What an excellent idea! Thanks a lot! I think it's a msut have for beginners like me. I was often confronted to this kind of doubt : are my 'find' parameters correct or do I have problem somewhere else in my code? I guess now I'll be able to get rid of those doubts regarding the find parameters. Great!
  17. Well THANK YOU very much ! I've made quite a lot of different tries on that problem but wa sunable to solve it by myself and now I go a little step further. That's very nice of you to take the time to provide such detailled explanations in your answers. I still have a long way to go to better understand those 'pages' issues... But what makes it incredible is how your explanations often make it so simple and clear. That's when I feel like improving a lot in a few seconds and when Processwire becomes something incredibly powerful... And good thing also about the selectorValue() sanitizer... I've missed that one, although I had problems with commas in another field of my site ;-) Well... I can then go on with my coding. Thanks again!
  18. Hello, I'm back again with my beginner issues... This time, I'd like to update a field found in a repeater across multiple pages. My code : $found = $pages->find("parent=/invitations/$user->name, guests.guest_name=".$form['oldname']); foreach ($found as $f) { foreach ($f->guests as $g) { if ($g->guest_name == $form['oldname']) { $f->of(false); $out .= '/01:'.$g->guest_name; // THIS IS TO CHECK IF IT WORKS $g->guest_name = $form['name']; $out .= '/02:'.$g->guest_name; // CHANGE APPARENTLY OCCURRED $f->save(); // BUT NEVER SAVES??? } } } Let me try to explain a little : the name of a 'guest' is modified on the front-end. I want to adjust all 'invitations' under the '$user->name' branch (that's how I organized my pages, maybe it's not the best solution...) where the 'oldname' was found (in a 'guests' repeater having 'guest_name' text fields). So I look for the pages and I try to loop each page to check which field has the 'oldname' and when I find it, I change it to the 'newname' ($form['name']) and try to save this change... I have tried many things, but this never worked ! Although I did the same stuff to delete a field (If I remove the guest) and it worked! I just don't understand, so if someone could give me a hand, I'd greatly appreciate... Thanks!
  19. Thanks a lot for this nice answer! I don't really understand this... I think maybe my problem comes from the fact that my repeater only has 1 text filed (guest_name). Actually, my pages record the names of 'guests' and when a user deletes a guest, I'm trying to 'delete' (or remove?) the same name in every page belonging to the logged in user where the name is found... Since I had multiple names in each page, I decided on using a repeater. Maybe that was not a good idea ? Exactly! But I still don't undertand the difference with delete (for the moment). I've tried what you suggest : - Code 01 & Code 02 work fine! And I understand how they work. Thanks for reminding me that the repeater acts as a 'Page' and a pagearray. I think that's the part I wasn't aware of during my tests and that your answer helped me 'tidying up' what I've read so far. - Code 03 : I haven't really tried since I have more than 1 pages containing the 'guest_name' value. During my tests, I understood that 'get' limited the search to 1 page whereas 'find' returned a pagearray. Anyway, thanks again for the answer. I'm happy the code works. Still, I'd like to understand better why my previous code (with the 'delete' version, and no 'save()') ended up working (from what I've tested so far... Maybe there would be other issues raised in a different context) and how different it is from your 'remove and save' solutions.
  20. Well... I guess I found something by myself : This seems to work as expected : $name = $pages->get($id)->title; $found = $pages->find('created_users_id='.$user->id.',guests.guest_name='.$name); foreach ($found as $f) { foreach ($f->guests as $g) { if ($g->guest_name == $name) { $g->delete('guest_name'); } } } I re-read (re-re-re-re-read, actually ;-)) the documentations and from what I understood, 'remove' was not to be used for fields. I used 'delete' instead and it looks ok. Regarding my nested 'foreach', although I feel like there would be a really better way to do this, it seems to do the work...
  21. Hello, I am struggling again with my lack of understanding of PHP developement (I guess)... I would just like to get rid of a field (part of a repeater) in my page if I find a particular value. My code is the following : $name = $pages->get($id)->title; // THIS IS THE VALUE I SEARCH FOR $found = $pages->find('guests.guest_name='.$name); // THESE ARE THE PAGES CONTAINING THE VALUE foreach ($found as $f) { // LOOP THROUGH THE PAGES foreach ($f->guests as $g) { // LOOP THROUGH THE REPEATER TO GET RID ONLY OF THE FIELD CONTAINING THE NAME I AM LOOKING FOR if ($g->guest_name == $name) { // IF I FIND THE NAME IN THE FIELD $f->remove(guests.guest_name); // GET RID OF THE FIELD. THIS IS THE LINE I REALLY DON'T UNDERSTAND : REMOVE? DELETE? HOW TO USE IT...? } } } I've tried to show my way of seeing things here, since I'm not sure I'm thinking well about my issue. Feel free to put me on the right tracks ;-) And as always, thanks in advance for your help.
  22. Well... What can I say except THANK YOU both for that. I sometimes feel ashamed of not finding the answers by myself. Honestly, I spend a lot of time searching for them... Don't think I come and ask for help as a 'shortcut' ;-) Anyway, I wasn't that good on that one, but I've just learned so much thanks to both of you. Thanks!
  23. Hi there, I've been struggling for a couple of hours with something I guess one of you will find an answer rather quickly... Let me explain : I'm creating a list of checkboxes according to the number of 'guests' pages belonging to the logged in user. In my page, I'd like some of the checkboxes checked by default IF the logged in user has already recorded them as checked (and this state is saved in a repeater field named 'guests', having 'guest_name' as text input. My code is the following : // If user has guests, list them for easy multiple selection $guests = $pages->find("parent=/guests/, created_users_id=".$user->id); $sel = 0; if ( $guests->count() > 0 ) { $sel = 1; foreach ($guests as $guest) { foreach ($page->guests as $g) { // THIS IS A TEST TO SEE IF I CAN REACH THE REPEATER $out .= $g->guest_name; // IT WORKS AS EXPECTED } //$found = $page->matches("guests.guest_name=".$guest->title); // THIS DOESN'T WORK. WHY? if ( $found) { $checked = 'checked'; } else { $checked = ''; } $out .= '<label for="cb'.$guest->id.'"><input type="checkbox" name="friends[]" value="'. $guest->title .'" id="cb'.$guest->id.'" '. $checked .' />'.$guest->title.'</label>'; } } I've tried many different things : $page->is(), $pages->find(), tried to use has(), but I was incapable of making this work... I have a feeling the answer shouldn't be that hard, but as I said, I've been looking for it for a couple of hours now and I wish someone could give me a hand (again...) on that one. I hope I was clear enough in explaining the issue. Thanks in advance.
  24. Sorry about that... I am also discovering 'git' and I thought 'git fetch' was getting the last version. In fact, I used 'git pull' and now I have 2.2.9 and... Everything works as expected! Thanks a lot!
×
×
  • Create New...