/[drupal]/contributions/modules/civinode/lowlevel/civinode_groups.inc
ViewVC logotype

Contents of /contributions/modules/civinode/lowlevel/civinode_groups.inc

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


Revision 1.2 - (show annotations) (download) (as text)
Mon May 21 21:46:16 2007 UTC (2 years, 6 months ago) by torenware
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +1 -1 lines
File MIME type: text/x-php
Fix for issue #145538 for robeano
1 <?php
2 /**
3 *
4 * Low-level group access routines. This code is very lightly modified
5 * code taken from the CiviCRM 1.4 tree and is subject to its license
6 * and copyright.
7 *
8 *
9 */
10
11 /**
12 * Clone of CRM_Contact_BAO_GroupContact::getContactGroup
13 *
14 * Difference here is the lack of a permissions check which has been
15 * horking us for the last two weeks...
16 *
17 * function to get the list of groups for contact based on status of membership
18 *
19 * @param int $contactId contact id
20 * @param string $status state of membership
21 * @param int $numGroupContact number of groups for a contact that should be shown
22 * @param boolean $count true if we are interested only in the count
23 *
24 * @return array (reference )|int $values the relevant data object values for the contact or
25 the total count when $count is true
26 *
27 * $access public
28 */
29 function CiviNode_LL_getContactGroup( $contactId, $status = null,
30 $numGroupContact = null, $count = false ) {
31 civicrm_initialize(TRUE);
32 require_once 'CRM/Contact/DAO/GroupContact.php';
33
34 if ( $count ) {
35 $select = 'SELECT count(DISTINCT civicrm_group_contact.id)';
36 } else {
37 $select = 'SELECT
38 civicrm_group_contact.id as civicrm_group_contact_id,
39 civicrm_group.title as group_title,
40 civicrm_group.visibility as visibility,
41 civicrm_group_contact.status as status,
42 civicrm_group.id as group_id,
43 civicrm_subscription_history.date as date,
44 civicrm_subscription_history.method as method';
45 }
46
47 $where = ' WHERE civicrm_group_contact.contact_id = '
48 . CRM_Utils_Type::escape($contactId, 'Integer')
49 ." AND civicrm_group.is_active = '1' ";
50
51 if ( ! empty( $status ) ) {
52 $where .= ' AND civicrm_group_contact.status = "'
53 . CRM_Utils_Type::escape($status, 'String') . '"';
54 }
55 $tables = array( 'civicrm_group_contact' => 1,
56 'civicrm_group' => 1,
57 'civicrm_subscription_history' => 1 );
58 $whereTables = array( );
59 //$permission = CRM_Core_Permission::whereClause( CRM_Core_Permission::VIEW, $tables, $whereTables );
60 //$where .= " AND $permission ";
61
62 $from = CRM_Contact_BAO_Query::fromClause( $tables );
63
64 $order = $limit = '';
65 if (! $count ) {
66 $order = ' ORDER BY civicrm_group.title ';
67
68 if ( $numGroupContact ) {
69 $limit = " LIMIT 0, $numGroupContact";
70 }
71 }
72
73 $sql = $select . $from . $where . $order . $limit;
74
75 if ( $count ) {
76 return CRM_Core_DAO::singleValueQuery( $sql );
77 } else {
78 $groupContact =& new CRM_Contact_DAO_GroupContact( );
79 $groupContact->query($sql);
80 $values = array( );
81 while ( $groupContact->fetch() ) {
82 $id = $groupContact->civicrm_group_contact_id;
83 $values[$id]['id'] = $id;
84 $values[$id]['group_id'] = $groupContact->group_id;
85 $values[$id]['title'] = $groupContact->group_title;
86 $values[$id]['visibility'] = $groupContact->visibility;
87 switch($groupContact->status) {
88 case 'Added':
89 $prefix = 'in_';
90 break;
91 case 'Removed':
92 $prefix = 'out_';
93 break;
94 default:
95 $prefix = 'pending_';
96 }
97 $values[$id][$prefix . 'date'] = $groupContact->date;
98 $values[$id][$prefix . 'method'] = $groupContact->method;
99 }
100 return $values;
101 }
102 }
103
104 ?>

  ViewVC Help
Powered by ViewVC 1.1.2