CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Allowing users to only see groups they created
Pages: [1]

Author Topic: Allowing users to only see groups they created  (Read 474 times)

bpmccain

  • I post frequently
  • ***
  • Posts: 255
  • Karma: 5
  • CiviCRM version: 4.1
  • CMS version: Drupal 7.12
  • MySQL version: 5.2
  • PHP version: 5.2
Allowing users to only see groups they created
November 06, 2012, 05:57:22 pm
I've got a lot of different users on our database, and it would be great if they could create their own smart groups, which they could save, but only they could view them. The reason is that things like CiviMail could become REALLY messy with several hundred groups viewable by everyone, as opposed to just the four or five that they might have created.

Anyone done this before?

bpmccain

  • I post frequently
  • ***
  • Posts: 255
  • Karma: 5
  • CiviCRM version: 4.1
  • CMS version: Drupal 7.12
  • MySQL version: 5.2
  • PHP version: 5.2
Re: Allowing users to only see groups they created
November 08, 2012, 04:47:37 pm
Figured this out using hook_civicrm_aclGroup.

I use the source field to store the id number of the user that created the group. I then change the $currentGroups to be an array of all the group ids that have a source equal to the id of the $contactID accessing the hook.

Brian

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Allowing users to only see groups they created
November 08, 2012, 05:12:38 pm
oh most excellent :) very smart idea indeed

any ideas on what happens when admin(s) leave the org? for now a manual update will work

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

bpmccain

  • I post frequently
  • ***
  • Posts: 255
  • Karma: 5
  • CiviCRM version: 4.1
  • CMS version: Drupal 7.12
  • MySQL version: 5.2
  • PHP version: 5.2
Re: Allowing users to only see groups they created
November 08, 2012, 05:19:12 pm
I'm playing around with a couple of ideas.

Right now, we have a standalone admin account that isn't tied to a specific person - so that account would be passed along.

I am also planning on entering 0 into the Source field for any groups that are to be visible by all users.

bpmccain

  • I post frequently
  • ***
  • Posts: 255
  • Karma: 5
  • CiviCRM version: 4.1
  • CMS version: Drupal 7.12
  • MySQL version: 5.2
  • PHP version: 5.2
Re: Allowing users to only see groups they created
November 08, 2012, 06:25:34 pm
For completeness here is the code I am using:

Code: [Select]
function hooks_civicrm_post( $op, $objectName, $objectId, &$objectRef ) {
 
        require_once 'civicrm.config.php';
require_once 'CRM/Core/Config.php';

        if ( ($op == 'create') && ($objectName == 'Group')) {
global $user;
$results=civicrm_api("UFMatch","get", array (version => '3','sequential' =>'1', 'uf_id' =>$user->uid));
$creatorID = $results['id'];
$results=civicrm_api("Group","update", array (version => '3','sequential' =>'1', 'id' =>$objectId, 'source' => $creatorID));
}
}

function hooks_civicrm_aclGroup( $type, $contactID, $tableName, &$allGroups, &$currentGroups ) {
require_once 'civicrm.config.php';
require_once 'CRM/Core/Config.php';
    $results=civicrm_api("Group","get", array ('version' => '3','sequential' =>'1', 'source' =>$contactID));
$currentGroups = array();
foreach($results['values'] as $key => $values) {
$currentGroups[] = $values['id'];
}
$results=civicrm_api("Group","get", array ('version' => '3','sequential' =>'1', 'source' =>'0'));
foreach($results['values'] as $key => $values) {
$currentGroups[] = $values['id'];
}
}



Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • Allowing users to only see groups they created

This forum was archived on 2017-11-26.