Skip to content
This repository has been archived by the owner on May 21, 2020. It is now read-only.

Commit

Permalink
renomeado arquivo do sql de mysql, editando readme, e passando sqls p…
Browse files Browse the repository at this point in the history
…ara padrão
  • Loading branch information
jonathands committed Jul 30, 2012
1 parent cc72a29 commit e8d0183
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 56 deletions.
1 change: 1 addition & 0 deletions Forms/Business.php
Expand Up @@ -2,6 +2,7 @@

/**
* Application_Form_Business form file.
* This is a sample generated files
*/
class Application_Form_Business extends Zend_Form
{
Expand Down
1 change: 1 addition & 0 deletions Forms/Employee.php
Expand Up @@ -2,6 +2,7 @@

/**
* Application_Form_Employee form file.
* This is a sample generated files
*/
class Application_Form_Employee extends Zend_Form
{
Expand Down
31 changes: 14 additions & 17 deletions README
@@ -1,41 +1,38 @@
This is a library to create Zend Forms automatically based on information from the database.
This library is meant to create Zend Forms based on information retrieved from the database automatically.

Requirements for the usage:
PHP 5 >= 5.3.0

The forms files are created based on tables existing in the database, so for each table that exists in the database a form file will be created.
The form files are created based on tables existing at the database, so for each existing table a form file will be created.

To created the form files correctly each column of table must contain a comment labeling the field, this comment will be used in the field element of the form file being generated.
To created the form files correctly each column of the table must contain a comment labeling the field, this comment will be used as the name of the generated field element of the form file being generated.

At the moment of the creation of each field in the form file, some validations are considered. If the field type is string, the attribute maxlength is inserted on Zend Form Element. If the field type is integer, the Zend_Validate_Int is inserted in the Zend Form Element. If the field deny null values on column, the validator Zend_Validate_NotEmpty and option required will be inserted in the form element.
At the moment of the creation of each field in the form file, some validations are considered. If the field type is String, the attribute maxlength is used as a rule on Zend Form Element. If the field type is integer, the Zend_Validate_Int is used in the Zend Form Element. If the field deny null values on column, the validator Zend_Validate_NotEmpty and option required used.

On each columns of tables on database, if the column exist a foreign key, automatically the form element inserted will be Zend_Form_Element_Select.

You can create the forms files the following ways:
- In the pattern suggested by Zend ( verify Zend manual section recommended structure )
- In your personal library ( using namespaces )
Also if the column is a foreign key, the form element will be a Zend_Form_Element_Select.

You can create the forms files in the following ways:
- Using the structure suggested by Zend ( verify Zend manual, section: recommended structure )
- Using your personal library ( using namespaces )


1) The database:

To generate the forms, you can use database MySQL or PostgreSQL. Configure your database file zend-form-generator.php and enjoy the library.

There are two test databases that you can check the files and "database-mysql.sql" and "database-postgresql.sql".

Remember, you need to insert a comment in all the columns of the database to the form generator function properly.
To generate the forms, you can use MySQL or PostgreSQL database systems. To use the library you must configure your database connection data in the zend-form-generator.php file.
The package comes with 2 test databases and the files used to handle each database system are "database-mysql.sql" and "database-postgresql.sql".

Remember, you need to insert a comment in all the columns of the database so the form generator can function properly.


2) Run the library:

To generate your forms, just execute the following commands:
To generate your forms execute the following commands using the PHP CLI:

Generating forms inside the Forms folder using structure recommended by Zend:
$ php zend-form-generator.php generate-forms Forms


Generating forms inside the Forms folder using namespaces:
Generating forms inside the Forms folder using a namespaces:
$ php zend-form-generator.php generate-forms Forms Name\Your\Namespace


Expand All @@ -45,6 +42,6 @@ or
$ php zend-form-generator.php generate-forms --primary-keys Forms Name\Your\Namespace


Soon a feature to customize the forms using decorators will be added.
In the near future decorators will be added to give the ability to customize the generated forms.

