Hi - I have a request for a bit of help in terms of setting overall direction. What I want to do is probably similar to others, so hopefully this will be of use in the future.

I currently capture activity on comments that are inserted, nodes that are created, and nodes that are updated. There are 3 types of content and each has a different set of CCK fields. For example, content profile content type has no votingapi votes tied to it, where the other two do have votingapi enabled and capture user votes.

Using Activity 2, I'd like to create an activity stream view of not just the activities but also pull in additional content from the nodes. Building on the default activity_all view, I added a relationship to Node: Content Profile tied to Activity - User. Now I can pull in all the fields from the profile of the user who initiated the activity. I pull in a picture, name, etc. It works well for this use case.

My challenge comes in when I start getting into views of information from multiple different kinds of nodes. The votingapi is a good illustration. I'd like to create a relationship Node:Votes tied to Activity:Node to pull in the vote, and then use a field Vote results:Value tied to the Node:Votes relationship. If I had a view of only activity related to nodes that have votes, this would work. It does get the vote for the node, but it also displays voting buttons on activity messages that have nothing to do with voting like the profile node. An activity message is generated "User X updated their profile", but now in this case it also has bunk voting buttons attached. The same is true if I display a link to node comments - it appears on all activity messages (working properly for nodes with comments, heading to a 404 page for nodes that do not support comments.) Also, if I select "Require this relationship" for votingapi it also works, but gets rid of any node without voting enabled and all of the profile updates disappear.

So then my thinking went down the path of creating multiple different views of activity. I'd create one view for each type of node and attach my fields, then create one view of user activity, etc. The problem then is how to reconcile them into a single view. This gets back into merging output from different views and perhaps goes down the line of the old views fusion module.

