CI / Tests (PHP 8.1) (pull_request) Successful in 49s
CI / Tests (PHP 8.2) (pull_request) Successful in 49s
CI / No Debug Code (pull_request) Successful in 2s
CI / Coding Standards (pull_request) Successful in 2m47s
CI / PHPStan (pull_request) Successful in 3m16s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m41s
CI / Build Plugin Zip (pull_request) Skipped
Three bug fixes for the 1.2.1 section: - Fixed-size fields (question labels, offering titles/notes/e-transfer email, policy titles/slugs) no longer silently fail to save when the value exceeds its column length. The REST endpoints reject over-long values with a 400, the admin controllers refuse to insert them, and the form inputs carry a maxlength so the browser blocks over-long entry. Limits are MAX_* constants on the value objects, kept in lockstep with the schema columns. - Students are kept out of wp-admin entirely. New StudentAdminGuard redirects front-end-only users (no back-office capability) away from the dashboard and hides the admin bar for them, while administrators, studio admins, and instructors keep full access. - The Add/Edit Offering instructor picker now includes WordPress administrators when they act as instructors (the default single-account setup), so a solo studio owner is selectable instead of the dropdown being empty. composer test (618), composer lint, composer cs all pass. Co-Authored-By: Claude Opus 4.8 <[email protected]>
105 lines
2.8 KiB
PHP
105 lines
2.8 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Unsupervised\Schedular\Registration;
|
|
|
|
use Unsupervised\Schedular\Val;
|
|
|
|
class Question {
|
|
|
|
public const FIELD_TEXT = 'text';
|
|
public const FIELD_TEXTAREA = 'textarea';
|
|
public const FIELD_SELECT = 'select';
|
|
public const FIELD_CHECKBOX = 'checkbox';
|
|
|
|
/** Maximum length of a question label, matching the `label` VARCHAR(255) column. */
|
|
public const MAX_LABEL_LENGTH = 255;
|
|
|
|
/** Question is scoped to a single offering, asked at booking/enrolment time. */
|
|
public const SCOPE_OFFERING = 'offering';
|
|
|
|
/** Question is studio-wide, asked once at account signup (no offering). */
|
|
public const SCOPE_ACCOUNT = 'account';
|
|
|
|
/**
|
|
* All valid field types.
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
public const VALID_FIELD_TYPES = [
|
|
self::FIELD_TEXT,
|
|
self::FIELD_TEXTAREA,
|
|
self::FIELD_SELECT,
|
|
self::FIELD_CHECKBOX,
|
|
];
|
|
|
|
/**
|
|
* All valid scopes.
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
public const VALID_SCOPES = [
|
|
self::SCOPE_OFFERING,
|
|
self::SCOPE_ACCOUNT,
|
|
];
|
|
|
|
/**
|
|
* Build an intake question value object.
|
|
*
|
|
* @param int|null $offeringId The owning offering, or null for account-scoped questions.
|
|
* @param list<string>|null $options Choices for a `select` field.
|
|
*/
|
|
public function __construct(
|
|
public readonly ?int $offeringId,
|
|
public readonly string $label,
|
|
public readonly string $fieldType = self::FIELD_TEXT,
|
|
public readonly ?array $options = null,
|
|
public readonly bool $isRequired = false,
|
|
public readonly int $sortOrder = 0,
|
|
public readonly bool $isActive = true,
|
|
public readonly string $scope = self::SCOPE_OFFERING,
|
|
public readonly ?int $id = null,
|
|
) {}
|
|
|
|
public static function fromRow( \stdClass $row ): self {
|
|
$options = null;
|
|
if ( null !== $row->options && '' !== $row->options ) {
|
|
$decoded = json_decode( Val::string( $row->options ), true );
|
|
$options = is_array( $decoded )
|
|
? array_values( array_map( static fn( mixed $v ): string => Val::string( $v ), $decoded ) )
|
|
: null;
|
|
}
|
|
|
|
return new self(
|
|
offeringId: Val::intOrNull( $row->offering_id ),
|
|
label: Val::string( $row->label ),
|
|
fieldType: Val::string( $row->field_type ),
|
|
options: $options,
|
|
isRequired: Val::bool( $row->is_required ),
|
|
sortOrder: Val::int( $row->sort_order ),
|
|
isActive: Val::bool( $row->is_active ),
|
|
scope: Val::string( $row->scope ),
|
|
id: Val::int( $row->id ),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Returns a plain array representation of the question.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(): array {
|
|
return [
|
|
'id' => $this->id,
|
|
'offering_id' => $this->offeringId,
|
|
'scope' => $this->scope,
|
|
'label' => $this->label,
|
|
'field_type' => $this->fieldType,
|
|
'options' => $this->options,
|
|
'is_required' => $this->isRequired,
|
|
'sort_order' => $this->sortOrder,
|
|
'is_active' => $this->isActive,
|
|
];
|
|
}
|
|
}
|