CateResturant Documentation
Restaurant Category Controller Documentation
File: /controllers/cateResturantController.php
Purpose: Manages restaurant category configuration and product assignments for restaurant operations
Last Updated: December 20, 2024
Total Functions: 3
Lines of Code: ~315
---
๐ Overview
The Restaurant Category Controller is a specialized module for configuring restaurant product categories and their assignments. It handles:
- โข Restaurant category configuration display
- โข Product assignment to restaurant categories
- โข Category and product data management
- โข Restaurant-specific product catalog setup
- โข YouTube tutorial link integration
- โข Category hierarchy management for restaurant operations
Primary Functions
- โ Display restaurant category configuration interface
- โ Assign products to restaurant categories (up to 3 categories)
- โ Load and display product lists for assignment
- โ Category hierarchy management
- โ Product catalog integration
- โ YouTube tutorial integration
- โ Success/error handling for category updates
Related Controllers
- โข productCatController.php - Product category management
- โข productController.php - Product management
- โข restauranthall.php - Restaurant hall management
- โข restauranttable.php - Restaurant table management
---
๐๏ธ Database Tables
Primary Tables (Direct Operations)
| Table Name | Purpose | Key Columns |
|---|---|---|
| **resturantcategory** | Restaurant category assignments | id, categoryId, productId, date |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **productcat** | Product categories | productCatId, productCatName, parentExt | |
| **product** | Product master data | productId, productName, productCatId | |
| **youtubelink** | Tutorial videos | youtubelinkid, title, url | |
| **programsettings** | System configuration | programsettingsid, settingkey, settingvalue |
| Table Name | Purpose | Key Columns | |
|---|---|---|---|
| **sellbill** | Sales bills | sellbillid, sellbillclientid, sellbilltotalbill | |
| **returnsellbill** | Sales returns | returnsellbillid, returnsellbillclientid | |
| **sellbillandrutern** | Combined bills | sellbillid, sellbillclientid, sellbillprice | |
| **billsproduct** | Bill products | billsproductid, productid, quantity | |
| **billsreturnproduct** | Return products | billsreturnproductid, productid, quantity |
๐ Key Functions
1. show() / Default Action - Restaurant Category Configuration Display
Location: Line 188
Purpose: Display the restaurant category configuration interface with products and categories
Process Flow:
1. Include authentication check
2. Set default date parameters
3. Load category hierarchy via getCategoryChilds()
4. Load all products for assignment
5. Load YouTube tutorial links
6. Display via cateResturantview/show.html template
Template Variables:
- โข
$catDataReport- Category hierarchy data - โข
$products- Available products for assignment - โข
$youtubes- Tutorial video links
---
2. add() - Restaurant Category Assignment
Location: Line 276
Purpose: Process restaurant category assignments for up to 3 categories
Function Signature:
function add()
Process Flow:
1. Get current date
2. Process three category/product pairs:
- productCatId1 / productSearchId1
- productCatId2 / productSearchId2
- productCatId3 / productSearchId3
3. For each pair:
- Create new Resturantcategory object
- Set category and product IDs
- Set current date
- Set fixed ID (1, 2, or 3)
- Update via DAO
Assignment Logic:
$resturantCategory = new Resturantcategory();
$resturantCategory->categoryId = $productCatId1;
$resturantCategory->productId = $productSearchId1;
$resturantCategory->date = $startDate;
$resturantCategory->id = 1;
$ResturantCategoryDAO->update($resturantCategory);
---
3. getAllSubCat() - Category Hierarchy Navigation
Location: Line 237
Purpose: Recursively traverse product category hierarchy
Function Signature:
function getAllSubCat($catid, $mode)
Parameters:
- โข
$catid- Parent category ID - โข
$mode- Operation mode:
- 1 - Get all sub-categories
- 2 - Get last level categories only
Process Flow:
1. Query child categories for given parent
2. For each child:
- If mode 1: Add to category ID list and recurse
- If mode 2: Check if leaf node, add to last level list
3. Continue recursively until all levels processed
Global Variables Used:
- โข
$catsIDS- Comma-separated category ID list - โข
$lastLevelCatIDS- Array of leaf category IDs
---
๐ Workflows
Workflow 1: Restaurant Category Configuration
---
๐ URL Routes & Actions
| URL Parameter | Function Called | Description | |
|---|---|---|---|
| `do=` (empty) or `do=show` | Default action | Display category configuration interface | |
| `do=add` | `add()` | Process category assignments | |
| `do=sucess` | N/A | Display success message | |
| `do=error` | N/A | Display error message |
Category Configuration Display (do=show):
- โข No parameters required
- โข Loads all available categories and products
Process Assignments (do=add):
- โข
productCatId1- Category ID for first assignment - โข
productId1- Product ID for first assignment - โข
productCatId2- Category ID for second assignment - โข
productId2- Product ID for second assignment - โข
productCatId3- Category ID for third assignment - โข
productId3- Product ID for third assignment
---
๐งฎ Calculation Methods
Category Assignment Logic
// Process three fixed assignments
for ($i = 1; $i <= 3; $i++) {
$resturantCategory = new Resturantcategory();
$resturantCategory->categoryId = $_POST["productCatId{$i}"];
$resturantCategory->productId = $_REQUEST["productId{$i}"];
$resturantCategory->date = date('Y-m-d');
$resturantCategory->id = $i;
$ResturantCategoryDAO->update($resturantCategory);
}
Category Hierarchy Traversal
function getAllSubCat($catid, $mode) {
$result = $productCatExt->queryByParentExt($catid);
if (count($result) > 0) {
foreach ($result as $data) {
if ($mode == 1) {
$catsIDS .= "," . $data->productCatId;
getAllSubCat($data->productCatId, $mode);
} elseif ($mode == 2) {
$childData = $productCatExt->queryByParentExt($data->productCatId);
if (count($childData) == 0) {
array_push($lastLevelCatIDS, $data->productCatId);
} else {
getAllSubCat($data->productCatId, $mode);
}
}
}
}
}
---
๐ Security & Permissions
Authentication Requirements
include_once("../public/authentication.php");
Input Sanitization
- โข All
$_POSTand$_REQUESTparameters processed through framework - โข Numeric IDs used for database operations
- โข Date validation using PHP date functions
Data Validation
- โข Category and product existence verified through DAO queries
- โข Fixed assignment IDs (1, 2, 3) prevent ID manipulation
- โข Update operations use existing record structure
---
๐ Performance Considerations
Database Optimization Tips
1. Indexes Required:
- resturantcategory(categoryId, productId)
- productcat(parentExt) for hierarchy queries
- product(productCatId) for category filtering
2. Query Optimization:
- Category hierarchy loaded once per page
- Product list cached in template
- Limited to 3 assignments reduces update overhead
3. Memory Management:
- Minimal data processing
- Simple object creation and updates
- No complex calculations or loops
---
๐ Common Issues & Troubleshooting
1. Category Assignment Failures
Issue: Category assignments not saving properly
Cause: Missing product or category IDs in POST data
Debug:
var_dump($_POST['productCatId1'], $_REQUEST['productId1']);
2. Category Hierarchy Loading Issues
Issue: Categories not displaying in interface
Cause: Recursive function stack overflow or missing parent references
Fix:
// Add depth limit to recursive function
function getAllSubCat($catid, $mode, $depth = 0) {
if ($depth > 10) return; // Prevent infinite recursion
// ... existing code
getAllSubCat($data->productCatId, $mode, $depth + 1);
}
3. Product Loading Performance
Issue: Slow page load when many products exist
Cause: Loading all products without pagination
Solution:
- โข Implement product search/filtering
- โข Add AJAX-based product selection
- โข Use pagination for large product lists
---
๐งช Testing Scenarios
Test Case 1: Basic Category Assignment
1. Access category configuration page
2. Select 3 different categories
3. Assign 3 different products
4. Submit assignments
5. Verify database updates
6. Check success page display
Test Case 2: Category Hierarchy Navigation
1. Load page with multi-level categories
2. Verify hierarchy displays correctly
3. Test category selection from different levels
4. Confirm parent-child relationships maintained
Test Case 3: Error Handling
1. Submit form with missing data
2. Verify error handling
3. Test with invalid category/product IDs
4. Confirm graceful error messages
---
๐ Related Documentation
- โข CLAUDE.md - PHP 8.2 migration guide
- โข productCatController.md - Product category management
- โข productController.md - Product operations
- โข Restaurant Module Documentation - Complete restaurant system
---
Documented By: AI Assistant
Review Status: โ Complete
Next Review: When restaurant module changes occur