1

Situation: I have a simple video player set up using views with a pager. Views loads a set of related nodes, each with an embedded video. By using a pager, the user can advance to the next or previous video in the list.

Problem: I'd like to track whether a logged in user has viewed a video or not, then use this information to help a user see what they have left to watch in another view (a view that simply lists the nodes with embedded videos). So, I need to be able to list viewed/not viewed nodes with views at the user level.

I realize there is complexity around tracking whether a user has really watched a video or not, so ideally the logic that decides whether a user has watched a video or not (custom code, a rule, etc) can be extended/updated later. For now, simply tracking that the user viewed the node is fine.

Related question: since the user is viewing nodes thru the views-based player, and not by clicking node links, where is the best place to execute custom code to mark a node as viewed? I think it could be done with hook_views_pre_render, but I'm not sure that's the right place.

Any thoughts on a simple lightweight approach for Drupal 7? I thought of trying the Flag module (with a user-level flag), using either Rules or custom code to flag a video as "watched", but I haven't tried it yet. There is also a module called path rules that can trigger a rule based on paths: https://drupal.org/project/pathrules

Are there other modules I should consider that already do some of this?

1

1 Answer 1

0

I've worked out a solution based on the message module (https://drupal.org/project/message) and I think this will solve the problem well. Here's the basic approach:

  1. Install message and create a new message type to capture a specific event (i.e. lesson viewed in my case).

  2. Add an entity reference field to the message type created in #1 (messages are fieldable entities) in order to store a reference to the node that was viewed.

  3. Write a function to create the message type created in #1. There is example code in a example module that comes along with the message module.

  4. Hook the view that needs to trigger message creation and call the function created in #3.

  5. Create a view that lists messages. Messages have good views support.

  6. Add additional message types and logic to capture other kinds of activities (a user completing a video lesson, which in this case will mean working with the wistia api, since the videos are hosted on the wistia platform).

One question: I'm not sure where best to hook views to create a message when a user views a node through the view described in the original question . I'm currently using hook_views_post_render, which seems to work well, since the view provides access to the node id needed to create the message.

Overall, I think message will be a good solution for this problem and will provide a nice foundation for tracking other activities as needed. There's a good video overview of the message module here: https://vimeo.com/63919900

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.