ossn.lib.relations.php
Go to the documentation of this file.
1 <?php
2 /**
3  * Open Source Social Network
4  *
5  * @package (Informatikon.com).ossn
6  * @author OSSN Core Team <[email protected]>
7  * @copyright 2014 iNFORMATIKON TECHNOLOGIES
8  * @license General Public Licence http://www.opensource-socialnetwork.org/licence
9  * @link http://www.opensource-socialnetwork.org/licence
10  */
11 
12 /**
13  * Ossn Add Relations
14  *
15  * @params $from => relation from guid
16  * $to => relation to guid
17  * $type => relation type
18  * @param string $type
19  *
20  * @return bool
21  */
22 function ossn_add_relation($from, $to, $type) {
23  if ($from > 0 && $to > 0 && !empty($type) && $type !== 0) {
24  $add = new OssnDatabase;
25  $params['into'] = 'ossn_relationships';
26  $params['names'] = array(
27  'relation_from',
28  'relation_to',
29  'type',
30  'time'
31  );
32  $params['values'] = array(
33  $from,
34  $to,
35  $type,
36  time()
37  );
38  if ($add->insert($params)) {
39  return true;
40  }
41  }
42  return false;
43 }
44 /**
45  * Delete user relations if user is deleted
46  *
47  * @param OssnUser $user Entity of user
48  *
49  * @return bool
50  */
51 function ossn_delete_user_relations($user) {
52  if ($user) {
53  $delete = new OssnDatabase;
54  $params['from'] = 'ossn_relationships';
55  //delete friend requests and group member requests if user deleted
56  $params['wheres'] = array(
57  "relation_from='{$user->guid}' AND type='friend:request' OR",
58  "relation_to='{$user->guid}' AND type='friend:request' OR",
59  "relation_from='{$user->guid}' AND type='group:join' OR",
60  "relation_to='{$user->guid}' AND type='group:join:approve'"
61  );
62  if ($delete->delete($params)) {
63  return true;
64  }
65  }
66  return false;
67 }
68 /**
69  * Delete group relations if user is deleted
70  *
71  * @param (object) $group Group Entity
72  *
73  * @return bool
74  */
75 function ossn_delete_group_relations($group){
76  if ($group) {
77  $delete = new OssnDatabase;
78  $params['from'] = 'ossn_relationships';
79  //delete group member requests if group deleted
80  $params['wheres'] = array(
81  "relation_from='{$group->guid}' AND type='group:join:approve' OR",
82  "relation_to='{$group->guid}' AND type='group:join'"
83  );
84  if ($delete->delete($params)) {
85  return true;
86  }
87  }
88  return false;
89 }