Properties Documentation
Properties Controller Documentation
File: /controllers/propertiesController.php
Purpose: Manages system properties, permissions, and user group access rights
Last Updated: December 20, 2024
Total Functions: 4
Lines of Code: 228
---
๐ Overview
The Properties Controller is a system administration module that handles application properties, permissions, and user group access control. It provides:
- โข System property definition and management
- โข User group permission assignment
- โข Property inheritance and defaults
- โข Multi-language property support
- โข Bulk permission operations
- โข Property-based access control
- โข Dynamic permission matrix
Primary Functions
- โ System property creation and editing
- โ User group permission assignment
- โ Property default value management
- โ Multi-language property names
- โ Bulk permission updates
- โ Property hierarchy management
- โ Access control matrix
- โ Permission inheritance
Related Controllers
- โข firms.php - Company management
- โข propertyrightsreport.php - Property rights reporting
---
๐๏ธ Database Tables
Primary Tables (Direct Operations)
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **properties** | System property definitions | propertyid, propertyname, propertyname_en, propertyurl, propertyparent, propertydefault | |
| **relusergroupproperties** | User group property permissions | propertyid, usergroupid, propertyvalue | |
| **usergroup** | User group definitions | usergroupid, usergroupname, description |
๐ Key Functions
1. Default Action / Property Management - Property Administration Interface
Location: Line 73
Purpose: Display property management interface with existing properties
Process Flow:
1. Load all existing properties via loadproperity()
2. Assign property data to Smarty template
3. Display via propertiesview/add.html
4. Provide interface for adding new properties
Function Signature:
// Triggered when: $do is empty (default action)
$propertiesData = loadproperity();
$smarty->assign("propertiesData", $propertiesData);
Features:
- โข View all system properties
- โข Add new property form
- โข Property listing with hierarchy
- โข Multi-language support
---
2. add() - Create New System Property
Location: Line 84
Purpose: Add new system property with automatic user group permission setup
Function Signature:
elseif ($do == "add")
// Called via: POST request with property data
Process Flow:
1. Validate and extract POST data
2. Create new property record
3. Query all existing user groups
4. Auto-assign property to all user groups with default value
5. Handle success/error redirection
Property Creation Logic:
$myProperities->propertyname = $propertyName;
$myProperities->propertyparent = $propertyParent;
$myProperities->propertydefault = $propertyDefault;
$myProperities->propertyurl = $propertyurl;
$myProperities->propertyname_en = $propertyname_en;
$propertyId = $myProperitiesRecord->insert($myProperities);
Auto-Assignment Process:
foreach ($usergroupData as $usergroup) {
$myRelusergroup->propertyid = $propertyId;
$myRelusergroup->usergroupid = $usergroupId;
$myRelusergroup->propertyvalue = $propertyDefault;
$myRelusergroupRecord->insert($myRelusergroup);
}
---
3. show() - Property Listing View
Location: Line 106
Purpose: Display all properties in listing format
Process Flow:
1. Query all properties from database
2. Load property data for form population
3. Display via propertiesview/add.html (same template as default)
---
4. edit() / update() - Property Modification
Location: Line 118 (edit), Line 129 (update)
Purpose: Edit existing property details
Edit Process Flow:
$theid = $_GET['id'];
$getallpropwithid = $myProperitiesRecord->load($theid);
$smarty->assign("getallpropwithid", $getallpropwithid);
Update Process Flow:
$newprop = new Propertie;
$newprop->propertyid = $idprp;
$newprop->propertyname = $nameprp;
$newprop->propertyurl = $urlprp;
$myProperitiesRecord->updates($newprop);
---
๐ Workflows
Workflow 1: New Property Creation
---
Workflow 2: Property Permission Management
---
๐ URL Routes & Actions
| URL Parameter | Function Called | Description | |
|---|---|---|---|
| `do=` (empty) | Default action | Property management interface | |
| `do=add` | `add()` | Create new property | |
| `do=show` | `show()` | List all properties | |
| `do=edit` | `edit()` | Edit property form | |
| `do=update` | `update()` | Update property data | |
| `do=sucess` | Success page | Operation completed | |
| `do=error` | Error page | Operation failed |
Add Property (do=add):
- โข
propertyname- Property name (Arabic) - โข
propertyname_en- Property name (English) - โข
propertyparent- Parent property ID - โข
propertydefault- Default permission value - โข
propertyurl- Controller URL
Edit Property (do=edit):
- โข
id- Property ID to edit
Update Property (do=update):
- โข
propertyid- Property ID - โข
propertyname- Updated name - โข
propertyurl- Updated URL
---
๐ Security & Permissions
Access Control
// Authentication required for all operations
// include_once("../public/authentication.php");
Input Sanitization
- โข All POST data accessed through
$_POSTarrays - โข Property IDs cast to integers where appropriate
- โข SQL injection prevention via DAO layer
Permission Inheritance
- โข New properties auto-assigned to all user groups
- โข Default values applied consistently
- โข Hierarchical permission structure supported
---
๐ Performance Considerations
Database Optimization Tips
1. Indexes Required:
- properties(propertyparent)
- relusergroupproperties(propertyid, usergroupid)
- usergroup(usergroupid)
2. Query Optimization:
- Batch inserts for user group assignments
- Efficient property hierarchy queries
- Minimal database calls in loops
Memory Management
- โข Large user group counts may impact auto-assignment
- โข Property hierarchy depth should be limited
- โข Consider caching for frequently accessed properties
---
๐ Common Issues & Troubleshooting
1. Property Auto-Assignment Failures
Issue: New properties not assigned to all user groups
Cause: Transaction failures or missing user groups
Debug:
// Check user group count
$usergroupData = $myUserGroupRecord->queryAll();
echo "User groups found: " . count($usergroupData);
// Verify assignments after creation
$assignments = $myRelusergroupRecord->queryByPropertyId($propertyId);
2. Property Hierarchy Issues
Issue: Parent-child relationships not working
Cause: Circular references or invalid parent IDs
Debug:
-- Check for circular references
WITH RECURSIVE prop_tree AS (
SELECT propertyid, propertyparent, 1 as level
FROM properties WHERE propertyparent = 0
UNION ALL
SELECT p.propertyid, p.propertyparent, pt.level + 1
FROM properties p
JOIN prop_tree pt ON p.propertyparent = pt.propertyid
WHERE pt.level < 10
)
SELECT * FROM prop_tree WHERE level > 5;
3. Permission Matrix Performance
Issue: Slow loading with many properties/groups
Cause: N+1 query problems or missing indexes
Solution:
- โข Implement JOIN-based queries for permission matrix
- โข Add database indexes on foreign key columns
- โข Consider pagination for large permission sets
---
๐งช Testing Scenarios
Test Case 1: Property Creation
1. Access property management interface
2. Fill out new property form
3. Submit and verify success redirect
4. Check property appears in listing
5. Verify all user groups have default permission
Test Case 2: Property Hierarchy
1. Create parent property
2. Create child property with parent reference
3. Verify hierarchy displays correctly
4. Test permission inheritance
Test Case 3: Permission Management
1. Access permission matrix
2. Change property permissions for user group
3. Verify changes saved correctly
4. Test user access with new permissions
Test Case 4: Multi-language Support
1. Create property with Arabic and English names
2. Verify both names stored correctly
3. Test display in different language contexts
---
๐ Related Documentation
- โข CLAUDE.md - PHP 8.2 migration guide
- โข propertyrightsreport.md - Property rights reporting
- โข User Group Management - User group administration
---
Documented By: AI Assistant
Review Status: โ Complete
Next Review: When major changes occur