Files
luos/workflow/engine/src/ProcessMaker/Services/Api/Pmtable.php

317 lines
8.7 KiB
PHP
Raw Normal View History

<?php
2019-11-22 15:01:08 -04:00
namespace ProcessMaker\Services\Api;
2018-07-31 08:34:16 -04:00
use Exception;
use Luracast\Restler\RestException;
use ProcessMaker\BusinessModel\Table as BusinessModelTable;
2019-11-22 15:01:08 -04:00
use ProcessMaker\Model\AdditionalTables;
2018-07-31 08:34:16 -04:00
use ProcessMaker\Services\Api;
/**
* Pmtable Api Controller
*
* @protected
*/
class Pmtable extends Api
{
/**
2019-11-22 15:01:08 -04:00
* Get a list of the PM tables in the workspace. It does not include any Report Table
*
* @url GET
* @status 200
*
* @param boolean $offline {@from path}
*
2019-11-22 15:01:08 -04:00
* @return array
* @throws RestException
*
2016-07-21 09:52:33 -04:00
* @access protected
2019-12-13 10:13:19 -04:00
* @class AccessControl {@permission PM_LOGIN}
2019-11-22 15:01:08 -04:00
* @link https://wiki.processmaker.com/3.1/REST_API_Administration/PM_Tables#PM_Tables_List:_GET_.2Fpmtable
*/
2019-11-22 15:01:08 -04:00
public function doGetPmTables($offline = false)
{
try {
2019-11-22 15:01:08 -04:00
if ($offline) {
$response = AdditionalTables::getTablesOfflineStructure();
} else {
$pmTable = new BusinessModelTable();
$response = $pmTable->getTables();
}
return $response;
2019-11-22 15:01:08 -04:00
} catch (Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
/**
2019-11-22 15:01:08 -04:00
* Get the data of the offline PM tables
*
* @url GET /offline/data
* @status 200
*
* @param boolean $compress {@from path}
*
* @return array
*
2019-11-22 15:01:08 -04:00
* @throws RestException
*
2016-07-21 09:52:33 -04:00
* @access protected
2019-12-13 10:13:19 -04:00
* @class AccessControl {@permission PM_LOGIN}
2019-11-22 15:01:08 -04:00
* @link https://wiki.processmaker.com/3.1/REST_API_Administration/PM_Tables#PM_Tables_List:_GET_.2Fpmtable
*/
public function doGetPmTablesDataOffline($compress = true)
{
try {
$data = AdditionalTables::getTablesOfflineData();
if ($compress) {
$json = json_encode($data);
$compressed = gzcompress($json, 5);
echo $compressed;
} else {
return $data;
}
} catch (Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
/**
* Get the structure from a specific PM Table, including a list of its fields and their properties.
*
* @url GET /:pmt_uid
2019-11-22 15:01:08 -04:00
* @status 200
*
* @param string $pmt_uid {@min 1} {@max 32}
*
* @return array
* @throws RestException
*
* @access protected
* @class AccessControl {@permission PM_SETUP_PM_TABLES}
* @link https://wiki.processmaker.com/3.1/REST_API_Administration/PM_Tables#Get_PM_Table_Structure:_GET_.2Fpmtable.2F.7Bpmt_uid.7D
*/
public function doGetPmTable($pmt_uid)
{
try {
2019-11-22 15:01:08 -04:00
$oPmTable = new BusinessModelTable();
$response = $oPmTable->getTable($pmt_uid);
return $response;
2019-11-22 15:01:08 -04:00
} catch (Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
/**
2019-11-22 15:01:08 -04:00
* Get the data from a PM table
*
* @url GET /:pmt_uid/data
* @status 200
*
* @param string $pmt_uid {@min 1} {@max 32}
2016-07-20 11:59:03 -04:00
* @param string $filter
* @param string $q
*
2019-11-22 15:01:08 -04:00
* @return array
* @throws RestException
*
2016-07-21 09:52:33 -04:00
* @access protected
* @class AccessControl {@permission PM_SETUP_PM_TABLES}
2019-11-22 15:01:08 -04:00
*
*/
2016-07-20 11:59:03 -04:00
public function doGetPmTableData($pmt_uid, $filter = null, $q = "")
{
try {
2019-11-22 15:01:08 -04:00
$oPmTable = new BusinessModelTable();
2016-07-20 11:59:03 -04:00
$response = $oPmTable->getTableData($pmt_uid, null, $filter, false, $q);
return $response;
2019-11-22 15:01:08 -04:00
} catch (Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
/**
2019-11-22 15:01:08 -04:00
* Create a new PM Table
*
* @url POST
* @status 201
*
* @param array $request_data
* @param string $pmt_tab_name {@from body}
* @param string $pmt_tab_dsc {@from body}
*
2019-11-22 15:01:08 -04:00
* @return array
* @throws RestException
*
2016-07-21 09:52:33 -04:00
* @access protected
* @class AccessControl {@permission PM_SETUP_PM_TABLES}
*/
public function doPostPmTable(
$request_data,
$pmt_tab_name,
$pmt_tab_dsc = ''
) {
try {
2019-11-22 15:01:08 -04:00
$oReportTable = new BusinessModelTable();
$response = $oReportTable->saveTable($request_data);
if (isset($response['pro_uid'])) {
unset($response['pro_uid']);
}
return $response;
2019-11-22 15:01:08 -04:00
} catch (Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
2014-02-13 16:28:38 -04:00
/**
2019-11-22 15:01:08 -04:00
* Add a new record to a PM Table
2014-02-13 16:28:38 -04:00
*
2019-11-22 15:01:08 -04:00
* @url POST /:pmt_uid/data
* @status 201
2014-02-13 16:28:38 -04:00
*
2019-11-22 15:01:08 -04:00
* @param string $pmt_uid {@min 1} {@max 32}
* @param array $request_data
2014-02-13 16:28:38 -04:00
*
2019-11-22 15:01:08 -04:00
* @return array
* @throws RestException
2016-07-21 09:52:33 -04:00
* @access protected
* @class AccessControl {@permission PM_SETUP_PM_TABLES}
2014-02-13 16:28:38 -04:00
*/
public function doPostPmTableData(
$pmt_uid,
2014-04-28 12:15:48 -04:00
$request_data
2014-02-13 16:28:38 -04:00
) {
try {
2019-11-22 15:01:08 -04:00
$oReportTable = new BusinessModelTable();
2014-02-13 16:28:38 -04:00
$response = $oReportTable->saveTableData($pmt_uid, $request_data);
return $response;
2019-11-22 15:01:08 -04:00
} catch (Exception $e) {
2014-02-13 16:28:38 -04:00
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
/**
2019-11-22 15:01:08 -04:00
* Update the structure of a PM table.
2017-10-13 10:59:18 -04:00
*
* @url PUT /:pmt_uid
2019-11-22 15:01:08 -04:00
* @status 200
*
2017-10-13 10:59:18 -04:00
* @param string $pmt_uid {@min 1} {@max 32}
* @param array $request_data
*
2017-10-13 10:59:18 -04:00
* @return void
2019-11-22 15:01:08 -04:00
* @throws RestException
*
2016-07-21 09:52:33 -04:00
* @access protected
* @class AccessControl {@permission PM_SETUP_PM_TABLES}
*/
public function doPutPmTable(
$pmt_uid,
2014-04-28 12:15:48 -04:00
$request_data
) {
try {
$request_data['pmt_uid'] = $pmt_uid;
2018-07-31 08:34:16 -04:00
$pmTable = new BusinessModelTable();
$response = $pmTable->updateTable($request_data);
} catch (Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
2014-02-13 16:28:38 -04:00
/**
2019-11-22 15:01:08 -04:00
* Update the data of an existing record in a PM table.
2017-10-13 10:59:18 -04:00
*
* @url PUT /:pmt_uid/data
2019-11-22 15:01:08 -04:00
* @status 200
2017-10-13 10:59:18 -04:00
*
2014-02-13 16:28:38 -04:00
* @param string $pmt_uid {@min 1} {@max 32}
* @param array $request_data
2017-10-13 10:59:18 -04:00
*
2014-02-13 16:28:38 -04:00
* @return array
2017-10-13 10:59:18 -04:00
* @throws RestException
*
2016-07-21 09:52:33 -04:00
* @access protected
* @class AccessControl {@permission PM_SETUP_PM_TABLES}
2014-02-13 16:28:38 -04:00
*/
public function doPutPmTableData(
$pmt_uid,
2014-04-28 12:15:48 -04:00
$request_data
2014-02-13 16:28:38 -04:00
) {
try {
2019-11-22 15:01:08 -04:00
$oReportTable = new BusinessModelTable();
2014-02-13 16:28:38 -04:00
$response = $oReportTable->updateTableData($pmt_uid, $request_data);
return $response;
2019-11-22 15:01:08 -04:00
} catch (Exception $e) {
2014-02-13 16:28:38 -04:00
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
/**
2019-11-22 15:01:08 -04:00
* Delete a specified PM table and all its data.
*
* @url DELETE /:pmt_uid
* @status 200
*
* @param string $pmt_uid {@min 1} {@max 32}
*
* @return void
2019-11-22 15:01:08 -04:00
* @throws RestException
*
2016-07-21 09:52:33 -04:00
* @access protected
* @class AccessControl {@permission PM_SETUP_PM_TABLES}
*/
public function doDeletePmTable($pmt_uid)
{
try {
2019-11-22 15:01:08 -04:00
$oReportTable = new BusinessModelTable();
$response = $oReportTable->deleteTable($pmt_uid);
2019-11-22 15:01:08 -04:00
} catch (Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
2014-02-13 16:28:38 -04:00
/**
2019-11-22 15:01:08 -04:00
* Delete a record from a PM table, by specifying its primary key(s). The PM Table can have up to 3 primary key
* fields.
*
* @url DELETE /:pmt_uid/data/:key1/:value1
* @url DELETE /:pmt_uid/data/:key1/:value1/:key2/:value2
* @url DELETE /:pmt_uid/data/:key1/:value1/:key2/:value2/:key3/:value3
* @status 200
*
2014-02-13 16:28:38 -04:00
* @param string $pmt_uid {@min 1} {@max 32}
* @param string $key1 {@min 1}
* @param string $value1 {@min 1}
* @param string $key2
* @param string $value2
* @param string $key3
* @param string $value3
*
* @return array
2019-11-22 15:01:08 -04:00
* @throws RestException
2014-02-13 16:28:38 -04:00
*
2016-07-21 09:52:33 -04:00
* @access protected
* @class AccessControl {@permission PM_SETUP_PM_TABLES}
2014-02-13 16:28:38 -04:00
*/
public function doDeletePmTableData($pmt_uid, $key1, $value1, $key2 = '', $value2 = '', $key3 = '', $value3 = '')
{
try {
$rows = array($key1 => $value1);
if ($key2 != '') {
$rows[$key2] = $value2;
}
if ($key3 != '') {
$rows[$key3] = $value3;
}
2019-11-22 15:01:08 -04:00
$oReportTable = new BusinessModelTable();
2014-02-13 16:28:38 -04:00
$response = $oReportTable->deleteTableData($pmt_uid, $rows);
return $response;
2019-11-22 15:01:08 -04:00
} catch (Exception $e) {
2014-02-13 16:28:38 -04:00
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
}
}
}