From 23fabf9da31f3518c312f90c843b52d7d1aa0dd7 Mon Sep 17 00:00:00 2001 From: bjverde Date: Sun, 3 Feb 2019 18:43:17 -0200 Subject: [PATCH] :hammer: #36 - classe without save or delete --- classes/TCreateClass.class.php | 362 +++++++++++++++-------------- classes/TCreateDAO.class.php | 2 +- classes/TGeneratorHelper.class.php | 10 +- modulos/gen04.php | 6 +- 4 files changed, 199 insertions(+), 181 deletions(-) diff --git a/classes/TCreateClass.class.php b/classes/TCreateClass.class.php index 79e4e79..0ee0c13 100644 --- a/classes/TCreateClass.class.php +++ b/classes/TCreateClass.class.php @@ -1,175 +1,187 @@ - - * @license https://github.com/bjverde/sysgen/blob/master/LICENSE GPL-3.0 - * @link https://github.com/bjverde/sysgen - * - * PHP Version 5.6 - */ - -if (!defined('EOL')) { - define('EOL', "\n"); -} -if (!defined('TAB')) { - define('TAB', chr(9)); -} -if (!defined('DS')) { - define('DS', DIRECTORY_SEPARATOR); -} -class TCreateClass extends TCreateFileContent -{ - private $tableRef; - private $tableRefDAO; - private $tableRefVO; - private $withSqlPagination; - private $listColumnsName; - private $listColumnsProperties; - - public function __construct($tableRef) - { - $tableRef = ucfirst(strtolower($tableRef)); - $this->tableRef = $tableRef; - $this->tableRefDAO= $tableRef.'DAO'; - $this->tableRefVO = $tableRef.'VO'; - $this->setFileName($tableRef.'.class.php'); - $path = TGeneratorHelper::getPathNewSystem().DS.'classes'.DS; - $this->setFilePath($path); - } - //------------------------------------------------------------------------------------ - public function setWithSqlPagination($withSqlPagination) - { - return $this->withSqlPagination = $withSqlPagination; - } - public function getWithSqlPagination() - { - return $this->withSqlPagination; - } - //-------------------------------------------------------------------------------------- - public function setListColunnsName($listColumnsName) - { - if (!is_array($listColumnsName)) { - throw new InvalidArgumentException('List of Columns Properties not is a array'); - } - $this->listColumnsName = array_map('strtoupper', $listColumnsName); - } - public function getListColunnsName() - { - return $this->listColumnsName; - } - //-------------------------------------------------------------------------------------- - public function setListColumnsProperties($listColumnsProperties) - { - if (!is_array($listColumnsProperties)) { - throw new InvalidArgumentException('List of Columns Properties not is a array'); - } - $this->listColumnsProperties = $listColumnsProperties; - } - public function getListColumnsProperties() - { - return $this->listColumnsProperties; - } - //-------------------------------------------------------------------------------------- - private function addConstruct() - { - $this->addLine(TAB.'public function __construct(){'); - $this->addLine(TAB.'}'); - } - //-------------------------------------------------------------------------------------- - private function addSelectById() - { - $this->addLine(TAB.'public static function selectById( $id ){'); - $this->addLine(TAB.TAB.'$result = '.$this->tableRefDAO.'::selectById( $id );'); - $this->addLine(TAB.TAB.'return $result;'); - $this->addLine(TAB.'}'); - } - //-------------------------------------------------------------------------------------- - private function addSelectCount() - { - $this->addLine(TAB.'public static function selectCount( $where=null ){'); - $this->addLine(TAB.TAB.'$result = '.$this->tableRefDAO.'::selectCount( $where );'); - $this->addLine(TAB.TAB.'return $result;'); - $this->addLine(TAB.'}'); - } - //-------------------------------------------------------------------------------------- - private function addSelectAllPagination() - { - $this->addLine(TAB.'public static function selectAllPagination( $orderBy=null, $where=null, $page=null, $rowsPerPage= null){'); - $this->addLine(TAB.TAB.'$result = '.$this->tableRefDAO.'::selectAllPagination( $orderBy, $where, $page, $rowsPerPage );'); - $this->addLine(TAB.TAB.'return $result;'); - $this->addLine(TAB.'}'); - } - //-------------------------------------------------------------------------------------- - private function addSelectAll() - { - $this->addLine(TAB.'public static function selectAll( $orderBy=null, $where=null ){'); - $this->addLine(TAB.TAB.'$result = '.$this->tableRefDAO.'::selectAll( $orderBy, $where );'); - $this->addLine(TAB.TAB.'return $result;'); - $this->addLine(TAB.'}'); - } - //-------------------------------------------------------------------------------------- - private function addSave() - { - $columunPK = ucfirst(strtolower($this->listColumnsName[0])); - $this->addLine(TAB.'public static function save( '.$this->tableRefVO.' $objVo ){'); - $this->addLine(TAB.TAB.'$result = null;'); - $this->addLine(TAB.TAB.'if( $objVo->get'.$columunPK.'() ) {'); - $this->addLine(TAB.TAB.TAB.'$result = '.$this->tableRefDAO.'::update( $objVo );'); - $this->addLine(TAB.TAB.'} else {'); - $this->addLine(TAB.TAB.TAB.'$result = '.$this->tableRefDAO.'::insert( $objVo );'); - $this->addLine(TAB.TAB.'}'); - $this->addLine(TAB.TAB.'return $result;'); - $this->addLine(TAB.'}'); - } - //-------------------------------------------------------------------------------------- - private function addDelete() - { - $this->addLine(TAB.'public static function delete( $id ){'); - $this->addLine(TAB.TAB.'$result = '.$this->tableRefDAO.'::delete( $id );'); - $this->addLine(TAB.TAB.'return $result;'); - $this->addLine(TAB.'}'); - } - //-------------------------------------------------------------------------------------- - public function show($print = false) - { - $this->lines=null; - $this->addLine('addSysGenHeaderNote(); - $this->addBlankLine(); - $this->addLine('class '.$this->tableRef.' {'); - $this->addBlankLine(); - $this->addBlankLine(); - $this->addConstruct(); - - $this->addLine(); - $this->addSelectById(); - - $this->addLine(); - $this->addSelectCount(); - - if ($this->getWithSqlPagination() == GRID_SQL_PAGINATION) { - $this->addLine(); - $this->addSelectAllPagination(); - } - - $this->addLine(); - $this->addSelectAll(); - - $this->addLine(); - $this->addSave(); - - $this->addLine(); - $this->addDelete(); - - $this->addBlankLine(); - $this->addLine('}'); - $this->addLine('?>'); - if ($print) { - echo $this->getLinesString(); - } else { - return $this->getLinesString(); - } - } -} + + * @license https://github.com/bjverde/sysgen/blob/master/LICENSE GPL-3.0 + * @link https://github.com/bjverde/sysgen + * + * PHP Version 5.6 + */ + +if (!defined('EOL')) { + define('EOL', "\n"); +} +if (!defined('TAB')) { + define('TAB', chr(9)); +} +if (!defined('DS')) { + define('DS', DIRECTORY_SEPARATOR); +} +class TCreateClass extends TCreateFileContent +{ + private $tableRef; + private $tableRefDAO; + private $tableRefVO; + private $withSqlPagination; + private $listColumnsName; + private $listColumnsProperties; + private $tableType = null; + + public function __construct($tableRef) + { + $tableRef = ucfirst(strtolower($tableRef)); + $this->tableRef = $tableRef; + $this->tableRefDAO= $tableRef.'DAO'; + $this->tableRefVO = $tableRef.'VO'; + $this->setFileName($tableRef.'.class.php'); + $path = TGeneratorHelper::getPathNewSystem().DS.'classes'.DS; + $this->setFilePath($path); + } + //------------------------------------------------------------------------------------ + public function setWithSqlPagination($withSqlPagination) + { + return $this->withSqlPagination = $withSqlPagination; + } + public function getWithSqlPagination() + { + return $this->withSqlPagination; + } + //-------------------------------------------------------------------------------------- + public function setListColunnsName($listColumnsName) + { + if (!is_array($listColumnsName)) { + throw new InvalidArgumentException('List of Columns Properties not is a array'); + } + $this->listColumnsName = array_map('strtoupper', $listColumnsName); + } + public function getListColunnsName() + { + return $this->listColumnsName; + } + //-------------------------------------------------------------------------------------- + public function setListColumnsProperties($listColumnsProperties) + { + if (!is_array($listColumnsProperties)) { + throw new InvalidArgumentException('List of Columns Properties not is a array'); + } + $this->listColumnsProperties = $listColumnsProperties; + } + public function getListColumnsProperties() + { + return $this->listColumnsProperties; + } + //------------------------------------------------------------------------------------ + public function setTableType($tableType) + { + $this->tableType = $tableType; + } + public function getTableType() + { + return $this->tableType; + } + //-------------------------------------------------------------------------------------- + private function addConstruct() + { + $this->addLine(TAB.'public function __construct(){'); + $this->addLine(TAB.'}'); + } + //-------------------------------------------------------------------------------------- + private function addSelectById() + { + $this->addLine(TAB.'public static function selectById( $id ){'); + $this->addLine(TAB.TAB.'$result = '.$this->tableRefDAO.'::selectById( $id );'); + $this->addLine(TAB.TAB.'return $result;'); + $this->addLine(TAB.'}'); + } + //-------------------------------------------------------------------------------------- + private function addSelectCount() + { + $this->addLine(TAB.'public static function selectCount( $where=null ){'); + $this->addLine(TAB.TAB.'$result = '.$this->tableRefDAO.'::selectCount( $where );'); + $this->addLine(TAB.TAB.'return $result;'); + $this->addLine(TAB.'}'); + } + //-------------------------------------------------------------------------------------- + private function addSelectAllPagination() + { + $this->addLine(TAB.'public static function selectAllPagination( $orderBy=null, $where=null, $page=null, $rowsPerPage= null){'); + $this->addLine(TAB.TAB.'$result = '.$this->tableRefDAO.'::selectAllPagination( $orderBy, $where, $page, $rowsPerPage );'); + $this->addLine(TAB.TAB.'return $result;'); + $this->addLine(TAB.'}'); + } + //-------------------------------------------------------------------------------------- + private function addSelectAll() + { + $this->addLine(TAB.'public static function selectAll( $orderBy=null, $where=null ){'); + $this->addLine(TAB.TAB.'$result = '.$this->tableRefDAO.'::selectAll( $orderBy, $where );'); + $this->addLine(TAB.TAB.'return $result;'); + $this->addLine(TAB.'}'); + } + //-------------------------------------------------------------------------------------- + private function addSave() + { + $columunPK = ucfirst(strtolower($this->listColumnsName[0])); + $this->addLine(TAB.'public static function save( '.$this->tableRefVO.' $objVo ){'); + $this->addLine(TAB.TAB.'$result = null;'); + $this->addLine(TAB.TAB.'if( $objVo->get'.$columunPK.'() ) {'); + $this->addLine(TAB.TAB.TAB.'$result = '.$this->tableRefDAO.'::update( $objVo );'); + $this->addLine(TAB.TAB.'} else {'); + $this->addLine(TAB.TAB.TAB.'$result = '.$this->tableRefDAO.'::insert( $objVo );'); + $this->addLine(TAB.TAB.'}'); + $this->addLine(TAB.TAB.'return $result;'); + $this->addLine(TAB.'}'); + } + //-------------------------------------------------------------------------------------- + private function addDelete() + { + $this->addLine(TAB.'public static function delete( $id ){'); + $this->addLine(TAB.TAB.'$result = '.$this->tableRefDAO.'::delete( $id );'); + $this->addLine(TAB.TAB.'return $result;'); + $this->addLine(TAB.'}'); + } + //-------------------------------------------------------------------------------------- + public function show($print = false) + { + $this->lines=null; + $this->addLine('addSysGenHeaderNote(); + $this->addBlankLine(); + $this->addLine('class '.$this->tableRef.' {'); + $this->addBlankLine(); + $this->addBlankLine(); + $this->addConstruct(); + + $this->addLine(); + $this->addSelectById(); + + $this->addLine(); + $this->addSelectCount(); + + if ($this->getWithSqlPagination() == GRID_SQL_PAGINATION) { + $this->addLine(); + $this->addSelectAllPagination(); + } + + $this->addLine(); + $this->addSelectAll(); + + if ($this->getTableType() != TGeneratorHelper::TABLE_TYPE_VIEW) { + $this->addLine(); + $this->addSave(); + + $this->addLine(); + $this->addDelete(); + } + + $this->addBlankLine(); + $this->addLine('}'); + $this->addLine('?>'); + if ($print) { + echo $this->getLinesString(); + } else { + return $this->getLinesString(); + } + } +} diff --git a/classes/TCreateDAO.class.php b/classes/TCreateDAO.class.php index 4354d05..517f6fb 100644 --- a/classes/TCreateDAO.class.php +++ b/classes/TCreateDAO.class.php @@ -447,7 +447,7 @@ public function showDAO($print = false) $this->addSqlSelectAll(); // fim select - if ($this->getTableType() != TABLE_TYPE_VIEW) { + if ($this->getTableType() != TGeneratorHelper::TABLE_TYPE_VIEW) { // insert $this->addLine(); $this->addSqlInsert(); diff --git a/classes/TGeneratorHelper.class.php b/classes/TGeneratorHelper.class.php index 9406909..7431fc8 100644 --- a/classes/TGeneratorHelper.class.php +++ b/classes/TGeneratorHelper.class.php @@ -279,11 +279,12 @@ private static function getConfigByDBMS($DBMS) return $config; } - public static function createFilesClasses($tableName, $listColumnsProperties) + public static function createFilesClasses($tableName, $listColumnsProperties, $tableSchema, $tableType) { $DBMS = $_SESSION[APLICATIVO]['DBMS']['TYPE']; $configDBMS = self::getConfigByDBMS($DBMS); $generator = new TCreateClass($tableName); + $generator->setTableType($tableType); $generator->setListColumnsProperties($listColumnsProperties); $generator->setListColunnsName($listColumnsProperties['COLUMN_NAME']); $generator->setWithSqlPagination($configDBMS['TPGRID']); @@ -327,6 +328,13 @@ public static function createFilesForms($tableName, $listColumnsProperties) $geradorForm->setGridType($configDBMS['TPGRID']); $geradorForm->saveForm(); } + + public static function createFilesFormClassDaoVoFromTable($tableName, $listColumnsProperties, $tableSchema, $tableType) + { + self::createFilesDaoVoFromTable($tableName, $listColumnsProperties,$tableSchema,$tableType); + self::createFilesClasses($tableName, $listColumnsProperties, $tableSchema, $tableType); + self::createFilesForms($tableName, $listColumnsProperties); + } public static function getUrlNewSystem() { diff --git a/modulos/gen04.php b/modulos/gen04.php index d5fdcda..869766b 100644 --- a/modulos/gen04.php +++ b/modulos/gen04.php @@ -51,12 +51,10 @@ $tableType = strtoupper($listTables['TABLE_TYPE'][$key]); $key = $key + 1; if($tableType == TGeneratorHelper::TABLE_TYPE_TABLE){ - TGeneratorHelper::createFilesDaoVoFromTable($table, $listFieldsTable,$tableSchema,$tableType); - TGeneratorHelper::createFilesClasses($table, $listFieldsTable); - TGeneratorHelper::createFilesForms($table, $listFieldsTable); + TGeneratorHelper::createFilesFormClassDaoVoFromTable($table, $listFieldsTable,$tableSchema,$tableType); $html->add('
'.$key.Message::CREATED_TABLE_ITEN.$table); }else{ - TGeneratorHelper::createFilesDaoVoFromTable($table, $listFieldsTable,$tableSchema,$tableType); + TGeneratorHelper::createFilesFormClassDaoVoFromTable($table, $listFieldsTable,$tableSchema,$tableType); $html->add('
'.$key.Message::CREATED_VIEW_ITEN.$table); }