Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions Sharing Portal/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,21 @@
require("model/user.php");
require("model/relation.php");

$user = new User($mysqli);
$user = new User($mysqli);

//echo $user->MailOrUsername("deepanjan05");
//echo $user->MailOrUsername("deepanjan05");

$user->loginUser("deepanjan05", '1234');
$user->loginUser("deepanjan05", '1234');

$followers_data = new Relation($mysqli, $user);

$follower = $followers_data->getAllFollowersOfLoggedIn()['result'][0];

echo $user->getName(). " is followed by ". $follower->getName() . "<br>";
echo $user->getName() . " is followed by " . $follower->getName() . "<br>";

$follower = $followers_data->getAllUsersFollowedByLoggedIn()['result'][1];

echo $user->getName(). " follows ". $follower->getName() . "<br>";
echo $user->getName() . " follows " . $follower->getName() . "<br>";

echo $user->checkUsername("deepanjan0") . "<br>";

?>

149 changes: 75 additions & 74 deletions Sharing Portal/model/relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,24 @@ class Relation //extends AnotherClass
/**
* MySQL object - $conn - variable containing conection details
* @var MySQLi Object
*/
*/
private $conn;


/** ==============================================

/** ==============================================
ACCESSORS AND MODIFIERS
==============================================*/

function change_loggedInUser($id){
function change_loggedInUser($id)
{
$user = new User($this->conn);
$user->arrayToUser($user->getUser($id));
$this->loggedInUser = $user;
$this->followers = $this->getAllFollowers();
$this->following = $this->getAllFollowing();
}
}

/** ==============================================
/** ==============================================
CONSTRUCTORS AND DESTRUCTORS
==============================================*/

Expand All @@ -53,10 +54,10 @@ function __construct($conn, User $loggedInUser)
$this->loggedInUser = $loggedInUser;
$this->conn = $conn;
$this->followers = null;
$this->following = null;
$this->following = null;
}

/** ==============================================
/** ==============================================
METHODS
==============================================*/

Expand All @@ -66,35 +67,35 @@ function __construct($conn, User $loggedInUser)
*/
function getAllFollowersOfLoggedIn()
{
$sql = "SELECT user2 FROM relation WHERE user1 = '".$this->loggedInUser->getUid(). "'";
$sql = "SELECT user2 FROM relation WHERE user1 = '" . $this->loggedInUser->getUid() . "'";

$result = $this->conn->query($sql);
if(!$result || $result->num_rows<=0){
$errorH = alog("getuser error: numrows : ". $result->num_rows ."error:". $this->conn->error);
$error = "Error in displaying result for given User ID. Err no: #".$errorH;
error_log("Error: ".$errorH .": ". $result->num_rows ." - ". $this->conn->error);
$status = 501;
$msg = $error;
} else {
$res = array();
while ($user_ids = $result->fetch_assoc()) {
$status = 200;
$user = new User($this->conn);
$user->getUser($user_ids['user2']);

$res[] = $user;
}
$result->free();
}

$ret = array();
$ret['status'] = $status;
if($status==200){
$ret['result'] = $res;
} else {
$ret['message'] = $msg;
}
return $ret;
if (!$result || $result->num_rows <= 0) {
$errorH = alog("getuser error: numrows : " . $result->num_rows . "error:" . $this->conn->error);
$error = "Error in displaying result for given User ID. Err no: #" . $errorH;
error_log("Error: " . $errorH . ": " . $result->num_rows . " - " . $this->conn->error);
$status = 501;
$msg = $error;
} else {
$res = array();
while ($user_ids = $result->fetch_assoc()) {
$status = 200;
$user = new User($this->conn);
$user->getUser($user_ids['user2']);

$res[] = $user;
}
$result->free();
}

$ret = array();
$ret['status'] = $status;
if ($status == 200) {
$ret['result'] = $res;
} else {
$ret['message'] = $msg;
}
return $ret;
}

/**
Expand All @@ -103,35 +104,35 @@ function getAllFollowersOfLoggedIn()
*/
function getAllUsersFollowedByLoggedIn()
{
$sql = "SELECT user1 FROM relation WHERE user2 = '".$this->loggedInUser->getUid(). "'";
$sql = "SELECT user1 FROM relation WHERE user2 = '" . $this->loggedInUser->getUid() . "'";

$result = $this->conn->query($sql);
if(!$result || $result->num_rows<=0){
$errorH = alog("getuser error: numrows : ". $result->num_rows ."error:". $this->conn->error);
$error = "Error in displaying result for given User ID. Err no: #".$errorH;
error_log("Error: ".$errorH .": ". $result->num_rows ." - ". $this->conn->error);
$status = 501;
$msg = $error;
} else {
$res = array();
while ($user_ids = $result->fetch_assoc()) {
$status = 200;
$user = new User($this->conn);
$user->getUser($user_ids['user1']);

$res[] = $user;
}
$result->free();
}

$ret = array();
$ret['status'] = $status;
if($status==200){
$ret['result'] = $res;
} else {
$ret['message'] = $msg;
}
return $ret;
if (!$result || $result->num_rows <= 0) {
$errorH = alog("getuser error: numrows : " . $result->num_rows . "error:" . $this->conn->error);
$error = "Error in displaying result for given User ID. Err no: #" . $errorH;
error_log("Error: " . $errorH . ": " . $result->num_rows . " - " . $this->conn->error);
$status = 501;
$msg = $error;
} else {
$res = array();
while ($user_ids = $result->fetch_assoc()) {
$status = 200;
$user = new User($this->conn);
$user->getUser($user_ids['user1']);

$res[] = $user;
}
$result->free();
}

$ret = array();
$ret['status'] = $status;
if ($status == 200) {
$ret['result'] = $res;
} else {
$ret['message'] = $msg;
}
return $ret;
}

/**
Expand All @@ -143,7 +144,15 @@ function getAllUsersFollowedByLoggedIn()
*/
function checkFollowerOf(User $user)
{

$strId = (string)$this->loggedInUser->getUid() . "_" . (string)$user->getUid();
$sql = "SELECT * FROM relation WHERE str_id ='" . $strId . "'";
$result = $this->conn->query($sql);
if ($result == false) {
return -1;
} else if ($result->num_rows == 0) {
return 0;
}
return 1;
}

/**
Expand All @@ -155,9 +164,7 @@ function checkFollowerOf(User $user)
* ['message'] : Message corresponding the status code
*/
function addFollowerOf(User $user)
{

}
{ }

/**
* removes the user from 'following' list of loggedin User (Logged in users stops following this user (User $user))
Expand All @@ -168,9 +175,7 @@ function addFollowerOf(User $user)
* ['message'] : Message corresponding the status code
*/
function removeFollowerOf(User $user)
{

}
{ }

/**
* check if the user is being followed by loggedin User (Logged in users starts following this user (User $user))
Expand All @@ -180,9 +185,5 @@ function removeFollowerOf(User $user)
* 0 : Logged In user is not followed by $user
*/
function checkFollowedBy(User $user)
{

}


{ }
}