PackageItem.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace MGModule\DNSManager2\models\custom\package\item;
  3. use \Exception;
  4. use \MGModule\DNSManager2 as main;
  5. /**
  6. * Log class
  7. *
  8. * @Table(name=packageitem)
  9. */
  10. class PackageItem extends main\mgLibs\models\orm
  11. {
  12. /**
  13. * ID field
  14. *
  15. * @Column(id)
  16. * @var int
  17. */
  18. public $id;
  19. /**
  20. *
  21. * @Column(int=11, refrence=models\custom\package\Package::id,uniqueKey=1,isKey=1)
  22. * @var int
  23. */
  24. public $packageid;
  25. /**
  26. *
  27. * @Column(int,uniqueKey=1,isKey=1)
  28. * @var string
  29. */
  30. public $type;
  31. /**
  32. *
  33. * @Column(varchar,uniqueKey=1,isKey=1)
  34. * @var string
  35. */
  36. public $relid;
  37. /**
  38. *
  39. * @Column(int)
  40. * @var string
  41. */
  42. public $limit;
  43. public function setType($type) {
  44. if(!PackageItemTypeEnum::isValidValue($type))
  45. throw new Exception ("Wrong type provided");
  46. $this->type = $type;
  47. }
  48. public function save($data = array()) {
  49. if(!PackageItemTypeEnum::isValidValue($this->type)) {
  50. throw new Exception('Invalid Package Item Type ('. $this->type .')');
  51. }
  52. parent::save($data);
  53. }
  54. public function getPackage() {
  55. return new main\models\custom\package\Package($this->packageid);
  56. }
  57. public function getRelatedItem() {
  58. switch ($this->type) {
  59. case PackageItemTypeEnum::DOMAIN:
  60. return main\models\whmcs\domains\pricing\repository::factory()->byExtension($this->relid)->one();
  61. case PackageItemTypeEnum::PRODUCT:
  62. return main\models\whmcs\product\product::factory($this->relid);
  63. case PackageItemTypeEnum::ADDON:
  64. return main\models\whmcs\addon\addon::factory($this->relid);
  65. case PackageItemTypeEnum::OTHER:
  66. return new main\mgLibs\custom\relateditem\Other();
  67. }
  68. }
  69. }