5.2.4 RecommendationsTable API Reference
Last Updated: December 4, 2025
Status: Complete
Plugin: Awards
Source: plugins/Awards/src/Model/Table/RecommendationsTable.php
Overview
The RecommendationsTable class provides comprehensive data management for award recommendations within the Awards plugin. It implements a complex state machine, workflow management, and extensive association relationships for managing the complete recommendation lifecycle from submission through approval to award presentation.
Class Definition
namespace Awards\Model\Table;
class RecommendationsTable extends BaseTable
Database Table
- Table Name:
awards_recommendations - Display Field:
member_sca_name - Primary Key:
id
State Machine Integration
The table implements a sophisticated state machine for recommendation workflow:
- Automated State Transitions: Via
afterSave()lifecycle hooks - State Change Logging: Through
RecommendationsStatesLogsintegration - Dual Tracking: Status and state for comprehensive workflow management
- Transaction-Safe: State changes with audit trail and accountability
Associations
BelongsTo
| Association | Foreign Key | Join Type | Class Name | Description |
|---|---|---|---|---|
| Requesters | requester_id |
LEFT | Members |
Recommendation submitter |
| Members | member_id |
LEFT | Members |
Recommended member |
| ScheduledEvent | event_id |
LEFT | Awards.Events |
Scheduled event |
| AssignedEvent | event_id |
LEFT | Awards.Events |
Ceremony assignment |
| AssignedGathering | gathering_id |
LEFT | Gatherings |
Gathering assignment |
| Branches | branch_id |
- | Branches |
Organizational scope |
| Awards | award_id |
INNER | Awards.Awards |
Required award |
BelongsToMany
| Association | Join Table | Foreign Key | Target Foreign Key | Class Name |
|---|---|---|---|---|
| Events | awards_recommendations_events |
recommendation_id |
event_id |
Awards.Events |
| Gatherings | awards_recommendations_events |
recommendation_id |
gathering_id |
Gatherings |
HasMany
| Association | Foreign Key | Class Name | Conditions |
|---|---|---|---|
| Notes | entity_id |
Notes |
entity_type = 'Awards.Recommendations' |
| RecommendationStateLogs | recommendation_id |
Awards.RecommendationsStatesLog |
- |
Behaviors
| Behavior | Configuration | Purpose |
|---|---|---|
| Timestamp | - | Automatic created/modified field management |
| Muffin/Footprint.Footprint | - | User attribution tracking |
| Muffin/Trash.Trash | - | Soft deletion support |
| Sortable | field: 'stack_rank' |
Stack ranking for prioritization |
Validation Rules
Field Validations
| Field | Rules |
|---|---|
requester_id |
Optional, integer |
member_id |
Optional, integer |
branch_id |
Optional, integer |
award_id |
Required, integer, not empty |
requester_sca_name |
Required, scalar, max 255 characters, not empty |
member_sca_name |
Required, scalar, max 255 characters, not empty |
contact_email |
Required, scalar, max 255 characters, not empty |
contact_number |
Optional, scalar, max 100 characters |
reason |
Required, scalar, max 10,000 characters, not empty |
created_by |
Optional, integer |
modified_by |
Optional, integer |
deleted |
Optional, datetime |
given |
Optional, date |
Business Rules
| Rule | Error Field | Description |
|---|---|---|
| existsIn | requester_id |
Requester must exist in Members table |
| existsIn | member_id |
Member must exist in Members table |
| existsIn | branch_id |
Branch must exist in Branches table |
| existsIn | award_id |
Award must exist in Awards table |
Methods
afterSave
Lifecycle hook that detects state changes and triggers audit logging.
public function afterSave($created, $entity, $options): void
Monitors the state field for changes and calls logStateChange() when transitions occur.
logStateChange
Creates audit trail records for state transitions.
protected function logStateChange($entity): void
Records:
from_state/to_state: State transitionfrom_status/to_status: Status transitioncreated_by: User who made the change- Uses “New” as fallback for initial states
addBranchScopeQuery
Applies branch-based filtering to queries.
public function addBranchScopeQuery(SelectQuery $query, array $branchIDs): SelectQuery
Parameters:
$query- The query to modify$branchIDs- Array of branch IDs to filter by
Returns: Query filtered to awards within specified branches.
Usage Examples
Recommendation Submission
$recommendationsTable = TableRegistry::getTableLocator()->get('Awards.Recommendations');
$recommendation = $recommendationsTable->newEmptyEntity();
$recommendation = $recommendationsTable->patchEntity($recommendation, [
'requester_sca_name' => 'Duke John',
'member_sca_name' => 'Lady Jane',
'contact_email' => 'duke.john@example.com',
'award_id' => 1,
'reason' => 'Outstanding service to the realm...',
'state' => 'submitted',
'status' => 'pending'
]);
if ($recommendationsTable->save($recommendation)) {
// State change automatically logged
}
State Transition Processing
$recommendation = $recommendationsTable->get($recommendationId);
$recommendation->beforeState = $recommendation->state;
$recommendation->beforeStatus = $recommendation->status;
$recommendation = $recommendationsTable->patchEntity($recommendation, [
'state' => 'approved',
'status' => 'approved',
'modified_by' => $userId
]);
$recommendationsTable->save($recommendation); // Triggers automatic logging
Workflow Processing
// Find recommendations for processing
$pendingRecommendations = $recommendationsTable->find()
->where(['state' => 'submitted'])
->contain(['Awards', 'Members', 'Requesters'])
->orderBy(['created' => 'ASC'])
->toArray();
// Event assignment processing
$eventRecommendations = $recommendationsTable->find()
->innerJoinWith('Events')
->where(['Events.start_date <=' => date('Y-m-d')])
->where(['Events.end_date >=' => date('Y-m-d')])
->toArray();
Administrative Operations
// Branch-scoped recommendation discovery
$branchRecommendations = $recommendationsTable->find()
->innerJoinWith('Awards.Branches')
->where(['Awards.branch_id IN' => $authorizedBranchIds])
->contain(['RecommendationStateLogs'])
->toArray();
// Sortable stack ranking
$recommendationsTable->moveUp($recommendation, 3);
$recommendationsTable->moveDown($recommendation, 1);
Integration Points
Awards System Integration
- Award-specific recommendation validation and processing
- Integration with award hierarchy and organizational structure
- Administrative coordination for award presentation
Event Management Integration
- Event-based recommendation processing and ceremony coordination
- Temporal constraint management through event associations
- Administrative tools for recommendation-event assignment
State Logging Integration
- Comprehensive audit trail through
RecommendationsStatesLogs - Automated state change logging with user accountability
- Administrative oversight through state transition history
Member Management Integration
- Member-specific recommendation processing
- Support for both authenticated and guest submissions
- Integration with member profiles
Security Considerations
Data Integrity
- Validation rules ensuring proper recommendation data
- Foreign key constraints maintaining referential integrity
- Soft deletion preserving workflow and audit integrity
Access Control
- Integration with authorization policies for branch-scoped management
- Permission-based recommendation processing
- Administrative oversight for workflows
Schema Reference
CREATE TABLE awards_recommendations (
id INT AUTO_INCREMENT PRIMARY KEY,
requester_id INT NULL,
member_id INT NULL,
branch_id INT NULL,
award_id INT NOT NULL,
event_id INT NULL,
gathering_id INT NULL,
requester_sca_name VARCHAR(255) NOT NULL,
member_sca_name VARCHAR(255) NOT NULL,
contact_email VARCHAR(255) NOT NULL,
contact_number VARCHAR(100) NULL,
reason TEXT NOT NULL,
state VARCHAR(50),
status VARCHAR(50),
stack_rank INT NULL,
given DATE NULL,
created_by INT NULL,
modified_by INT NULL,
created DATETIME,
modified DATETIME,
deleted DATETIME NULL,
FOREIGN KEY (requester_id) REFERENCES members(id),
FOREIGN KEY (member_id) REFERENCES members(id),
FOREIGN KEY (branch_id) REFERENCES branches(id),
FOREIGN KEY (award_id) REFERENCES awards_awards(id),
FOREIGN KEY (event_id) REFERENCES awards_events(id)
);