From b76b82e1cb7c1198f26c1aab54579137b9fb3238 Mon Sep 17 00:00:00 2001
From: Matthew Juhl <mjuhl24@gmail.com>
Date: Wed, 19 May 2010 19:55:32 +0000
Subject: [PATCH] Add user to college group automatically on profile update.

---
 plugins/unl_theme/start.php | 46 +++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/plugins/unl_theme/start.php b/plugins/unl_theme/start.php
index 4f45d224..d4f84017 100644
--- a/plugins/unl_theme/start.php
+++ b/plugins/unl_theme/start.php
@@ -16,5 +16,51 @@ function unl_theme_init(){
 register_elgg_event_handler('init','system','unl_theme_init');
 
 
+function unl_profileupdate () {
+	/**
+	 * Enroll user in group for their selected college when possible.
+	 **/
+	
+	$college_groups_guids = array();
+	
+	$college_groups_guids['Engineering'] = 1091;
+	$college_groups_guids['Journalism and Mass Communications']= 6179;
+	$college_groups_guids['Business Administration'] = 905;
+	$college_groups_guids['Arts and Sciences'] = 5358;
+	$college_groups_guids['Hixson-Lied College of Fine and Performing Arts'] = 753;
+	$college_groups_guids['Law'] = 6949;
+	$college_groups_guids['Agricultural Sciences and Natural Resources'] = 6950;
+	$college_groups_guids['Architecture'] = 6951;
+	$college_groups_guids['Education and Human Sciences'] = $college_groups_guids['Human Resources and Family Sciences'] = $college_groups_guids['Teachers College'] = 6952;
+	
+	/* ADD OTHER COLLEGE GROUPS HERE */
+	
+	$data = form_get_profile_data_from_form_post();
+	$college = $data['profile_college']->value;
+	$user_guid = get_input('user_guid', get_loggedin_userid());
+	$user = get_entity($user_guid);
+	
+	if (isset($college_groups_guids[$college])) {
+		$group_guid = $college_groups_guids[$college];
+		$group = get_entity($group_guid);
+		
+		if ($group->join($user))
+			{
+				system_message(elgg_echo("groups:joined"));
+
+				// Remove any invite or join request flags
+				remove_entity_relationship($group->guid, 'invited', $user->guid);
+				remove_entity_relationship($user->guid, 'membership_request', $group->guid);
+
+				// add to river
+				add_to_river('river/group/create','join',$user->guid,$group->guid);
+			}
+	}
+	
+    
+}
+
+register_elgg_event_handler('profileupdate','all','unl_profileupdate');
+
 register_action("login",false,$CONFIG->pluginspath. "unl_theme/actions/login.php"); 
 ?>
\ No newline at end of file
-- 
GitLab