screen grab

http://grab.by/8Q6S

We attached the like flag to a couple of the heartbeat templates at http://oursite.com/admin/build/heartbeat/list

while the like buttons are showing up and do seem functional, only the person that liked something can see that they liked it.. admin liked a post, styol cant see that he liked it.. both can see what they themselves liked though

Comments

Stalski’s picture

Status: Active » Postponed

That is correct. This is on the TODO list.
Feel free to post a patch for this. I'll be happy to put it in.

The plan for now was to finish drupal7 stable and backport that piece into drupal6

vishun’s picture

Here is what I came up with for heartbeat-message-row.tpl.php -- there is probably room for improvement but its a decent start. Don't forget to change out 'hb_like' for the machine-readable name of the flag.

        <?php
         
          // anonymous isnt allowed to flag, only output for logged in users
          if ($user->uid!=0) {
            print ' <small>&bull;</small> '.flag_create_link('hb_like', $message->uaid);
          }
          
          // get a list of who flagged this item
          $who = flag_get_content_flags('heartbeat_message',$message->uaid);
          if (isset($who)) {
            $wholiked = array();
            $likers = null;
                     
            // build username links
            foreach ($who as $key => $value) {
              $name = user_load($key)->name;
              $wholiked[]['view'] = '<a href="/user/'.$key.'">'.$name.'</a>';
            }
            
            // deal with multiple users, comma's, and and's
            $count = count($wholiked);
            if ($count==2) {
              $wholiked[0]['comma'] = ' and ';
            } else if ($count>2) {
              foreach ($wholiked as $key => $value) { 
                $wholiked[$key]['comma'] = ', ';
              }
              $wholiked[$count-2]['comma'] = ' and ';
              $wholiked[$count-1]['comma'] = '';
            }
            
            foreach ($wholiked as $wl) {
              $likers = $wl['view'].$wl['comma'];
            }
            
            // appended label
            $likers .= ' liked this';
          }
        ?>
Stalski’s picture

Status: Postponed » Closed (won't fix)

This won't be included anymore in drupal6. In drupal7 there is system that produces button AND attachment for the flags on activity.

Thank you for the code, I think it still can help others wanting something like that. I also admit that the flag implementation within heartbeat for drupal6 is not mature enough.

marinex’s picture

@vishun Hi I look at your solution, it nice results, but you have bug in:

            foreach ($wholiked as $wl) {
              $likers = $wl['view'].$wl['comma'];
            }

there should be .= operator so:

            foreach ($wholiked as $wl) {
              $likers .= $wl['view'].$wl['comma'];
            }

For others, good place for this snippet is in the heartbeat-message-row.tpl.php after first:

<br class="clearfix" />

If you enable your custom flag on your template settings page maybe you need to comment this:

          // anonymous isnt allowed to flag, only output for logged in users
          //if ($user->uid!=0) {
          //  print ' <small>&bull;</small> '.flag_create_link('hb_like', $message->uaid);
          //}

otherwise you will be have twice same flag.

And you dont forget print your result:

print '<div class="likers">' . $likers . '</div>';