still some bugs and auth issues to iron out. need to implement a new action button/bar, the card for moments in a space, creating new moments and essays, dynamically refreshing the spaces view when a new post is created.
This commit is contained in:
+71
-12
@@ -6,18 +6,20 @@ require_once 'post.php';
|
||||
|
||||
class Space
|
||||
{
|
||||
private int $spaceId;
|
||||
private int $id;
|
||||
private string $name;
|
||||
private string $description;
|
||||
private int $visibility;
|
||||
private array $members;
|
||||
private array $posts;
|
||||
private ?Space $parent;
|
||||
|
||||
public function __construct(?int $spaceId, string $name, string $description, array $members, $posts, ?Space $parent = null)
|
||||
public function __construct(?int $id, string $name, string $description, int $visibility, array $members, array $posts, ?Space $parent = null)
|
||||
{
|
||||
$this->spaceId = $spaceId ?? randomId(2);
|
||||
$this->id = $id ?? randomId(2);
|
||||
$this->name = $name;
|
||||
$this->description = $description;
|
||||
$this->visibility = $visibility;
|
||||
$this->members = $members;
|
||||
$this->posts[] = $posts;
|
||||
$this->parent = $parent;
|
||||
@@ -25,9 +27,33 @@ class Space
|
||||
/* $stmt = 'INSERT INTO spaces (spaceId, name, description, parentSpaceIdk)'; */
|
||||
}
|
||||
|
||||
public static function retrieveFromDB(int $space, ?int $user): ?Space
|
||||
public function getCardHTML(): string
|
||||
{
|
||||
if ($user) {
|
||||
$html = '
|
||||
<div class="full_width std_border padding center top_margin bottom_margin">
|
||||
<a href="spaces.php?view=show&id=' . $this->id . '" class="divLink">
|
||||
<div class="row space_between full_width">
|
||||
<div class="column std_width">
|
||||
<h4>' . $this->name . '</h4>
|
||||
</div>
|
||||
|
||||
<div class="">
|
||||
<span>Something</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row full_width">
|
||||
<p>' . $this->description . '</p>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
';
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
public static function retrieveFromDB(int $space, int $user = -1): ?Space
|
||||
{
|
||||
if ($user != -1) {
|
||||
$stmt = 'SELECT * FROM spaceMembers WHERE space = ? AND user = ?';
|
||||
$isMember = exec_stmt($stmt, 'ii', $space, $user)->fetch_assoc();
|
||||
if (!$isMember)
|
||||
@@ -40,20 +66,48 @@ class Space
|
||||
}
|
||||
|
||||
$stmt = 'SELECT * FROM space WHERE id = ?';
|
||||
$space = exec_stmt($stmt, 'i', $space)->fetch_assoc();
|
||||
$rawSpace = exec_stmt($stmt, 'i', $space)->fetch_assoc();
|
||||
|
||||
if (!empty($space['parentSpace']))
|
||||
$parent = Space::retrieveFromDB($space['parentSpace'], $user);
|
||||
if (!empty($rawSpace['parentSpace']))
|
||||
$parent = Space::retrieveFromDB($rawSpace['parentSpace'], $user);
|
||||
else
|
||||
$parent = null;
|
||||
|
||||
$stmt = 'SELECT user FROM spaceMembers WHERE space = ?';
|
||||
$members = exec_stmt($stmt, 'i', $space)->fetch_assoc();
|
||||
$members = [];
|
||||
$rawMembers = exec_stmt($stmt, 'i', $rawSpace['id']);
|
||||
foreach ($rawMembers as $m) {
|
||||
$members[] = User::retrieveFromDB($m['user']);
|
||||
}
|
||||
|
||||
$stmt = 'SELECT post FROM spacePosts WHERE space = ?';
|
||||
$posts = exec_stmt($stmt, 'i', $space)->fetch_assoc();
|
||||
$posts = [];
|
||||
$rawPosts = exec_stmt($stmt, 'i', $rawSpace['id']);
|
||||
while ($row = $rawPosts->fetch_assoc()) {
|
||||
$posts[] = Post::retrieveFromDB($row['post']);
|
||||
}
|
||||
|
||||
return new Space($space['id'], $space['name'], $space['description'], $members, $posts, $parent);
|
||||
$space = new Space($rawSpace['id'], $rawSpace['name'], $rawSpace['description'], $rawSpace['visibility'], $members, $posts, $parent);
|
||||
|
||||
foreach ($posts as $p)
|
||||
$p->setSpace($space);
|
||||
|
||||
return $space;
|
||||
}
|
||||
|
||||
public function allowUser(User $user)
|
||||
{
|
||||
$stmt = 'SELECT space FROM spaceMembers WHERE user = ?';
|
||||
$result = exec_stmt($stmt, 'i', $user->getId())->fetch_assoc();
|
||||
if ($result['space'] == $this->id)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getPosts()
|
||||
{
|
||||
return $this->posts;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
@@ -63,7 +117,7 @@ class Space
|
||||
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->spaceId;
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
@@ -75,4 +129,9 @@ class Space
|
||||
{
|
||||
return $this->description;
|
||||
}
|
||||
|
||||
public function getVisibility(): int
|
||||
{
|
||||
return $this->visibility;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user