This commit is contained in:
Roly Rudy Gutierrez Pinto
2019-05-23 16:30:49 -04:00
parent 8252428a0c
commit 250976c159
4 changed files with 878 additions and 143 deletions

View File

@@ -1,4 +1,5 @@
<?php <?php
/** /**
* Model factory for a process * Model factory for a process
*/ */
@@ -11,7 +12,7 @@ $factory->define(\ProcessMaker\Model\Task::class, function(Faker $faker) {
return $process->PRO_UID; return $process->PRO_UID;
}, },
'TAS_UID' => G::generateUniqueID(), 'TAS_UID' => G::generateUniqueID(),
'TAS_ID' => $faker->unique()->numberBetween(1, 2000), 'TAS_ID' => $faker->unique()->numberBetween(1, 100000),
'TAS_TITLE' => $faker->sentence(2), 'TAS_TITLE' => $faker->sentence(2),
'TAS_TYPE' => 'NORMAL', 'TAS_TYPE' => 'NORMAL',
'TAS_TYPE_DAY' => 1, 'TAS_TYPE_DAY' => 1,

View File

@@ -0,0 +1,733 @@
<?php
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use ProcessMaker\Model\Application;
use ProcessMaker\Model\Process;
use ProcessMaker\Model\Task;
use ProcessMaker\Model\User;
use Tests\TestCase;
class PmDynaformTest extends TestCase
{
use DatabaseTransactions;
/**
* Constructor of the class.
*/
protected function setUp()
{
$_SERVER["REQUEST_URI"] = "";
}
/**
* Check if the "populateTable" function returns an array value if entered all parameters.
* @test
* @covers ReportTables::populateTable
*/
public function it_should_populating_data_with_all_parameters()
{
$tableName = 'TestReportTable';
$result = $this->prepareData($tableName, 1);
$connectionShortName = 'wf';
$type = 'NORMAL';
$fields = $result->fields;
$proUid = $result->processUid;
$grid = '';
$reportTables = new ReportTables();
$reportTables->populateTable($tableName, $connectionShortName, $type, $fields, $proUid, $grid);
$expected = $result->dataFields;
$expected['APP_UID'] = $result->applicationUid;
$expected['APP_NUMBER'] = $result->applicationNumber;
$actual = (array) DB::table($tableName)
->select()
->first();
$this->assertEquals($expected, $actual);
}
/**
* Check if the "populateTable" function returns an array value if entered all
* parameters and type and grid are correct values.
* @test
* @covers ReportTables::populateTable
*/
public function it_should_populating_data_with_all_parameters_with_type_is_grid()
{
$tableName = 'TestReportTable';
$result = $this->prepareData($tableName, 18, true);
$connectionShortName = 'wf';
$type = 'GRID';
$fields = $result->fields;
$proUid = $result->processUid;
$grid = 'var_Grid1';
$reportTables = new ReportTables();
$reportTables->populateTable($tableName, $connectionShortName, $type, $fields, $proUid, $grid);
$indexRow = 1;
$expected = $result->appData[$grid];
foreach ($expected as &$row) {
$row['APP_UID'] = $result->applicationUid;
$row['APP_NUMBER'] = $result->applicationNumber;
$row['ROW'] = (string) ($indexRow++);
}
$expected = array_values($expected);
$actual = DB::table($tableName)
->select()
->get();
$actual->transform(function ($item, $key) {
return (array) $item;
});
$actual = $actual->toArray();
$this->assertEquals($expected, $actual);
}
/**
* Check if the "populateTable" function returns an array value if entered all
* parameters and type and grid are incorrect values.
* @test
* @covers ReportTables::populateTable
*/
public function it_should_populating_data_with_all_parameters_with_type_is_grid_null()
{
$tableName = 'TestReportTable';
$result = $this->prepareData($tableName, 19, true);
$connectionShortName = 'wf';
$type = 'GRID';
$fields = $result->fields;
$proUid = $result->processUid;
$grid = null;
$reportTables = new ReportTables();
$reportTables->populateTable($tableName, $connectionShortName, $type, $fields, $proUid, $grid);
$actual = DB::table($tableName)
->select()
->get();
$actual->transform(function ($item, $key) {
return (array) $item;
});
$actual = $actual->toArray();
$this->assertEquals([], $actual);
}
/**
* Check if the "populateTable" function returns an empty array if only the
* name of the report table has been entered.
* @test
* @covers ReportTables::populateTable
*/
public function this_should_populate_the_reports_table_only_with_the_mandatory_parameter_tableName()
{
$tableName = 'TestReportTable';
$result = $this->prepareData($tableName, 2);
$reportTables = new ReportTables();
$reportTables->populateTable($tableName);
$expected = $result->dataFields;
$expected['APP_UID'] = $result->applicationUid;
$expected['APP_NUMBER'] = $result->applicationNumber;
$actual = (array) DB::table($tableName)
->select()
->first();
$this->assertEquals([], $actual);
}
/**
* Check if the "populateTable" function returns an empty array if you have
* entered the name of the table of the reportTable and the name of the
* connection.
* @test
* @covers ReportTables::populateTable
*/
public function this_should_populate_the_reports_table_with_the_connectionShortName_parameter()
{
$tableName = 'TestReportTable';
$result = $this->prepareData($tableName, 3);
$connectionShortName = 'wf';
$reportTables = new ReportTables();
$reportTables->populateTable($tableName, $connectionShortName);
$expected = $result->dataFields;
$expected['APP_UID'] = $result->applicationUid;
$expected['APP_NUMBER'] = $result->applicationNumber;
$actual = (array) DB::table($tableName)
->select()
->first();
$this->assertEquals([], $actual);
}
/**
* Check if the "populateTable" function returns an empty array if you have
* entered the name of the table of the reportTable and the name of the
* connection is null.
* @test
* @covers ReportTables::populateTable
*/
public function this_should_populate_the_reports_table_with_the_connectionShortName_parameter_is_null()
{
$tableName = 'TestReportTable';
$result = $this->prepareData($tableName, 8);
$connectionShortName = null;
$reportTables = new ReportTables();
$reportTables->populateTable($tableName, $connectionShortName);
$expected = $result->dataFields;
$expected['APP_UID'] = $result->applicationUid;
$expected['APP_NUMBER'] = $result->applicationNumber;
$actual = (array) DB::table($tableName)
->select()
->first();
$this->assertEquals([], $actual);
}
/**
* Check if the "populateTable" function returns an empty array if you have
* entered the name of the table of the reportTable and the name of the
* connection is incorrect value.
* @test
* @covers ReportTables::populateTable
*/
public function this_should_populate_the_reports_table_with_the_connectionShortName_parameter_is_incorrect_value()
{
$tableName = 'TestReportTable';
$result = $this->prepareData($tableName, 9);
$connectionShortName = G::generateUniqueID();
$reportTables = new ReportTables();
$reportTables->populateTable($tableName, $connectionShortName);
$expected = $result->dataFields;
$expected['APP_UID'] = $result->applicationUid;
$expected['APP_NUMBER'] = $result->applicationNumber;
$actual = (array) DB::table($tableName)
->select()
->first();
$this->assertEquals([], $actual);
}
/**
* Check if the "populateTable" function returns an empty array if you have
* entered the name of the table of the reportTable, the name of the
* connection and type.
* @test
* @covers ReportTables::populateTable
*/
public function this_should_populate_the_reports_table_with_the_parameters_connectionShortName_type()
{
$tableName = 'TestReportTable';
$result = $this->prepareData($tableName, 4);
$connectionShortName = 'wf';
$type = 'NORMAL';
$reportTables = new ReportTables();
$reportTables->populateTable($tableName, $connectionShortName, $type);
$expected = $result->dataFields;
$expected['APP_UID'] = $result->applicationUid;
$expected['APP_NUMBER'] = $result->applicationNumber;
$actual = (array) DB::table($tableName)
->select()
->first();
$this->assertEquals([], $actual);
}
/**
* Check if the "populateTable" function returns an empty array if you have
* entered the name of the table of the reportTable, the name of the
* connection and type is grid.
* @test
* @covers ReportTables::populateTable
*/
public function this_should_populate_the_reports_table_with_the_parameters_connectionShortName_type_is_grid()
{
$tableName = 'TestReportTable';
$result = $this->prepareData($tableName, 11);
$connectionShortName = 'wf';
$type = 'GRID';
$reportTables = new ReportTables();
$reportTables->populateTable($tableName, $connectionShortName, $type);
$expected = $result->dataFields;
$expected['APP_UID'] = $result->applicationUid;
$expected['APP_NUMBER'] = $result->applicationNumber;
$actual = (array) DB::table($tableName)
->select()
->first();
$this->assertEquals([], $actual);
}
/**
* Check if the "populateTable" function returns an empty array if you have
* entered the name of the table of the reportTable, the name of the
* connection and type is null.
* @test
* @covers ReportTables::populateTable
*/
public function this_should_populate_the_reports_table_with_the_parameters_connectionShortName_type_is_null()
{
$tableName = 'TestReportTable';
$result = $this->prepareData($tableName, 10);
$connectionShortName = 'wf';
$type = null;
$reportTables = new ReportTables();
$reportTables->populateTable($tableName, $connectionShortName, $type);
$expected = $result->dataFields;
$expected['APP_UID'] = $result->applicationUid;
$expected['APP_NUMBER'] = $result->applicationNumber;
$actual = (array) DB::table($tableName)
->select()
->first();
$this->assertEquals([], $actual);
}
/**
* Check if the "populateTable" function returns an empty array if you have
* entered the name of the table of the reportTable, the name of the
* connection, the type and fields.
* @test
* @covers ReportTables::populateTable
*/
public function this_should_populate_the_reports_table_with_the_parameters_connectionShortName_type_fields()
{
$tableName = 'TestReportTable';
$result = $this->prepareData($tableName, 5);
$connectionShortName = 'wf';
$type = 'NORMAL';
$fields = $result->fields;
$reportTables = new ReportTables();
$reportTables->populateTable($tableName, $connectionShortName, $type, $fields);
$expected = $result->dataFields;
$expected['APP_UID'] = $result->applicationUid;
$expected['APP_NUMBER'] = $result->applicationNumber;
$actual = (array) DB::table($tableName)
->select()
->first();
$this->assertEquals([], $actual);
}
/**
* Check if the "populateTable" function returns an empty array if you have
* entered the name of the table of the reportTable, the name of the
* connection, the type and fields is null.
* @test
* @covers ReportTables::populateTable
*/
public function this_should_populate_the_reports_table_with_the_parameters_connectionShortName_type_fields_is_null()
{
$tableName = 'TestReportTable';
$result = $this->prepareData($tableName, 12);
$connectionShortName = 'wf';
$type = 'NORMAL';
$fields = null;
$reportTables = new ReportTables();
$reportTables->populateTable($tableName, $connectionShortName, $type, $fields);
$expected = $result->dataFields;
$expected['APP_UID'] = $result->applicationUid;
$expected['APP_NUMBER'] = $result->applicationNumber;
$actual = (array) DB::table($tableName)
->select()
->first();
$this->assertEquals([], $actual);
}
/**
* Check if the "populateTable" function returns an empty array if you have
* entered the name of the table of the reportTable, the name of the
* connection, the type and fields is empty array.
* @test
* @covers ReportTables::populateTable
*/
public function this_should_populate_the_reports_table_with_the_parameters_connectionShortName_type_fields_is_empty_array()
{
$tableName = 'TestReportTable';
$result = $this->prepareData($tableName, 13);
$connectionShortName = 'wf';
$type = 'NORMAL';
$fields = [];
$reportTables = new ReportTables();
$reportTables->populateTable($tableName, $connectionShortName, $type, $fields);
$expected = $result->dataFields;
$expected['APP_UID'] = $result->applicationUid;
$expected['APP_NUMBER'] = $result->applicationNumber;
$actual = (array) DB::table($tableName)
->select()
->first();
$this->assertEquals([], $actual);
}
/**
* Check if the "populateTable" function returns an empty array if you have
* entered the name of the table of the reportTable, the name of the
* connection, the type and fields is incorrect value.
* @test
* @covers ReportTables::populateTable
*/
public function this_should_populate_the_reports_table_with_the_parameters_connectionShortName_type_fields_is_incorrect_value()
{
$tableName = 'TestReportTable';
$result = $this->prepareData($tableName, 14);
$connectionShortName = 'wf';
$type = 'NORMAL';
$fields = "";
$reportTables = new ReportTables();
$reportTables->populateTable($tableName, $connectionShortName, $type, $fields);
$expected = $result->dataFields;
$expected['APP_UID'] = $result->applicationUid;
$expected['APP_NUMBER'] = $result->applicationNumber;
$actual = (array) DB::table($tableName)
->select()
->first();
$this->assertEquals([], $actual);
}
/**
* Check if the "populateTable" function returns an array value if you have
* entered the name of the table of the reportTable, the name of the
* connection, the type, the fields and process identifier.
* @test
* @covers ReportTables::populateTable
*/
public function this_should_populate_the_reports_table_with_the_parameters_connectionShortName_type_fields_proUid()
{
$tableName = 'TestReportTable';
$result = $this->prepareData($tableName, 6);
$connectionShortName = 'wf';
$type = 'NORMAL';
$fields = $result->fields;
$proUid = $result->processUid;
$reportTables = new ReportTables();
$reportTables->populateTable($tableName, $connectionShortName, $type, $fields, $proUid);
$expected = $result->dataFields;
$expected['APP_UID'] = $result->applicationUid;
$expected['APP_NUMBER'] = $result->applicationNumber;
$actual = (array) DB::table($tableName)
->select()
->first();
$this->assertEquals($expected, $actual);
}
/**
* Check if the "populateTable" function returns an empty array if you have
* entered the name of the table of the reportTable, the name of the
* connection, the type, the fields and process identifier is null.
* @test
* @covers ReportTables::populateTable
*/
public function this_should_populate_the_reports_table_with_the_parameters_connectionShortName_type_fields_proUid_is_null()
{
$tableName = 'TestReportTable';
$result = $this->prepareData($tableName, 15);
$connectionShortName = 'wf';
$type = 'NORMAL';
$fields = $result->fields;
$proUid = null;
$reportTables = new ReportTables();
$reportTables->populateTable($tableName, $connectionShortName, $type, $fields, $proUid);
$expected = $result->dataFields;
$expected['APP_UID'] = $result->applicationUid;
$expected['APP_NUMBER'] = $result->applicationNumber;
$actual = (array) DB::table($tableName)
->select()
->first();
$this->assertEquals([], $actual);
}
/**
* Check if the "populateTable" function returns an array value if you have
* entered the name of the table of the reportTable, the name of the
* connection, the type, the fields, the process identifier and grid name.
* @test
* @covers ReportTables::populateTable
*/
public function this_should_populate_the_reports_table_with_the_parameters_connectionShortName_type_fields_proUid_grid()
{
$tableName = 'TestReportTable';
$result = $this->prepareData($tableName, 7);
$connectionShortName = 'wf';
$type = 'NORMAL';
$fields = $result->fields;
$proUid = $result->processUid;
$grid = '';
$reportTables = new ReportTables();
$reportTables->populateTable($tableName, $connectionShortName, $type, $fields, $proUid, $grid);
$expected = $result->dataFields;
$expected['APP_UID'] = $result->applicationUid;
$expected['APP_NUMBER'] = $result->applicationNumber;
$actual = (array) DB::table($tableName)
->select()
->first();
$this->assertEquals($expected, $actual);
}
/**
* Check if the "populateTable" function returns an array value if you have
* entered the name of the table of the reportTable, the name of the
* connection, the type, the fields, the process identifier and grid name if null.
* @test
* @covers ReportTables::populateTable
*/
public function this_should_populate_the_reports_table_with_the_parameters_connectionShortName_type_fields_proUid_grid_if_null()
{
$tableName = 'TestReportTable';
$result = $this->prepareData($tableName, 16);
$connectionShortName = 'wf';
$type = 'NORMAL';
$fields = $result->fields;
$proUid = $result->processUid;
$grid = null;
$reportTables = new ReportTables();
$reportTables->populateTable($tableName, $connectionShortName, $type, $fields, $proUid, $grid);
$expected = $result->dataFields;
$expected['APP_UID'] = $result->applicationUid;
$expected['APP_NUMBER'] = $result->applicationNumber;
$actual = (array) DB::table($tableName)
->select()
->first();
$this->assertEquals($expected, $actual);
}
/**
* Get mapping fields supported by report table.
* @return array
*/
private function getMapFields()
{
return [
[
'sFieldName' => 'var_Text1',
'sType' => 'char'
],
[
'sFieldName' => 'var_Textarea1',
'sType' => 'text'
],
[
'sFieldName' => 'var_Dropdown1',
'sType' => 'char'
],
[
'sFieldName' => 'var_Suggest1',
'sType' => 'char'
],
[
'sFieldName' => 'var_DateTime1',
'sType' => 'date'
],
[
'sFieldName' => 'var_String1',
'sType' => 'char'
],
[
'sFieldName' => 'var_Integer1',
'sType' => 'number'
],
[
'sFieldName' => 'var_Boolean1',
'sType' => 'boolean'
],
[
'sFieldName' => 'var_Array1',
'sType' => 'array'
]
];
}
/**
* Create fields data by type supported.
* @param array $types
* @return array
*/
private function createFieldsByType($types = [])
{
$fields = [];
$mapping = [];
$faker = Faker\Factory::create();
$date = $faker->dateTime();
$mapFields = $this->getMapFields();
foreach ($mapFields as $key => $value) {
if (!in_array($value['sType'], $types)) {
continue;
}
switch ($value['sType']) {
case 'number':
$mapping[] = $value;
$fields[$value['sFieldName']] = (string) random_int(0, 100);
break;
case 'char':
$mapping[] = $value;
$fields[$value['sFieldName']] = G::generateUniqueID();
break;
case 'text':
$mapping[] = $value;
$fields[$value['sFieldName']] = G::generateUniqueID();
break;
case 'date':
$mapping[] = $value;
$fields[$value['sFieldName']] = $date->format('Y-m-d H:i:s');
break;
case 'boolean':
$mapping[] = $value;
$fields[$value['sFieldName']] = ['0' => 0];
break;
}
}
return [
'data' => $fields,
'mapping' => $mapping
];
}
/**
* Prepare data initial for test, the grid parameter is optional if you want
* to create a grid type field.
*
* @param string $tableName
* @param integer $applicationNumber
* @param boolean $grid
* @return object
*/
private function prepareData($tableName, $applicationNumber, $grid = null)
{
$faker = Faker\Factory::create();
$date = $faker->dateTime();
$userUid = G::generateUniqueID();
$processUid = G::generateUniqueID();
$taskUid = G::generateUniqueID();
$applicationUid = G::generateUniqueID();
$structure = $this->createFieldsByType(['number', 'char', 'text', 'date']);
$fields = $structure['mapping'];
$dataFields = $structure['data'];
$appData = [
'SYS_LANG' => 'en',
'SYS_SKIN' => 'neoclassic',
'SYS_SYS' => 'workflow',
'APPLICATION' => G::generateUniqueID(),
'PROCESS' => G::generateUniqueID(),
'TASK' => '',
'INDEX' => 2,
'USER_LOGGED' => $userUid,
'USR_USERNAME' => 'admin',
'APP_NUMBER' => $applicationNumber,
'PIN' => '97ZN'
];
$appData = array_merge($appData, $dataFields);
if ($grid === true) {
$gridFields = [
'var_Grid1' => [
'1' => $dataFields,
'2' => $dataFields,
]
];
$appData = array_merge($appData, $gridFields);
}
$user = factory(User::class)->create([
'USR_UID' => $userUid
]);
$process = factory(Process::class)->create([
'PRO_UID' => $processUid
]);
$task = factory(Task::class)->create([
'PRO_UID' => $process->PRO_UID
]);
$application = factory(Application::class)->create([
'PRO_UID' => $process->PRO_UID,
'APP_UID' => $applicationUid,
'APP_NUMBER' => $applicationNumber,
'APP_DATA' => serialize($appData)
]);
Schema::dropIfExists($tableName);
Schema::create($tableName, function ($table) use ($dataFields, $grid) {
$table->string('APP_UID');
$table->string('APP_NUMBER');
if ($grid === true) {
$table->string('ROW');
}
foreach ($dataFields as $key => $value) {
$table->string($key);
}
});
$result = new stdClass();
$result->userUid = $userUid;
$result->processUid = $processUid;
$result->taskUid = $taskUid;
$result->applicationUid = $applicationUid;
$result->applicationNumber = $applicationNumber;
$result->fields = $fields;
$result->dataFields = $dataFields;
$result->appData = $appData;
$result->user = $user;
$result->process = $process;
$result->task = $task;
$result->application = $application;
return $result;
}
}

