Upgraded phpmyadmin to 4.0.4 (All Languages) - No modifications yet
[openemr.git] / phpmyadmin / libraries / plugins / export / TableProperty.class.php
bloba928a6c3d121546952122d709c130ca53ee87d55
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Holds the TableProperty class
6 * @package PhpMyAdmin-Export
7 * @subpackage CodeGen
8 */
9 if (! defined('PHPMYADMIN')) {
10 exit;
13 /**
14 * TableProperty class
16 * @package PhpMyAdmin-Export
17 * @subpackage CodeGen
19 class TableProperty
21 /**
22 * Name
24 * @var string
26 public $name;
28 /**
29 * Type
31 * @var string
33 public $type;
35 /**
36 * Wheter the key is nullable or not
38 * @var bool
40 public $nullable;
42 /**
43 * The key
45 * @var int
47 public $key;
49 /**
50 * Default value
52 * @var mixed
54 public $defaultValue;
56 /**
57 * Extension
59 * @var string
61 public $ext;
63 /**
64 * Constructor
66 * @param array $row table row
68 * @return void
70 function __construct($row)
72 $this->name = trim($row[0]);
73 $this->type = trim($row[1]);
74 $this->nullable = trim($row[2]);
75 $this->key = trim($row[3]);
76 $this->defaultValue = trim($row[4]);
77 $this->ext = trim($row[5]);
80 /**
81 * Gets the pure type
83 * @return string type
85 function getPureType()
87 $pos = strpos($this->type, "(");
88 if ($pos > 0) {
89 return substr($this->type, 0, $pos);
91 return $this->type;
94 /**
95 * Tells whether the key is null or not
97 * @return bool true if the key is not null, false otherwise
99 function isNotNull()
101 return $this->nullable == "NO" ? "true" : "false";
105 * Tells whether the key is unique or not
107 * @return bool true if the key is unique, false otherwise
109 function isUnique()
111 return $this->key == "PRI" || $this->key == "UNI" ? "true" : "false";
115 * Gets the .NET primitive type
117 * @return string type
119 function getDotNetPrimitiveType()
121 if (strpos($this->type, "int") === 0) {
122 return "int";
124 if (strpos($this->type, "long") === 0) {
125 return "long";
127 if (strpos($this->type, "char") === 0) {
128 return "string";
130 if (strpos($this->type, "varchar") === 0) {
131 return "string";
133 if (strpos($this->type, "text") === 0) {
134 return "string";
136 if (strpos($this->type, "longtext") === 0) {
137 return "string";
139 if (strpos($this->type, "tinyint") === 0) {
140 return "bool";
142 if (strpos($this->type, "datetime") === 0) {
143 return "DateTime";
145 return "unknown";
149 * Gets the .NET object type
151 * @return string type
153 function getDotNetObjectType()
155 if (strpos($this->type, "int") === 0) {
156 return "Int32";
158 if (strpos($this->type, "long") === 0) {
159 return "Long";
161 if (strpos($this->type, "char") === 0) {
162 return "String";
164 if (strpos($this->type, "varchar") === 0) {
165 return "String";
167 if (strpos($this->type, "text") === 0) {
168 return "String";
170 if (strpos($this->type, "longtext") === 0) {
171 return "String";
173 if (strpos($this->type, "tinyint") === 0) {
174 return "Boolean";
176 if (strpos($this->type, "datetime") === 0) {
177 return "DateTime";
179 return "Unknown";
183 * Gets the index name
185 * @return string containing the name of the index
187 function getIndexName()
189 if (strlen($this->key) > 0) {
190 return "index=\""
191 . htmlspecialchars($this->name, ENT_COMPAT, 'UTF-8')
192 . "\"";
194 return "";
198 * Tells whether the key is primary or not
200 * @return bool true if the key is primary, false otherwise
202 function isPK()
204 return $this->key=="PRI";
208 * Formats a string for C#
210 * @param string $text string to be formatted
212 * @return string formatted text
214 function formatCs($text)
216 $text = str_replace(
217 "#name#",
218 ExportCodegen::cgMakeIdentifier($this->name, false),
219 $text
221 return $this->format($text);
225 * Formats a string for XML
227 * @param string $text string to be formatted
229 * @return string formatted text
231 function formatXml($text)
233 $text = str_replace(
234 "#name#",
235 htmlspecialchars($this->name, ENT_COMPAT, 'UTF-8'),
236 $text
238 $text = str_replace(
239 "#indexName#",
240 $this->getIndexName(),
241 $text
243 return $this->format($text);
247 * Formats a string
249 * @param string $text string to be formatted
251 * @return string formatted text
253 function format($text)
255 $text = str_replace(
256 "#ucfirstName#",
257 ExportCodegen::cgMakeIdentifier($this->name),
258 $text
260 $text = str_replace(
261 "#dotNetPrimitiveType#",
262 $this->getDotNetPrimitiveType(),
263 $text
265 $text = str_replace(
266 "#dotNetObjectType#",
267 $this->getDotNetObjectType(),
268 $text
270 $text = str_replace(
271 "#type#",
272 $this->getPureType(),
273 $text
275 $text = str_replace(
276 "#notNull#",
277 $this->isNotNull(),
278 $text
280 $text = str_replace(
281 "#unique#",
282 $this->isUnique(),
283 $text
285 return $text;