This repository has been archived on 2024-06-26. You can view files and clone it, but cannot push or open issues or pull requests.
sakura/app/Controllers/NotificationsController.php

55 lines
1.2 KiB
PHP
Raw Normal View History

2016-03-28 14:47:43 +00:00
<?php
/**
* Holds the notification controllers.
* @package Sakura
*/
namespace Sakura\Controllers;
2016-08-07 14:10:27 +00:00
use Sakura\CurrentSession;
2016-03-28 14:47:43 +00:00
use Sakura\Notification;
/**
* Notification stuff.
* @package Sakura
* @author Julian van de Groep <me@flash.moe>
*/
class NotificationsController extends Controller
{
/**
* Get the notification JSON object for the currently authenticated user.
2016-08-05 02:35:37 +00:00
* @return string
2016-03-28 14:47:43 +00:00
*/
public function notifications()
{
2016-08-07 14:10:27 +00:00
return $this->json(CurrentSession::$user->notifications());
2016-03-28 14:47:43 +00:00
}
/**
* Mark a notification as read.
2016-08-05 02:35:37 +00:00
* Not entirely set on this one yet but 1 for success and 0 for fail.
* @param int
* @return string
2016-03-28 14:47:43 +00:00
*/
public function mark($id = 0)
{
if (!CurrentSession::$user->activated) {
2016-03-28 14:47:43 +00:00
return '0';
}
// Create the notification object
$alert = new Notification($id);
// Verify that the currently authed user is the one this alert is for
2016-08-07 14:10:27 +00:00
if ($alert->user !== CurrentSession::$user->id) {
2016-03-28 14:47:43 +00:00
return '0';
}
// Toggle the read status and save
$alert->toggleRead();
$alert->save();
return '1';
}
}