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

https://bitbucket.org/ferOnti/processmaker · PHP · 166 lines · 116 code · 18 blank · 32 comment · 9 complexity · fcdaca3682e6eb2a1550e360cbc3ae46 MD5 · raw file

  1. <?php
  2. class Services_Rest_SubProcess
  3. {
  4. /**
  5. * Implementation for 'GET' method for Rest API
  6. *
  7. * @param mixed $spUid 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($spUid=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(SubProcessPeer::SP_UID);
  26. $criteria->addSelectColumn(SubProcessPeer::PRO_UID);
  27. $criteria->addSelectColumn(SubProcessPeer::TAS_UID);
  28. $criteria->addSelectColumn(SubProcessPeer::PRO_PARENT);
  29. $criteria->addSelectColumn(SubProcessPeer::TAS_PARENT);
  30. $criteria->addSelectColumn(SubProcessPeer::SP_TYPE);
  31. $criteria->addSelectColumn(SubProcessPeer::SP_SYNCHRONOUS);
  32. $criteria->addSelectColumn(SubProcessPeer::SP_SYNCHRONOUS_TYPE);
  33. $criteria->addSelectColumn(SubProcessPeer::SP_SYNCHRONOUS_WAIT);
  34. $criteria->addSelectColumn(SubProcessPeer::SP_VARIABLES_OUT);
  35. $criteria->addSelectColumn(SubProcessPeer::SP_VARIABLES_IN);
  36. $criteria->addSelectColumn(SubProcessPeer::SP_GRID_IN);
  37. $dataset = AppEventPeer::doSelectRS($criteria);
  38. $dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
  39. while ($dataset->next()) {
  40. $result[] = $dataset->getRow();
  41. }
  42. } else {
  43. $record = SubProcessPeer::retrieveByPK($spUid);
  44. if ($record) {
  45. $result = $record->toArray(BasePeer::TYPE_FIELDNAME);
  46. } else {
  47. $paramValues = "";
  48. foreach ($argumentList as $arg) {
  49. $paramValues .= (strlen($paramValues) ) ? ', ' : '';
  50. if (!is_null($arg)) {
  51. $paramValues .= "$arg";
  52. } else {
  53. $paramValues .= "NULL";
  54. }
  55. }
  56. throw new RestException(417, "table SubProcess ($paramValues)" );
  57. }
  58. }
  59. } catch (RestException $e) {
  60. throw new RestException($e->getCode(), $e->getMessage());
  61. } catch (Exception $e) {
  62. throw new RestException(412, $e->getMessage());
  63. }
  64. return $result;
  65. }
  66. /**
  67. * Implementation for 'POST' method for Rest API
  68. *
  69. * @param mixed $spUid Primary key
  70. *
  71. * @return array $result Returns array within multiple records or a single record depending if
  72. * a single selection was requested passing id(s) as param
  73. */
  74. protected function post($spUid, $proUid, $tasUid, $proParent, $tasParent, $spType, $spSynchronous, $spSynchronousType, $spSynchronousWait, $spVariablesOut, $spVariablesIn, $spGridIn)
  75. {
  76. try {
  77. $result = array();
  78. $obj = new SubProcess();
  79. $obj->setSpUid($spUid);
  80. $obj->setProUid($proUid);
  81. $obj->setTasUid($tasUid);
  82. $obj->setProParent($proParent);
  83. $obj->setTasParent($tasParent);
  84. $obj->setSpType($spType);
  85. $obj->setSpSynchronous($spSynchronous);
  86. $obj->setSpSynchronousType($spSynchronousType);
  87. $obj->setSpSynchronousWait($spSynchronousWait);
  88. $obj->setSpVariablesOut($spVariablesOut);
  89. $obj->setSpVariablesIn($spVariablesIn);
  90. $obj->setSpGridIn($spGridIn);
  91. $obj->save();
  92. } catch (Exception $e) {
  93. throw new RestException(412, $e->getMessage());
  94. }
  95. }
  96. /**
  97. * Implementation for 'PUT' method for Rest API
  98. *
  99. * @param mixed $spUid Primary key
  100. *
  101. * @return array $result Returns array within multiple records or a single record depending if
  102. * a single selection was requested passing id(s) as param
  103. */
  104. protected function put($spUid, $proUid, $tasUid, $proParent, $tasParent, $spType, $spSynchronous, $spSynchronousType, $spSynchronousWait, $spVariablesOut, $spVariablesIn, $spGridIn)
  105. {
  106. try {
  107. $obj = SubProcessPeer::retrieveByPK($spUid);
  108. $obj->setProUid($proUid);
  109. $obj->setTasUid($tasUid);
  110. $obj->setProParent($proParent);
  111. $obj->setTasParent($tasParent);
  112. $obj->setSpType($spType);
  113. $obj->setSpSynchronous($spSynchronous);
  114. $obj->setSpSynchronousType($spSynchronousType);
  115. $obj->setSpSynchronousWait($spSynchronousWait);
  116. $obj->setSpVariablesOut($spVariablesOut);
  117. $obj->setSpVariablesIn($spVariablesIn);
  118. $obj->setSpGridIn($spGridIn);
  119. $obj->save();
  120. } catch (Exception $e) {
  121. throw new RestException(412, $e->getMessage());
  122. }
  123. }
  124. /**
  125. * Implementation for 'DELETE' method for Rest API
  126. *
  127. * @param mixed $spUid Primary key
  128. *
  129. * @return array $result Returns array within multiple records or a single record depending if
  130. * a single selection was requested passing id(s) as param
  131. */
  132. protected function delete($spUid)
  133. {
  134. $conn = Propel::getConnection(SubProcessPeer::DATABASE_NAME);
  135. try {
  136. $conn->begin();
  137. $obj = SubProcessPeer::retrieveByPK($spUid);
  138. if (! is_object($obj)) {
  139. throw new RestException(412, 'Record does not exist.');
  140. }
  141. $obj->delete();
  142. $conn->commit();
  143. } catch (Exception $e) {
  144. $conn->rollback();
  145. throw new RestException(412, $e->getMessage());
  146. }
  147. }
  148. }