asdlkif
This commit is contained in:
@@ -6,8 +6,8 @@ class MessageModel
|
||||
{
|
||||
$database = DatabaseFactory::getFactory()->getConnection();
|
||||
|
||||
$sql = "INSERT INTO messages (sender_id, receiver_id, group_type, subject, message)
|
||||
VALUES (:sender_id, :receiver_id, :group_type, :subject, :message)";
|
||||
$sql = "INSERT INTO messages (sender_id, receiver_id, group_type, subject, message, is_read)
|
||||
VALUES (:sender_id, :receiver_id, :group_type, :subject, :message, 0)";
|
||||
$query = $database->prepare($sql);
|
||||
return $query->execute(array(
|
||||
':sender_id' => $sender_id,
|
||||
@@ -170,6 +170,36 @@ class MessageModel
|
||||
return $query->fetchAll();
|
||||
}
|
||||
|
||||
public static function getGlobalMessages()
|
||||
{
|
||||
$database = DatabaseFactory::getFactory()->getConnection();
|
||||
|
||||
$sql = "SELECT m.*, u.user_name as sender_name,
|
||||
'received' as message_type
|
||||
FROM messages m
|
||||
JOIN users u ON m.sender_id = u.user_id
|
||||
WHERE m.group_type = 'global'
|
||||
AND m.receiver_id IS NULL
|
||||
ORDER BY m.created_at ASC";
|
||||
|
||||
$query = $database->prepare($sql);
|
||||
$query->execute();
|
||||
return $query->fetchAll();
|
||||
}
|
||||
|
||||
public static function sendToGlobal($sender_id, $message)
|
||||
{
|
||||
$database = DatabaseFactory::getFactory()->getConnection();
|
||||
|
||||
$sql = "INSERT INTO messages (sender_id, group_type, subject, message, is_read)
|
||||
VALUES (:sender_id, 'global', 'Global Chat', :message, 1)";
|
||||
$query = $database->prepare($sql);
|
||||
return $query->execute(array(
|
||||
':sender_id' => $sender_id,
|
||||
':message' => $message
|
||||
));
|
||||
}
|
||||
|
||||
public static function getAllUsers($current_user_id)
|
||||
{
|
||||
$database = DatabaseFactory::getFactory()->getConnection();
|
||||
|
||||
@@ -14,12 +14,20 @@ class NoteModel
|
||||
{
|
||||
$database = DatabaseFactory::getFactory()->getConnection();
|
||||
|
||||
$sql = "SELECT user_id, note_id, note_text FROM notes WHERE user_id = :user_id";
|
||||
$sql = "SELECT note_id, note_text, note_timestamp FROM notes WHERE user_id = :user_id ORDER BY note_timestamp DESC";
|
||||
$query = $database->prepare($sql);
|
||||
$query->execute(array(':user_id' => Session::get('user_id')));
|
||||
|
||||
// fetchAll() is the PDO method that gets all result rows
|
||||
return $query->fetchAll();
|
||||
$notes = $query->fetchAll();
|
||||
|
||||
// Add markdown HTML to each note
|
||||
require_once __DIR__ . '/../libs/SimpleMarkdown.php';
|
||||
foreach ($notes as &$note) {
|
||||
$note->note_html = SimpleMarkdown::parse($note->note_text);
|
||||
}
|
||||
|
||||
return $notes;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -29,13 +37,21 @@ class NoteModel
|
||||
*/
|
||||
public static function getNote($note_id)
|
||||
{
|
||||
$database = DatabaseFactory::getFactory()->getConnectionWithMySQLI();
|
||||
$database = DatabaseFactory::getFactory()->getConnection();
|
||||
|
||||
$sql = "SELECT user_id, note_id, note_text FROM notes WHERE user_id = :user_id AND note_id = :note_id LIMIT 1";
|
||||
$sql = "SELECT note_id, note_text, note_timestamp FROM notes WHERE user_id = :user_id AND note_id = :note_id LIMIT 1";
|
||||
$query = $database->prepare($sql);
|
||||
$query->execute(array(':user_id' => Session::get('user_id'), ':note_id' => $note_id));
|
||||
|
||||
return $query;
|
||||
$result = $query->fetch();
|
||||
|
||||
// Add markdown HTML
|
||||
if ($result) {
|
||||
require_once __DIR__ . '/../libs/SimpleMarkdown.php';
|
||||
$result->note_html = SimpleMarkdown::parse($result->note_text);
|
||||
}
|
||||
|
||||
return $result ? $result : null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user