elgg _set_plugin_user_setting to save the last visited page

i want to save the last visited page of a user,

(get the guid and save it)

should i use elgg _set_plugin_user_setting to save it ? or is there better solution ?

 

[Edited]

okay, to avoid misunderstanding,  i will explain my purpose :

I want to make a feature :  Recommendation (show entities list that contains user favourite topic)

So i need data of user 's favourite topic

Simple example: Alex read Pokemon Go article , his favourite topic is Pokemon Go

I need the data of last 10 visited page (the title, url or just tags of the article)

I dont know how to save the data , elgg_set_plugin_user_setting , or annotations or something else (safe ,not use big resource and not make problem in the future)

i'm sorry if i make you confused

 

  • Aha, I think I got you wrong, Do you want to log what users visited your website?
    I thought you wanted to log every lastpage 'a user' visited

  • plugin settings aren't stored as arrays.  You could do that and store it as a serialized array if you want to pretend we're in wordpress ;)

    Annotations would probably be the best bet here - listen to Dries, just make sure you're clearing out the old ones because that could bloat db real fast otherwise (trust me, I've done it).

    Also, instead of $_SERVER['REQUEST_URI'] you should probably use

    current_page_url()

  • okay, to avoid misunderstanding,  i will explain my purpose :

    I want to make a feature :  Recommendation (show entities list that contains user favourite topic)

    So i need data of user 's favourite topic

    Simple example: Alex read Pokemon Go article , his favourite topic is Pokemon Go

    I need the data of last 10 visited page (the title, url or just tags of the article)

    I dont know how to save the data , elgg_set_plugin_user_setting , or annotations or something else (safe ,not use big resource and not make problem in the future)

    i'm sorry if i make you confused

     

     

  • @matt becket , so the conclusion the annotations is the best way ? okay i will try it

  • @dries : i've re-explained my purpose above , i hope you understand now and can help me :)

  • I think I would implement this by creating a relationship between the user and the piece of content:

    add_entity_relationship ($user_guid, 'has_read', $content_guid)
    

    This way I could always get the latest data.

    Consider this:

    1. You create the blog "My awesome Pomekon Go article"
    2. I read it, so now I have the annotation containing "My awesome Pomekon Go article"
    3. Later you notice a typo and change the title to "My awesome Pokemon Go article"
    4. The annotation attached to me now still has the wrong title

    However, if done with relationships, it would be possible to query the exact blog post in case you later need the title:

    $favorite_posts = elgg_get_entities_from_relationship ([
        'guid_one' => $user_guid,
        'relationship' => 'has_read',
    ]);
    
    foreach ($favorite_posts as $post) {
        echo $post->title;
    }
    
  • @juho i think it will work, thanks

    but how to get last 10 visited page  ? can i put 'limit'=>10 , 'order_by' => time_created dsc ?

  • Yep relationships will work too, just make sure you manage them in a spot where it's clearly the page for the content.  Eg. blog/all will load 10 blogs and output them with elgg_view_entity(), you don't want to log them all as read.

    Originally we assumed you needed to log *every* url visited, in which case relationships wouldn't work, but for content full-views only, that is the best way.

  • Okay i want to ask (maybe) once again  ,

    what should i choose ?

    create_annotation

    or

    add_entity_relationship

    which one that use less resource (memory, CPU usage, etc) ?

    note: i will save data every user open full-view content , example: Alex read Pokemon Go article,

    i'm sorry i'm not expert about database, i just dont want get problem in the future coz i think i will not be able to solve about database problem.

    So help me to choose ,

  • From what you have described, go with the relationships as per Juho's suggestion