diff options
Diffstat (limited to 'lib/ocs')
-rw-r--r-- | lib/ocs/result.php | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/lib/ocs/result.php b/lib/ocs/result.php new file mode 100644 index 00000000000..a7199cb5ac7 --- /dev/null +++ b/lib/ocs/result.php @@ -0,0 +1,65 @@ +<?php + +class OC_OCS_Result{ + + private $data, $message, $statuscode, $items, $perpage; + + /** + * create the OCS_Result object + * @param $data mixed the data to return + */ + public function __construct($data=null, $code=100, $message=null){ + $this->data = $data; + $this->statuscode = $code; + $this->message = $message; + } + + /** + * sets the statuscode + * @param $code int + */ + public function setCode(int $code){ + $this->statuscode = $code; + } + + /** + * optionally set the total number of items available + * @param $items int + */ + public function setItems(int $items){ + $this->items = $items; + } + + /** + * optionally set the the number of items per page + * @param $items int + */ + public function setItemsPerPage(int $items){ + $this->perpage = $items; + } + + /** + * set a custom message for the response + * @param $message string the message + */ + public function setMessage(string $message){ + $this->message = $message; + } + + /** + * returns the data associated with the api result + * @return array + */ + public function getResult(){ + $return = array(); + $return['meta'] = array(); + $return['meta']['status'] = ($this->statuscode === 100) ? 'ok' : 'failure'; + $return['meta']['statuscode'] = $this->statuscode; + $return['meta']['message'] = $this->message; + $return['data'] = $this->data; + // Return the result data. + return $return; + } + + +}
\ No newline at end of file |