ConfigOptionsHelper.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace ThurData\Servers\KerioEmail\Core\Helper;
  3. use ThurData\Servers\KerioEmail\Core\FileReader\Reader;
  4. use ThurData\Servers\KerioEmail\Core\ServiceLocator;
  5. use WHMCS\Database\Capsule;
  6. /**
  7. * Autometes some of database queries
  8. *
  9. * @author
  10. */
  11. class ConfigOptionsHelper
  12. {
  13. /**
  14. * Helper to perform Configurable Options queries for module
  15. *
  16. * @param int $productID
  17. * @param string $optionName
  18. * @return Object
  19. */
  20. public function getConfigurableOption(int $productID, string $optionName) {
  21. $configOption = Capsule::table('tblproductconfigoptions')
  22. ->join('tblhostingconfigoptions', 'tblproductconfigoptions.id', '=', 'tblhostingconfigoptions.configid')
  23. ->where('tblhostingconfigoptions.relid', '=', $productID)
  24. ->where('tblproductconfigoptions.optionname', 'like', $optionName.'%')
  25. ->select('*')
  26. ->get();
  27. return $configOption->pull(0);
  28. }
  29. /**
  30. * Helper to perform Configurable Options queries for module
  31. *
  32. * @param int $optionID
  33. * @param array $optionValues
  34. * @return bool
  35. */
  36. public function updateConfigurableOption(int $optionID, array $optionValues) {
  37. try {
  38. $updateOption = Capsule::table('tblhostingconfigoptions')
  39. ->where('id', $optionID)
  40. ->update($optionValues);
  41. } catch (\Exception $e) {
  42. logModuleCall(
  43. 'kerioEmail',
  44. __FUNCTION__,
  45. $updateOption,
  46. 'Error: could not update option ' . $optionID .' in database.',
  47. $e->getMessage()
  48. );
  49. return false;
  50. }
  51. return true;
  52. }
  53. }