Ver código fonte

Updating classes for new changes see BT#571

Julio Montoya 15 anos atrás
pai
commit
466646a4d2

+ 0 - 1
main/inc/lib/message.lib.php

@@ -10,7 +10,6 @@
 ==============================================================================
 */
 
-
 require_once api_get_path(LIBRARY_PATH).'online.inc.php';
 require_once api_get_path(LIBRARY_PATH).'fileUpload.lib.php';
 require_once api_get_path(LIBRARY_PATH).'fileDisplay.lib.php';

+ 2 - 2
main/inc/lib/online.inc.php

@@ -128,9 +128,9 @@ function LoginDelete($user_id)
 function WhoIsOnline($valid, $friends = false)
 {
 	$valid = (int) $valid;
-	$current_date=date('Y-m-d H:i:s',time());
+	$current_date		= date('Y-m-d H:i:s',time());
 	$track_online_table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ONLINE);
-	$friend_user_table = Database::get_main_table(TABLE_MAIN_USER_FRIEND);
+	$friend_user_table  = Database::get_main_table(TABLE_MAIN_USER_REL_USER);
 	$query = '';
 	if ($friends) {
 		// 	who friends from social network is online	

+ 4 - 92
main/inc/lib/social.lib.php

@@ -10,107 +10,19 @@
 ==============================================================================
 */
 
-// Relation type between users
-define('USERUNKNOW',		0);
-define('SOCIALUNKNOW',		1);
-define('SOCIALPARENT',		2);
-define('SOCIALFRIEND',		3);
-define('SOCIALGOODFRIEND',	4);
-define('SOCIALENEMY',		5);
-define('SOCIALDELETED',		6);
-
 //PLUGIN PLACES
 define('SOCIAL_LEFT_PLUGIN',	1);
 define('SOCIAL_CENTER_PLUGIN',	2);
 define('SOCIAL_RIGHT_PLUGIN',	3);
 
-define('MESSAGE_STATUS_INVITATION_PENDING',	'5');
-define('MESSAGE_STATUS_INVITATION_ACCEPTED','6');
-define('MESSAGE_STATUS_INVITATION_DENIED',	'7');
-
 require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
 require_once api_get_path(LIBRARY_PATH).'message.lib.php';
 
 class SocialManager extends UserManager {
 
 	private function __construct() {
-
-	}
-	
-	/**
-	 * Allow to register contact to social network
-	 * @param int user friend id
-	 * @param int user id
-	 * @param int relation between users see constants definition
-	 */
-	public static function register_friend ($friend_id,$my_user_id,$relation_type) {		
-		$tbl_my_friend = Database :: get_main_table(TABLE_MAIN_USER_FRIEND);
-		
-		$friend_id = intval($friend_id);
-		$my_user_id = intval($my_user_id);
-		$relation_type = intval($relation_type);
-		
-		$sql = 'SELECT COUNT(*) as count FROM ' . $tbl_my_friend . ' WHERE friend_user_id=' .$friend_id.' AND user_id='.$my_user_id;
-		$result = Database::query($sql, __FILE__, __LINE__);
-		$row = Database :: fetch_array($result, 'ASSOC');
-		
-		if ($row['count'] == 0) {
-			$current_date=date('Y-m-d H:i:s');
-			$sql_i = 'INSERT INTO ' . $tbl_my_friend . '(friend_user_id,user_id,relation_type,last_edit)values(' . $friend_id . ','.$my_user_id.','.$relation_type.',"'.$current_date.'");';
-			Database::query($sql_i, __FILE__, __LINE__);
-			return true;
-		} else {
-			$sql = 'SELECT COUNT(*) as count FROM ' . $tbl_my_friend . ' WHERE friend_user_id=' . $friend_id . ' AND user_id='.$my_user_id;
-			$result = Database::query($sql, __FILE__, __LINE__);
-			$row = Database :: fetch_array($result, 'ASSOC');
-			if ($row['count'] == 1) {
-				$sql_i = 'UPDATE ' . $tbl_my_friend . ' SET relation_type='.$relation_type.' WHERE friend_user_id=' . $friend_id.' AND user_id='.$my_user_id;				
-				Database::query($sql_i, __FILE__, __LINE__);
-				return true;
-			} else {
-				return false;
-			}			
-		}
-		
 	}
-
-	/**
-	 * Deletes a contact	  
-	 * @param int user friend id
-	 * @param bool true will delete ALL friends relationship from $friend_id
-	 * @author isaac flores paz <isaac.flores@dokeos.com>
-	 * @author Julio Montoya <gugli100@gmail.com> Cleaning code
-	 */
-	public static function removed_friend ($friend_id, $real_removed = false) {
-		$tbl_my_friend  = Database :: get_main_table(TABLE_MAIN_USER_FRIEND);
-		$tbl_my_message = Database :: get_main_table(TABLE_MAIN_MESSAGE);
-		$friend_id = intval($friend_id);
 		
-		if ($real_removed == true) {			
-			//Delete user friend
-			$sql_delete_relationship1 = 'UPDATE ' . $tbl_my_friend .' SET relation_type='.SOCIALDELETED.' WHERE friend_user_id='.$friend_id;			
-			$sql_delete_relationship2 = 'UPDATE ' . $tbl_my_friend . ' SET relation_type='.SOCIALDELETED.' WHERE user_id=' . $friend_id;
-			Database::query($sql_delete_relationship1, __FILE__, __LINE__);
-			Database::query($sql_delete_relationship2, __FILE__, __LINE__);					
-		} else {
-			$user_id=api_get_user_id();
-			$sql = 'SELECT COUNT(*) as count FROM ' . $tbl_my_friend . ' WHERE user_id=' . $user_id . ' AND relation_type<>6 AND friend_user_id='.$friend_id;
-			$result = Database::query($sql, __FILE__, __LINE__);
-			$row = Database :: fetch_array($result, 'ASSOC');
-			if ($row['count'] == 1) {
-				//Delete user friend
-				$sql_i = 'UPDATE ' . $tbl_my_friend .' SET relation_type='.SOCIALDELETED.' WHERE user_id=' . $user_id.' AND friend_user_id='.$friend_id;
-				$sql_j = 'UPDATE ' . $tbl_my_message.' SET msg_status=7 WHERE user_receiver_id=' . $user_id.' AND user_sender_id='.$friend_id.' AND update_date="0000-00-00 00:00:00" ';
-				//Delete user
-				$sql_ij = 'UPDATE ' . $tbl_my_friend . ' SET relation_type='.SOCIALDELETED.' WHERE user_id=' . $friend_id.' AND friend_user_id='.$user_id;
-				$sql_ji = 'UPDATE ' . $tbl_my_message . ' SET msg_status=7 WHERE user_receiver_id=' . $friend_id.' AND user_sender_id='.$user_id.' AND update_date="0000-00-00 00:00:00" ';
-				Database::query($sql_i, __FILE__, __LINE__);
-				Database::query($sql_j, __FILE__, __LINE__);
-				Database::query($sql_ij, __FILE__, __LINE__);
-				Database::query($sql_ji, __FILE__, __LINE__);
-			}			
-		}
-	}
 	/**
 	 * Allow to see contacts list
 	 * @author isaac flores paz <florespaz@bidsoftperu.com>
@@ -157,7 +69,7 @@ class SocialManager extends UserManager {
 	 */
 	public static function get_relation_between_contacts ($user_id,$user_friend) {
 		$tbl_my_friend_relation_type = Database :: get_main_table(TABLE_MAIN_USER_FRIEND_RELATION_TYPE);
-		$tbl_my_friend = Database :: get_main_table(TABLE_MAIN_USER_FRIEND);
+		$tbl_my_friend = Database :: get_main_table(TABLE_MAIN_USER_REL_USER);
 		$sql= 'SELECT rt.id as id FROM '.$tbl_my_friend_relation_type.' rt ' .
 			  'WHERE rt.id=(SELECT uf.relation_type FROM '.$tbl_my_friend.' uf WHERE  user_id='.((int)$user_id).' AND friend_user_id='.((int)$user_friend).')';
 		$res=Database::query($sql,__FILE__,__LINE__);
@@ -165,7 +77,7 @@ class SocialManager extends UserManager {
 		if (Database::num_rows($res)>0) {
 			return $row['id'];
 		} else {
-			return USERUNKNOW;
+			return USER_UNKNOW;
 		}
 	}
 	
@@ -181,7 +93,7 @@ class SocialManager extends UserManager {
 	 */
 	public static function get_friends($user_id, $id_group=null, $search_name=null, $load_extra_info = true) {
 		$list_ids_friends=array();
-		$tbl_my_friend = Database :: get_main_table(TABLE_MAIN_USER_FRIEND);
+		$tbl_my_friend = Database :: get_main_table(TABLE_MAIN_USER_REL_USER);
 		$tbl_my_user = Database :: get_main_table(TABLE_MAIN_USER);
 		$sql='SELECT friend_user_id FROM '.$tbl_my_friend.' WHERE relation_type<>6 AND friend_user_id<>'.((int)$user_id).' AND user_id='.((int)$user_id);
 		if (isset($id_group) && $id_group>0) {
@@ -372,7 +284,7 @@ class SocialManager extends UserManager {
 	 * @return void()
 	 */
 	public static function qualify_friend ($id_friend_qualify,$type_qualify) {
-		$tbl_user_friend=Database::get_main_table(TABLE_MAIN_USER_FRIEND);
+		$tbl_user_friend=Database::get_main_table(TABLE_MAIN_USER_REL_USER);
 		$user_id=api_get_user_id();
 		$sql='UPDATE '.$tbl_user_friend.' SET relation_type='.((int)$type_qualify).' WHERE user_id='.((int)$user_id).' AND friend_user_id='.((int)$id_friend_qualify).';';
 		Database::query($sql,__FILE__,__LINE__);

+ 103 - 2
main/inc/lib/usermanager.lib.php

@@ -23,13 +23,24 @@ define('USER_FIELD_TYPE_DIVIDER', 9);
 define('USER_FIELD_TYPE_TAG', 10); 
 
 //User image sizes
-
 define('USER_IMAGE_SIZE_ORIGINAL',	1);
 define('USER_IMAGE_SIZE_BIG', 		2);
 define('USER_IMAGE_SIZE_MEDIUM', 	3);
 define('USER_IMAGE_SIZE_SMALL', 	4);
 
 
+// Relation type between users
+define('USER_UNKNOW',					0);
+define('USER_RELATION_TYPE_UNKNOW',		1);
+define('USER_RELATION_TYPE_PARENT',		2); // should be deprecated is useless
+define('USER_RELATION_TYPE_FRIEND',		3);
+define('USER_RELATION_TYPE_GOODFRIEND',	4); // should be deprecated is useless
+define('USER_RELATION_TYPE_ENEMY',		5); // should be deprecated is useless
+define('USER_RELATION_TYPE_DELETED',	6);
+define('USER_RELATION_TYPE_RRHH',		7);
+
+
+
 class UserManager 
 {
 	private function __construct () {
@@ -263,7 +274,7 @@ class UserManager
 			//Delete user from groups
 			
 			//Delete from user friend lists 
-			SocialManager::removed_friend($user_id,true);
+			SocialManager::remove_user_rel_user($user_id,true);
 		}
 		// add event to system log
 		$time = time();
@@ -2859,4 +2870,94 @@ class UserManager
 		}
 		return $course_list;
 	}
+	
+	/**
+	 * Allow to register contact to social network
+	 * @param int user friend id
+	 * @param int user id
+	 * @param int relation between users see constants definition
+	 */
+	public static function relate_users ($friend_id,$my_user_id,$relation_type) {
+		$tbl_my_friend = Database :: get_main_table(TABLE_MAIN_USER_REL_USER);
+		
+		$friend_id = intval($friend_id);
+		$my_user_id = intval($my_user_id);
+		$relation_type = intval($relation_type);
+		
+		$sql = 'SELECT COUNT(*) as count FROM ' . $tbl_my_friend . ' WHERE friend_user_id=' .$friend_id.' AND user_id='.$my_user_id;
+		$result = Database::query($sql, __FILE__, __LINE__);
+		$row = Database :: fetch_array($result, 'ASSOC');
+		$current_date=date('Y-m-d H:i:s');
+		
+		if ($row['count'] == 0) {			
+			$sql_i = 'INSERT INTO ' . $tbl_my_friend . '(friend_user_id,user_id,relation_type,last_edit)values(' . $friend_id . ','.$my_user_id.','.$relation_type.',"'.$current_date.'");';
+			Database::query($sql_i, __FILE__, __LINE__);
+			return true;
+		} else {
+			$sql = 'SELECT COUNT(*) as count, relation_type  FROM ' . $tbl_my_friend . ' WHERE friend_user_id=' . $friend_id . ' AND user_id='.$my_user_id;
+			$result = Database::query($sql, __FILE__, __LINE__);
+			$row = Database :: fetch_array($result, 'ASSOC');
+			if ($row['count'] == 1) {
+				//only for the case of a RRHH
+				if ($row['relation_type'] != $relation_type && $relation_type == USER_RELATION_TYPE_RRHH) {
+					$sql_i = 'INSERT INTO ' . $tbl_my_friend . '(friend_user_id,user_id,relation_type,last_edit)values(' . $friend_id . ','.$my_user_id.','.$relation_type.',"'.$current_date.'");';		
+				} else {
+					$sql_i = 'UPDATE ' . $tbl_my_friend . ' SET relation_type='.$relation_type.' WHERE friend_user_id=' . $friend_id.' AND user_id='.$my_user_id;
+				}				
+				Database::query($sql_i, __FILE__, __LINE__);
+				return true;
+			} else {
+				return false;
+			}			
+		}		
+	}
+	
+	/**
+	 * Deletes a contact	  
+	 * @param int user friend id
+	 * @param bool true will delete ALL friends relationship from $friend_id
+	 * @author isaac flores paz <isaac.flores@dokeos.com>
+	 * @author Julio Montoya <gugli100@gmail.com> Cleaning code
+	 */
+	public static function remove_user_rel_user ($friend_id, $real_removed = false, $with_status_condition = '') {
+		$tbl_my_friend  = Database :: get_main_table(TABLE_MAIN_USER_REL_USER);
+		$tbl_my_message = Database :: get_main_table(TABLE_MAIN_MESSAGE);
+		$friend_id = intval($friend_id);
+		
+		if ($real_removed == true) {			
+			//Delete user friend
+			/*
+			$sql_delete_relationship1 = 'UPDATE ' . $tbl_my_friend .'  SET relation_type='.USER_RELATION_TYPE_DELETED.' WHERE friend_user_id='.$friend_id;			
+			$sql_delete_relationship2 = 'UPDATE ' . $tbl_my_friend . ' SET relation_type='.USER_RELATION_TYPE_DELETED.' WHERE user_id=' . $friend_id;
+			Database::query($sql_delete_relationship1, __FILE__, __LINE__);
+			Database::query($sql_delete_relationship2, __FILE__, __LINE__);*/
+			$extra_condition = '';				
+			if ($with_status_condition != '') {
+				$extra_condition = ' AND relation_type = '.intval($with_status_condition);
+			}
+			$sql_delete_relationship1 = 'DELETE FROM ' . $tbl_my_friend .'  WHERE friend_user_id='.$friend_id.' '.$extra_condition;			
+			$sql_delete_relationship2 = 'DELETE FROM ' . $tbl_my_friend . ' WHERE user_id=' . $friend_id.' '.$extra_condition;
+			Database::query($sql_delete_relationship1, __FILE__, __LINE__);
+			Database::query($sql_delete_relationship2, __FILE__, __LINE__);	
+				
+		} else {
+			$user_id = api_get_user_id();
+			$sql = 'SELECT COUNT(*) as count FROM ' . $tbl_my_friend . ' WHERE user_id=' . $user_id . ' AND relation_type <>'.USER_RELATION_TYPE_DELETED.' AND friend_user_id='.$friend_id;
+			$result = Database::query($sql, __FILE__, __LINE__);
+			$row = Database :: fetch_array($result, 'ASSOC');
+			if ($row['count'] == 1) {
+				//Delete user rel user
+				$sql_i = 'UPDATE ' . $tbl_my_friend .' SET relation_type='.USER_RELATION_TYPE_DELETED.' WHERE user_id='.$user_id.' AND friend_user_id='.$friend_id;
+				$sql_j = 'UPDATE ' . $tbl_my_message.' SET msg_status='.MESSAGE_STATUS_INVITATION_DENIED.' WHERE user_receiver_id=' . $user_id.' AND user_sender_id='.$friend_id.' AND update_date="0000-00-00 00:00:00" ';
+				//Delete user
+				$sql_ij = 'UPDATE ' . $tbl_my_friend . '  SET relation_type='.USER_RELATION_TYPE_DELETED.' WHERE user_id=' . $friend_id.' AND friend_user_id='.$user_id;
+				$sql_ji = 'UPDATE ' . $tbl_my_message . ' SET msg_status='.MESSAGE_STATUS_INVITATION_DENIED.' WHERE user_receiver_id=' . $friend_id.' AND user_sender_id='.$user_id.' AND update_date="0000-00-00 00:00:00" ';
+				Database::query($sql_i, __FILE__, __LINE__);
+				Database::query($sql_j, __FILE__, __LINE__);
+				Database::query($sql_ij, __FILE__, __LINE__);
+				Database::query($sql_ji, __FILE__, __LINE__);
+			}			
+		}
+	}
+	
 }