2014-01-22 17:18:33 -04:00
|
|
|
<?php
|
2014-04-02 17:02:02 -04:00
|
|
|
namespace ProcessMaker\Services\Api\Project;
|
2014-01-22 17:18:33 -04:00
|
|
|
|
|
|
|
|
use \ProcessMaker\Services\Api;
|
|
|
|
|
use \Luracast\Restler\RestException;
|
2015-11-20 18:57:26 -04:00
|
|
|
use \ProcessMaker\Util\DateTime;
|
|
|
|
|
use \ProcessMaker\BusinessModel\Validator;
|
2014-01-22 17:18:33 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Project\WebEntry Api Controller
|
|
|
|
|
*
|
|
|
|
|
* @protected
|
|
|
|
|
*/
|
|
|
|
|
class WebEntry extends Api
|
|
|
|
|
{
|
2014-04-22 13:11:32 -04:00
|
|
|
private $webEntry;
|
|
|
|
|
|
2015-11-20 18:57:26 -04:00
|
|
|
private $arrayFieldIso8601 = [
|
|
|
|
|
"we_create_date",
|
|
|
|
|
"we_update_date"
|
|
|
|
|
];
|
|
|
|
|
|
2014-01-22 17:18:33 -04:00
|
|
|
/**
|
2014-04-22 13:11:32 -04:00
|
|
|
* Constructor of the class
|
|
|
|
|
*
|
|
|
|
|
* return void
|
|
|
|
|
*/
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$this->webEntry = new \ProcessMaker\BusinessModel\WebEntry();
|
|
|
|
|
|
|
|
|
|
$this->webEntry->setFormatFieldNameInUppercase(false);
|
|
|
|
|
$this->webEntry->setArrayFieldNameForException(array("processUid" => "prj_uid"));
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @url GET /:prj_uid/web-entries
|
2014-01-22 17:18:33 -04:00
|
|
|
*
|
2014-01-27 15:21:15 -04:00
|
|
|
* @param string $prj_uid {@min 32}{@max 32}
|
2014-01-22 17:18:33 -04:00
|
|
|
*/
|
2014-04-22 13:11:32 -04:00
|
|
|
public function doGetWebEntries($prj_uid)
|
2014-01-22 17:18:33 -04:00
|
|
|
{
|
|
|
|
|
try {
|
2014-04-22 13:11:32 -04:00
|
|
|
$response = $this->webEntry->getWebEntries($prj_uid);
|
2014-01-22 17:18:33 -04:00
|
|
|
|
2015-11-20 18:57:26 -04:00
|
|
|
return DateTime::convertUtcToIso8601($response, $this->arrayFieldIso8601);
|
2014-04-22 13:11:32 -04:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @url GET /:prj_uid/web-entry/:we_uid
|
|
|
|
|
*
|
|
|
|
|
* @param string $prj_uid {@min 32}{@max 32}
|
|
|
|
|
* @param string $we_uid {@min 32}{@max 32}
|
|
|
|
|
*/
|
|
|
|
|
public function doGetWebEntry($prj_uid, $we_uid)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$response = $this->webEntry->getWebEntry($we_uid);
|
2014-01-22 17:18:33 -04:00
|
|
|
|
2015-11-20 18:57:26 -04:00
|
|
|
return DateTime::convertUtcToIso8601($response, $this->arrayFieldIso8601);
|
2014-01-22 17:18:33 -04:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-24 16:06:50 -04:00
|
|
|
/**
|
2014-01-27 15:21:15 -04:00
|
|
|
* @url POST /:prj_uid/web-entry
|
2014-01-24 16:06:50 -04:00
|
|
|
*
|
2014-02-07 14:52:35 -04:00
|
|
|
* @param string $prj_uid {@min 32}{@max 32}
|
2014-01-24 16:06:50 -04:00
|
|
|
* @param array $request_data
|
|
|
|
|
*
|
|
|
|
|
* @status 201
|
|
|
|
|
*/
|
2014-05-28 15:01:18 -04:00
|
|
|
public function doPostWebEntry($prj_uid, array $request_data)
|
2014-02-07 14:52:35 -04:00
|
|
|
{
|
2014-01-24 16:06:50 -04:00
|
|
|
try {
|
2015-11-20 18:57:26 -04:00
|
|
|
Validator::throwExceptionIfDataNotMetIso8601Format($request_data, $this->arrayFieldIso8601);
|
|
|
|
|
$arrayData = $this->webEntry->create($prj_uid, $this->getUserId(), DateTime::convertDataToUtc($request_data, $this->arrayFieldIso8601));
|
2014-01-24 16:06:50 -04:00
|
|
|
|
|
|
|
|
$response = $arrayData;
|
|
|
|
|
|
2015-11-20 18:57:26 -04:00
|
|
|
return DateTime::convertUtcToIso8601($response, $this->arrayFieldIso8601);
|
2014-01-24 16:06:50 -04:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-22 17:18:33 -04:00
|
|
|
|
|
|
|
|
/**
|
2014-04-22 13:11:32 -04:00
|
|
|
* @url PUT /:prj_uid/web-entry/:we_uid
|
2014-01-22 17:18:33 -04:00
|
|
|
*
|
2014-04-22 13:11:32 -04:00
|
|
|
* @param string $prj_uid {@min 32}{@max 32}
|
|
|
|
|
* @param string $we_uid {@min 32}{@max 32}
|
|
|
|
|
* @param array $request_data
|
2014-01-22 17:18:33 -04:00
|
|
|
*/
|
2014-05-28 15:01:18 -04:00
|
|
|
public function doPutWebEntry($prj_uid, $we_uid, array $request_data)
|
2014-01-22 17:18:33 -04:00
|
|
|
{
|
|
|
|
|
try {
|
2015-11-20 18:57:26 -04:00
|
|
|
Validator::throwExceptionIfDataNotMetIso8601Format($request_data, $this->arrayFieldIso8601);
|
|
|
|
|
$arrayData = $this->webEntry->update($we_uid, $this->getUserId(), DateTime::convertDataToUtc($request_data, $this->arrayFieldIso8601));
|
2014-04-22 13:11:32 -04:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-01-22 17:18:33 -04:00
|
|
|
|
2014-04-22 13:11:32 -04:00
|
|
|
/**
|
|
|
|
|
* @url DELETE /:prj_uid/web-entry/:we_uid
|
|
|
|
|
*
|
|
|
|
|
* @param string $prj_uid {@min 32}{@max 32}
|
|
|
|
|
* @param string $we_uid {@min 32}{@max 32}
|
|
|
|
|
*/
|
|
|
|
|
public function doDeleteWebEntry($prj_uid, $we_uid)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
$this->webEntry->delete($we_uid);
|
2014-01-22 17:18:33 -04:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|