• Content Count

  • Joined

  • Last visited

Community Reputation

55 Excellent

About celfred

  • Rank
    Sr. Member

Profile Information

  • Gender
  • Location

Recent Profile Visitors

3,750 profile views
  1. celfred

    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.
  2. celfred

    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 !
  3. celfred

    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 !
  4. celfred

    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 ?
  5. 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 !
  6. 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 !
  7. @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
  8. 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.
  9. celfred

    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...
  10. celfred

    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.
  11. 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 !
  12. 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 )
  13. celfred

    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 !
  14. celfred

    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 !
  15. celfred

    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)