Skip to content

IndicatorReviewTask

Intro

The IndicatorReviewTask model represents verification tasks assigned to verifiers in the multi-level indicator approval workflow. These tasks are automatically created by event listeners when submissions are made or approved, and serve as the entry point for the verification process.

Model and Relationships

The IndicatorReviewTask model has the following key relationships:

  • Submission: Belongs-to relationship with IndicatorSubmission model
  • Assigned User: Belongs-to relationship with User model (verifier_user_id) - the verifier
  • Review: Has-one relationship with IndicatorSubmissionReview model (when verification is completed)

Key Fields

Assignment Fields

  • indicator_submission_id: Links to the submission being verified
  • verifier_user_id: The verifier responsible for this review
  • verification_level: Level of verification (1 or 2)
  • status: Current review task status
  • assigned_at: When the task was created
  • completed_at: When verification was completed (nullable)

Status Management

Uses IndicatorReviewTaskStatusEnum for status tracking:

  • PENDING: Initial status when review task is created
  • COMPLETED: Set when verifier completes the review (approve or reject)

Multi-Level Verification System

The system supports a two-level verification process:

Level 1 Verification

  • Created automatically when IndicatorSubmissionSubmitted event is dispatched
  • Assigned to users with verifier_1_role_id role
  • Approval creates Level 2 task (if Level 2 verifiers exist) or completes workflow
  • Rejection returns submission to admin for revision

Level 2 Verification

  • Created when Level 1 verification is approved
  • Assigned to users with verifier_2_role_id role
  • Approval completes the entire workflow
  • Rejection returns submission to admin for revision

Task Creation Logic

Review tasks are created by event listeners with automatic verifier assignment:

// Level 1 task creation (IndicatorSubmissionSubmittedListener)
$verifier1Role = Role::where('name', 'verifier_1_role_id')->first();
if ($verifier1Role && $verifier1Role->users()->exists()) {
    $verifier = $verifier1Role->users()->first();
    IndicatorReviewTask::create([
        'indicator_submission_id' => $submission->id,
        'verifier_user_id' => $verifier->id,
        'verification_level' => 1,
        'status' => IndicatorReviewTaskStatusEnum::PENDING,
    ]);
}

Usage in Filament

The model is used in the IndicatorVerifications Filament resource:

  • User-scoped queries: Only show tasks assigned to current user
  • Tabbed interface: Pending vs Completed tasks
  • Verification modal: Provides data for approve/reject interface

Query Scoping

public static function getEloquentQuery(): Builder
{
    return parent::getEloquentQuery()
        ->where('verifier_user_id', auth()->id())
        ->with(['submission.task.indicator', 'submission.task.entrepreneur']);
}

Verification Completion

When a verifier completes their review:

  1. IndicatorSubmissionReview record is created with decision and feedback
  2. IndicatorReviewTask status is updated to COMPLETED
  3. Appropriate event is dispatched (IndicatorSubmissionApproved or IndicatorSubmissionRejected)
  4. Next level task may be created or workflow completes

Display in Tables

Review tasks display comprehensive information in verification tables:

  • Indicator name and type
  • Entrepreneur and organisation details
  • Submission date and verification level
  • Completion status and date

Role-Based Assignment

Task assignment depends on role availability:

// Verifier role lookup
$verifierRole = Role::where('name', "verifier_{$level}_role_id")->first();

if ($verifierRole && $verifierRole->users()->exists()) {
    $verifier = $verifierRole->users()->first();
    // Create review task
} else {
    // No verifier available - skip this level or complete workflow
}

Query Patterns

User-specific Tasks

// Get pending review tasks for current user
$pendingTasks = IndicatorReviewTask::where('verifier_user_id', auth()->id())
    ->where('status', IndicatorReviewTaskStatusEnum::PENDING)
    ->get();

Level-specific Queries

// Get all Level 1 verification tasks
$level1Tasks = IndicatorReviewTask::where('verification_level', 1)->get();
// Eager load for performance
$tasks = IndicatorReviewTask::with([
    'submission.task.indicator',
    'submission.task.entrepreneur',
    'submission.task.organisation',
    'review' // If completed
])->get();

Important Notes

  • Review tasks are created automatically by event listeners, not manually
  • The verification level determines the approval workflow progression
  • If no verifiers are available for a level, that level is skipped
  • User scoping is critical for proper visibility control in Filament interface
  • Completed tasks maintain their assignment for audit purposes
  • The relationship with IndicatorSubmissionReview provides access to the actual verification decision and feedback