/workflow/engine/services/rest/crud/Translation.php

https://bitbucket.org/ferOnti/processmaker · PHP · 143 lines · 93 code · 18 blank · 32 comment · 9 complexity · 890b4b550dc5e085b5cd3d72d7128f1a MD5 · raw file

  1. <?php
  2. class Services_Rest_Translation
  3. {
  4. /**
  5. * Implementation for 'GET' method for Rest API
  6. *
  7. * @param mixed $trnCategory, $trnId, $trnLang Primary key
  8. *
  9. * @return array $result Returns array within multiple records or a single record depending if
  10. * a single selection was requested passing id(s) as param
  11. */
  12. protected function get($trnCategory=null, $trnId=null, $trnLang=null)
  13. {
  14. $result = array();
  15. try {
  16. $noArguments = true;
  17. $argumentList = func_get_args();
  18. foreach ($argumentList as $arg) {
  19. if (!is_null($arg)) {
  20. $noArguments = false;
  21. }
  22. }
  23. if ($noArguments) {
  24. $criteria = new Criteria('workflow');
  25. $criteria->addSelectColumn(TranslationPeer::TRN_CATEGORY);
  26. $criteria->addSelectColumn(TranslationPeer::TRN_ID);
  27. $criteria->addSelectColumn(TranslationPeer::TRN_LANG);
  28. $criteria->addSelectColumn(TranslationPeer::TRN_VALUE);
  29. $criteria->addSelectColumn(TranslationPeer::TRN_UPDATE_DATE);
  30. $dataset = AppEventPeer::doSelectRS($criteria);
  31. $dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
  32. while ($dataset->next()) {
  33. $result[] = $dataset->getRow();
  34. }
  35. } else {
  36. $record = TranslationPeer::retrieveByPK($trnCategory, $trnId, $trnLang);
  37. if ($record) {
  38. $result = $record->toArray(BasePeer::TYPE_FIELDNAME);
  39. } else {
  40. $paramValues = "";
  41. foreach ($argumentList as $arg) {
  42. $paramValues .= (strlen($paramValues) ) ? ', ' : '';
  43. if (!is_null($arg)) {
  44. $paramValues .= "$arg";
  45. } else {
  46. $paramValues .= "NULL";
  47. }
  48. }
  49. throw new RestException(417, "table Translation ($paramValues)" );
  50. }
  51. }
  52. } catch (RestException $e) {
  53. throw new RestException($e->getCode(), $e->getMessage());
  54. } catch (Exception $e) {
  55. throw new RestException(412, $e->getMessage());
  56. }
  57. return $result;
  58. }
  59. /**
  60. * Implementation for 'POST' method for Rest API
  61. *
  62. * @param mixed $trnCategory, $trnId, $trnLang Primary key
  63. *
  64. * @return array $result Returns array within multiple records or a single record depending if
  65. * a single selection was requested passing id(s) as param
  66. */
  67. protected function post($trnCategory, $trnId, $trnLang, $trnValue, $trnUpdateDate)
  68. {
  69. try {
  70. $result = array();
  71. $obj = new Translation();
  72. $obj->setTrnCategory($trnCategory);
  73. $obj->setTrnId($trnId);
  74. $obj->setTrnLang($trnLang);
  75. $obj->setTrnValue($trnValue);
  76. $obj->setTrnUpdateDate($trnUpdateDate);
  77. $obj->save();
  78. } catch (Exception $e) {
  79. throw new RestException(412, $e->getMessage());
  80. }
  81. }
  82. /**
  83. * Implementation for 'PUT' method for Rest API
  84. *
  85. * @param mixed $trnCategory, $trnId, $trnLang Primary key
  86. *
  87. * @return array $result Returns array within multiple records or a single record depending if
  88. * a single selection was requested passing id(s) as param
  89. */
  90. protected function put($trnCategory, $trnId, $trnLang, $trnValue, $trnUpdateDate)
  91. {
  92. try {
  93. $obj = TranslationPeer::retrieveByPK($trnCategory, $trnId, $trnLang);
  94. $obj->setTrnValue($trnValue);
  95. $obj->setTrnUpdateDate($trnUpdateDate);
  96. $obj->save();
  97. } catch (Exception $e) {
  98. throw new RestException(412, $e->getMessage());
  99. }
  100. }
  101. /**
  102. * Implementation for 'DELETE' method for Rest API
  103. *
  104. * @param mixed $trnCategory, $trnId, $trnLang Primary key
  105. *
  106. * @return array $result Returns array within multiple records or a single record depending if
  107. * a single selection was requested passing id(s) as param
  108. */
  109. protected function delete($trnCategory, $trnId, $trnLang)
  110. {
  111. $conn = Propel::getConnection(TranslationPeer::DATABASE_NAME);
  112. try {
  113. $conn->begin();
  114. $obj = TranslationPeer::retrieveByPK($trnCategory, $trnId, $trnLang);
  115. if (! is_object($obj)) {
  116. throw new RestException(412, 'Record does not exist.');
  117. }
  118. $obj->delete();
  119. $conn->commit();
  120. } catch (Exception $e) {
  121. $conn->rollback();
  122. throw new RestException(412, $e->getMessage());
  123. }
  124. }
  125. }