PMCORE-3193 Service - Create a services to get the Pm tables list to be used in a suggest list
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\BusinessModel;
|
||||
|
||||
use ProcessMaker\BusinessModel\Table;
|
||||
use ProcessMaker\Model\AdditionalTables;
|
||||
use Tests\TestCase;
|
||||
|
||||
class TableTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Method setUp.
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
AdditionalTables::truncate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method tearDown.
|
||||
*/
|
||||
public function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
/**
|
||||
* This test getTables() method.
|
||||
* @test
|
||||
* @covers \ProcessMaker\BusinessModel\Table::getTables()
|
||||
*/
|
||||
public function it_should_test_getTables_method()
|
||||
{
|
||||
$additionalTables = factory(AdditionalTables::class)
|
||||
->create();
|
||||
|
||||
$proUid = $additionalTables->PRO_UID;
|
||||
$search = $additionalTables->ADD_TAB_NAME;
|
||||
|
||||
$table = new Table();
|
||||
$result = $table->getTables($proUid, true, false, $search);
|
||||
|
||||
//assertions
|
||||
$this->assertNotEmpty($result);
|
||||
$this->assertEquals($additionalTables->ADD_TAB_NAME, $result[0]['rep_tab_name']);
|
||||
|
||||
$search = '';
|
||||
$table = new Table();
|
||||
$result = $table->getTables($proUid, true, false, $search);
|
||||
|
||||
//assertions
|
||||
$this->assertNotEmpty($result);
|
||||
$this->assertEquals($additionalTables->ADD_TAB_NAME, $result[0]['rep_tab_name']);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ use Fields;
|
||||
use G;
|
||||
use PmTable;
|
||||
use ProcessMaker\BusinessModel\ReportTable as BusinessModelRpt;
|
||||
use ProcessMaker\Model\AdditionalTables as ModelAdditionalTables;
|
||||
use stdClass;
|
||||
|
||||
class Table
|
||||
@@ -23,34 +24,25 @@ class Table
|
||||
'or','throw','protected','public','static','switch','xor','try','use','var','while'];
|
||||
|
||||
/**
|
||||
* List of Tables in process
|
||||
* @var string $pro_uid. Uid for process
|
||||
* @var string $reportFlag. If is report table
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* List of Tables in process.
|
||||
* @param string $proUid
|
||||
* @param bool $reportFlag
|
||||
* @param bool $offline
|
||||
* @param string $search
|
||||
* @return array
|
||||
*/
|
||||
public function getTables($pro_uid = '', $reportFlag = false, $offline = false)
|
||||
public function getTables(string $proUid = '', bool $reportFlag = false, bool $offline = false, string $search = ''): array
|
||||
{
|
||||
//VALIDATION
|
||||
if ($reportFlag) {
|
||||
$pro_uid = $this->validateProUid($pro_uid);
|
||||
$proUid = $this->validateProUid($proUid);
|
||||
}
|
||||
|
||||
$reportTables = array();
|
||||
$oCriteria = new \Criteria('workflow');
|
||||
$oCriteria->addSelectColumn(\AdditionalTablesPeer::ADD_TAB_UID);
|
||||
$oCriteria->add(\AdditionalTablesPeer::PRO_UID, $pro_uid, \Criteria::EQUAL);
|
||||
$oDataset = \AdditionalTablesPeer::doSelectRS($oCriteria);
|
||||
$oDataset->setFetchmode(\ResultSet::FETCHMODE_ASSOC);
|
||||
while ($oDataset->next()) {
|
||||
$row = $oDataset->getRow();
|
||||
$reportTables[] = $this->getTable($row['ADD_TAB_UID'], $pro_uid, $reportFlag, false);
|
||||
}
|
||||
|
||||
return $reportTables;
|
||||
$additionalTables = ModelAdditionalTables::where('PRO_UID', '=', $proUid)
|
||||
->where('ADD_TAB_NAME', 'LIKE', "%{$search}%")
|
||||
->get();
|
||||
$additionalTables->transform(function ($object) use ($proUid, $reportFlag) {
|
||||
return $this->getTable($object->ADD_TAB_UID, $proUid, $reportFlag, false);
|
||||
});
|
||||
return $additionalTables->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,33 +1,29 @@
|
||||
<?php
|
||||
namespace ProcessMaker\Services\Api\Project;
|
||||
|
||||
use \ProcessMaker\Services\Api;
|
||||
use \Luracast\Restler\RestException;
|
||||
use Luracast\Restler\RestException;
|
||||
use ProcessMaker\BusinessModel\Table;
|
||||
use ProcessMaker\Services\Api;
|
||||
|
||||
/**
|
||||
* Project\ReportTable Api Controller
|
||||
*
|
||||
* @author Brayan Pereyra <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @protected
|
||||
*/
|
||||
class ReportTable extends Api
|
||||
{
|
||||
/**
|
||||
* @param string $prj_uid {@min 1} {@max 32}
|
||||
*
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
* Get list of the report tables by project.
|
||||
* @url GET /:proUid/report-tables
|
||||
* @param string $proUid {@min 1} {@max 32}
|
||||
* @param string $search
|
||||
* @return array
|
||||
*
|
||||
* @url GET /:prj_uid/report-tables
|
||||
* @throws RestException
|
||||
*/
|
||||
public function doGetReportTables($prj_uid)
|
||||
public function doGetReportTables(string $proUid, string $search = '')
|
||||
{
|
||||
try {
|
||||
$oReportTable = new \ProcessMaker\BusinessModel\Table();
|
||||
$response = $oReportTable->getTables($prj_uid, true);
|
||||
$reportTable = new Table();
|
||||
$response = $reportTable->getTables($proUid, true, false, $search);
|
||||
return $response;
|
||||
} catch (\Exception $e) {
|
||||
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage()));
|
||||
@@ -38,9 +34,6 @@ class ReportTable extends Api
|
||||
* @param string $prj_uid {@min 1} {@max 32}
|
||||
* @param string $rep_uid {@min 1} {@max 32}
|
||||
* @return array
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @url GET /:prj_uid/report-table/:rep_uid
|
||||
*/
|
||||
public function doGetReportTable($prj_uid, $rep_uid)
|
||||
@@ -58,9 +51,6 @@ class ReportTable extends Api
|
||||
* @param string $prj_uid {@min 1} {@max 32}
|
||||
* @param string $rep_uid {@min 1} {@max 32}
|
||||
* @return array
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @url GET /:prj_uid/report-table/:rep_uid/populate
|
||||
*/
|
||||
public function doGetPopulateReportTable($prj_uid, $rep_uid)
|
||||
@@ -78,9 +68,6 @@ class ReportTable extends Api
|
||||
* @param string $prj_uid {@min 1} {@max 32}
|
||||
* @param string $rep_uid {@min 1} {@max 32}
|
||||
* @return array
|
||||
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
|
||||
* @copyright Colosa - Bolivia
|
||||
*
|
||||
* @url GET /:prj_uid/report-table/:rep_uid/data
|
||||
*/
|
||||
public function doGetReportTableData($prj_uid, $rep_uid)
|
||||
|
||||
Reference in New Issue
Block a user