StudentSettings Documentation
Student Settings Controller Documentation
File: /controllers/studentSettings.php
Purpose: Manages student system settings, payment configurations, and administrative controls
Last Updated: December 21, 2024
Total Functions: 3
Lines of Code: ~419
---
๐ Overview
The Student Settings Controller handles the configuration and administration of the student management system. It provides functionality for:
- โข Payment system configuration (multiple payment options)
- โข Payment period settings (1-8 months, yearly)
- โข Student/player type selection
- โข Welcome message management
- โข User group permissions for payment editing/deletion
- โข Payment plan creation and management
- โข Bulk payment settings import
- โข Excel data import capabilities (commented out)
Primary Functions
- โ Configure payment systems (up to 3 different systems)
- โ Manage payment periods (monthly to yearly)
- โ Set student vs player designation
- โ Configure welcome messages
- โ Manage payment plan settings
- โ Handle user group permissions
- โ Process payment setting updates
- โ Support bulk payment configurations
Related Controllers
- โข studentSubjectsController.php - Subject management
- โข studentsAddSubject.php - Student-subject assignments
- โข studentsExamsController.php - Exam management
- โข studentAbsence.php - Attendance tracking
---
๐๏ธ Database Tables
Primary Tables (Direct Operations)
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **studentsetting** | Main system settings | studentsettingid, studentorplayer, paymentsystems1-3, payonemonths-payeightmonths, payyear, welcomemessage, studentaddsubjectid, showdel | |
| **studentsettingpays** | Payment plan configurations | studentsettingpayid, name, countmonths, price, stopping, addtoday, adduserid | |
| **usergroup** | User permission groups | usergroupid, groupname, permissions |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **studentaddsubjects** | Student-subject assignments | studentaddsubjectid, studentsubjectid, studentsubjectgroupid | |
| **studentsubjects** | Available subjects | studentsubjectid, subjectname, subjectprice | |
| **studentsubjectgroups** | Subject group classifications | studentsubjectgroupid, subjectgroupname, subjectgroupprice | |
| **user** | System users | userid, username, usergroupid |
๐ Key Functions
1. Default Action - Settings Management Interface
Location: Lines 8-107
Purpose: Main settings configuration interface and update processing
Function Signature:
// Triggered when: empty $do
$studentsetting = R::load('studentsetting', 1);
$studentsettingpaysitr = filter_input(INPUT_POST, 'studentsettingpaysitr');
Process Flow:
1. Load main settings record (ID=1)
2. Load user groups for permission assignment
3. Process payment plan iterations
4. Create or update payment plans
5. Update main settings if studentsettingid = 1
6. Load related subject/group data
7. Display settings form
Payment Plan Processing:
for ($i1 = 1; $i1 <= $studentsettingpaysitr; $i1++) {
$studentsettingpayid = filter_input(INPUT_POST, 'studentsettingpayid' . $i1);
if (!$studentsettingpayid) {
$studentsettingpayssave = R::dispense('studentsettingpays'); // New
} else {
$studentsettingpayssave = R::load('studentsettingpays', $studentsettingpayid); // Update
}
}
---
2. pays - Payment Plan Row Generator
Location: Lines 108-113
Purpose: Generate additional payment plan rows for dynamic form building
Function Signature:
// Triggered when: do=pays
$itr = filter_input(INPUT_POST, 'itr');
Process Flow:
1. Receive iteration count from AJAX
2. Assign iteration number to Smarty
3. Display payment row template
4. Return HTML for dynamic insertion
---
3. removeappend - Payment Plan Deletion
Location: Lines 114-120
Purpose: Remove payment plan configurations
Function Signature:
// Triggered when: do=removeappend
$id = filter_input(INPUT_POST, 'id');
Process Flow:
1. Load payment plan by ID
2. Permanently delete (R::trash)
3. Return success status (1)
---
4. studentsPay() - Payment Processing Function
Location: Lines 319-412
Purpose: Generate student payment records and update student payment status
Function Signature:
function studentsPay()
Process Flow:
1. Load all students from database
2. Find student subject details for each student
3. Calculate payment dates and amounts
4. Create payment records in studentspays table
5. Update student records with payment information
6. Handle payment period calculations
Payment Calculation Logic:
$paystartdate = $startdate;
$payenddate = date('Y-m-d', strtotime("+1 month", strtotime($startdate)));
$studentspaymentsystems = R::load('studentspaymentsystems', $student->parentsphone);
$paymonths = $studentspaymentsystems->paymentmonth;
$payprice = $studentspaymentsystems->paymentprice;
---
๐ Workflows
Workflow 1: Payment System Configuration
---
๐ URL Routes & Actions
| URL Parameter | Function Called | Description | |
|---|---|---|---|
| `do=` (empty) | Default action | Main settings configuration interface | |
| `do=pays` | Row generator | Generate additional payment plan rows | |
| `do=removeappend` | Delete function | Remove payment plan configuration | |
| `do=excel` | Import function | Excel data import (commented out) |
Main Settings (empty do):
- โข
studentsettingid- Settings record ID (must be 1) - โข
studentorplayer- Student/player designation - โข
paymentsystems1-3- Payment system flags - โข
payonemonthstopayeightmonths- Monthly payment amounts - โข
payyear- Yearly payment amount - โข
welcomemessage- Welcome text - โข
studentsettingpaysitr- Number of payment plans
Payment Plans (dynamic):
- โข
studentsettingpayid{N}- Payment plan ID - โข
name{N}- Payment plan name - โข
countmonths{N}- Number of months - โข
price{N}- Payment price - โข
stopping{N}- Stop flag
AJAX Actions:
- โข
itr- Iteration count for row generation - โข
id- Payment plan ID for deletion
---
๐งฎ Calculation Methods
Payment Period Configuration
// Multiple payment period options
$studentsetting->paythreemonths = $paythreemonths;
$studentsetting->paysixmonths = $paysixmonths;
$studentsetting->payeightmonths = $payeightmonths;
$studentsetting->paytwomonths = $paytwomonths;
$studentsetting->payonemonths = $payonemonths;
$studentsetting->payfourmonths = $payfourmonths;
$studentsetting->payyear = $payyear;
Payment System Selection
// Ensure at least one payment system is active
if (!$paymentsystems1 && !$paymentsystems2 && !$paymentsystems3) {
$paymentsystems1 = 1; // Default to system 1
}
Permission Array Processing
// Convert permission arrays to comma-separated strings
$studentsetting->showpayedit = 'aa,' . implode(",", $showpayedit);
$studentsetting->showpaydel = 'aa,' . implode(",", $showpaydel);
---
๐ Security & Permissions
User Permission Integration
$usergroup = R::getAll('select * from usergroup where 1');
$smarty->assign("usergroup", $usergroup);
Input Validation
- โข Payment price validation:
if (!$name || $price < 1) {continue;} - โข Settings ID validation:
if($studentsettingid == 1) - โข Filter input sanitization:
filter_input(INPUT_POST, 'fieldname')
Audit Trail
- โข All records include audit fields:
- addtoday - Creation timestamp
- adduserid - Creating user ID
- updatetoday - Last update timestamp
- updateuserid - Last updating user ID
---
๐ Performance Considerations
Database Optimization
1. Single Settings Record: Uses ID=1 for main settings (singleton pattern)
2. Efficient Queries: Direct loads by primary key
3. Minimal Joins: Simple table relationships
Memory Management
- โข Payment plan iteration controlled by form input
- โข Limited data loading (single settings record)
- โข Smarty template variable cleanup
Potential Issues
- โข Excel import functionality is commented out (lines 121-183)
- โข Large payment plan configurations may impact form processing
- โข Permission arrays stored as concatenated strings
---
๐ Common Issues & Troubleshooting
1. Settings Not Saving
Issue: Changes to settings don't persist
Cause: studentsettingid != 1 check fails
Debug:
// Verify settings ID
if($studentsettingid == 1) {
echo "Settings will be saved";
} else {
echo "Settings ID: " . $studentsettingid . " - must be 1";
}
2. Payment Plans Not Creating
Issue: Payment plans don't save despite form submission
Cause: Validation fails on name or price
Fix:
// Check validation logic
if (!$name || $price < 1) {
echo "Validation failed - Name: " . $name . " Price: " . $price;
continue;
}
3. Permission Arrays Empty
Issue: Permission settings reset to default
Cause: Array implode on non-array data
Fix:
// Ensure arrays exist before imploding
$showpayedit = isset($_POST['showpayedit']) && is_array($_POST['showpayedit'])
? $_POST['showpayedit'] : [];
---
๐งช Testing Scenarios
Test Case 1: Basic Settings Update
1. Navigate to student settings
2. Modify payment systems and periods
3. Update welcome message
4. Save settings
5. Verify changes persist after reload
Test Case 2: Payment Plan Management
1. Add new payment plan with valid data
2. Verify plan appears in list
3. Edit existing payment plan
4. Delete payment plan
5. Confirm deletion successful
Test Case 3: Permission Configuration
1. Set edit/delete permissions for user groups
2. Login as different user group
3. Verify permission enforcement
4. Test with multiple user groups
---
๐ Related Documentation
- โข CLAUDE.md - PHP 8.2 migration guide
- โข studentSubjectsController.md - Subject management
- โข studentsAddSubject.md - Student assignments
- โข Database Schema Documentation - Table relationships
---
Documented By: AI Assistant
Review Status: โ Complete
Next Review: When major changes occur