/[drupal]/contributions/modules/flag/includes/flag.activity.inc
ViewVC logotype

Diff of /contributions/modules/flag/includes/flag.activity.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1, Mon Nov 2 06:17:02 2009 UTC revision 1.1.2.1, Mon Nov 2 06:17:02 2009 UTC
# Line 0  Line 1 
1    <?php
2    // $Id$
3    
4    /**
5     * @file
6     * Provides Flag integration with Activity2.
7     * @see http://drupal.org/project/activity
8     */
9    
10    /**
11     * Implementation of hook_activity_grants().
12     */
13    function flag_activity_grants($activity) {
14      $flags = flag_get_flags();
15      $realms = array();
16      // Assign all those flags for nodes.
17      foreach ($flags as $fid => $flag) {
18        // This will also work for comments as those activity records have nids.
19        if ($activity->nid && $flag->content_type == 'node') {
20          $realms['flag_' . $flag->fid] = array($activity->nid);
21        }
22        elseif ($flag->content_type == 'user') {
23          $realms['flag_' . $flag->fid] = array($activity->uid);
24        }
25      }
26      return $realms;
27    }
28    
29    /**
30     * Implementation of hook_activity_access_grants().
31     */
32    function flag_activity_access_grants($account) {
33      // Get all the user and node flags.
34      $user_flags = flag_get_user_flags('user', NULL, $account->uid);
35      $node_flags = flag_get_user_flags('node', NULL, $account->uid);
36    
37      $flag_grants = array();
38      if (!empty($node_flags)) {
39        foreach ($node_flags as $flagged_objects) {
40          foreach ($flagged_objects as $nid => $flagged) {
41            // Tell activity to grant user $account access to those flagged with
42            // $fid that are $nid.
43            $flag_grants['flag_' . $flagged->fid][] = $nid;
44          }
45        }
46      }
47    
48      if (!empty($user_flags)) {
49        foreach ($user_flags as $flagged_objects) {
50          foreach ($flagged_objects as $uid => $flagged) {
51            // Tell Activity to grant user $account access to those flagged with
52            // $fid that are $uid.
53            $flag_grants['flag_' . $flagged->fid][] = $uid;
54          }
55        }
56      }
57    
58      return $flag_grants;
59    }
60    
61    /**
62     * Implementation of hook_activity_type_check().
63     */
64    function flag_activity_type_check($token_objects, $types) {
65      return (in_array($token_objects['flag']->fid, $types));
66    }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.1.2.1

  ViewVC Help
Powered by ViewVC 1.1.2