Skip to content

Commit d5e5528

Browse files
committed
Functions added
1 parent 06ef9c4 commit d5e5528

File tree

2 files changed

+62
-2
lines changed

2 files changed

+62
-2
lines changed

app/config/loader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
$loader = new \Phalcon\Loader();
44
$loader->registerDirs([
55
APP_PATH . '/tasks',
6-
APP_PATH . '/models'
6+
APP_PATH . '/views'
77
]);
88
$loader->register();

app/tasks/MainTask.php

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function mainAction($namespace = 'null', $trait = 'null')
2828
private function checkDatabaseConnection()
2929
{
3030
try {
31-
$this->db->listTables();
31+
$this->db->connect();
3232
} catch (PDOException $e) {
3333
echo "An error occured during connection to the database.", PHP_EOL;
3434
echo "Please check the config in `./app/config/config.php`.";
@@ -58,4 +58,64 @@ private function checkOutputFolder()
5858
}
5959
return true;
6060
}
61+
62+
/**
63+
* Return the Phalcon type (Numeric, Date, Text, ...) according to column type.
64+
* @param string $type
65+
* @return string
66+
*/
67+
private function getPhalconBaseType($type)
68+
{
69+
$types = [
70+
\Phalcon\Db\Column::TYPE_INTEGER => "Numeric",
71+
\Phalcon\Db\Column::TYPE_DATE => "Date",
72+
\Phalcon\Db\Column::TYPE_VARCHAR => "Text",
73+
\Phalcon\Db\Column::TYPE_DECIMAL => "Numeric",
74+
\Phalcon\Db\Column::TYPE_DATETIME => "Text",
75+
\Phalcon\Db\Column::TYPE_CHAR => "Text",
76+
\Phalcon\Db\Column::TYPE_TEXT => "Textarea",
77+
\Phalcon\Db\Column::TYPE_FLOAT => "Numeric",
78+
\Phalcon\Db\Column::TYPE_BOOLEAN => "Numeric",
79+
\Phalcon\Db\Column::TYPE_DOUBLE => "Numeric",
80+
\Phalcon\Db\Column::TYPE_TINYBLOB => "Textarea",
81+
\Phalcon\Db\Column::TYPE_BLOB => "Textarea",
82+
\Phalcon\Db\Column::TYPE_MEDIUMBLOB => "Textarea",
83+
\Phalcon\Db\Column::TYPE_LONGBLOB => "Textarea",
84+
\Phalcon\Db\Column::TYPE_BIGINTEGER => "Numeric",
85+
\Phalcon\Db\Column::TYPE_JSON => "Textarea",
86+
\Phalcon\Db\Column::TYPE_JSONB => "Textarea",
87+
\Phalcon\Db\Column::TYPE_TIMESTAMP => "Numeric"
88+
];
89+
90+
return isset($types[$type]) ? $types[$type] : "Text";
91+
}
92+
93+
/**
94+
* Return a better Phalcon type (Check, Select, Password, ...) according to the column.
95+
* @param \Phalcon\Db\Column $column
96+
* @return string
97+
*/
98+
private function getBestPhalconType($column)
99+
{
100+
$size = $column->getSize();
101+
$columntype = $this->getPhalconBaseType($column->getType());
102+
103+
if ($columntype == "Numeric") {
104+
if ($size == 1) {
105+
$columntype = "Check";
106+
} else if ($size == 11) {
107+
// Could be also a Radio but Select is arbitrary choose here
108+
$columntype = "Select";
109+
}
110+
} else if ($columntype == "Text") {
111+
if ($size > 255) {
112+
$columntype = "Textarea";
113+
}
114+
if (preg_match("#(pass|pwd)#i", $column->getName())) {
115+
$columntype = "Password";
116+
}
117+
}
118+
119+
return $columntype;
120+
}
61121
}

0 commit comments

Comments
 (0)