Tasks.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <?php
  2. namespace OntraportAPI;
  3. /**
  4. * Class Tasks
  5. *
  6. * @author ONTRAPORT
  7. *
  8. * @package OntraportAPI
  9. */
  10. class Tasks extends BaseApi
  11. {
  12. /**
  13. * $var string endpoint for single task
  14. */
  15. protected $_endpoint = "Task";
  16. /**
  17. * $var string endpoint for plural tasks
  18. */
  19. protected $_endpointPlural = "Tasks";
  20. /**
  21. * @param Ontraport $client
  22. */
  23. public function __construct(Ontraport $client)
  24. {
  25. parent::__construct($client);
  26. }
  27. /*
  28. * @TODO: This is just a placeholder, the API needs to be fixed to only use the new endpoint standards
  29. */
  30. private $_mainTaskEndpoint = "task";
  31. // Task-specific function endpoints
  32. const TASK_ASSIGN = "assign";
  33. const TASK_CANCEL = "cancel";
  34. const TASK_COMPLETE = "complete";
  35. const TASK_RESCHEDULE = "reschedule";
  36. /**
  37. * @brief Retrieve a single specified task
  38. *
  39. * @param mixed[] $requestParams The parameters to submit with GET request.
  40. * Possible array keys: "id" (required)
  41. *
  42. * @return string JSON formatted response
  43. */
  44. public function retrieveSingle($requestParams)
  45. {
  46. return parent::_retrieveSingle($requestParams);
  47. }
  48. /**
  49. * @brief Retrieve multiple tasks according to specific criteria, handle pagination
  50. *
  51. * @param mixed[] $requestParams Array of parameters to submit with GET request. All parameters are optional but if "ids"
  52. * are not specified, all will be selected.
  53. * Possible array keys: "ids","start","range","sort","sortDir","condition","search",
  54. * "searchNotes","group_ids","performAll","externs","listFields"
  55. *
  56. * @return string JSON formatted array of response data: each page of data will be an element in that array.
  57. */
  58. public function retrieveMultiplePaginated($requestParams)
  59. {
  60. return parent::_retrieveMultiplePaginated($requestParams);
  61. }
  62. /**
  63. * @brief Retrieve multiple tasks according to specific criteria
  64. *
  65. * @param mixed[] $requestParams Array of parameters to submit with GET request. All parameters are optional but if "ids"
  66. * are not specified, all will be selected.
  67. * Possible array keys: "ids","start","range","sort","sortDir","condition","search",
  68. * "searchNotes","group_ids","performAll","externs","listFields"
  69. *
  70. * @return string JSON formatted response
  71. */
  72. public function retrieveMultiple($requestParams)
  73. {
  74. return parent::_retrieveMultiple($requestParams);
  75. }
  76. /**
  77. * @brief Update a task's data
  78. *
  79. * @param mixed[] $requestParams Array of parameters to submit with GET request. All parameters are optional.
  80. * Possible array keys: "id" (required),"owner","date_due","status"
  81. *
  82. * @return string JSON formatted response
  83. */
  84. public function update($requestParams)
  85. {
  86. return parent::_update($requestParams);
  87. }
  88. /**
  89. * @brief Retrieve information (such as number of tasks) about task collection
  90. *
  91. * @param mixed[] $requestParams Array of parameters to submit with GET request. All parameters are optional.
  92. * Possible array keys: "condition","search","searchNotes","group_ids","performAll"
  93. *
  94. * @return string JSON formatted response
  95. */
  96. public function retrieveCollectionInfo($requestParams)
  97. {
  98. return parent::_retrieveCollectionInfo($requestParams);
  99. }
  100. /**
  101. * @brief Retrieve meta for a task object
  102. *
  103. * @return string JSON formatted meta for task object
  104. */
  105. public function retrieveMeta()
  106. {
  107. return parent::_retrieveMeta();
  108. }
  109. /**
  110. * @brief Assign a task to one or more contacts
  111. *
  112. * @param mixed[] $requestParams Array of parameters to submit with POST request.
  113. * Possible array keys: "object_type_id" (required),"ids" (required),"group_ids",
  114. * "performAll","message"
  115. *
  116. * @return string JSON formatted response
  117. */
  118. public function assign($requestParams)
  119. {
  120. $options["headers"] = self::retrieveContentTypeHeader(self::CONTENT_TYPE_JSON);
  121. $requiredParams = array(
  122. "object_type_id",
  123. "ids"
  124. );
  125. return $this->client->request($requestParams, $this->_mainTaskEndpoint . "/" . self::TASK_ASSIGN, "post", $requiredParams, $options);
  126. }
  127. /**
  128. * @brief Cancel a task or list of tasks
  129. *
  130. * @param mixed[] $requestParams Array of parameters to submit with POST request.
  131. * Possible array keys: "objectID" (required),"ids","start","range","condition","search","searchNotes",
  132. * "group_ids","performAll"
  133. *
  134. * @return string JSON formatted response
  135. */
  136. public function cancel($requestParams)
  137. {
  138. $options["headers"] = self::retrieveContentTypeHeader(self::CONTENT_TYPE_JSON);
  139. $requiredParams = array("objectID");
  140. return $this->client->request($requestParams, $this->_mainTaskEndpoint . "/" . self::TASK_CANCEL, "post", $requiredParams, $options);
  141. }
  142. /**
  143. * @brief Marks one or more tasks as completed
  144. *
  145. * @param mixed[] $requestParams Array of parameters to submit with POST request.
  146. * Possible array keys: "object_type_id" (required),"ids","group_ids","performAll","data"
  147. *
  148. * @return string JSON formatted response
  149. */
  150. public function complete($requestParams)
  151. {
  152. $options["headers"] = self::retrieveContentTypeHeader(self::CONTENT_TYPE_JSON);
  153. $requiredParams = array("object_type_id");
  154. return $this->client->request($requestParams, $this->_mainTaskEndpoint."/". self::TASK_COMPLETE, "post", $requiredParams, $options);
  155. }
  156. /**
  157. * @brief Reschedules a task
  158. *
  159. * @param mixed[] $requestParams Array of parameters to submit with POST request.
  160. * Possible array keys: "id" (required),"newtime"
  161. *
  162. * @return string JSON formatted response
  163. */
  164. public function reschedule($requestParams)
  165. {
  166. $options["headers"] = self::retrieveContentTypeHeader(self::CONTENT_TYPE_JSON);
  167. $requiredParams = array("id");
  168. return $this->client->request($requestParams, $this->_mainTaskEndpoint . "/" . self::TASK_RESCHEDULE, "post", $requiredParams, $options);
  169. }
  170. }