Skip to content

Commit

Permalink
🔨 #36 - classe without save or delete
Browse files Browse the repository at this point in the history
  • Loading branch information
bjverde committed Feb 3, 2019
1 parent d0cb848 commit 23fabf9
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 181 deletions.
362 changes: 187 additions & 175 deletions classes/TCreateClass.class.php
Original file line number Diff line number Diff line change
@@ -1,175 +1,187 @@
<?php
/**
* SysGen - System Generator with Formdin Framework
* Download Formdin Framework: https://github.com/bjverde/formDin
*
* @author Bjverde <[email protected]>
* @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('<?php');
$this->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();
}
}
}
<?php
/**
* SysGen - System Generator with Formdin Framework
* Download Formdin Framework: https://github.com/bjverde/formDin
*
* @author Bjverde <[email protected]>
* @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('<?php');
$this->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();
}
}
}
2 changes: 1 addition & 1 deletion classes/TCreateDAO.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 9 additions & 1 deletion classes/TGeneratorHelper.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down Expand Up @@ -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()
{
Expand Down
Loading

0 comments on commit 23fabf9

Please sign in to comment.