Merged in bugfix/PMCORE-3193 (pull request #8021)

PMCORE-3193 Service - Create a services to get the Pm tables list to be used in a suggest list

Approved-by: Julio Cesar Laura Avendaño
This commit is contained in:
Roly Rudy Gutierrez Pinto
2021-08-04 15:30:06 +00:00
committed by Julio Cesar Laura Avendaño
3 changed files with 82 additions and 47 deletions

View File

@@ -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']);
}
}

View File

@@ -8,6 +8,7 @@ use Fields;
use G; use G;
use PmTable; use PmTable;
use ProcessMaker\BusinessModel\ReportTable as BusinessModelRpt; use ProcessMaker\BusinessModel\ReportTable as BusinessModelRpt;
use ProcessMaker\Model\AdditionalTables as ModelAdditionalTables;
use stdClass; use stdClass;
class Table class Table
@@ -23,34 +24,25 @@ class Table
'or','throw','protected','public','static','switch','xor','try','use','var','while']; 'or','throw','protected','public','static','switch','xor','try','use','var','while'];
/** /**
* List of Tables in process * List of Tables in process.
* @var string $pro_uid. Uid for process * @param string $proUid
* @var string $reportFlag. If is report table * @param bool $reportFlag
* * @param bool $offline
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com> * @param string $search
* @copyright Colosa - Bolivia
*
* @return array * @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) { if ($reportFlag) {
$pro_uid = $this->validateProUid($pro_uid); $proUid = $this->validateProUid($proUid);
} }
$additionalTables = ModelAdditionalTables::where('PRO_UID', '=', $proUid)
$reportTables = array(); ->where('ADD_TAB_NAME', 'LIKE', "%{$search}%")
$oCriteria = new \Criteria('workflow'); ->get();
$oCriteria->addSelectColumn(\AdditionalTablesPeer::ADD_TAB_UID); $additionalTables->transform(function ($object) use ($proUid, $reportFlag) {
$oCriteria->add(\AdditionalTablesPeer::PRO_UID, $pro_uid, \Criteria::EQUAL); return $this->getTable($object->ADD_TAB_UID, $proUid, $reportFlag, false);
$oDataset = \AdditionalTablesPeer::doSelectRS($oCriteria); });
$oDataset->setFetchmode(\ResultSet::FETCHMODE_ASSOC); return $additionalTables->toArray();
while ($oDataset->next()) {
$row = $oDataset->getRow();
$reportTables[] = $this->getTable($row['ADD_TAB_UID'], $pro_uid, $reportFlag, false);
}
return $reportTables;
} }
/** /**

View File

@@ -1,33 +1,29 @@
<?php <?php
namespace ProcessMaker\Services\Api\Project; 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 * Project\ReportTable Api Controller
*
* @author Brayan Pereyra <brayan@colosa.com>
* @copyright Colosa - Bolivia
*
* @protected * @protected
*/ */
class ReportTable extends Api class ReportTable extends Api
{ {
/** /**
* @param string $prj_uid {@min 1} {@max 32} * Get list of the report tables by project.
* * @url GET /:proUid/report-tables
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com> * @param string $proUid {@min 1} {@max 32}
* @copyright Colosa - Bolivia * @param string $search
* @return array * @return array
* * @throws RestException
* @url GET /:prj_uid/report-tables
*/ */
public function doGetReportTables($prj_uid) public function doGetReportTables(string $proUid, string $search = '')
{ {
try { try {
$oReportTable = new \ProcessMaker\BusinessModel\Table(); $reportTable = new Table();
$response = $oReportTable->getTables($prj_uid, true); $response = $reportTable->getTables($proUid, true, false, $search);
return $response; return $response;
} catch (\Exception $e) { } catch (\Exception $e) {
throw (new RestException(Api::STAT_APP_EXCEPTION, $e->getMessage())); 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 $prj_uid {@min 1} {@max 32}
* @param string $rep_uid {@min 1} {@max 32} * @param string $rep_uid {@min 1} {@max 32}
* @return array * @return array
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia
*
* @url GET /:prj_uid/report-table/:rep_uid * @url GET /:prj_uid/report-table/:rep_uid
*/ */
public function doGetReportTable($prj_uid, $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 $prj_uid {@min 1} {@max 32}
* @param string $rep_uid {@min 1} {@max 32} * @param string $rep_uid {@min 1} {@max 32}
* @return array * @return array
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia
*
* @url GET /:prj_uid/report-table/:rep_uid/populate * @url GET /:prj_uid/report-table/:rep_uid/populate
*/ */
public function doGetPopulateReportTable($prj_uid, $rep_uid) 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 $prj_uid {@min 1} {@max 32}
* @param string $rep_uid {@min 1} {@max 32} * @param string $rep_uid {@min 1} {@max 32}
* @return array * @return array
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia
*
* @url GET /:prj_uid/report-table/:rep_uid/data * @url GET /:prj_uid/report-table/:rep_uid/data
*/ */
public function doGetReportTableData($prj_uid, $rep_uid) public function doGetReportTableData($prj_uid, $rep_uid)