View File

@@ -1,7 +1,10 @@
<?php <?php
use Illuminate\Support\Facades\DB;
use ProcessMaker\Model\Application;
/** /**
* ReportTables - Report tables * Report Tables
*/ */
class ReportTables class ReportTables
{ {
@@ -184,218 +187,188 @@ class ReportTables
* This Function fills the table * This Function fills the table
* *
* @access public * @access public
* * @param string $tableName Table name
* @param string $sTableName Table name * @param string $connectionShortName Connection name
* @param string $sConnection Connection name * @param string $type
* @param string $sType * @param array $fields
* @param array $aFields * @param string $proUid
* @param string $sProcessUid * @param string $grid
* @param string $sGrid * @see ConsolidatedCases->processConsolidated()
* * @see Processes->createReportTables()
* @see workflow/engine/methods/cases/caseConsolidated.php
* @see workflow/engine/methods/processes/consolidated.php ajax_con->con_save_properties()
* @see workflow/engine/methods/reportTables/reportTables_Save.php
* @link https://wiki.processmaker.com/3.0/Report_Tables
* @return void * @return void
*/ */
public function populateTable( public function populateTable($tableName, $connectionShortName = 'report', $type = 'NORMAL', $fields = [], $proUid = '', $grid = '')
$sTableName,
$sConnection = 'report',
$sType = 'NORMAL',
$aFields = array(),
$sProcessUid = '',
$sGrid = ''
)
{ {
$sTableName = $this->sPrefix . $sTableName; $tableName = $this->sPrefix . $tableName;
//we have to do the propel connection //we have to do the propel connection
$PropelDatabase = $this->chooseDB($sConnection); $database = $this->chooseDB($connectionShortName);
$con = Propel::getConnection($PropelDatabase); $connection = Propel::getConnection($database);
$stmt = $con->createStatement(); $statement = $connection->createStatement();
if ($sType == 'GRID') { if ($type == 'GRID') {
$aAux = explode('-', $sGrid); $aux = explode('-', $grid);
$sGrid = $aAux[0]; $grid = $aux[0];
} }
$case = new Cases();
try { try {
switch (DB_ADAPTER) { switch (DB_ADAPTER) {
case 'mysql': case 'mysql':
//select cases for this Process, ordered by APP_NUMBER $applications = Application::getByProUid($proUid);
$oCriteria = new Criteria('workflow'); foreach ($applications as $application) {
$oCriteria->add(ApplicationPeer::PRO_UID, $sProcessUid); $appData = $case->unserializeData($application->APP_DATA);
$oCriteria->addAscendingOrderByColumn(ApplicationPeer::APP_NUMBER); DB::delete("DELETE FROM `{$tableName}` WHERE APP_UID = '{$application->APP_UID}'");
$oDataset = ApplicationPeer::doSelectRS($oCriteria); if ($type == 'NORMAL') {
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); $query = 'INSERT INTO `' . $tableName . '` (';
$oDataset->next(); $query .= '`APP_UID`,`APP_NUMBER`';
while ($aRow = $oDataset->getRow()) { foreach ($fields as $field) {
$aData = unserialize($aRow['APP_DATA']); $query .= ',`' . $field['sFieldName'] . '`';
//delete previous record from this report table ( previous records in case this is a grid )
$deleteSql = 'DELETE FROM `' . $sTableName . "` WHERE APP_UID = '" . $aRow['APP_UID'] . "'";
$rsDel = $stmt->executeQuery($deleteSql);
if ($sType == 'NORMAL') {
$sQuery = 'INSERT INTO `' . $sTableName . '` (';
$sQuery .= '`APP_UID`,`APP_NUMBER`';
foreach ($aFields as $aField) {
$sQuery .= ',`' . $aField['sFieldName'] . '`';
} }
$sQuery .= ") VALUES ('" . $aRow['APP_UID'] . "'," . (int)$aRow['APP_NUMBER']; $query .= ") VALUES ('" . $application->APP_UID . "'," . $application->APP_NUMBER;
foreach ($aFields as $aField) { foreach ($fields as $field) {
switch ($aField['sType']) { switch ($field['sType']) {
case 'number': case 'number':
$sQuery .= ',' . (isset($aData[$aField['sFieldName']]) ? (float)str_replace( $query .= ',' . (isset($appData[$field['sFieldName']]) ? (float) str_replace(',', '', $appData[$field['sFieldName']]) : '0');
',',
'',
$aData[$aField['sFieldName']]
) : '0');
break; break;
case 'char': case 'char':
case 'text': case 'text':
if (!isset($aData[$aField['sFieldName']])) { if (!isset($appData[$field['sFieldName']])) {
$aData[$aField['sFieldName']] = ''; $appData[$field['sFieldName']] = '';
} }
$sQuery .= ",'" . (isset($aData[$aField['sFieldName']]) ? mysqli_real_escape_string( $string = $appData[$field['sFieldName']];
$con->getResource(), if (is_array($string)) {
$aData[$aField['sFieldName']] $string = implode($string, ",");
) : '') . "'"; }
$query .= ",'" . (isset($appData[$field['sFieldName']]) ? mysqli_real_escape_string($connection->getResource(), $string) : '') . "'";
break; break;
case 'date': case 'date':
$value = (isset($aData[$aField['sFieldName']]) && trim($aData[$aField['sFieldName']])) != '' ? "'" . $aData[$aField['sFieldName']] . "'" : 'NULL'; $value = (isset($appData[$field['sFieldName']]) && trim($appData[$field['sFieldName']])) != '' ? "'" . $appData[$field['sFieldName']] . "'" : 'NULL';
$sQuery .= "," . $value; $query .= "," . $value;
break; break;
} }
} }
$sQuery .= ')'; $query .= ')';
$rs = $stmt->executeQuery($sQuery); DB::insert($query);
} else { } else {
if (isset($aData[$sGrid])) { if (isset($appData[$grid])) {
foreach ($aData[$sGrid] as $iRow => $aGridRow) { foreach ($appData[$grid] as $indexRow => $gridRow) {
$sQuery = 'INSERT INTO `' . $sTableName . '` ('; $query = 'INSERT INTO `' . $tableName . '` (';
$sQuery .= '`APP_UID`,`APP_NUMBER`,`ROW`'; $query .= '`APP_UID`,`APP_NUMBER`,`ROW`';
foreach ($aFields as $aField) { foreach ($fields as $field) {
$sQuery .= ',`' . $aField['sFieldName'] . '`'; $query .= ',`' . $field['sFieldName'] . '`';
} }
$sQuery .= ") VALUES ('" . $aRow['APP_UID'] . "'," . (int)$aRow['APP_NUMBER'] . ',' . $iRow; $query .= ") VALUES ('" . $application->APP_UID . "'," . (int) $application->APP_NUMBER . ',' . $indexRow;
foreach ($aFields as $aField) { foreach ($fields as $field) {
switch ($aField['sType']) { switch ($field['sType']) {
case 'number': case 'number':
$sQuery .= ',' . (isset($aGridRow[$aField['sFieldName']]) ? (float)str_replace( $query .= ',' . (isset($gridRow[$field['sFieldName']]) ? (float) str_replace(',', '', $gridRow[$field['sFieldName']]) : '0');
',',
'',
$aGridRow[$aField['sFieldName']]
) : '0');
break; break;
case 'char': case 'char':
case 'text': case 'text':
if (!isset($aGridRow[$aField['sFieldName']])) { if (!isset($gridRow[$field['sFieldName']])) {
$aGridRow[$aField['sFieldName']] = ''; $gridRow[$field['sFieldName']] = '';
} }
$sQuery .= ",'" . (isset($aGridRow[$aField['sFieldName']]) ? mysqli_real_escape_string( $stringEscape = mysqli_real_escape_string($connection->getResource(), $gridRow[$field['sFieldName']]);
$con->getResource(), $query .= ",'" . (isset($gridRow[$field['sFieldName']]) ? $stringEscape : '') . "'";
$aGridRow[$aField['sFieldName']]
) : '') . "'";
break; break;
case 'date': case 'date':
$value = (isset($aGridRow[$aField['sFieldName']]) && trim($aGridRow[$aField['sFieldName']])) != '' ? "'" . $aGridRow[$aField['sFieldName']] . "'" : 'NULL'; $value = (isset($gridRow[$field['sFieldName']]) && trim($gridRow[$field['sFieldName']])) != '' ? "'" . $gridRow[$field['sFieldName']] . "'" : 'NULL';
$sQuery .= "," . $value; $query .= "," . $value;
break; break;
} }
} }
$sQuery .= ')'; $query .= ')';
$rs = $stmt->executeQuery($sQuery); DB::insert($query);
} }
} }
} }
$oDataset->next();
} }
break; break;
/** /**
* For SQLServer code * For SQLServer code
* Note: It is only possible to create Report Tables in MySQL databases. The list will only show connections to those databases even if the project has connections to other DBMS.
* This section is not used and has been marked for deletion.
* @link https://wiki.processmaker.com/3.0/Report_Tables#Creating_Report_Tables
* @deprecated
*/ */
case 'mssql': case 'mssql':
$oCriteria = new Criteria('workflow'); $criteria = new Criteria('workflow');
$oCriteria->add(ApplicationPeer::PRO_UID, $sProcessUid); $criteria->add(ApplicationPeer::PRO_UID, $proUid);
$oCriteria->addAscendingOrderByColumn(ApplicationPeer::APP_NUMBER); $criteria->addAscendingOrderByColumn(ApplicationPeer::APP_NUMBER);
$oDataset = ApplicationPeer::doSelectRS($oCriteria); $dataset = ApplicationPeer::doSelectRS($criteria);
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC); $dataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$oDataset->next(); $dataset->next();
while ($aRow = $oDataset->getRow()) { while ($row = $dataset->getRow()) {
$aData = unserialize($aRow['APP_DATA']); $appData = unserialize($row['APP_DATA']);
//verify use mssql //verify use mssql
mysqli_query( mysqli_query(
$con->getResource(), $connection->getResource(), 'DELETE FROM [' . $tableName . "] WHERE APP_UID = '" . $row['APP_UID'] . "'"
'DELETE FROM [' . $sTableName . "] WHERE APP_UID = '" . $aRow['APP_UID'] . "'"
); );
if ($sType == 'NORMAL') { if ($type == 'NORMAL') {
$sQuery = 'INSERT INTO [' . $sTableName . '] ('; $query = 'INSERT INTO [' . $tableName . '] (';
$sQuery .= '[APP_UID],[APP_NUMBER]'; $query .= '[APP_UID],[APP_NUMBER]';
foreach ($aFields as $aField) { foreach ($fields as $field) {
$sQuery .= ',[' . $aField['sFieldName'] . ']'; $query .= ',[' . $field['sFieldName'] . ']';
} }
$sQuery .= ") VALUES ('" . $aRow['APP_UID'] . "'," . (int)$aRow['APP_NUMBER']; $query .= ") VALUES ('" . $row['APP_UID'] . "'," . (int) $row['APP_NUMBER'];
foreach ($aFields as $aField) { foreach ($fields as $field) {
switch ($aField['sType']) { switch ($field['sType']) {
case 'number': case 'number':
$sQuery .= ',' . (isset($aData[$aField['sFieldName']]) ? (float)str_replace( $query .= ',' . (isset($appData[$field['sFieldName']]) ? (float) str_replace(',', '', $appData[$field['sFieldName']]) : '0');
',',
'',
$aData[$aField['sFieldName']]
) : '0');
break; break;
case 'char': case 'char':
case 'text': case 'text':
if (!isset($aData[$aField['sFieldName']])) { if (!isset($appData[$field['sFieldName']])) {
$aData[$aField['sFieldName']] = ''; $appData[$field['sFieldName']] = '';
} }
$sQuery .= ",'" . (isset($aData[$aField['sFieldName']]) ? mysqli_real_escape_string( $stringEscape = mysqli_real_escape_string($connection->getResource(), $appData[$field['sFieldName']]);
$con->getResource(), $query .= ",'" . (isset($appData[$field['sFieldName']]) ? $stringEscape : '') . "'";
$aData[$aField['sFieldName']]
) : '') . "'";
break; break;
case 'date': case 'date':
$sQuery .= ",'" . (isset($aData[$aField['sFieldName']]) ? $aData[$aField['sFieldName']] : '') . "'"; $query .= ",'" . (isset($appData[$field['sFieldName']]) ? $appData[$field['sFieldName']] : '') . "'";
break; break;
} }
} }
$sQuery .= ')'; $query .= ')';
$rs = $stmt->executeQuery($sQuery); $rs = $statement->executeQuery($query);
} else { } else {
if (isset($aData[$sGrid])) { if (isset($appData[$grid])) {
foreach ($aData[$sGrid] as $iRow => $aGridRow) { foreach ($appData[$grid] as $indexRow => $gridRow) {
$sQuery = 'INSERT INTO [' . $sTableName . '] ('; $query = 'INSERT INTO [' . $tableName . '] (';
$sQuery .= '`APP_UID`,`APP_NUMBER`,`ROW`'; $query .= '`APP_UID`,`APP_NUMBER`,`ROW`';
foreach ($aFields as $aField) { foreach ($fields as $field) {
$sQuery .= ',[' . $aField['sFieldName'] . ']'; $query .= ',[' . $field['sFieldName'] . ']';
} }
$sQuery .= ") VALUES ('" . $aRow['APP_UID'] . "'," . (int)$aRow['APP_NUMBER'] . ',' . $iRow; $query .= ") VALUES ('" . $row['APP_UID'] . "'," . (int) $row['APP_NUMBER'] . ',' . $indexRow;
foreach ($aFields as $aField) { foreach ($fields as $field) {
switch ($aField['sType']) { switch ($field['sType']) {
case 'number': case 'number':
$sQuery .= ',' . (isset($aGridRow[$aField['sFieldName']]) ? (float)str_replace( $query .= ',' . (isset($gridRow[$field['sFieldName']]) ? (float) str_replace(',', '', $gridRow[$field['sFieldName']]) : '0');
',',
'',
$aGridRow[$aField['sFieldName']]
) : '0');
break; break;
case 'char': case 'char':
case 'text': case 'text':
if (!isset($aGridRow[$aField['sFieldName']])) { if (!isset($gridRow[$field['sFieldName']])) {
$aGridRow[$aField['sFieldName']] = ''; $gridRow[$field['sFieldName']] = '';
} }
$sQuery .= ",'" . (isset($aGridRow[$aField['sFieldName']]) ? mysqli_real_escape_string( $stringEscape = mysqli_real_escape_string($connection->getResource(), $gridRow[$field['sFieldName']]);
$con->getResource(), $query .= ",'" . (isset($gridRow[$field['sFieldName']]) ? $stringEscape : '') . "'";
$aGridRow[$aField['sFieldName']]
) : '') . "'";
break; break;
case 'date': case 'date':
$sQuery .= ",'" . (isset($aGridRow[$aField['sFieldName']]) ? $aGridRow[$aField['sFieldName']] : '') . "'"; $query .= ",'" . (isset($gridRow[$field['sFieldName']]) ? $gridRow[$field['sFieldName']] : '') . "'";
break; break;
} }
} }
$sQuery .= ')'; $query .= ')';
$rs = $stmt->executeQuery($sQuery); $rs = $statement->executeQuery($query);
} }
} }
} }
$oDataset->next(); $dataset->next();
} }
break; break;
} }
} catch (Exception $oError) { } catch (Exception $oError) {
throw ($oError); throw ($oError);

View File

@@ -3,6 +3,7 @@
namespace ProcessMaker\Model; namespace ProcessMaker\Model;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
class Application extends Model class Application extends Model
{ {
@@ -24,4 +25,31 @@ class Application extends Model
{ {
return $this->hasOne(User::class, 'APP_CUR_USER', 'USR_UID'); return $this->hasOne(User::class, 'APP_CUR_USER', 'USR_UID');
} }
/**
* Get Applications by PRO_UID, ordered by APP_NUMBER.
* @param string $proUid
* @return object
* @see ReportTables->populateTable()
*/
public static function getByProUid($proUid)
{
$query = Application::query()
->select()
->proUid($proUid)
->orderBy('APP_NUMBER', 'ASC');
return $query->get();
}
/**
* Scope for query to get the applications by PRO_UID.
* @param \Illuminate\Database\Eloquent\Builder $query
* @param string $proUid
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeProUid($query, $proUid)
{
$result = $query->where('PRO_UID', '=', $proUid);
return $result;
}
} }