Skip to content

Commit

Permalink
Updated Console Generators as per Connection Update PDO::ATTR_CASE =>…
Browse files Browse the repository at this point in the history
… PDO::CASE_NATURAL,
  • Loading branch information
sanjoydesk committed Jun 19, 2015
1 parent 8caf5b5 commit b2bd361
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

class GeneratorCommand extends Command
{

public $applicationDir;
public $controller;
public $model;
Expand All @@ -36,11 +35,9 @@ class GeneratorCommand extends Command
private $output;
private $viewType;

public static function __callStatic($method, $arguments = array())
public static function instance()
{
if ($method == 'instance') {
return new self();
}
return new self();
}

public function setSchema($table)
Expand All @@ -59,8 +56,8 @@ public function getPrimaryKey()

if (count($this->columns) > 0) {
foreach ($this->columns as $key => $value) {
if ($value->column_key == 'PRI' || $value->extra == 'auto_increment') {
$primaryKey = $value->column_name;
if ($value->COLUMN_KEY == 'PRI' || $value->EXTRA == 'auto_increment') {
$primaryKey = $value->COLUMN_NAME;
break;
}
}
Expand Down Expand Up @@ -93,7 +90,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->controller = Inflector::classify($input->getArgument('name')) . 'Controller';
// Model name
$this->model = Inflector::classify($input->getArgument('model'));
/** Check for argument database name if not given we will use default
/**
* Check for argument database name if not given we will use default
* database connection
*/
$this->database = (!is_null($input->getArgument('database'))) ?
Expand All @@ -102,7 +100,6 @@ protected function execute(InputInterface $input, OutputInterface $output)

// By default we will generate plain php layout and view pages
$this->viewType = ($input->getOption('template') == false) ? 'php' : 'twig';

$this->columns = $this->getColumns();

if (empty($this->columns)) {
Expand Down Expand Up @@ -163,7 +160,7 @@ private function generateModel()
{
$modelInstance = Model::instance($this);
$modelTemplateDir =
dirname(dirname(__FILE__)) . DS . 'src' . DS . ucfirst('apps') . DS . ucfirst('models') . DS;
dirname(dirname(__FILE__)) . DS . 'src' . DS . 'Apps' . DS . 'Models' . DS;

$modelInstance->setModelTemplatePath($modelTemplateDir);
$modelInstance->updateTemplate();
Expand All @@ -178,7 +175,7 @@ private function generateViews()
{
$viewInstance = View::instance($this);
$viewInstance->setLayoutType($this->viewType);
$viewTemplateDir = dirname(dirname(__FILE__)) . DS . 'src' . DS . ucfirst('apps') . DS . ucfirst('views') . DS;
$viewTemplateDir = dirname(dirname(__FILE__)) . DS . 'src' . DS . 'Apps' . DS . 'Views' . DS;
$viewInstance->setTableColumns($this->columns);
$viewInstance->setViewTemplatePath($viewTemplateDir);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private function getColumns()
return $this->tableSchema->connect(
$this->database,
Inflector::tabilize($this->model)
)->getColumns();
)->{__FUNCTION__}();
}

/**
Expand All @@ -75,8 +75,8 @@ public function getPrimaryKey()

if (count($this->columns) > 0) {
foreach ($this->columns as $key => $value) {
if ($value->column_key == 'PRI' || $value->extra == 'auto_increment') {
$primaryKey = $value->column_name;
if ($value->COLUMN_KEY == 'PRI' || $value->EXTRA == 'auto_increment') {
$primaryKey = $value->COLUMN_NAME;
break;
}
}
Expand Down Expand Up @@ -110,11 +110,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
// Check for argument database name if not given we will use default
// database connection
$this->database = $this->getDatabase($input);

$this->columns = $this->getColumns();

if (empty($this->columns)) {
throw new \Exception("Please check your model name. It seems doesn't exists in the database.");
throw new \Exception("Please check your model name. It seems table doesn't exists into database.");
}

$this->applicationDir = CYGNITE_BASE.DS.APPPATH;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ private function buildFormOpen()
private function generateFormElements($value)
{
$form = $label = '';
$label = Inflector::underscoreToSpace($value->column_name);
$label = Inflector::underscoreToSpace($value->COLUMN_NAME);
$form .= "\t\t".'->addElement("label", "'.$label.'", array("class" => "col-sm-2 control-label","style" => "width:100%;"))'.PHP_EOL;

$form .= "\t\t".'->addElement("text", "'.$value->column_name.'", array("value" => (isset($this->model->'.$value->column_name.')) ? $this->model->'.$value->column_name.' : "", "class" => "form-control"))'.PHP_EOL;
$form .= "\t\t".'->addElement("text", "'.$value->COLUMN_NAME.'", array("value" => (isset($this->model->'.$value->COLUMN_NAME.')) ? $this->model->'.$value->COLUMN_NAME.' : "", "class" => "form-control"))'.PHP_EOL;
return $form;
}

Expand Down Expand Up @@ -155,7 +155,7 @@ private function generateDbCode($value)
{
$code = '';
$code .=
"\t".'$'.Inflector::tabilize($this->model).'->'.$value->column_name.' = $postArray["'.$value->column_name.'"];'.PHP_EOL;
"\t\t\t\t".'$'.Inflector::tabilize($this->model).'->'.$value->COLUMN_NAME.' = $postArray["'.$value->COLUMN_NAME.'"];'.PHP_EOL;

return $code;
}
Expand All @@ -168,7 +168,7 @@ private function generateDbCode($value)
private function generateValidator($value)
{
$validationCode = '';
$validationCode .= "\t\t->addRule('".$value->column_name."', 'required|min:5')".PHP_EOL;
$validationCode .= "\t\t\t->addRule('".$value->COLUMN_NAME."', 'required|min:5')".PHP_EOL;

return $validationCode;
}
Expand All @@ -186,7 +186,7 @@ public function updateTemplate()

foreach ($this->columns as $key=> $value) {

if ($value->column_name !== 'id') {
if ($value->COLUMN_NAME !== 'id') {
if ($this->isFormGenerator == false) {
$codeDb .= $this->generateDbCode($value);
}
Expand All @@ -199,7 +199,7 @@ public function updateTemplate()

$this->setForm($form);
$this->setDbCode($codeDb);
$this->setValidationCode($validationCode.';');
$this->setValidationCode($validationCode."\t\t\t;");
}

private function setForm($form)
Expand Down
16 changes: 8 additions & 8 deletions vendor/cygnite/framework/src/Cygnite/Console/Generator/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,17 +264,17 @@ private function replaceTableElements($type = 'th')

foreach ($this->getTableColumns() as $key=> $value) {

if ($value->column_name !== 'id') {
if ($value->COLUMN_NAME !== 'id') {

if ($type == 'th') {
$tableHead = Inflector::underscoreToSpace($value->column_name);
$tableHead = Inflector::underscoreToSpace($value->COLUMN_NAME);
$column .= "\t\t\t".'<'.$type.'>'.$tableHead.'</'.$type.'>'.PHP_EOL;
} else{
$rowType = '';
if ($this->layoutType == 'php') {
$rowType = '<?php echo $row->'.$value->column_name.'; ?>';
$rowType = '<?php echo $row->'.$value->COLUMN_NAME.'; ?>';
} else {
$rowType = '{{row.'.$value->column_name.'}}';
$rowType = '{{row.'.$value->COLUMN_NAME.'}}';
}
$column .= "\t\t\t".'<'.$type.'>'.$rowType.'</'.$type.'>'.PHP_EOL;
}
Expand Down Expand Up @@ -309,18 +309,18 @@ private function replaceViewTemplateContents($content)
$column = '';
foreach ($this->getTableColumns() as $key=> $value) {

if ($value->column_name !== 'id') {
if ($value->COLUMN_NAME !== 'id') {

if ($this->layoutType == 'php') {
$rowType = '<?php echo $record->'.$value->column_name.'; ?>';
$rowType = '<?php echo $record->'.$value->COLUMN_NAME.'; ?>';
} else {
$rowType = '{{ record.'.$value->column_name.' }}';
$rowType = '{{ record.'.$value->COLUMN_NAME.' }}';
}

$column .=
"\t\t\t".'<div class="form-group">
<label class="col-sm-2 control-label">'.
Inflector::underscoreToSpace($value->column_name).
Inflector::underscoreToSpace($value->COLUMN_NAME).
'</label>
<div class="col-sm-10">
<p class="form-control-static"><span>'.$rowType.'</span></p>
Expand Down
6 changes: 3 additions & 3 deletions vendor/cygnite/framework/src/Cygnite/Database/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -492,10 +492,10 @@ public function addPrimaryKey($columns)
{
$schema = self::SELECT . " EXISTS
(
" . self::SELECT . " * FROM " . $this->_informationSchema . ".columns
" . self::SELECT . " * FROM " . $this->_informationSchema . ".COLUMNS
WHERE " . $this->_tableSchema . "= '" . $this->database . "' AND
table_name ='" . $this->tableName . "' AND
column_key = 'PRI'
TABLE_NAME ='" . $this->tableName . "' AND
COLUMN_KEY = 'PRI'
) AS has_primary_key;";

Expand Down

0 comments on commit b2bd361

Please sign in to comment.