VendorCategoryModel.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\Models;
  3. use CodeIgniter\Model;
  4. class VendorCategoryModel extends Model
  5. {
  6. protected $table = 'vendor_categories';
  7. protected $primaryKey = 'id';
  8. protected $useAutoIncrement = true;
  9. protected $returnType = 'array';
  10. protected $useSoftDeletes = false;
  11. protected $allowedFields = [
  12. 'code', 'name_ko', 'name_en', 'description', 'sort_order', 'is_active'
  13. ];
  14. protected $useTimestamps = true;
  15. protected $createdField = 'created_at';
  16. protected $updatedField = null;
  17. protected $validationRules = [
  18. 'code' => 'required|max_length[50]|is_unique[vendor_categories.code,id,{id}]',
  19. 'name_ko' => 'required|max_length[100]',
  20. 'name_en' => 'permit_empty|max_length[100]',
  21. 'description' => 'permit_empty|max_length[65535]',
  22. 'sort_order' => 'permit_empty|integer',
  23. 'is_active' => 'permit_empty|in_list[0,1]'
  24. ];
  25. // 활성화된 카테고리만 조회
  26. public function getActiveCategories()
  27. {
  28. return $this->where('is_active', 1)
  29. ->orderBy('sort_order', 'ASC')
  30. ->findAll();
  31. }
  32. // 코드로 카테고리 조회
  33. public function getCategoryByCode($code)
  34. {
  35. return $this->where('code', $code)->first();
  36. }
  37. }