Files
aowow/includes/components/frontend/announcement.class.php
Sarjuuk 226f521439 Template/Endpoints (Base)
* redo page render following the logic of:
      Response ─┬─> TextResponse ─> TextResponseImpl
                └─> TemplateResponse ─> TemplateResponseImpl
    * split up giant files, one per response path
    * caching becomes a trait, implemented where necessary
        * TextResponses (Ajax) can now be cached
    * make use of previously defined php classes for js objects
        * Tabs, Listview, Tooltip, Announcement, Markup, Book, ...
    * \Aowow\Template\PageTemplate is the new class to be cached
    * do not discard error messages generated after vars have been sent to template
      and store in session for display at a later time
    * implement tracking consent management
    * move logic out of template into their respective endpoints
2025-09-25 15:32:18 +02:00

70 lines
2.1 KiB
PHP

<?php
namespace Aowow;
if (!defined('AOWOW_REVISION'))
die('illegal access');
class Announcement implements \JsonSerializable
{
public const MODE_PAGE_TOP = 0;
public const MODE_CONTENT_TOP = 1;
public const STATUS_DISABLED = 0;
public const STATUS_ENABLED = 1;
public const STATUS_DELETED = 2;
public readonly int $status;
private bool $editable = false;
public function __construct(
public readonly int $id,
private string $name,
private LocString $text,
private int $mode = self::MODE_CONTENT_TOP,
int $status = self::STATUS_ENABLED,
private string $style = '')
{
// a negative id displays ENABLE/DISABLE and DELETE links for this announcement
// TODO - the ugroup check mirrors the js. Add other checks like ownership status? (ownership currently not stored)
if (User::isInGroup(U_GROUP_ADMIN | U_GROUP_BUREAU) /* && User::$id == $authorId */)
$this->editable = true;
if ($this->mode != self::MODE_PAGE_TOP && $this->mode != self::MODE_CONTENT_TOP)
$this->mode = self::MODE_PAGE_TOP;
if ($status != self::STATUS_DISABLED && $status != self::STATUS_ENABLED && $status != self::STATUS_DELETED)
$this->status = self::STATUS_DELETED;
else
$this->status = $status;
}
public function jsonSerialize() : array
{
$json = array(
'parent' => 'announcement-' . $this->id,
'id' => $this->editable ? -$this->id : $this->id,
'mode' => $this->mode,
'status' => $this->status,
'name' => $this->name,
'text' => (string)$this->text // force LocString to naive string for display
);
if ($this->style)
$json['style'] = $this->style;
return $json;
}
public function __toString() : string
{
if ($this->status == self::STATUS_DELETED)
return '';
return "new Announcement(".Util::toJSON($this).");\n";
}
}
?>