Here are my goals:

  • Single activity2 view for all updates
  • Selectively inserted content from nodes that are referenced in the activity message (like voting on that node, a CCK picture field from the node, or a link directly to the comments on the node) when not all activity messages relate to nodes

    My question is: What's the best approach? A single view for all content? If so, how would I reconcile the differences between content types and fields?

    Thanks in advance for any thoughts. If you point me in the right direction I am more than happy to write out a detailed solution to the problem.

  • Comments

    Scott Reynolds’s picture

    I would instead sugguest creating a patch for view->render_field() (view.inc of views module).

    Right there it does a check to see if it should render the field. There you should check to see if the SQL result returned a NULL value.

    maybe?

    /**
       * Render a specific field via the field ID and the row #.
       */
      function render_field($field, $row) {
        if (isset($this->field[$field]) && isset($this->result[$row]) && isset($this->result[$row]->$field)) {
          return $this->field[$field]->advanced_render($this->result[$row]);
        }
      }
    
    rjbrown99’s picture

    Thanks for the reply. That might work for the voting scenario, but I am also running into a situation where an activity message related to a comment is also displaying a CCK photo from the node. What I am really trying to do is to create 'micro views' tied to each type of activity, similar to how the activity module itself is laid out for the various templates. For example, I would create 'microviews' like this:

    1) Comment on a node - Only display the activity message

    2) Added a new node of type photo (where photo is a CCK filefield) - Show the activity message, a thumbnail of the photo, and voting buttons

    3) Added a new node of type gallery (where this is a CCK nodereference to images) - Show the activity message, thumbnails of each photo, and voting buttons

    I could create one view for each of these using the existing activity filters for operation and type. This would work well, but I lose the consolidated view of all updates that I am trying to achieve without a way to 'blend' the views together. What I'm really aiming to do is to arrive at something that looks a little like the Facebook wall where updates are focused around the activity view.

    Perhaps I could do something like use the viewfield module to save a view into a CCK field for each nodetype in question, which would then be tokenized, and could be exposed directly within the different activity templates as a token. Assuming it would work, I would pass an argument into that viewfield of the nid in question to have it pull out the relevant fields. Or maybe this is descending into insanity.

    Scott Reynolds’s picture

    Status: Active » Postponed (maintainer needs more info)

    You can do this already out of the box. Thanks to the CCK people who decided that cck fields should always be left joined, this will create an AWEFULLY BAD query. You can use Views Caching plugins and I would encourage you too. #372994: Ability to INNER JOIN to node for a specific field

    1. Set up your node relationship make in NOT required
    2. Add image field for photo type (use node relationship)
    3. Add a Relationship from node to Content: gallery_reference_field.
    4. Add in image field for photo type (use relationship from step previous)

    Again the voting is the issue and I pointed out why. You could also look at how the voting buttons are rendered and put a !empty($values->{$this->field_alias} before the rendering.

    I just tested almost everything out without the voting and I got it to display like i expected. (message for just comments, Message Plus cck field (photo), Message plus all the values for the cck field(gallery))

    Please try this and if it doesn't work export your view please and share it with us

    PS: you can also investigate using just tokens in the message to achieve this. You might be interested in #485436: Activity publisher as theme hooks

    edit:fix recipe for gallery images and removed assertion that i tested everything. It should work, I have used that technique before but haven't tested it out.

    rjbrown99’s picture

    Thanks again for your help and guidance. My lack of SQL knowledge and the differences between LEFT JOIN and INNER JOIN means I didn't fully understand everything in #372994: Ability to INNER JOIN to node for a specific field, but the relevant comment seems to be #11 where webchick is suggesting a module enhancement to convert the LEFT JOIN to INNER JOIN. I'm a big fan of making things faster so I might give that a try.

    Recap to Date

    I'll document more of what I have done. To recap for anyone that happens to come across this thread, I started with the default Activity 2.x-dev view and am building on it by including more CCK fields. Here's the latest.

    I started with two relationships - Activity: Node, which is required, and Activity: User, which is also required. I added one new relationship Node: Content Profile attached to Activty: User, required. This is to pull in the activity user's content profile fields.

    Without adding more relationships, I added a field Content: Photos attached to the Activity - Node relationship. This successfully pulls in a photo from the referenced node the activity took place on, but it shows the photo on all activity messages related to that node, including the activity templates where "Record an activity message when: comment insert types Photos". I want the CCK photo field to show on activity mesages where "Record an activity message when: node insert types Photos", but not on adding of comments.

    Moving Forward

    To address your reply, I started by changing the Activity: Node relationship to remove the "Required". My Content: Photos field is already attached to this relationship so I didn't change it. It still shows the photo field output on all messages related to the node - both for new photo nodes and for comments.

    To try with the gallery type, I created a new relationship from Content: Items (the CCK nodereference field for the gallery) attached to the relationship Activity - Node, using delta item #1. I then added a field Content: Items tied to the Items reference created in the previous sentence. It still shows the field output on all activity messages that relate to the node.

    The only challenge with using tokens is that I am using special imagecache output handlers that are tied to Javascript actions for hover zoom and the like. One of the advantages of using views is I can just pick my imagecache handler and off we go. With tokens this may require adding one token for each handler so they can be properly selected in the template.

    I created an HTML page with the SQL query the view outputs, a screen capture of the view from the Drupal UI, and an export of the view itself. Here it is. I'm not opposed to bringing this information into the ticket, but it's probably better to solve the problem and then post the correct view which is why I kept it out of here - less clutter. To clarify, this version of the view correctly outputs all of the fields, but it outputs the CCK field for all activity messages (comments + node adds). My goal is to only output certain CCK fields based on activity type (node insert vs comment insert).

    Perhaps part of the problem is I didn't fully grab your input from the most recent post. I did spent a few hours now rearranging relationships and fields to no avail.

    Scott Reynolds’s picture

    If you remove the labels from the optional fields how does that work out?

    rjbrown99’s picture

    The Content: Items field and Content: Photos fields are set to Label: None in the current view.

    Scott Reynolds’s picture

    To try with the gallery type, I created a new relationship from Content: Items (the CCK nodereference field for the gallery) attached to the relationship Activity - Node, using delta item #1

    You are going to want to use delta All to get all the thumbnails.

    What isn't working they way you want to?

    rjbrown99’s picture

    With delta all, it repeats each of the activity messages - once per delta item.

    The real problem is still that the photos CCK field is showing up on activity messages of all types related to that node, while I want it to only show up for specific activity templates. It's the same for voting but you helped explain away that issue.

    The goal is -

    1) For activity template "Nodeapi Record an activity message when: node insert types Photos", display the CCK photo field in the view in addition to the activity message.

    2) For activity template "Comment Record an activity message when: comment insert types Photos", display only the activity message but not the photo. Since the field is in there already, it re-pulls this.

    There are other cases of wanting to selectively display content from the referenced node the activity message is tied to, but that's a somewhat clean example so let's go with that. I'm trying to tie specific 'mini views' of content from the node to each different type of activity template.

    Scott Reynolds’s picture

    Status: Postponed (maintainer needs more info) » Fixed

    This can be achieved via Views only by doing some heavy theming. I would achieve it this way

    1.) add the Activity Type field and exclude it from display
    2.) Create the views-view-row--view-wall.tpl.php
    3.) only output the conditional fields if the Activity Type matches the proper one

    If you have never themed Views before: http://views-help.doc.logrus.com/help/views/analyze-theme

    You can also have a look at #485436: Activity publisher as theme hooks. This issue is about creating much more expressive messages, so you don't have to do all these relationships to achieve what you want.

    rjbrown99’s picture

    Thanks Scott, that's a very good idea and I had not thought of that. I'm going to give it a go at the theme layer. Assuming I will be successful I'll post some sample code back to this thread.

    Status: Fixed » Closed (fixed)

    Automatically closed -- issue fixed for 2 weeks with no activity.

    pribeh’s picture

    Status: Closed (fixed) » Active

    Hey,

    I've been trying to get this right. I've setup an Activity view with the respective fields such as "imagefield" and "activity: type". Then I've placed the following code inside a views-view-fields.tpl.php.

    <?php if ($fields['type']->content == "node"): ?>
    <?php print $fields['field_image_fid']->content; ?>
    <?php endif; ?>
    

    This works but I'm wondering if this a correct way of doing this(?).

    Thanks

    Scott Reynolds’s picture

    Status: Active » Fixed

    Sure there isn't any error there. In this case, you are printing sanitized content.

    In Views 3, there is an option for every field to hide if empty, which would solve this.

    pribeh’s picture

    Oh, I'm just trying to print the imagefield if the Activity is a node. The above solution seems to work fine. Currently it displays an imagefield (or any other node related field) along with a comment in an Activity view. Would Views 3 then not display an imagefield along with a comment with said option? I thought this had something to do with the Activity Node relationship.

    Thanks.

    Scott Reynolds’s picture

    Views 3 would allow you to avoid having to do

    <?php if ($fields['type']->content == "node"): 
     // DO STUFF HERE
    <?php endif;

    It prevents having to check to see if this field has value or not. It just wouldn't print it if the activity type wasn't node.

    And yes that has to do with the relationship, though thats too simple of a way to look at it. The relationship isn't required, so this means that all fields that use that relationship could be empty. Views 3 says "Hide if empty" will prevent markup from being printed out. In Views 2, the markup will be printed but nothing will be in the markup. It screws up styling.

    pribeh’s picture

    ya, that extra markup forces me to always use a template with conditionals as a result. Good to know I won't always have to do that with views 3. Thanks for the info Scott - I appreciate it.

    Status: Fixed » Closed (fixed)

    Automatically closed -- issue fixed for 2 weeks with no activity.