Jump to content

celfred

Members
  • Posts

    186
  • Joined

  • Last visited

Everything posted by celfred

  1. @jmartsch Thanks a lot for your help ! It works now ! But one thing worth mentionning : I was on a 'Page List Select' and it wasn't working, until I found out I had to use the 'Select' type of field ?
  2. Hello, I'm struggling with this : a 'group' field of 'Page' type. The parent of selectable pages is '/groups', the template is 'group', and a member can create some groups in the /groups tree. I would like this user to see only the groups he or she has created so in my 'Find selector' in the backend, I would like to use : template=group, created_users_id=$user->id But that doesn't seem to work... I still get the list of all available groups in the /groups tree. Any idea ? I had a feeling I had already seen that before (something like $user->id must be replaced by users_id or something, but I can't find anything in the Forums... and all my tests keep failing...
  3. Perfect ! It works ! Thanks a lot !
  4. @adrian I was indeed about to tell you I'm updating from... 3.6.9 ! I managed to get back the old version from my remote site). So far, I've tried what you said : Starting with a 'regular' update trhough the module page, clicking on update. It detects the 4?15.4 version. It downloads and then still triggers the same error. Then, I went to check the cookies. I couldn't find the TracyPanelSticky you mentionned, but trying to erase all Tracy cookies (and eventually deleting all my localhost cookies), and also deleting the TracyDebugger folder in my modules folder, and deleting the TracyDebugger folder in my assets/cache/Filecompiler/site/modules... still the same result ? In short, I have deleted all traces I could find of TracyDebugger and tried re-installing 4.15.4 but the error persists. You were perfectly right about the 'sticky panel' : I remember I had the var-dump panel sticky before updating. Thanks a lot for your help.
  5. @adrian : Well, I am upgrading through Setup > Modules > New and I type the className. Everything downloads and then I click 'Install now'. I've checked the path and no, the file doesn't exist. I've tried the Modules > Refresh and re-installed Tracydebugger : same problem. Here's the line mentionned that triggers the issue : File: .../modules/TracyDebugger/TracyDebugger.module.php:1341 Thanks for your quick reply. Edit : I've checked on Github in panels folder, and there is no TemplateEditorPanel.php file... I really don't get it...
  6. Hello to all, I've just tried updating the module and got an error. I then deleted it completely to start all over again (on my local site), and as soon as it is downloaded, even if I choose to leave it uninstalled, I still have the same fatal error (I must delete the TracyDebugger folder in my modules completely to be able to access my site). Here's the error : require_once(): Failed opening required '/home/celfred/PlanetAlert/site/modules/TracyDebugger/panels/TemplateEditorPanel.php' (include_path='.:/usr/share/php') And I'm sorry to say I have no idea what to do... So if one of you could give me a hint, that would be great. I was using TracyDebugger more and more (for minor debugging, I guess you can tell from my question) but I would like to use it more ?
  7. Well that's a great answer ! Thanks a lot @Robin S I was completely unaware of the distinction and your explanation is perfect. I had to struggle with similar issues before and that's quite a step forward for me. Thanks ! I'm gonna take some time to think about all this and read over my code.
  8. Hello, I'm facing a weird behavior (to me)... Why are these requests not returning the same values ? // Test 01 : not working > returns empty $allPlayers = $pages->find("team=$team"); // Returns the 10 players (1 of them has HP=14, others have HP>15, no players have coma=1) $dangerPlayers = $allPlayers->find("(HP<=15), (coma=1)")->sort("coma, HP"); // Returns nothing ??? // Test 02 : Working as expected $dangerPlayers = $pages->find("parent.name=players, team=$team, (HP<=15), (coma=1)")->sort("coma, HP"); // Returns the low HP player If you can explain this to me, I would appreciate because this is causing me a headache right now ? Thanks !
  9. Thanks a lot for your quick help. But I'm not that good and I am running PW 3.0.62 both on local and production. I won't update right now because I'm not able to easily manage different version on local and remote... So I'll manage little by little and do the update later ? But thanks !
  10. Hello, I am discovering PHP tests and this great module (thanks !). Just to mention in case it helps others. The first example kept failing on my website until I understood it was due to the multilanguage setup. Eventually, test 01 became : public function testHomeTitle() { $expected = 'Home'; // we expect the page title to be "Home" $actual = wire('pages')->get(1)->title->getLanguageValue("default"); // check what's the actual title Assert::equal($expected, $actual); // check whether they are equal } and passed ? This may seem perfectly obvious to most of you, but it might help a few ? By the way, I wish I could use my usual debugging tools to debug my tests (sounds quite funny to say ? ) and write something like bd($actual); Here I had to fiddle until I found out about my multiLanguage thing... Would you have any tips on that ?
  11. Thanks a lot for your explanation. I understand things better now ? I've just tested and made sure my cache was up to date, but no change... What's surprising is that with the initial config, I tested somewhere else on my site and it worked. Of course, I double-checked all permissions for the template I'm trying to have the 'Edit' button for... and I'm testing only as a superuser. So that's still a bit myserious to me. But since the problem doesn't occur somewhere else, I guess I AM the culprit who messes things up. That's not a big deal either. I'll do more testing and come back here if I find an explanation. Thanks for your help !
  12. Hello, Another question I have, related not only to FEEL module, but I'm facing it with it so here it is : I load a page via ajax. In the loaded page, I would like to have a $page->feel() to have my front-end link, but the result is nothing. I thought having namespace ProcessWire; at the top of my ajax-loaded page would do the trick, but it doesn't... Does anyone know what I should do ? Thanks !
  13. @tpr Thanks for your quick reply, but with no luck.. I had tried to set the 'user-admin' permission to the 'teacher' role (and I'm trying again right now), but still no Edit link appearing. If I set 'superuser' role back, the link comes back... Another idea ? More info : if I try to front-end edit using the built-in PW capabilities method D gives the same result : not editable even though I'm setting all permissions like superuser's permissions, but editable by double-clicking if I add the 'superuser' role to my 'teacher'. I just don't get it... EDIT : As a follow-up, I have applied a workaround : building a linked page to my user (with a specific editable template) and behavior is now as expected... I should dig a little for the 'official' user profile page front-end edit, but I am not a 'superuser' myself ?
  14. Hi, I'm struggling with something : My 'user' template has page-edit permission for my 'teacher' role My 'teacher' role has page-edit, page-edit-front and profile-edit permissions And yet if I type $user->feel() in my template page (while logged as a 'teacher' user), I get nothing ? If I add 'superuser' role to my logged-in teacher, I get the 'Edit' link. I thought $user were behaving like regular pages... So I've been looking thorugh all my permissions roles for hours but I can't get it to work... I'm lost... Maybe $user is not possible in this context ? If anyone has an idea on where I could look or can explain what's going on here, I'd appreciate.
  15. Hey, Sorry to come back on this, but I'm still struggling... Why is this working as expected ? $notTeacherActions = $pages->find("template=task, owner.singleTeacher=$user"); // Returns 2 pages having the $user in the owner repeater singleTeacher field Whereas this is not : $notTeacherActions = $pages->find("template=task, owner.singleTeacher!=$user"); // Returns nothing where it should return all tasks NOT having this particular user in the singleTeacher owner repeater ? I have a feeling this has to do with my misunderstanding in the previous posts... So I continue here ? By the way, still in this issue, I'm stuck with : $globalActions = $pages->get("name=tasks")->children(); // I have 62 tasks pages $adminActions = $globalActions->find("adminOnly=1"); // I have 10 adminActions $allActions = $globalActions->find("adminOnly=0"); // I have 45 non admin (available to the logged-in user bd($allActions->count()); // This shows me the 45 // The following are my tests to understand... Which I don't :( // First tests from $pages $teacherActions = $pages->get("name=tasks")->children("owner.singleTeacher=$user"); // This returns 2 $notTeacherActions = $pages->find("template=task, owner.singleTeacher!=$user"); // This returns nothing... $notTeacherActions = $pages->get("name=tasks")->children("adminOnly=0")->not("owner.singleTeacher=$user")->sort("category.title"); // This actually returns 45 ($allActions, including the 2 returned in $teacherActions...) bd('from $pages:'.$teacherActions->count().'/'.$notTeacherActions->count()); // I get 2 and 45 // Second test from $allActions // THIS SEEMS LINKED TO MY ORIGINAL REQUEST (AND I'M STILL LOST !) $teacherActions = $allActions->find("owner.singleTeacher=$user"); $notTeacherActions = $allActions->not("owner.singleTeacher=$user")->sort("category.title"); bd('from $allActions:'.$teacherActions->count().'/'.$notTeacherActions->count()); // Returns 0 and 45 As you can see, I still have a long way to go tu understand all this... Sorry if I'm being hard to follow, but I am indeed confused on this issue...
  16. I'm starting understanding things better ? Thanks a lot for this helpul answer ! I'll keep exploring to build a better knowledge of what I'm doing exactly.
  17. Hello, Another newbie question. My Processwire sites is growing and I'm wondering if my way of doing things sounds goog to you. I tend to avoid what I consider 'heavy and frequent' database requests in my functions. For example : // In functions.php myfunction($player) { wire('$pages')->find("myselectors"); // This means about 300 database requests do something... (like $p->newTmpField = 1;) return $player; } // In template.php $allPlayers = $pages->find("template=player"); // About 300 players foreach ($allPlayers as $p) { myfunction($p); } // Now I have access to newTmpField, for example. I tend to replace with : // In function.php myfunction($allPlayers) { foreach($allPlayers as $p) { // do something like set $p->newTmpField = 1 } return $allPlayers; } // In template.php $allPlayers = $pages->find("template=player"); myfunction($allPlayers); // Now $players have been modified. For example, I have $allPlayer->find("newTmpField=1"); So for the moment, I tend to choose the second solution which makes only 1 database request, but what do more experimented developers would recommend ? What I find useful with Page objects in functons arguments is that I have the whole 'tree' I can then 'find' in my function. But as you can see, I need to understand things better. I have a feeling my 'practical' explanation is not really convincing ? Thanks if someone can take a few minutes to give me advice !
  18. Hello ! I have somehting I don't understand here... Here's my code : $allPlayers = $pages->find("parent.name=players, team=$selectedTeam"); $allTrains = $allPlayers->find("template=event, task.name~=ut-action, refPage!='', date>=$startDate, date<=$endDate, sort=refPage, sort=date"); bd('$allTrains:'.$allTrains->count()); // DISPLAYS 0 ???? foreach($allPlayers as $p) { $allTrainings = $p->find("template=event, task.name~=ut-action, refPage!='', date>=$startDate, date<=$endDate, sort=refPage, sort=date"); $test += $allTrainings->count(); } bd('$test:'.$test); // DISPLAYS 883 pages (normal) As you can read from my comments, I have no idea why my first $allTrains stays at 0 while the second request actually finds the corresponding pages. If someone could explain I'd appreciate a lot. I have been struggling with this for hours now... For your information, my pages having template 'event' are in a subtree like so : - player 01 - history-1 - event 01 - event 02 - event ... - history-2 - event 01 - event ... - player 02 - history-1 - event 01 - event 02 - event ... - history-2 - event 01 - event ... - player ... - history-1 - event 01 - event 02 - event ... - history-2 - event 01 - event ... Thanks in advance. (sorry for my preceding 'tree' which doesn't look like much. I need to find a way to output this better ? )
  19. Hello, First of all, thanks a lot for your great answer. You took the the time to post nice explanations and this will help me a lot to improve. No problem of course. This is exactly what I expected : general comments about some newbie mistakes you can quickly notice in my code. Well, maybe this sounds obvious to a a lot of readers, but I guess I needed to be reminded of that advice I do that sometimes because I feel better this way. I'll re-read my code and try to think differentely in the future by applying what you explain afterwards. Thanks for your nice example. It is very much inspiring to me. I feel like understanding things better thanks to your reply so again, thanks a lot @Robin S for your help ! It's not always easy to learn coding by yourself and every time I end up asking the PW community for help, I get a nice answer that cheers me up and makes me understand things better. That's really cool !
  20. Still trying to understand things better. I've been looking at @Robin S's answer and I'm facing another issue. To set my nbBonus for each group, I had this function : function groupBonus($players) { $nbBonus = 0; // Sort players by nb of places $players->sort('places.count'); // Get min/max nb of places in the group $min = $players->first()->places->count; $max = $players->last()->places->count; if ($min == 0) { // 1 player has 0 places, so NO bonus possible return 0; } else { // No player has 0 places, let's check if they all have 1,2,3... places for ($i=1; $i<=$min; $i++) { $nbPlaces = $players->find("places.count>=$i")->count; if ($nbPlaces == $players->count) { $nbBonus++; } } } return $nbBonus; } So my parameter $players was a PageArray() I had thanks to a 'find' request. But now, it is a regular PHP array and this throws an error because I'm trying to use lines such as $players->sort('places.count')... All in all, I was trying to rework my function to work on regular PHP arrays, but then I have other headaches because I use many PW ways afterwards and I eventually wondered if I could simply turn my $players regular PHP array into a pageArray() again ? And eventually, I wonder what you feel seems to be the best way for me ? Would it be preferable to work on regular PHP arrays all through my functions or should I 'convert' as soon as possible (if possible) so I can use PW way (or what I understand being PW way...) And if you can give me a hint on what I should read more about (at this point) concerning my programming skills, I'd appreciate as well because I see that my skills are getting too low for what I want to do on my project Thanks !
  21. Hello, First of all, THANKS a lot for your answer which helps me better understand things. I'll go ahead and dig what you're mentionning with 'multisort'. It seems quite interesting and I have a feeling it fills a big lack in my knowledge In the meantime, I have managed to do some stuff yesterday night which seems to do the job. In case you have a little time to read through it and see things I shouldn't do, I would be glad to have some kind of feedback on that (but as I said, I'll test your code above during the day). Roughly speaking, if I want the 'group' scoreboard, I loop through 'allPlayers' to get a list of groups and teams which I add to PageArrays. Then, I loop through all groups, get involved players and (here the thing !) I clone the group page to add it to a $uniqueGroup pageArray. And this page holds the calculated 'bonus' and 'karma'. Then, I do my thing with the 'reindex' (see code below) to try and get the logged in player's position and return all my variables to be able, then, to display a particular scoreboard (top 10, top 3 + 'surrounded' player...) I know my explanations are hard to follow. Here's the code : function setScoreboard($allPlayers, $player, $field) { if ($field != 'group') { $allPlayers->sort($field); } else { $allPlayers->filter("team.name!=no-team")->sort("team.name"); $allGroups = new PageArray(); $allTeams = new PageArray(); $already = []; $uniqueGroups = new PageArray(); foreach($allPlayers as $p) { $groupId = $p->team->id.$p->group->id; $p->groupId = $groupId; if (!in_array($groupId, $already)) { $allGroups->add($p->group); $allTeams->add($p->team); } array_push($already, $groupId); } foreach($allGroups as $group) { $index = 0; foreach($allTeams as $team) { $players = $allPlayers->find("group=$group, team=$team"); if ($players->count() > 0) { $newGroup = clone $group; $newGroup->team = $team; $newGroup->id = $group->id.$team->id; $newGroup->focus = 0; // Check for group bonus $newGroup->nbBonus = groupBonus($players); $newGroup->yearlyKarma = $newGroup->nbBonus*30; // Add individual karmas foreach($players as $p) { // Karma is divided by number of players in the newGroup to be fair with smaller newGroups $newGroupYearlyKarma = round($p->yearlyKarma/$players->count); (int) $newGroup->yearlyKarma = $newGroup->yearlyKarma + $newGroupYearlyKarma; $newGroup->details .= $p->title.' '; if ($p->name == $player->name) { $newGroup->focus = 1; } } $uniqueGroups->add($newGroup); $index++; } } } $allPlayers = $uniqueGroups->sort('-yearlyKarma'); } $allPlayersReindexed = new PageArray(); $allPlayersReindexed->import($allPlayers); if ($player) { if ($field != 'group') { $playerPos = $allPlayersReindexed->getItemKey($player)+1; } else { $playerGroup = $allPlayersReindexed->get("focus=1"); $playerPos = $allPlayersReindexed->getItemKey($playerGroup)+1; } } else { $playerPos = false; } if ($playerPos) { // Player is in the charts if ($playerPos <= 5) { // Good position, get Top 6 $topPlayers = $allPlayersReindexed->slice(0, 6); $prevPlayers = false; } else { $topPlayers = $allPlayersReindexed->slice(0, 3); // Get top 3 players $prevIndex = $playerPos-3; $prevPlayers = $allPlayersReindexed->slice($prevIndex, 4); } } else { // No ranking (or complete scoreboard) $topPlayers = $allPlayersReindexed->slice(0, 10); // Get Top 10 $prevPlayers = false; } return array($topPlayers, $prevPlayers, $playerPos, $allPlayersReindexed->count); } If you want to have a look of what is the final page, you can see there (on that page, I use Ajax requests to load all scoreboards individually (and the 'group' scoreboard is actually not functionnning well), but I intended to get rid of this server load since my $allPlayers is already loaded in my head.inc, I imagined optimizing my page by simply managing my scoreboards in PHP functions. Anyway, thanks again for your help ! And feel free to give me advice if you see horrors in my code (but again, I'll take the time to analyze the solution in @Robin S's answer)
  22. Hello, I've been struggling for hours with this, and it is driving me crazy. I guess I completely misunderstand basic concepts, but I'm facing a wall here hence this message... Here's what I'm trying to do : I have a list of players in $allPlayers (pages) Each player has (among others) 2 pageArray fields : 'group' and 'team'. I'm trying to loop through all the players to build another pageArray (or WireArray or whatever...) to gather the players in groups/teams accordingly and deal with the different info I have on them and calculate a score. My main problem is that some players are in a different team but their group has the same name (and I need to restrict players to their own team mates). Here's my 'code' so far (which doesn't work) : // Build group list (for players having a team) $allPlayers->filter("team.name!=no-team")->sort("team.name"); $allGroups = new PageArray(); $uniqueGroups = []; $uGroups = new PageArray(); // This was a test, see below... $already = []; foreach($allPlayers as $p) { // Assign a groupId to each player $groupId = $p->team->id.$p->group->id; $p->groupId = $groupId; if (!in_array($groupId, $already)) { // The following lines were a test but didn't work and I DON'T UNDERSTAND WHY ? // $uG = new Page(); // $uG->of(false); // $uG->template = 'player'; // $uG->name = $groupId; // $uGroups->add($uG); // bd($uGroups->count()); // !! Keeps showing 1 ? My purpose was to be able to use $uGroups->karma, $uGroups->nbBonus... afterwards array_push($uniqueGroups, $groupId); } array_push($already, $groupId); } // Then, I loop through $uniqueGroups, get the players and calulate my score foreach($uniqueGroups as $group) { // Limit to groupId players for group scores $players = $allPlayers->find("groupId=$group"); // Check for group bonus and calculate scores [...] // I cut to simplify my post // But my other problem is storing my score : I can't use $group->karma or $group->nbBonus since $group is a ragular PHP array ? } // Then, I wanted to create a new pageArray (hence my $uGroups above) to be able to sort them with the following $uGroups->sort("-karma"); And I'm stuck... More than 5 hours today already on this, and still blocked I've tried playing with WireData, WireArray... but I'm all lost here. You can understand why I'm posting in the 'Getting started' forum ! For further information, this part of code is embedded in a setScoreboard() function and this is the 'group' part of it. If anyone can devote a little time to give me a clue on how to think about this, I'd greatly appreciate ! Thanks ! PS : The more I write about this, the more I think I am able to get the group members and scores (with my awkward coding), but then I am unable of simply storing this information before rendering it. Here I'm referring to my comment in my code where I say that TracyDebugger keeps showing me only 1 $uGroups page. I wish I could dynamically build a 'uniqueGroup' page with Pagefields for Group, Team, pageArray for Members, Integer fields for calculated Karma, nbBonus...... sigh......
  23. Yep. I could have thought of it. Good idea ! Thanks a lot
  24. Hello, I'm facing an issue with my page fieldtype. Pages appear in the order they were created although I'd like to see them sorted in alphabetical order (by title). The pages are well-sorted in my tree, but in that particular Page fieldtype (on another page), I can't find any place where I would decide on what field I can sort them. Am I missing something here ? Let me know if I'm not clear enough in my explanations. Thanks in advance for a clue
  25. As always in this community, a quick, straight to the point and perfect answer. Many thanks to you @kongondo Sorry for missing it in the docs. I promise I searched for it but I was stuck in the $page part of the API and didn't see the restore()... My bad. Just to mention, I typed 'restore' in the search box (top left), but the API linked in your post above didn't appear in the results Anyway, the answer was quite simple (just as I thought, in the PW 'philosophy') and I'm happy with that. Thanks again !
×
×
  • Create New...