Skip to the content.

← Back to Awards Plugin

5.2.2 LevelsTable API Reference

Last Updated: December 4, 2025
Status: Complete
Plugin: Awards
Source: plugins/Awards/src/Model/Table/LevelsTable.php

Overview

The LevelsTable class provides comprehensive data management for award levels within the Awards plugin, implementing a hierarchical precedence system that organizes awards into distinct levels with clear ordering and organizational structure.

Class Definition

namespace Awards\Model\Table;

class LevelsTable extends BaseTable

Database Table

Hierarchical Organization

The LevelsTable implements a hierarchical system where each level represents a distinct tier in the award progression system:

Associations

HasMany

Association Foreign Key Class Name Description
Awards level_id Awards.Awards Links levels to multiple awards for hierarchical organization

Behaviors

Behavior Purpose
Timestamp Automatic created/modified field management
Muffin/Footprint.Footprint User attribution tracking (created_by/modified_by)
Muffin/Trash.Trash Soft deletion support via deleted field

Validation Rules

Field Validations

Field Rules
name Required, scalar, max 255 characters, not empty, must be unique
progression_order Optional, integer
created_by Optional, integer
modified_by Optional, integer
deleted Optional, datetime

Business Rules

Rule Error Field Description
isUnique name Level names must be unique system-wide

Methods

getAllLevelNames

Retrieves all award level names ordered by progression for hierarchical display.

public function getAllLevelNames(): array

Returns: Array of level names in hierarchical progression order.

Query Details:

Usage Examples

Basic Level Creation

// Create a new award level
$levelsTable = TableRegistry::getTableLocator()->get('Awards.Levels');
$level = $levelsTable->newEmptyEntity();
$level = $levelsTable->patchEntity($level, [
    'name' => 'Knight',
    'progression_order' => 3
]);

if ($levelsTable->save($level)) {
    // Level created successfully
}

Hierarchy Management

// Retrieve all levels in progression order
$levels = $levelsTable->find()
    ->where(['deleted IS' => null])
    ->orderBy(['progression_order' => 'ASC'])
    ->toArray();

// Get level names for organizational display
$levelNames = $levelsTable->getAllLevelNames();

Administrative Operations

// Update level progression order
$level = $levelsTable->get($levelId);
$level = $levelsTable->patchEntity($level, [
    'progression_order' => $newOrder
]);
$levelsTable->save($level);

// Soft delete level with referential integrity protection
$levelsTable->delete($level); // Uses Trash behavior

Precedence Analytics

// Find awards by level precedence
$awards = $levelsTable->Awards->find()
    ->innerJoinWith('Levels')
    ->orderBy(['Levels.progression_order' => 'ASC'])
    ->toArray();

Administrative Interface Population

// Populate dropdown for award creation forms
$levelNames = $levelsTable->getAllLevelNames();
$this->set('levelOptions', array_combine($levelNames, $levelNames));

Reporting Integration

// Generate level-based reports
$levelNames = $levelsTable->getAllLevelNames();
$reportData = [];
foreach ($levelNames as $levelName) {
    $reportData[$levelName] = $this->generateLevelStatistics($levelName);
}

Integration Points

Awards Management System

Domain System Integration

Reporting System Integration

Administrative Interface Integration

Security Considerations

Data Integrity

Access Control

Schema Reference

CREATE TABLE awards_levels (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(255) NOT NULL UNIQUE,
    progression_order INT NULL,
    created_by INT NULL,
    modified_by INT NULL,
    created DATETIME,
    modified DATETIME,
    deleted DATETIME NULL
);