mirror of
https://github.com/Fluffy-Bean/image-gallery.git
synced 2025-06-05 18:03:13 +00:00
Cleaning up Groups code
This commit is contained in:
parent
1be364c4ef
commit
be80166795
5 changed files with 260 additions and 183 deletions
73
app/app.php
73
app/app.php
|
@ -135,14 +135,20 @@ class Image {
|
|||
Returns array with image info
|
||||
*/
|
||||
function get_image_info($conn, $id) {
|
||||
// Setting SQL query
|
||||
$sql = "SELECT * FROM images WHERE id = ".$id;
|
||||
// Getting results
|
||||
$query = mysqli_query($conn, $sql);
|
||||
// Fetching associated info
|
||||
$image_array = mysqli_fetch_assoc($query);
|
||||
$sql = "SELECT * FROM images WHERE id = ?";
|
||||
|
||||
if ($stmt = mysqli_prepare($conn, $sql)) {
|
||||
// Bind variables to the prepared statement as parameters
|
||||
mysqli_stmt_bind_param($stmt, "i", $id);
|
||||
|
||||
$stmt->execute();
|
||||
$query = $stmt->get_result();
|
||||
|
||||
// Fetching associated info
|
||||
$group_array = mysqli_fetch_assoc($query);
|
||||
}
|
||||
|
||||
return($image_array);
|
||||
return($group_array);
|
||||
}
|
||||
/*
|
||||
Check if user is image owner
|
||||
|
@ -164,6 +170,57 @@ class Image {
|
|||
}
|
||||
}
|
||||
|
||||
class Group {
|
||||
function get_group_info($conn, $id) {
|
||||
// Setting SQL query
|
||||
$sql = "SELECT * FROM groups WHERE id = ?";
|
||||
|
||||
if ($stmt = mysqli_prepare($conn, $sql)) {
|
||||
// Bind variables to the prepared statement as parameters
|
||||
mysqli_stmt_bind_param($stmt, "i", $id);
|
||||
|
||||
$stmt->execute();
|
||||
$query = $stmt->get_result();
|
||||
|
||||
// Fetching associated info
|
||||
$group_array = mysqli_fetch_assoc($query);
|
||||
}
|
||||
|
||||
return($group_array);
|
||||
}
|
||||
|
||||
function get_group_members($conn, $id){
|
||||
$user_array = array();
|
||||
|
||||
$sql = "SELECT * FROM groups WHERE id = ?";
|
||||
|
||||
if ($stmt = mysqli_prepare($conn, $sql)) {
|
||||
// Bind variables to the prepared statement as parameters
|
||||
mysqli_stmt_bind_param($stmt, "i", $id);
|
||||
|
||||
$stmt->execute();
|
||||
$query = $stmt->get_result();
|
||||
|
||||
// Fetching associated info
|
||||
$group_array = mysqli_fetch_assoc($query);
|
||||
}
|
||||
|
||||
$image_list = explode(" ", $group_array['image_list']);
|
||||
|
||||
foreach ($image_list as $image) {
|
||||
$image_request = mysqli_query($conn, "SELECT author FROM images WHERE id = ".$image);
|
||||
|
||||
while ($author = mysqli_fetch_column($image_request)) {
|
||||
if (!in_array($author, $user_array)) {
|
||||
array_push($user_array, $author);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return($user_array);
|
||||
}
|
||||
}
|
||||
|
||||
class Diff {
|
||||
function time($past_time, $full_date = false) {
|
||||
$now = new \DateTime;
|
||||
|
@ -193,4 +250,4 @@ class Diff {
|
|||
if (!$full_date) $string = array_slice($string, 0, 1);
|
||||
return $string ? implode(', ', $string) . ' ago' : 'just now';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue