BUG 000 PM tables ver2 ready - propel & phing integration
This commit is contained in:
@@ -57,40 +57,50 @@ class pmTables extends Controller
|
||||
public function edit($httpData)
|
||||
{
|
||||
require_once PATH_CONTROLLERS . 'pmTablesProxy.php';
|
||||
$addTabUid = isset($httpData->id) ? $httpData->id : false;
|
||||
$table = false;
|
||||
$repTabPluginPermissions = false;
|
||||
$additionalTables = new AdditionalTables();
|
||||
require_once 'classes/model/AdditionalTables.php';
|
||||
G::loadClass('pmTable');
|
||||
|
||||
if ($addTabUid !== false) { // if is a edit request
|
||||
require_once 'classes/model/AdditionalTables.php';
|
||||
$additionalTables = new AdditionalTables();
|
||||
$table = false;
|
||||
$addTabUid = isset($httpData->id) ? $httpData->id : false;
|
||||
$dataNumRows = 0;
|
||||
$repTabPluginPermissions = false;
|
||||
$columnsTypes = PmTable::getPropelSupportedColumnTypes();
|
||||
$jsFile = isset($httpData->tableType) && $httpData->tableType == 'report' ? 'editReport' : 'edit';
|
||||
$columnsTypesList = array();
|
||||
|
||||
foreach ($columnsTypes as $columnTypeName => $columnType) {
|
||||
$columnsTypesList[] = array($columnTypeName, $columnType);
|
||||
}
|
||||
|
||||
if ($addTabUid) {
|
||||
$tableData = $additionalTables->getAllData($httpData->id, 0, 2);
|
||||
$dataNumRows = $tableData['count'];
|
||||
}
|
||||
|
||||
if ($addTabUid !== false) { // if it is a edit request
|
||||
$tableFields = array();
|
||||
$fieldsList = array();
|
||||
|
||||
$table = $additionalTables->load($addTabUid, true);
|
||||
//fix for backware compatibility
|
||||
$table['DBS_UID'] = $table['DBS_UID'] == null || $table['DBS_UID'] == '' ? 'workflow': $table['DBS_UID'];
|
||||
$_SESSION['ADD_TAB_UID'] = $addTabUid;
|
||||
|
||||
//list dynaform fields
|
||||
switch ($table['ADD_TAB_TYPE']) {
|
||||
case 'NORMAL':
|
||||
case 'GRID':
|
||||
if ($table['ADD_TAB_TYPE'] == 'NORMAL' || $table['ADD_TAB_TYPE'] == 'GRID') {
|
||||
$repTabPluginPermissions = $this->_getSimpleReportPluginDef();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$jsFile = isset($httpData->tableType) && $httpData->tableType == 'report' ? 'editReport' : 'edit';
|
||||
|
||||
$this->includeExtJS('pmTables/' . $jsFile, $this->debug);
|
||||
|
||||
//fix for backware compatibility
|
||||
if ($table) {
|
||||
$table['DBS_UID'] = $table['DBS_UID'] == null || $table['DBS_UID'] == '' ? 'workflow': $table['DBS_UID'];
|
||||
}
|
||||
$this->includeExtJS('pmTables/' . $jsFile);
|
||||
|
||||
$this->setJSVar('ADD_TAB_UID', $addTabUid);
|
||||
$this->setJSVar('PRO_UID', isset($_GET['PRO_UID'])? $_GET['PRO_UID'] : false);
|
||||
$this->setJSVar('TABLE', $table);
|
||||
$this->setJSVar('dbg', isset($httpData->dbg));
|
||||
$this->setJSVar('columnsTypes', $columnsTypesList);
|
||||
$this->setJSVar('dataNumRows', $dataNumRows);
|
||||
$this->setJSVar('_plugin_permissions', $repTabPluginPermissions);
|
||||
|
||||
G::RenderPage('publish', 'extJs');
|
||||
@@ -108,6 +118,7 @@ class pmTables extends Controller
|
||||
|
||||
$this->includeExtJS('pmTables/data', $this->debug);
|
||||
$this->setJSVar('tableDef', $tableDef);
|
||||
|
||||
//g::pr($tableDef['FIELDS']);
|
||||
G::RenderPage('publish', 'extJs');
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ class pmTablesProxy extends HttpProxyController
|
||||
* save pm table
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
{
|
||||
require_once 'classes/model/AdditionalTables.php';
|
||||
require_once 'classes/model/Fields.php';
|
||||
try {
|
||||
@@ -186,25 +186,53 @@ class pmTablesProxy extends HttpProxyController
|
||||
$data['PRO_UID'] = trim($data['PRO_UID']);
|
||||
$data['columns'] = G::json_decode($_POST['columns']); //decofing data columns
|
||||
$isReportTable = $data['PRO_UID'] != '' ? true : false;
|
||||
|
||||
// Reserved Words
|
||||
$aReservedWords = array(
|
||||
'ALTER', 'CLOSE', 'COMMIT', 'CREATE', 'DECLARE',
|
||||
'DELETE', 'DROP', 'FETCH', 'FUNCTION', 'GRANT',
|
||||
'INDEX', 'INSERT', 'OPEN', 'REVOKE', 'ROLLBACK',
|
||||
'SELECT', 'SYNONYM', 'TABLE', 'UPDATE', 'VIEW',
|
||||
'APP_UID', 'ROW'
|
||||
);
|
||||
|
||||
$oAdditionalTables = new AdditionalTables();
|
||||
$oFields = new Fields();
|
||||
$repTabClassName = $oAdditionalTables->getPHPName($data['REP_TAB_NAME']);
|
||||
$columns = $data['columns'];
|
||||
|
||||
// Reserved Words
|
||||
$reservedWords = array(
|
||||
'ALTER', 'CLOSE', 'COMMIT', 'CREATE', 'DECLARE', 'DELETE', 'DROP', 'FETCH', 'FUNCTION', 'GRANT',
|
||||
'INDEX', 'INSERT', 'OPEN', 'REVOKE', 'ROLLBACK', 'SELECT', 'SYNONYM', 'TABLE', 'UPDATE', 'VIEW', 'APP_UID', 'ROW'
|
||||
);
|
||||
|
||||
// verify if exists.
|
||||
$aNameTable = $oAdditionalTables->loadByName($data['REP_TAB_NAME']);
|
||||
if ($data['REP_TAB_UID'] == '') { //new report table
|
||||
if ($isReportTable) { //setting default columns
|
||||
$defaultColumns = $this->_getReportTableDefaultColumns($data['REP_TAB_TYPE']);
|
||||
$columns = array_merge($defaultColumns, $columns);
|
||||
}
|
||||
|
||||
/** validations **/
|
||||
if(is_array($oAdditionalTables->loadByName($data['REP_TAB_NAME']))) {
|
||||
throw new Exception('The table "' . $data['REP_TAB_NAME'] . '" already exits.');
|
||||
}
|
||||
|
||||
$repTabClassName = $oAdditionalTables->getPHPName($data['REP_TAB_NAME']);
|
||||
if (in_array(strtoupper($data['REP_TAB_NAME']), $reservedWords) ) {
|
||||
throw new Exception('Could not create the table with the name "' . $data['REP_TAB_NAME'] . '" because it is a reserved word.');
|
||||
}
|
||||
}
|
||||
|
||||
//backward compatility
|
||||
foreach ($columns as $i => $column) {
|
||||
switch ($column->field_type) {
|
||||
case 'INT': $columns[$i]->field_type = 'INTEGER'; break;
|
||||
case 'TEXT': $columns[$i]->field_type = 'LONGVARCHAR'; break;
|
||||
}
|
||||
}
|
||||
|
||||
$repTabData = array(
|
||||
G::loadClass('pmTable');
|
||||
ob_start();
|
||||
$pmTable = new pmTable($data['REP_TAB_NAME']);
|
||||
$pmTable->setDataSource($data['REP_TAB_CONNECTION']);
|
||||
$pmTable->setColumns($columns);
|
||||
$pmTable->build();
|
||||
$buildResult = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
// Updating additional table struture information
|
||||
$addTabData = array(
|
||||
'ADD_TAB_UID' => $data['REP_TAB_UID'],
|
||||
'ADD_TAB_NAME' => $data['REP_TAB_NAME'],
|
||||
'ADD_TAB_CLASS_NAME' => $repTabClassName,
|
||||
@@ -215,60 +243,22 @@ class pmTablesProxy extends HttpProxyController
|
||||
'ADD_TAB_TYPE' => $data['REP_TAB_TYPE'],
|
||||
'ADD_TAB_GRID' => $data['REP_TAB_GRID']
|
||||
);
|
||||
|
||||
$columns = $data['columns'];
|
||||
|
||||
if ($data['REP_TAB_UID'] == '') { //new report table
|
||||
|
||||
if ($isReportTable) { //setting default columns
|
||||
$defaultColumns = $this->_getReportTableDefaultColumns($data['REP_TAB_TYPE']);
|
||||
$columns = array_merge($defaultColumns, $columns);
|
||||
}
|
||||
|
||||
/** validations **/
|
||||
if(is_array($aNameTable)) {
|
||||
throw new Exception('The table "' . $data['REP_TAB_NAME'] . '" already exits.');
|
||||
}
|
||||
|
||||
if (in_array(strtoupper($data['REP_TAB_NAME']), $aReservedWords) ) {
|
||||
throw new Exception('Could not create the table with the name "' . $data['REP_TAB_NAME'] . '" because it is a reserved word.');
|
||||
}
|
||||
//create record
|
||||
$addTabUid = $oAdditionalTables->create($repTabData);
|
||||
|
||||
$addTabUid = $oAdditionalTables->create($addTabData);
|
||||
} else { //editing report table
|
||||
$addTabUid = $data['REP_TAB_UID'];
|
||||
//loading old data before update
|
||||
$addTabBeforeData = $oAdditionalTables->load($addTabUid, true);
|
||||
//updating record
|
||||
$oAdditionalTables->update($repTabData);
|
||||
$addTabUid = $data['REP_TAB_UID'];
|
||||
$oAdditionalTables->update($addTabData);
|
||||
|
||||
//removing old data fields references
|
||||
$oCriteria = new Criteria('workflow');
|
||||
$oCriteria->add(FieldsPeer::ADD_TAB_UID, $data['REP_TAB_UID']);
|
||||
//$oCriteria->add(FieldsPeer::FLD_NAME, 'APP_UID', Criteria::NOT_EQUAL);
|
||||
//$oCriteria->add(FieldsPeer::FLD_NAME, 'ROW', Criteria::NOT_EQUAL);
|
||||
FieldsPeer::doDelete($oCriteria);
|
||||
|
||||
//getting old fieldnames
|
||||
$oldFields = array();
|
||||
foreach ($addTabBeforeData['FIELDS'] as $field) {
|
||||
$oldFields[$field['FLD_UID']] = $field;
|
||||
}
|
||||
}
|
||||
|
||||
$aFields = array();
|
||||
$fieldsList = array();
|
||||
$editFieldsList = array();
|
||||
|
||||
|
||||
// Updating pmtable fields
|
||||
foreach ($columns as $i => $column) {
|
||||
//new feature, to reorder the columns
|
||||
// if (isset($oldFields[$column->uid])) { // the the field alreaday exists
|
||||
// if ($oldFields[$column->uid]['FLD_INDEX'] != $i) { // if its index has changed
|
||||
// $column->uid = ''; //set as new field,
|
||||
// }
|
||||
// }
|
||||
|
||||
$field = array(
|
||||
'FLD_UID' => $column->uid,
|
||||
'FLD_INDEX' => $i,
|
||||
@@ -276,50 +266,40 @@ class pmTablesProxy extends HttpProxyController
|
||||
'FLD_NAME' => $column->field_name,
|
||||
'FLD_DESCRIPTION' => $column->field_label,
|
||||
'FLD_TYPE' => $column->field_type,
|
||||
'FLD_SIZE' => $column->field_size,
|
||||
'FLD_NULL' => (isset($column->field_null) && $column->field_null ? 1 : 0),
|
||||
'FLD_AUTO_INCREMENT' => (isset($column->field_bai) && $column->field_bai ? 1 : 0),
|
||||
'FLD_KEY' => (isset($column->field_key) && $column->field_key ? 1 : 0),
|
||||
'FLD_SIZE' => $column->field_size=='' ? NULL : $column->field_size,
|
||||
'FLD_NULL' => $column->field_null ? 1 : 0,
|
||||
'FLD_AUTO_INCREMENT' => $column->field_autoincrement ? 1 : 0,
|
||||
'FLD_KEY' => $column->field_key ? 1 : 0,
|
||||
'FLD_FOREIGN_KEY' => 0,
|
||||
'FLD_FOREIGN_KEY_TABLE' => '',
|
||||
'FLD_DYN_NAME' => $column->field_dyn,
|
||||
'FLD_DYN_UID' => $column->field_uid,
|
||||
'FLD_FILTER' => (isset($column->field_filter) && $column->field_filter ? 1 : 0)
|
||||
'FLD_FILTER' => (isset($column->field_filter) && $column->field_filter) ? 1 : 0
|
||||
);
|
||||
|
||||
$fieldUid = $oFields->create($field);
|
||||
$fieldsList[] = $field;
|
||||
|
||||
if($data['REP_TAB_UID'] == '') { //new
|
||||
$aFields[] = array(
|
||||
'sType' => $column->field_type,
|
||||
'iSize' => $column->field_size,
|
||||
'sFieldName' => $column->field_name,
|
||||
'bNull' => (isset($column->field_null) ? $column->field_null : 1),
|
||||
'bAI' => (isset($column->field_bai) ? $column->field_bai : 0),
|
||||
'bPrimaryKey' => (isset($column->field_key) ? $column->field_key : 0)
|
||||
);
|
||||
} else { //editing
|
||||
$field['FLD_UID'] = $fieldUid;
|
||||
$aFields[$fieldUid] = $field;
|
||||
}
|
||||
}
|
||||
if ($data['REP_TAB_UID'] == '') { //create a new report table
|
||||
$oAdditionalTables->createTable($data['REP_TAB_NAME'], $data['REP_TAB_CONNECTION'], $aFields);
|
||||
|
||||
} else { //editing
|
||||
//print_R($aFields);
|
||||
$oAdditionalTables->updateTable($data['REP_TAB_NAME'], $data['REP_TAB_CONNECTION'], $aFields, $oldFields);
|
||||
}
|
||||
$oAdditionalTables->createPropelClasses($data['REP_TAB_NAME'], '', $fieldsList, $addTabUid, $data['REP_TAB_CONNECTION']);
|
||||
if ($isReportTable) {
|
||||
$oAdditionalTables->populateReportTable($data['REP_TAB_NAME'], $data['REP_TAB_CONNECTION'], $data['REP_TAB_TYPE'], $fieldsList, $data['PRO_UID'], $data['REP_TAB_GRID']);
|
||||
$oFields->create($field);
|
||||
}
|
||||
|
||||
// if ($isReportTable) {
|
||||
// $oAdditionalTables->populateReportTable($data['REP_TAB_NAME'], $data['REP_TAB_CONNECTION'], $data['REP_TAB_TYPE'], $fieldsList, $data['PRO_UID'], $data['REP_TAB_GRID']);
|
||||
// }
|
||||
|
||||
$result->success = true;
|
||||
$result->msg = $buildResult;
|
||||
} catch (Exception $e) {
|
||||
$buildResult = ob_get_contents();
|
||||
ob_end_clean();
|
||||
$result->success = false;
|
||||
$result->msg = $e->getMessage();
|
||||
|
||||
// if it is a propel exception message
|
||||
if (preg_match('/(.*)\s\[(.*):\s(.*)\]\s\[(.*):\s(.*)\]/', $e->getMessage(), $match)) {
|
||||
$result->msg = $match[3];
|
||||
$result->type = ucfirst($pmTable->getDbConfig()->adapter);
|
||||
}
|
||||
else {
|
||||
$result->msg = $e->getMessage();
|
||||
$result->type = G::loadTranslation('ID_EXCEPTION');
|
||||
}
|
||||
|
||||
$result->trace = $e->getTraceAsString();
|
||||
}
|
||||
|
||||
@@ -332,16 +312,16 @@ class pmTablesProxy extends HttpProxyController
|
||||
*/
|
||||
public function delete($httpData)
|
||||
{
|
||||
G::LoadClass('reportTables');
|
||||
$rows = G::json_decode(stripslashes($httpData->rows));
|
||||
$rp = new reportTables();
|
||||
$at = new AdditionalTables();
|
||||
|
||||
try {
|
||||
foreach ($rows as $row ) {
|
||||
if($row->type == 'CLASSIC') {
|
||||
G::LoadClass('reportTables');
|
||||
$rp = new reportTables();
|
||||
$rp->deleteReportTable($row->id);
|
||||
} else {
|
||||
$at = new AdditionalTables();
|
||||
$at->deleteAll($row->id);
|
||||
}
|
||||
}
|
||||
@@ -415,7 +395,8 @@ class pmTablesProxy extends HttpProxyController
|
||||
throw new Exception("ERROR: $className class file doesn't exit!");
|
||||
}
|
||||
|
||||
require_once $sPath . $this->className . '.php';
|
||||
//require_once $sPath . $this->className . '.php';
|
||||
require_once 'classes/' . $this->className . '.php';
|
||||
$toSave = false;
|
||||
|
||||
if (is_array($rows)) { //multiple
|
||||
@@ -1043,6 +1024,7 @@ class pmTablesProxy extends HttpProxyController
|
||||
$application->field_key = 1;
|
||||
$application->field_null = 0;
|
||||
$application->field_filter = false;
|
||||
$application->field_autoincrement = false;
|
||||
array_push($defaultColumns, $application);
|
||||
|
||||
$application = new stdClass(); //APP_NUMBER
|
||||
@@ -1051,12 +1033,13 @@ class pmTablesProxy extends HttpProxyController
|
||||
$application->field_uid = '';
|
||||
$application->field_name = 'APP_NUMBER';
|
||||
$application->field_label = 'APP_NUMBER';
|
||||
$application->field_type = 'INT';
|
||||
$application->field_type = 'INTEGER';
|
||||
$application->field_size = 11;
|
||||
$application->field_dyn = '';
|
||||
$application->field_key = 0;
|
||||
$application->field_null = 0;
|
||||
$application->field_filter = false;
|
||||
$application->field_autoincrement = false;
|
||||
array_push($defaultColumns, $application);
|
||||
|
||||
//if it is a grid report table
|
||||
@@ -1067,12 +1050,13 @@ class pmTablesProxy extends HttpProxyController
|
||||
$gridIndex->field_uid = '';
|
||||
$gridIndex->field_name = 'ROW';
|
||||
$gridIndex->field_label = 'ROW';
|
||||
$gridIndex->field_type = 'INT';
|
||||
$gridIndex->field_type = 'INTEGER';
|
||||
$gridIndex->field_size = '11';
|
||||
$gridIndex->field_dyn = '';
|
||||
$gridIndex->field_key = 1;
|
||||
$gridIndex->field_null = 0;
|
||||
$gridIndex->field_filter = false;
|
||||
$application->field_autoincrement = false;
|
||||
array_push($defaultColumns, $gridIndex);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user