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 Profiles (Moderator: Dave Greenberg) »
  • Show users in a group
Pages: [1]

Author Topic: Show users in a group  (Read 727 times)

johns

  • I’m new here
  • *
  • Posts: 20
  • Karma: 1
    • Free Software Foundation
  • CiviCRM version: 4.3
  • CMS version: Drupal
Show users in a group
June 15, 2010, 01:17:18 pm
I'm making essentially a petition, using a profile by which an anonymous user can submit her first and last name and email address, and be added to a mailing group, in order to sign the petition.

I would then like to provide a link which says "See other people who have signed the petition". I would like this to show the first and last name of everyone who has signed, and a count of how many people there are -- so, everyone in that mailing group.

What's the best way to do this? I created a search results profile, but that doesn't seem to show the number of people (at least not with only 4 results/members).

Using CiviCRM 3.0.3, will upgrade soon. On Drupal. But I would prefer to actually display the results on our Plone site, so I was hoping to be able to embed the HTML for the form.

Any ideas?
Support free software by supporting the Free Software Foundation: http://u.fsf.org/buildusup

vanalive

  • I post occasionally
  • **
  • Posts: 35
  • Karma: 1
Re: Show users in a group
July 27, 2010, 12:43:40 pm
This is t show a rotating block of signers:


<a href="../petition"><script type="text/javascript">

/***********************************************
* Fading Scroller- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var delay = 2000; //set delay between message change (in miliseconds)
var maxsteps=30; // number of steps to take to change from start color to endcolor
var stepdelay=40; // time in miliseconds of a single step
//**Note: maxsteps*stepdelay will be total time in miliseconds of fading effect
var startcolor= new Array(255,255,255); // start color (red, green, blue)
var endcolor=new Array(0,0,0); // end color (red, green, blue)

var fcontent=new Array();
begintag='<div style="font: normal 14px Arial; padding: 5px;">'; //set opening tag, such as font declarations
<?php
global $user;
civicrm_initialize(true);
require_once 'CRM/Core/Config.php';
require_once 'CRM/Core/Error.php';
$config = CRM_Core_Config::singleton( );
require_once 'api/v2/Contact.php';
require_once 'api/v2/Group.php';
require_once 'api/v2/GroupContact.php';
$myGroup = 'petition';
$rowCount = 20;
$itemnumber = 0;

$results = getGroupMembers( $myGroup );

if ($results) {
    foreach ($results as $myContact) {
        $string =
            'fcontent[' . $itemnumber . '] = "' . $myContact['first_name'] . ' ' . $myContact['last_name'] . ': ' .
            $myContact['city'] . ', ' . $myContact['state_province'];
        $itemnumber = $itemnumber + 1;
        echo $string . '";';
    }
} else {
    echo 'No group found with that name.';
}

function getGroupMembers( $group_title ) {
    // Check if CiviCRM is installed here.
    if (!module_exists('civicrm')) return false;

    // Initialization call is required to use CiviCRM APIs.
    civicrm_initialize( );

    // Pass group 'title' to civicrm_groups_get to retrieve the group_id.
    $groupGet = array( 'title' => $group_title );
    $groups   =& civicrm_group_get( $groupGet );
    $groupID  = array_keys($groups);
    // Pass 'group' => group.id into search API to find members of that group
    // Only one group with that title, so we can reference
    // first result in returned array from get_groups.
    // Also pass on the required return properties and sort by criteria in params
    $params = array(
                    'group'            => array($groupID[0] => 1 ),
                    'return.first_name' => 1,
                    'return.last_name'     => 1,
                    'return.city'     => 1,
                    'return.state_province'     => 1,
                    'sort'             => 'contact_id DESC',
                'rowCount'            => $rowCount


                    );

    $contacts =& civicrm_contact_search( $params );
    if (!$contacts) return false;
    return $contacts;
}

?>

closetag='</div>';

var fwidth='200px'; //set scroller width
var fheight='40px'; //set scroller height

var fadelinks=1;  //should links inside scroller content also fade like text? 0 for no, 1 for yes.

///No need to edit below this line/////////////////


var ie4=document.all&&!document.getElementById;
var DOM2=document.getElementById;
var faderdelay=0;
var index=0;


/*Rafael Raposo edited function*/
//function to change content
function changecontent(){
  if (index>=fcontent.length)
    index=0
  if (DOM2){
    document.getElementById("fscroller").style.color="rgb("+startcolor[0]+", "+startcolor[1]+", "+startcolor[2]+")"
    document.getElementById("fscroller").innerHTML=begintag+fcontent[index]+closetag
    if (fadelinks)
      linkcolorchange(1);
    colorfade(1, 15);
  }
  else if (ie4)
    document.all.fscroller.innerHTML=begintag+fcontent[index]+closetag;
  index++
}

