Jump to content

celfred

Members
  • Posts

    189
  • Joined

  • Last visited

Posts posted by celfred

  1. 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 ?

     

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

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

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

  5. 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 !

  6. 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...

     

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

  8. On 1/22/2020 at 4:49 PM, MadeMyDay said:

    @celfred: This has nothing to do with the map itself. It takes 15 seconds four your server to generate a response, after that the map and all of its content loads fast. So I assume your process of building the list of markers is somewhat ineffective. Can you show the code with which you generate the $allElements Array?

     

    @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... 

  9. 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 ?

  10. Hi there,

    I have quite a weird issue here. On my local site, the Trash page has completely disappeared ! I've looked everywhere and I can't find it. I have no idea what has happened and how long it has been this way... On my remote, Trash is there.

    I also have 2 'Admin' in the tree... 

    If I do a 'Find' search, I get a Trash page but I can't act on it.

    Any clue on what I could do ?

    Screenshot attached. 

    backend-no-trash.png

  11. Back again on my preceding matters (sorry to insist...)

    I've just noticed this recurring line in my modules log :

    Quote

    "Configurable module check failed for WirePDF, retrying..."

    Do you think this could explain my previous case ?

    Any advice on what I should do ? Should I try and reinstall Oages2Pdf completely ? (I'm scared of breaking things).

    Thanks !

  12. Hi there,

    I'm unable to set the page orientation to landscape. Any clues ?

    Here's what I have in my 'pages2pdf' folder (hence my PDF template) (triggered by a simple front-end link on which I added ?pages2pdf=1' in the url) :

    	$pdf = $modules->get("WirePDF");
    	$df->pageOrientation = "L";
    	echo "This is a test";
    	

    But my PDF is still in portrait mode ?

    I have also tried this in the front-end page having the PDF download link :

    	echo $modules->get("Pages2Pdf")->render(["pageOrientation"=>"L"]);
    	

    but clicking the generated link still gives me a PDF in portrait mode ?

    On my site, I have many PDF generated this way, but there were all in portrait mde so I've never had to manage such an issue.

    If you have an idea, I'd appreciate. Thanks !

    Celfred

    Edit : Still stuck ? For further information, I'm using pages2Pdf 1.1.7 and PW 3.0.123. What I find weird, in my backend modules list, I have WirePDF saying version 0.0.0 and Inactive. Is this normal ?

  13. Oh, I've just re-re-re-re-read the API documentation, and maybe I've seen something :

    Does $session->set($key, $value) only work with strings for $value ? Maybe this is my issue trying to pass a PageArray ???

    And then, how would you do that, then, passing a 'big' pageArray without having to do the DB request again ? I thought I could do it through $session ?

  14. Thanks for your concern @arjen. I appreciate your help.

    35 minutes ago, arjen said:

    What does getAllPlayers() do? Does this contain a selector with permission access?

    It doesn't do much except a $pages->find("template=player, team=$selectedTeam") according to the logged in user.

    But your comment made me think of another test. I simplified by wroting :

     $session->set('allPlayers', 'test');

    But I get nothing on my ajaxContent.php page... $session->getAll() lists previously set variables only.

    So I kept trying things and went on delogging my user and trying to re-log and noticed it didn't work as expected any longer. So I switched to my dev branch and logging in functionality came back. So I started inspecting my code and here's what I noticed :

    • If I put this in my head.inc :

    $session->set('allTeams', 'test');

    Everything works as expected. No more issue anywhere.

    • If i put this instead :

    $session->set('allTeams, $allTeams);

    $allTeams being a pageArray that the actual logged-in user receives from a $pages request (actually the different classes for the logged-in teacher), my logging-in system doesn't work any longer and I get my initial issue. Actually, I interpret this as an impossibility to update in any way my $session...

     

    So I'm slowly stepping forward, but I still don't understand anything about this behavior...

    You also mentionned :

    52 minutes ago, arjen said:

    Perhaps checking in a incognito screen to check if you get both scenarios the same variables.

    And I have no idea of what that means, sorry... If incognito screen is a 'guest' view, for the moment, I just want a specific role to have this functionality.

    I stay tuned for explanations ? 

  15. Hello,

    I'm facing a weird issue here. I have a page loaded with this code inside (my comments in line ends) :

    if ($session->allPlayers) { // Set in a head.inc file. I have also a $session->set('allTeams', $allTeams); in my head.inc
      $allPlayers = $session->allPlayers;
    } else {
      $allPlayers = getAllPlayers($user, false);
      $session->set('allPlayers', $allPlayers);
    }
    bd($session->getAll()); // HERE, I get a number of 11 variables which is what I expect
    

    In the same page, I have a link pointing to ajaxContent.php that loads stuff via Ajax.

    I just write this in my ajaxContent.php to test :

    bd($session->getAll()); // HERE, I get only 9 variables. All my newly set $session variables ($allTeams and $allPlayers) are not conveyed to ajaxContent.php ???

    Would you have any idea why is that ??? Another thing : I have a $session->headMenu set in my head.inc, and this one works fine. I can retrieve it in my ajaxContent.php page.

    I've tried cleaning all caches but it doesn't change anything ? 

    At first, I expected it to be a 15-minute update to my site... It turns out to be a 2-hour issue and I'm still  stuck.

    Thanks for your ideas ! 

  16. Back here with... quite an amount of shame...

    I'm sorry I have taken time from you all. Here's the thing : my site/ready.php which I thought did not have access to bd() because I couldn't even see a simple bd('ok'); was not at the right place. A bell just rang in my head a few minutes ago after making a fresh re-install of a blank profile ! I came back to my original local site and thought : "No way, Fred ! site/ready.php NOT your-website-root/ready.php !!!!" I moved ready.php and.... tada ! (Of course...). What a nerd...

    So again, SORRY for having taken some of your time, but thanks for your helpful answers. I still have learned quite a lot from our exchange and that is the most important thing.

    I'm glad I posted in 'Getting started' ;)

    • Like 3
  17. @Robin S : OK ! I'll test during the day. Actually, I think I did test in site/ready.php but I was wondering if bd() would work there and I imagined then that I had no simple way to see if everything worked (see my dev level !). Since I already had a couple of working hooks in templates/_init.php, I used it again here...

    So most of my last tests (disabling all modules for example) need to be re-tested in site/ready.php. I'll do this during the day and tell you how this is going.

    @adrian Oh ok; Then, I'll do that also from a blank-site profile.

    Thanks a lot !

  18. Indeed Tracy allows to easily disable modules. I did check them all and... no change...

    Regarding a fresh install, that sounds like a huge task to me : reinstall a new database, reinstall the different modules I use, re-import data... and how will I put that back to my remote site if it solves the issue ? I'm speechless ? 

    I've just started looking at the 'Export Profile' and trying to follow the instructions on a new local installation. But it fails. I get many errors creating the database (pa.pages does not exist, pa.modules does not exist...) and it freezes. I guess my files are too large... And I'm wondering if that's the proper way to do things I have a feeling doing an export on a new install will export the problem as well, no ? I tend to think I'll have to do all steps I've mentionned in my preceding paragraph one by one (can you confirm this is what I should do ?) but then that would take me a very long time... So I would tell you in a few days (or even weeks ?)

    I can't understand how I got into this situation ? Anyway, thanks a lot for your help and as I said, once you'd confirm I have to re-install things 1 by 1, I will get to it at my possible pace ? 

  19. Thanks again, but nothing changes...

    So you know :

    • I disabled FrontEndEdit module
    • I cleaned all my files in the assets/cache/folder
    • I updated on my local site to PW 3.0.123

    And my Page::render hook is still ignored. I tried Page::loaded and this one works well (I get my 'inside' message).

    This is driving me crazy ? 

  20. I'm viewing my homepage on localhost (the page can be seen there), but actually I went on many other pages to test, checked cache and so on... but no change...

    2 minutes ago, adrian said:

    Other than that, I wonder if you can try updating to the latest PW version, just in case.

    I was just thinking about this. But I'm afraid I won't be able to do that right now. I always get scared of such a major update in case I break things ?  I prefer having more time ahead of me to do such an action. I'm not trusting my dev abilities !

    So I stay tuned for ideas and I'll keep you updated when I update. But thanks a lot for your help @adrian.

  21. Ah... This TracyDebugger is indeed extraordinary ?

    There might be a clue here : my Page hooks are in lesser number than yours (no 'if', no 'links').

    If I use Page::path, my 'inside' gets triggered, but as soon as I use Page::render, nothing happens ? And why is Page::render not listed our tables (only renderField or renderValue) ?

     

    Capture du 2019-03-13 16-49-00.png

  22. Well... I have this in the preceding lines which seems to work ok :

    	  $wire->addHook('LazyCron::everyDay', null, 'checkActivity'); // Check all players activity
      $wire->addHook('LazyCron::everyDay', null, 'randomSpecial'); // Set random special monsters
      $wire->addHook('LazyCron::everyDay', null, 'emptyTmp'); // Empty /tmp subtree every night
      $wire->addHook('LazyCron::everyDay', null, 'cleanTest'); // Init test-team players
    	

    Is there a basic hook other that Page::render which I could test with ? (I must admit I'm getting lost in all those hooks, hence my post in the 'Get started' forum ? )

    For info, I'm with PW 3.0.62.

    Thanks for the help !

×
×
  • Create New...