Forums

Group Location

In the option group fields there is a field called location. It looks like it can be set/updated through the API, but doesn't necessarily have initial data. Is there a way to set the location field without having to use the API? I just want to pull the location using the API. 

Hi Steve,


The Location field is only used if you have locations set under Settings > Locations. You can set this for the group under it's Edit tab once the locations are set up. Locations are primarily used for Multi-campus churches. 


If you're just wanting the address of the group you want to use the meeting_address/city/state/postcode/country fields.


Hope this helps,

Stewart

Thank you. Should I be able to pull that as well from groups/getAll?

These fields should indeed come using getInfo or getAll by default


Stewart

Here's what I'm using. The 'location's field isn't populating even though their is data in the field. All the other fields are appearing.

<?php
require_once('Elvanto_API.php');
 
$auth_details = array('api_key' => 'xxx');
$elvanto = new Elvanto_API($auth_details);
 
$results = $elvanto->call('groups/getAll', $params=array("suspended" => "no"));
$new_results = $results->groups->group;
?>

<?php foreach ($new_results as $result):?>
<div class="views-group-wrapper"><a href="../paseo/paseo-home?id=<?php echo $result->id?>">
	<div class="views-group-text-wrapper">
		<div class="views-group-title-wrapper"><?php echo $result->name;?></div>
		<div class="views-group-category-wrapper"><i class="fa fa-clock-o views-category-wrapper" aria-hidden="true"></i>  <?php echo $result->meeting_day;?> | <?php echo $result->meeting_time;?></div>
		<div class="views-group-category-wrapper"><i class="fa fa-map-marker views-category-wrapper" aria-hidden="true"></i>  <?php echo $result->locations;?></div> 
		<div class="views-group-overview-wrapper"><?php echo $result->meeting_address;?></div>
	</div>
	<div class="views-group-link-wrapper">view</div>
	</a>
</div>
<?php endforeach; ?>

 

The location field isn't a a text field. Instead it can look like this, if the group has 3 locations. 

"locations": {
	"location": [
	{
		"id": "ID_1", 
		"name": "Nashville Campus"
	}, 
	{
		"id": "ID_2", 
		"name": "North"
	}, 
	{
		"id": "ID_3", 
		"name": "South"
	}
	]
},

You'll likely want to perform a foreach inside the location field to echo each location name individually. 

Thank you. What should the foreach look like? I've tried several iterations and nothing has worked. 

Hi Steve,


Even better than a foreach loop. You can do the following.


Change your div for the locations to the following:

<div class="views-group-category-wrapper"><i class="fa fa-map-marker views-category-wrapper" aria-hidden="true"></i>  <?php 
    $locations = array_map(function($obj) { return $obj["name"]; }, $result->locations->location);
    echo implode($locations, ", ");
?></div> 

 It does make the code a bit... uglier... but it should work :)

Ugly is fine with me. I updated the code as shown above and it's still working.  Now I'm getting a response of NULL which I didn't get before. 

Can you post a var_dump in at the start of your for_each loop, so that the first thing it does is var_dump $result? (Remove any private information of course)


I'll check that out.

Here you go. 


object(stdClass)#834 (13) {
["id"]=>
string(36) "16ba55e5-f2bb-11e5-a9d9-06e39d13679f"
["date_added"]=>
string(19) "2016-03-25 18:55:05"
["date_modified"]=>
string(19) "2016-06-07 22:53:23"
["name"]=>
string(19) "Women's Group - 50+"
["status"]=>
string(6) "Active"
["meeting_address"]=>
string(138) ""
["meeting_city"]=>
string(22) ""
["meeting_state"]=>
string(0) ""
["meeting_postcode"]=>
string(0) ""
["meeting_country"]=>
string(0) ""
["meeting_day"]=>
string(9) "Wednesday"
["meeting_time"]=>
string(7) "5:30 PM"
["meeting_frequency"]=>
string(11) "Every Month"
}

Ahh, I see the issue now. Should have seen it earlier!


The API Call you're sending isn't asking to send the location information back. In your $params add "fields" => array("locations")


By default the groups/getAll doesn't return the "locations" field.


Is this what you mean?

 

$results = $elvanto->call('groups/getAll', $params=array("suspended" => "no","fields"=>array("locations")))

 

That should do it :)

Unfortunately, it's still not working. Here's the code in it's entirety again just in case I flubbed something.


 

<?php
require_once('Elvanto_API.php');
 
$auth_details = array('api_key' => 'xxx');
$elvanto = new Elvanto_API($auth_details);
 
$results = $elvanto->call('groups/getAll', $params=array("suspended" => "no","fields" => array("locations")));
$new_results = $results->groups->group;
?>

<?php foreach ($new_results as $result):?>
<div class="views-group-wrapper"><a href="../paseo/paseo-home?id=<?php echo $result->id?>&fields[0]=locations">
	<div class="views-group-text-wrapper">
		<div class="views-group-title-wrapper"><?php echo $result->name;?></div>
		<div class="views-group-category-wrapper"><i class="fa fa-clock-o views-category-wrapper" aria-hidden="true"></i>  <?php echo $result->meeting_day;?> | <?php echo $result->meeting_time;?></div>
		<div class="views-group-category-wrapper"><i class="fa fa-map-marker views-category-wrapper" aria-hidden="true"></i>
		<?php 
        $locations = array_map(function($obj) { return $obj["name"]; }, $result->locations->location);
        echo implode(',',$locations);
echo $locations;
         ?>
		</div> 
		<div class="views-group-overview-wrapper"><?php echo $result->meeting_address;?></div>
	</div>
	<div class="views-group-link-wrapper">view</div>
	</a>
</div>
<?php endforeach; ?>

 


Login or Signup to post a comment