Merge branch 'master' of bitbucket.org:colosa/processmaker

This commit is contained in:
Victor Saisa Lopez
2014-02-12 11:11:58 -04:00

View File

@@ -8,8 +8,9 @@ use \Fields;
class Table class Table
{ {
/** /**
* List of ReportTables in process * List of Tables in process
* @var string $pro_uid. Uid for Process * @var string $pro_uid. Uid for process
* @var string $reportFlag. If is report table
* *
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com> * @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia * @copyright Colosa - Bolivia
@@ -38,9 +39,10 @@ class Table
} }
/** /**
* Get data for ReportTable * Get data for Table
* @var string $tab_uid. Uid for Table * @var string $tab_uid. Uid for table
* @var string $pro_uid. Uid for Process * @var string $pro_uid. Uid for process
* @var string $reportFlag. If is report table
* @var string $validate. Flag for validate * @var string $validate. Flag for validate
* *
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com> * @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
@@ -56,7 +58,7 @@ class Table
$pro_uid = $this->validateProUid($pro_uid); $pro_uid = $this->validateProUid($pro_uid);
$tabData['PRO_UID'] = $pro_uid; $tabData['PRO_UID'] = $pro_uid;
} }
$tab_uid = $this->validateTabUid($tab_uid); $tab_uid = $this->validateTabUid($tab_uid, $reportFlag);
} }
$tabData = array(); $tabData = array();
@@ -87,9 +89,18 @@ class Table
} }
// TABLE FIELDS // TABLE FIELDS
$hiddenFields = array(
'fld_foreign_key', 'fld_foreign_key_table',
'fld_dyn_name', 'fld_dyn_uid', 'fld_filter'
);
foreach ($table['FIELDS'] as $valField) { foreach ($table['FIELDS'] as $valField) {
$fieldTemp = array(); $fieldTemp = array();
$fieldTemp = array_change_key_case($valField, CASE_LOWER); $fieldTemp = array_change_key_case($valField, CASE_LOWER);
foreach ($fieldTemp as $key => $value) {
if (in_array($key, $hiddenFields)) {
unset($fieldTemp[$key]);
}
}
$tabData['FIELDS'][] = $fieldTemp; $tabData['FIELDS'][] = $fieldTemp;
} }
@@ -99,8 +110,9 @@ class Table
/** /**
* Generate Data for Report Table * Generate Data for Report Table
* @var string $pro_uid. Uid for Process * @var string $pro_uid. Uid for process
* @var string $rep_uid. Uid for Report Table * @var string $rep_uid. Uid for report table
* @var string $validate. Flag for validate
* *
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com> * @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia * @copyright Colosa - Bolivia
@@ -128,10 +140,10 @@ class Table
} }
/** /**
* Get data for ReportTable * Get data for Table
* @var string $tab_uid. Uid for Report Table * @var string $tab_uid. Uid for table
* @var string $pro_uid. Uid for Process * @var string $pro_uid. Uid for process
* @var string $validate. Flag for validate * @var string $reportFlag. If is report table
* *
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com> * @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia * @copyright Colosa - Bolivia
@@ -144,7 +156,7 @@ class Table
if ($reportFlag) { if ($reportFlag) {
$pro_uid = $this->validateProUid($pro_uid); $pro_uid = $this->validateProUid($pro_uid);
} }
$tab_uid = $this->validateTabUid($tab_uid); $tab_uid = $this->validateTabUid($tab_uid, $reportFlag);
$additionalTables = new AdditionalTables(); $additionalTables = new AdditionalTables();
$table = $additionalTables->load($tab_uid, true); $table = $additionalTables->load($tab_uid, true);
@@ -168,10 +180,10 @@ class Table
/** /**
* Save Data for Table * Save Data for Table
* @var string $tab_data. Data for Table * @var string $tab_data. Data for table
* @var string $pro_uid. Uid for Process * @var string $pro_uid. Uid for process
* @var string $reportFlag. Flag for Report Table * @var string $reportFlag. If is report table
* @var string $createRep. Flag for create Table * @var string $createRep. Flag for create table
* *
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com> * @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia * @copyright Colosa - Bolivia
@@ -236,13 +248,14 @@ class Table
if (is_array( $oAdditionalTables->loadByName( $tableName ) )) { if (is_array( $oAdditionalTables->loadByName( $tableName ) )) {
throw new \Exception(G::loadTranslation('ID_PMTABLE_ALREADY_EXISTS', array($tableName))); throw new \Exception(G::loadTranslation('ID_PMTABLE_ALREADY_EXISTS', array($tableName)));
} }
if (in_array( strtoupper( $tableName ), $reservedWords ) || }
in_array( strtoupper( $tableName ), $reservedWordsSql )) { if (in_array( strtoupper( $tableName ), $reservedWords ) ||
throw (new \Exception(G::LoadTranslation("ID_PMTABLE_INVALID_NAME", array($tableName)))); in_array( strtoupper( $tableName ), $reservedWordsSql )) {
} throw (new \Exception(G::LoadTranslation("ID_PMTABLE_INVALID_NAME", array($tableName))));
} }
//backward compatility //backward compatility
$flagKey = false;
$columnsStd = array(); $columnsStd = array();
foreach ($columns as $i => $column) { foreach ($columns as $i => $column) {
if (isset($columns[$i]['fld_dyn'])) { if (isset($columns[$i]['fld_dyn'])) {
@@ -268,6 +281,18 @@ class Table
$columns[$i]['field_size'] = $columns[$i]['fld_size']; $columns[$i]['field_size'] = $columns[$i]['fld_size'];
unset($columns[$i]['fld_size']); unset($columns[$i]['fld_size']);
} }
if (isset($columns[$i]['fld_key'])) {
$columns[$i]['field_key'] = $columns[$i]['fld_key'];
unset($columns[$i]['fld_key']);
}
if (isset($columns[$i]['fld_null'])) {
$columns[$i]['field_null'] = $columns[$i]['fld_null'];
unset($columns[$i]['fld_null']);
}
if (isset($columns[$i]['fld_autoincrement'])) {
$columns[$i]['field_autoincrement'] = $columns[$i]['fld_autoincrement'];
unset($columns[$i]['fld_autoincrement']);
}
if (in_array(strtoupper($columns[$i]['field_name']), $reservedWordsSql) || if (in_array(strtoupper($columns[$i]['field_name']), $reservedWordsSql) ||
in_array( strtolower( $columns[$i]['field_name']), $reservedWordsPhp )) { in_array( strtolower( $columns[$i]['field_name']), $reservedWordsPhp )) {
@@ -315,8 +340,14 @@ class Table
unset($temp->_index); unset($temp->_index);
unset($temp->field_filter); unset($temp->field_filter);
} }
if ($temp->field_key == 1 || $temp->field_key == true) {
$flagKey = true;
}
$columnsStd[$i] = $temp; $columnsStd[$i] = $temp;
} }
if (!$flagKey) {
throw (new \Exception("The fields must have a key 'fld_key'"));
}
$pmTable = new \pmTable($tableName); $pmTable = new \pmTable($tableName);
$pmTable->setDataSource($tableCon); $pmTable->setDataSource($tableCon);
@@ -404,9 +435,10 @@ class Table
} }
/** /**
* Update Data for ReportTable * Update Data for Table
* @var string $tab_data. Data for ReportTable * @var string $tab_data. Data for table
* @var string $pro_uid. Uid for Process * @var string $pro_uid. Uid for process
* @var string $reportFlag. If is report table
* *
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com> * @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia * @copyright Colosa - Bolivia
@@ -421,7 +453,7 @@ class Table
} else { } else {
$tab_uid = $tab_data['pmt_uid']; $tab_uid = $tab_data['pmt_uid'];
} }
$tab_uid = $this->validateTabUid($tab_uid); $tab_uid = $this->validateTabUid($tab_uid, $reportFlag);
$dataValidate = array(); $dataValidate = array();
$oCriteria = new \Criteria('workflow'); $oCriteria = new \Criteria('workflow');
@@ -455,9 +487,10 @@ class Table
} }
/** /**
* Delete ReportTable * Delete Table
* @var string $pro_uid. Uid for Process * @var string $tab_uid. Uid for table
* @var string $tab_uid. Uid for Report Table * @var string $pro_uid. Uid for process
* @var string $reportFlag. If is report table
* *
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com> * @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia * @copyright Colosa - Bolivia
@@ -469,7 +502,7 @@ class Table
if ($reportFlag) { if ($reportFlag) {
$pro_uid = $this->validateProUid($pro_uid); $pro_uid = $this->validateProUid($pro_uid);
} }
$tab_uid = $this->validateTabUid($tab_uid); $tab_uid = $this->validateTabUid($tab_uid, $reportFlag);
$at = new AdditionalTables(); $at = new AdditionalTables();
$table = $at->load( $tab_uid ); $table = $at->load( $tab_uid );
@@ -710,29 +743,34 @@ class Table
} }
/** /**
* Validate Report Table Uid * Validate Table Uid
* @var string $rep_uid. Uid for report table * @var string $tab_uid. Uid for table
* *
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com> * @author Brayan Pereyra (Cochalo) <brayan@colosa.com>
* @copyright Colosa - Bolivia * @copyright Colosa - Bolivia
* *
* @return string * @return string
*/ */
public function validateTabUid ($rep_uid) public function validateTabUid ($tab_uid, $reportFlag = true)
{ {
$rep_uid = trim($rep_uid); if ($reportFlag) {
if ($rep_uid == '') { $label = 'The report table with rep_uid:';
throw (new \Exception("The report table with rep_uid: '', does not exist.")); } else {
$label = 'The pm table with pmt_uid:';
}
$tab_uid = trim($tab_uid);
if ($tab_uid == '') {
throw (new \Exception($label . "'', does not exist."));
} }
$oAdditionalTables = new \AdditionalTables(); $oAdditionalTables = new \AdditionalTables();
if (!($oAdditionalTables->exists($rep_uid))) { if (!($oAdditionalTables->exists($tab_uid))) {
throw (new \Exception("The report table with rep_uid: '$rep_uid', does not exist.")); throw (new \Exception($label . "'$tab_uid', does not exist."));
} }
return $rep_uid; return $tab_uid;
} }
/** /**
* Validate Report Table Name * Validate Table Name
* @var string $rep_tab_name. Name for report table * @var string $rep_tab_name. Name for report table
* *
* @author Brayan Pereyra (Cochalo) <brayan@colosa.com> * @author Brayan Pereyra (Cochalo) <brayan@colosa.com>