Exclude Groups From JSON API endpoing from LW

Hello,

Is there a way to add an exclude some groups from Groups JSON API feed from LW? Like this feed:

https://events.iu.edu/live/json/groups/

Can we add exclude_group parameter to it with one or multiple groups to exclude? I tried this but it does not seem to work:

https://events.iu.edu/live/json/groups/exclude_group/Test

Thanks,

Akbar

Hi Akbar,

We haven’t yet had a request to extend exclude_groups to the groups widget and endpoint, but I’ll file that suggestion for the roadmap.

In the meantime, you can do this – a little inelegantly , but it works – using filter to exclude groups by ID.

For instance, here’s your same endpoint but excluding groups 526 and 318.

https://events.iu.edu/live/json/groups/filter/id|not_equals|526/filter/id|not_equals|318

Hope this helps!
Karl

Thanks Karl. That was helpful.

Additionally, is there a way for us to obtains a list of all tags for all groups using one feed URL?

Thanks,

Akbar

Glad that helped!

Not currently in core—but, a number of schools use versions of a custom taxonomy client module that adds additional /live endpoints, one of which I think is for /live/taxonomy/tags. That could be extended to cover any selection of tags (all groups, global only, etc) pretty straightforwardly I’d imagine.

Any example I could see?

I also do not see a taxonomy module in client/module in my Events Calendar.

Hi Akbar,

I think your news site LiveWhale installation is using the taxonomy module, and the same code should work similarly for LiveWhale Calendar, as a starting point.

Karl

I assume news_tags will probably become events_tags? Or is it something else?

I set up taxonomy for events.

https://events.iu.edu/live/taxonomy/tags

I gives me only global tag. Although there is code for all tags there as well.

Thanks Akbar – I’m not able to SFTP into servers from here in the forum to get hands-on, but if you want to share sample code we can offer advice in the forum. In this case, you may rename news_tags to events_tags, sure. And if there’s gid IS NULL logic currently querying for global tags, that could be removed to pull all tags.

<?php

