Add Registration Questions domain (per-offering intake forms)
CI / Coding Standards (pull_request) Successful in 51s
CI / PHPStan (pull_request) Successful in 1m0s
CI / Tests (PHP 8.1) (pull_request) Successful in 46s
CI / Tests (PHP 8.2) (pull_request) Successful in 48s
CI / Tests (PHP 8.3) (pull_request) Successful in 47s
CI / No Debug Code (pull_request) Successful in 3s
CI / Coding Standards (pull_request) Successful in 51s
CI / PHPStan (pull_request) Successful in 1m0s
CI / Tests (PHP 8.1) (pull_request) Successful in 46s
CI / Tests (PHP 8.2) (pull_request) Successful in 48s
CI / Tests (PHP 8.3) (pull_request) Successful in 47s
CI / No Debug Code (pull_request) Successful in 3s
Implements #5: studio admin / instructors author intake questions scoped per offering; answers are stored against a lesson or group enrolment via a polymorphic registration reference. - src/Registration/: Question + Answer value objects, QuestionRepository and AnswerRepository, QuestionEndpoint (REST), QuestionController + templates/admin/questions.php (Offerings -> Questions submenu) - us_questions and us_question_answers tables in Schema.php - REST: public GET /offerings/{id}/questions; POST/PATCH/DELETE /questions gated by manage_questions + offering ownership (owner or studio admin) - Field types text/textarea/select/checkbox; select options stored as JSON - Wiring in Plugin, RestRegistrar, AdminMenu AnswerRepository is built now and consumed by the booking/enrolment flow in #3/#4. Tests: tests/Unit/Registration/ (19 tests). composer test (63 total), cs, and PHPStan level 6 all pass. Refs #5 Co-Authored-By: Claude Opus 4.8 <[email protected]>
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Unsupervised\Schedular\Registration;
|
||||
|
||||
class Question {
|
||||
|
||||
public const FIELD_TEXT = 'text';
|
||||
public const FIELD_TEXTAREA = 'textarea';
|
||||
public const FIELD_SELECT = 'select';
|
||||
public const FIELD_CHECKBOX = 'checkbox';
|
||||
|
||||
/**
|
||||
* All valid field types.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
public const VALID_FIELD_TYPES = [
|
||||
self::FIELD_TEXT,
|
||||
self::FIELD_TEXTAREA,
|
||||
self::FIELD_SELECT,
|
||||
self::FIELD_CHECKBOX,
|
||||
];
|
||||
|
||||
/**
|
||||
* Build an intake question value object.
|
||||
*
|
||||
* @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 ?int $id = null,
|
||||
) {}
|
||||
|
||||
public static function fromRow( object $row ): self {
|
||||
$options = null;
|
||||
if ( null !== $row->options && '' !== $row->options ) {
|
||||
$decoded = json_decode( (string) $row->options, true );
|
||||
$options = is_array( $decoded ) ? array_values( array_map( 'strval', $decoded ) ) : null;
|
||||
}
|
||||
|
||||
return new self(
|
||||
offeringId: (int) $row->offering_id,
|
||||
label: $row->label,
|
||||
fieldType: $row->field_type,
|
||||
options: $options,
|
||||
isRequired: (bool) $row->is_required,
|
||||
sortOrder: (int) $row->sort_order,
|
||||
isActive: (bool) $row->is_active,
|
||||
id: (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,
|
||||
'label' => $this->label,
|
||||
'field_type' => $this->fieldType,
|
||||
'options' => $this->options,
|
||||
'is_required' => $this->isRequired,
|
||||
'sort_order' => $this->sortOrder,
|
||||
'is_active' => $this->isActive,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user