// colorfade() partially by Marcio Galli for Netscape Communications.  ////////////
// Modified by Dynamicdrive.com

function linkcolorchange(step){
  var obj=document.getElementById("fscroller").getElementsByTagName("A");
  if (obj.length>0){
    for (i=0;i<obj.length;i++)
      obj.style.color=getstepcolor(step);
  }
}

/*Rafael Raposo edited function*/
var fadecounter;
function colorfade(step) {
  if(step<=maxsteps) {   
    document.getElementById("fscroller").style.color=getstepcolor(step);
    if (fadelinks)
      linkcolorchange(step);
    step++;
    fadecounter=setTimeout("colorfade("+step+")",stepdelay);
  }else{
    clearTimeout(fadecounter);
    document.getElementById("fscroller").style.color="rgb("+endcolor[0]+", "+endcolor[1]+", "+endcolor[2]+")";
    setTimeout("changecontent()", delay);
   
  }   
}

/*Rafael Raposo's new function*/
function getstepcolor(step) {
  var diff
  var newcolor=new Array(3);
  for(var i=0;i<3;i++) {
    diff = (startcolor-endcolor);
    if(diff > 0) {
      newcolor = startcolor-(Math.round((diff/maxsteps))*step);
    } else {
      newcolor = startcolor+(Math.round((Math.abs(diff)/maxsteps))*step);
    }
  }
  return ("rgb(" + newcolor[0] + ", " + newcolor[1] + ", " + newcolor[2] + ")");
}

if (ie4||DOM2)
  document.write('<div id="fscroller" style="border:1px solid black;width:'+fwidth+';height:'+fheight+'"></div>');

if (window.addEventListener)
window.addEventListener("load", changecontent, false)
else if (window.attachEvent)
window.attachEvent("onload", changecontent)
else if (document.getElementById)
window.onload=changecontent

</script>
..Add your name
</a>

vanalive

  • I post occasionally
  • **
  • Posts: 35
  • Karma: 1
Re: Show users in a group
July 27, 2010, 12:45:58 pm
This is to list anyone in the group.  (You'll need to replace the group with your own group name)

<?php
global $user;
civicrm_initialize(true);
require_once 'CRM/Core/Config.php';
require_once 'CRM/Core/Error.php';
$config = CRM_Core_Config::singleton( );
require_once 'api/v2/Contact.php';
require_once 'api/v2/Group.php';
require_once 'api/v2/GroupContact.php';
$myGroup = 'petition';
$rowCount = 200;


$results = getGroupMembers( $myGroup );

if ($results) {
    foreach ($results as $myContact) {
        $string =
            $myContact['first_name'] . ' ' . $myContact['last_name'] . ': ' .
            $myContact['city'] . ', ' . $myContact['state_province'];
        echo $string . '<br />';
    }
} else {
    echo 'No group found with that name.';
}

function getGroupMembers( $group_title ) {
    // Check if CiviCRM is installed here.
    if (!module_exists('civicrm')) return false;

    // Initialization call is required to use CiviCRM APIs.
    civicrm_initialize( );

    // Pass group 'title' to civicrm_groups_get to retrieve the group_id.
    $groupGet = array( 'title' => $group_title );
    $groups   =& civicrm_group_get( $groupGet );
    $groupID  = array_keys($groups);
    // Pass 'group' => group.id into search API to find members of that group
    // Only one group with that title, so we can reference
    // first result in returned array from get_groups.
    // Also pass on the required return properties and sort by criteria in params
    $params = array(
                    'group'            => array($groupID[0] => 1 ),
                    'return.first_name' => 1,
                    'return.last_name'     => 1,
                    'return.city'     => 1,
                    'return.state_province'     => 1,
                    'sort'             => 'contact_id DESC',
                'rowCount'            => $rowCount


                    );

    $contacts =& civicrm_contact_search( $params );
    if (!$contacts) return false;
    return $contacts;
}

?>


Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Profiles (Moderator: Dave Greenberg) »
  • Show users in a group

This forum was archived on 2017-11-26.