Enjoy!
File renamed without changes.
78 changes: 39 additions & 39 deletions library/Ionix/Zend/Form/Generator/Db/Pgsql.php
Expand Up @@ -32,15 +32,15 @@ public function __construct( $db )
public function getDatabaseSchemas( $database )
{
$stmt = $this->getDb()
->query("SELECT table_schema
FROM information_schema.COLUMNS
WHERE (
table_schema != 'information_schema'
AND table_schema != 'pg_catalog'
)
AND table_catalog = :database
GROUP BY table_schema
ORDER BY table_schema", array(':database' => $database));
->query("SELECT table_schema ".
"FROM information_schema.COLUMNS ".
"WHERE ( ".
"table_schema != 'information_schema' ".
"AND table_schema != 'pg_catalog' ".
") ".
"AND table_catalog = :database ".
"GROUP BY table_schema ".
"ORDER BY table_schema", array(':database' => $database));
$result = $stmt->fetchAll();

$databaseSchemas = array();
Expand All @@ -58,12 +58,12 @@ public function getDatabaseSchemas( $database )
public function getDatabaseTables( $schema )
{
$stmt = $this->getDb()
->query("SELECT table_name
FROM information_schema.COLUMNS
WHERE
table_schema = :schema
GROUP BY table_name
ORDER BY table_name", array(':schema' => $schema));
->query("SELECT table_name ".
"FROM information_schema.COLUMNS ".
"WHERE ".
"table_schema = :schema ".
"GROUP BY table_name ".
"ORDER BY table_name", array(':schema' => $schema));
$result = $stmt->fetchAll();

$databaseTables = array();
Expand All @@ -81,12 +81,12 @@ public function getDatabaseTables( $schema )
public function getTableColumns( $table, $schema = null )
{
$stmt = $this->getDb()
->query("SELECT *,
(SELECT pg_catalog.obj_description(oid) FROM pg_catalog.pg_class c
WHERE c.relname=cols.table_name) AS table_comment
,(SELECT pg_catalog.col_description(oid,cols.ordinal_position::int) FROM pg_catalog.pg_class c where c.relname=cols.table_name) as column_comment
FROM information_schema.columns cols
WHERE table_name = :table AND table_schema = :schema", array(':table' => $table, ':schema' => $schema));
->query("SELECT *, ".
"(SELECT pg_catalog.obj_description(oid) FROM pg_catalog.pg_class c ".
"WHERE c.relname=cols.table_name) AS table_comment ".
",(SELECT pg_catalog.col_description(oid,cols.ordinal_position::int) FROM pg_catalog.pg_class c where c.relname=cols.table_name) as column_comment ".
"FROM information_schema.columns cols ".
"WHERE table_name = :table AND table_schema = :schema", array(':table' => $table, ':schema' => $schema));
$result = $stmt->fetchAll();

$tableColumns = array();
Expand All @@ -113,15 +113,15 @@ public function getTableColumns( $table, $schema = null )
public function getTablePrimaryKeys( $table, $schema = null )
{
$stmt = $this->getDb()
->query("SELECT
kcu.column_name,
tc.table_name
FROM
information_schema.table_constraints AS tc
JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name
JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name
WHERE constraint_type = 'PRIMARY KEY'
AND tc.table_schema = :schema", array(':schema' => $schema));
->query("SELECT ".
"kcu.column_name, ".
"tc.table_name ".
"FROM ".
"information_schema.table_constraints AS tc ".
"JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name ".
"JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name ".
"WHERE constraint_type = 'PRIMARY KEY' ".
"AND tc.table_schema = :schema", array(':schema' => $schema));
$result = $stmt->fetchAll();

$tablePrimaryKeys = array();
Expand All @@ -144,15 +144,15 @@ public function getTablePrimaryKeys( $table, $schema = null )
public function getTableForeignKeys( $table, $schema = null )
{
$stmt = $this->getDb()
->query("SELECT
kcu.column_name,
tc.table_name
FROM
information_schema.table_constraints AS tc
JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name
JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name
WHERE constraint_type = 'FOREIGN KEY'
AND tc.table_schema = :schema", array(':schema' => $schema));
->query("SELECT ".
"kcu.column_name, ".
"tc.table_name ".
"FROM ".
"information_schema.table_constraints AS tc ".
"JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name ".
"JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name ".
"WHERE constraint_type = 'FOREIGN KEY' ".
"AND tc.table_schema = :schema", array(':schema' => $schema));
$result = $stmt->fetchAll();

$tableForeignKeys = array();
Expand Down

0 comments on commit e8d0183

Please sign in to comment.