Can get all the likes of a user

This commit is contained in:
Pierre
2018-05-13 17:50:54 +02:00
parent b6d0d88622
commit c95e2d7498
3 changed files with 101 additions and 1 deletions

View File

@ -111,6 +111,29 @@ class Likes {
}
/**
* Get all the likes of a user, as UserLike objects
*
* @param int $userID The ID of the target user
* @return array The list of likes
*/
public function get_all_user(int $userID) : array {
//Query the database
$table = self::LIKES_TABLE;
$condition = "WHERE ID_personne = ?";
$condValues = array($userID);
$entries = cs()->db->select($table, $condition, $condValues);
$likes = array();
//Process the list of likes
foreach($entries as $entry)
$likes[] = $this->dbToUserLike($entry);
return $likes;
}
/**
* Delete all the likes associated to an element
*
@ -146,6 +169,25 @@ class Likes {
}
/**
* Turn database entry into UserLike object
*
* @param array $entry The database entry
* @return UserLike Generated user like object
*/
private static function dbToUserLike(array $entry) : UserLike {
$like = new UserLike();
$like->set_id($entry["ID"]);
$like->set_userID($entry["ID_personne"]);
$like->set_time_sent(strtotime($entry["Date_envoi"]));
$like->set_elem_id($entry["ID_type"]);
$like->set_elem_type($entry["type"]);
return $like;
}
}
//Register class