-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔨 #36 - classe without save or delete
- Loading branch information
bjverde
committed
Feb 3, 2019
1 parent
d0cb848
commit 23fabf9
Showing
4 changed files
with
199 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.