public static function unHideMsg($id) { $database = new Database(); $sql = "UPDATE " . TABLE_MESSAGES . " SET deleted = 0 WHERE id = {$id}"; return $database->xcute($sql); }
public function get_stream($uid = USER_ID) { global $connection; $database = new Database(); // getting the posts data $sql = "SELECT DISTINCT ac.*, CONCAT(u.firstName, ' ', u.lastName) AS u_fullname, CONCAT(p.firstName, ' ', p.lastName) AS p_fullname, u.id AS u_id, p.id AS p_id,\n\t\t\t\tpic.thumb_path AS path, picp.thumb_path AS p_path FROM " . SELF::$table . " AS ac\n\n\t\t\t\tINNER JOIN " . TABLE_FOLLOWING . " AS f ON ac.user_id = f.user_id OR ac.user_id = f.follower_id\n\t\t\t\tINNER JOIN " . TABLE_USERS . " AS u ON ac.user_id = u.id\n\t\t\t\tINNER JOIN " . TABLE_USERS . " AS p ON ac.poster_id = p.id\n\t\t\t\tLEFT JOIN " . TABLE_PROFILE_PICS . " AS pic ON ac.user_id = pic.user_id\n\t\t\t\tLEFT JOIN " . TABLE_PROFILE_PICS . " AS picp ON ac.poster_id = picp.user_id\n\n\t\t\t\tWHERE ac.date <= '{$this->timeline}' AND ac.date >= '{$this->maxTime}' AND (f.follower_id = :uid OR ac.user_id = {$uid})\n\t\t\t\tORDER BY date DESC"; $stmt = $database->xcute($sql, [':uid' => $uid]); if ($database->error === TRUE) { $this->errors = $database->errors; } else { while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $row['type'] = 'ac'; if (empty($row['p_path'])) { $row['p_path'] = DEF_PIC; } $this->feed[] = $row; } } // getting user interactions data NEEDS REWEORK $following_ids = []; $sql = "SELECT fl.user_id FROM " . TABLE_FOLLOWING . " AS fl\n\n\t\t\t\tWHERE fl.follower_id = :uid"; $stmt = $database->xcute($sql, [':uid' => $uid]); if ($database->error === TRUE) { $this->errors = $database->errors; } else { while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $following_ids[] = $row['user_id']; } } $followers = []; foreach ($following_ids as $id) { $sql = "SELECT fl.*, u.firstName AS u_firstname, u_fl.firstname AS f_firstname\n\t\t\t\t\tFROM " . TABLE_FOLLOWING . " AS fl\n\n\t\t\t\t\tINNER JOIN " . TABLE_USERS . " AS u ON fl.user_id = u.id\n\t\t\t\t\tINNER JOIN " . TABLE_USERS . " AS u_fl ON fl.follower_id = u_fl.id\n\n\t\t\t\t\tWHERE fl.date <= '{$this->timeline}' AND fl.date >= '{$this->maxTime}' AND fl.follower_id = {$id} AND fl.user_id != {$uid}"; $stmt = $connection->query($sql); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $row['type'] = 'fl'; $this->feed[] = $row; } } // getting the comments data $sql = "SELECT cmt.*, cmt.created AS date, CONCAT(u.firstName, ' ', u.lastName) AS fullname, pic.thumb_path AS path FROM " . TABLE_COMMENTS . " AS cmt\n\n\n\t\t\t\tINNER JOIN " . TABLE_FOLLOWING . " AS f ON cmt.uid = f.user_id\n\t\t\t\tINNER JOIN " . TABLE_USERS . " AS u ON cmt.uid = u.id\n\t\t\t\tINNER JOIN " . TABLE_PROFILE_PICS . " AS pic ON cmt.uid = pic.user_id\n\n\t\t\t\tWHERE date <= '{$this->timeline}' AND date >= '{$this->maxTime}' AND f.follower_id = :uid\n\t\t\t\tORDER BY date DESC"; $stmt = $database->xcute($sql, [':uid' => $uid]); if ($database->error === TRUE) { $this->errors = $database->errors; } else { while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { unset($row['created']); // don't need it unset($row['last_modified']); // don't need it if (empty($row['path'])) { $row['path'] = DEF_PIC; } $row['type'] = 'cmt'; $this->feed[] = $row; } } // getting the points data $sql = "SELECT ps.*, u.firstName, pic.thumb_path FROM " . TABLE_POINTS . " AS ps\n\n\t\t\t\tINNER JOIN " . TABLE_FOLLOWING . " AS f ON ps.user_id = f.user_id\n\t\t\t\tINNER JOIN " . TABLE_USERS . " AS u ON ps.user_id = u.id\n\t\t\t\tINNER JOIN " . TABLE_PROFILE_PICS . " AS pic ON ps.user_id = pic.user_id\n\n\t\t\t\tWHERE ps.date <= '{$this->timeline}' AND ps.date >= '{$this->maxTime}' AND f.follower_id = :uid\n\t\t\t\tORDER BY date DESC"; $stmt = $database->xcute($sql, [':uid' => $uid]); if ($database->error === TRUE) { $this->errors = $database->errors; } else { while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $row['type'] = 'ps'; $this->feed[] = $row; } } // getting the questions data $sql = "SELECT DISTINCT qs.*, qs.created AS date, u.firstName, pic.thumb_path AS path FROM " . TABLE_QUESTIONS . " AS qs\n\n\t\t\t\tINNER JOIN " . TABLE_FOLLOWING . " AS f ON qs.uid = f.user_id\n\t\t\t\tINNER JOIN " . TABLE_USERS . " AS u ON qs.uid = u.id\n\t\t\t\tINNER JOIN " . TABLE_PROFILE_PICS . " AS pic ON qs.uid = pic.user_id\n\n\t\t\t\tWHERE qs.created < '{$this->timeline}' AND qs.created > '{$this->maxTime}' AND f.follower_id = :uid AND qs.status = 1 OR qs.uid = :uid\n\t\t\t\tORDER BY date DESC"; $stmt = $database->xcute($sql, [':uid' => $uid]); if ($database->error === TRUE) { $this->errors = $database->errors; } else { while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { unset($row['created']); // don't need it unset($row['last_modified']); // don't need it if (empty($row['path'])) { $row['path'] = DEF_PIC; } $row['type'] = 'qs'; $this->feed[] = $row; } } }