if (!empty($LIVE_URL['REQUEST'])) { // if valid request
	require $LIVE_URL['DIR'].'/livewhale.php'; // load LiveWhale
	$request=array_shift($LIVE_URL['REQUEST']); // get command name
	switch($request) {
		case 'tags':
			$gid=array_shift($LIVE_URL['REQUEST']); // get secondary group id
			if (!empty($gid)) {
				// Starred Tags in a specific group id
				$key='events_tags_'.$gid;
				$tags = $_LW->getVariable($key);
				if (empty($tags)) { // if tags not cached
					$tags=[];
					foreach($_LW->dbo->query('select', 'livewhale_tags.id,livewhale_tags.title', 'livewhale_tags', 'livewhale_tags.is_starred IS NOT NULL AND livewhale_tags.gid='.(int)$gid, 'livewhale_tags.title ASC')
					->groupBy('livewhale_tags.id')->run() as $res2) { // fetch tags
						$tags[]=[
							'id'=>$res2['id'],
							'title'=>trim($res2['title'])
						];
					};
					$_LW->setVariable($key, $tags, 300); // cache for 5min
				};
				echo json_encode($tags);
			} else {
				// Starred Tags in Newsroom group
				$key='events_tags';
				$tags = $_LW->getVariable($key);
				if (empty($tags)) { // if tags not cached
					$tags=[];
					foreach($_LW->dbo->query('select', 'livewhale_tags.id,livewhale_tags.title', 'livewhale_tags', 'livewhale_tags.is_starred IS NOT NULL AND livewhale_tags.gid=2', 'livewhale_tags.title ASC')
					->groupBy('livewhale_tags.id')->run() as $res2) { // fetch tags
						$tags[]=[
							'id'=>$res2['id'],
							'title'=>trim($res2['title'])
						];
					};
					$_LW->setVariable($key, $tags, 300); // cache for 5min
				};
				echo json_encode($tags);
			}
		break;

		case 'all_tags':
			// All Tags
			$key='events_all_tags';
			$tags = $_LW->getVariable($key);
			if (empty($tags)) { // if tags not cached
				$tags=[];
				foreach($_LW->dbo->query('select', 'livewhale_tags.id,livewhale_tags.title', 'livewhale_tags', '', 'livewhale_tags.title ASC')
				->groupBy('livewhale_tags.id')->run() as $res2) { // fetch tags
					$tags[]=[
						'id'=>$res2['id'],
						'title'=>trim($res2['title'])
					];
				};
				$_LW->setVariable($key, $tags, 300); // cache for 5min
			};
			echo json_encode($tags);
		break;

		case 'categories':
			// Starred Event Types
			
			$key='events_categories';
			$events_categories = $_LW->getVariable($key);
			if (empty($events_categories)) { // if events_categories not cached
				$events_categories=[];
				foreach($_LW->dbo->query('select', 'livewhale_events_categories.id,livewhale_events_categories.title', 'livewhale_events_categories', '', 'livewhale_events_categories.title ASC')
					->groupBy('livewhale_events_categories.title')->run() as $res2) { // fetch categories
					$events_categories[]=[
						'id'=>$res2['id'],
						'title'=>trim($res2['title'])
					];
				};
				$_LW->setVariable($key, $events_categories, 300); // cache for 5min
			};
			echo json_encode($events_categories);
		break;


		case 'audiences':	
			$key='audiences';
			$audiences = $_LW->getVariable($key);
			if (empty($audiences)) { // if audiences not cached
				$audiences=[];
				
				foreach($_LW->CONFIG['CUSTOM_FIELDS']['global'] as $custom_field) {
					if ($custom_field['name'] == 'audience') {
						$audiences = $custom_field['options'];
						break;
					}
				}
				$_LW->setVariable($key, $audiences, 300); // cache for 5min
			};
			echo json_encode($audiences);
		break;

		case 'campuses':	
			$key='campuses';
			$campuses = $_LW->getVariable($key);
			if (empty($campuses)) { // if campuses not cached
				$campuses=[];
				
				foreach($_LW->CONFIG['CUSTOM_FIELDS']['global'] as $custom_field) {
					if ($custom_field['name'] == 'iu_campus') {
						$campuses = $custom_field['options'];
						break;
					}
				}
				$_LW->setVariable($key, $campuses, 300); // cache for 5min
			};
			echo json_encode($campuses);
		break;

		//IU Addition - Added an API end point for Tags to include Group ID the tags belong to
		case 'group_tags':
			// Group Starred Tags

			$gid = isset($_GET['gid']) ? $_GET['gid'] : null;
			$starred = isset($_GET['starred']);

			$key="taxonomy_group_tags+$gid";
			$tags = $_LW->getVariable($key);			
			if (empty($tags)) { // if tags not cached

				$tags=[];
				
				$where = [];
				if($starred) $where[] = 'livewhale_tags.is_starred IS NOT NULL';
				if($gid) $where[] = "livewhale_tags.gid =$gid";
				$where = count($where) ? implode(' AND ', $where) : 1;
				
				foreach($_LW->dbo->query('select', 'livewhale_tags.id,livewhale_tags.gid,livewhale_tags.title', 'livewhale_tags', $where, 'livewhale_tags.title ASC')
				->groupBy('livewhale_tags.id')->run() as $res2) { // fetch tags
					$tags[]=[
						'id'=>$res2['id'],
						'gid'=>$res2['gid'],
						'name'=>trim($res2['title'])
					];
				};
				$_LW->setVariable($key, $tags, 300); // cache for 5min
			};
			echo json_encode($tags);
		break;

	};
};
exit;

?>

Ah I see - The case: 'foo': section is different results for each block of code by that url.

So, looks like it’s expecting /tags/{gid} for a group tags, and empty to get global tags.

A bit farther down, looks like all_tags is gonna return every tag (e.g., /live/taxonomy/all_tags).

But it is not doing that:

https://events.iu.edu/live/taxonomy/tags/90

90 being the group ID for Biology.

And all_tags returns nothing.

Sorry to hear it’s giving you trouble—the code as you pasted it works on my install (/live/taxonomy/all_tags shows all tags).

One other thing to notice, the first block for /tags/{gid} is commented with // Starred Tags in a specific group id – if you wanted all tags instead of only starred tags, you’d want to remove the livewhale_tags.is_starred IS NOT NULL AND from the query string.

Hope this helps! If you’d like hands-on help getting this to work for your specific use case or installation, feel free to reach out via Personalized Email Support or use the Request Help Form.

No worries. We can live without it.

Not sure what the difference would be between your environment and ours since it the exact same script as written by LW with the exception of news being replaced by events.

Thanks.

Yes, that is odd! I actually tested it on my own LWC server, so it was also running on events. It could be an issue with the filename (mine is /client/modules/taxonomy/live/taxonomy.php), or something else interfering.

Are you saying that you used the exact same script I posted here and it runs in your environment? My file path is the same as yours.

That’s right, I copied it to that file path on my install and it worked (I did have to log out then log in, sometimes that’s necessary for LW to “discover” new client/ scripts). Let us know if you’d like more assistance—happy to get in there to see what’s up with you via Personalized Email Support or the Request Help Form.

Thanks Karl. We would save our Support hours for better things.

Akbar