CI / Tests (PHP 8.1) (pull_request) Successful in 50s
CI / Tests (PHP 8.2) (pull_request) Successful in 1m12s
CI / No Debug Code (pull_request) Successful in 3s
CI / Coding Standards (pull_request) Successful in 2m50s
CI / PHPStan (pull_request) Successful in 3m4s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m42s
CI / Build Plugin Zip (pull_request) Skipped
The Policies admin page listed versions but never showed what any of them said, so revising a policy meant retyping it blind into an empty draft box. Each version row now has a View action that renders that version's text on the page, editable in place. A draft is saved back to itself; editing a published or archived version branches a new draft and leaves the original alone, because acceptances are recorded against policy_version_id and text a student agreed to must stay exactly as they saw it. That viewer also exposed why a studio reported the acceptance box as unreadable — one squashed line, overlapping words, a horizontal scrollbar. Bodies are typed into a bare textarea, so most carry no markup, and the raw text was emitted with its blank lines intact but nothing to turn them into paragraphs. PolicyVersion::bodyHtml() now renders every body the way WordPress renders post content (kses, then wpautop) and feeds all three consumers: the booking/enrolment JSON, the signup form, and the new viewer. Bodies written with markup are unaffected. The other half was that .us-policy-body had no CSS whatsoever and inherited whatever the theme did with an unstyled block in a form. It is now a bounded reading box that scrolls vertically and breaks long tokens, so a pasted URL cannot force the page sideways and a long policy cannot push the accept checkbox out of view. RegistrationPage was also never enqueueing the plugin stylesheet, which is why the signup gate looked worst of all. Closes #126 Closes #127 Co-Authored-By: Claude Opus 5 <[email protected]>
74 lines
2.1 KiB
PHP
74 lines
2.1 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Unsupervised\Schedular\Policy;
|
|
|
|
use Unsupervised\Schedular\Val;
|
|
|
|
class PolicyVersion {
|
|
|
|
public const STATUS_DRAFT = 'draft';
|
|
public const STATUS_PUBLISHED = 'published';
|
|
public const STATUS_ARCHIVED = 'archived';
|
|
|
|
/**
|
|
* All valid version statuses.
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
public const VALID_STATUSES = [ self::STATUS_DRAFT, self::STATUS_PUBLISHED, self::STATUS_ARCHIVED ];
|
|
|
|
public function __construct(
|
|
public readonly int $policyId,
|
|
public readonly int $versionNumber,
|
|
public readonly ?string $body = null,
|
|
public readonly string $status = self::STATUS_DRAFT,
|
|
public readonly ?string $publishedAt = null,
|
|
public readonly ?int $id = null,
|
|
) {}
|
|
|
|
public static function fromRow( \stdClass $row ): self {
|
|
return new self(
|
|
policyId: Val::int( $row->policy_id ),
|
|
versionNumber: Val::int( $row->version_number ),
|
|
body: Val::stringOrNull( $row->body ),
|
|
status: Val::string( $row->status ),
|
|
publishedAt: Val::stringOrNull( $row->published_at ),
|
|
id: Val::int( $row->id ),
|
|
);
|
|
}
|
|
|
|
public function isPublished(): bool {
|
|
return self::STATUS_PUBLISHED === $this->status;
|
|
}
|
|
|
|
/**
|
|
* The body as display-ready HTML.
|
|
*
|
|
* Policy bodies are typed into a plain textarea, so most are written as
|
|
* blank-line-separated prose with no markup at all — dropped into a page
|
|
* as-is that collapses into one unreadable run of text. Running the same
|
|
* `wpautop()` WordPress applies to post content turns those breaks into
|
|
* paragraphs, and leaves bodies that do carry markup alone.
|
|
*/
|
|
public function bodyHtml(): string {
|
|
return wpautop( wp_kses_post( (string) $this->body ) );
|
|
}
|
|
|
|
/**
|
|
* Returns a plain array representation of the version.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(): array {
|
|
return [
|
|
'id' => $this->id,
|
|
'policy_id' => $this->policyId,
|
|
'version_number' => $this->versionNumber,
|
|
'body' => $this->body,
|
|
'status' => $this->status,
|
|
'published_at' => $this->publishedAt,
|
|
];
|
|
}
|
|
}
|