Crud.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. <?php
  2. namespace app\admin\command;
  3. use fast\Form;
  4. use think\Config;
  5. use think\console\Command;
  6. use think\console\Input;
  7. use think\console\input\Option;
  8. use think\console\Output;
  9. use think\Db;
  10. use think\Exception;
  11. use think\Lang;
  12. class Crud extends Command
  13. {
  14. protected function configure()
  15. {
  16. $this
  17. ->setName('crud')
  18. ->addOption('table', 't', Option::VALUE_REQUIRED, 'table name without prefix', null)
  19. ->addOption('controller', 'c', Option::VALUE_OPTIONAL, 'controller name', null)
  20. ->addOption('model', 'm', Option::VALUE_OPTIONAL, 'model name', null)
  21. ->addOption('force', 'f', Option::VALUE_OPTIONAL, 'force override', null)
  22. ->addOption('local', 'l', Option::VALUE_OPTIONAL, 'local model', 1)
  23. ->setDescription('Build CRUD controller and model from table');
  24. }
  25. protected function execute(Input $input, Output $output)
  26. {
  27. $adminPath = dirname(__DIR__) . DS;
  28. //表名
  29. $table = $input->getOption('table') ?: '';
  30. //自定义控制器
  31. $controller = $input->getOption('controller');
  32. //自定义模型
  33. $model = $input->getOption('model');
  34. //强制覆盖
  35. $force = $input->getOption('force');
  36. //是否为本地model,为0时表示为全局model将会把model放在app/common/model中
  37. $local = $input->getOption('local');
  38. if (!$table)
  39. {
  40. throw new Exception('table name can\'t empty');
  41. }
  42. $dbname = Config::get('database.database');
  43. $prefix = Config::get('database.prefix');
  44. $tableName = $prefix . $table;
  45. $tableInfo = Db::query("SHOW TABLE STATUS LIKE '{$tableName}'", [], TRUE);
  46. if (!$tableInfo)
  47. {
  48. throw new Exception("table not found");
  49. }
  50. $tableInfo = $tableInfo[0];
  51. //根据表名匹配对应的Fontawesome图标
  52. $iconPath = ROOT_PATH . str_replace('/', DS, '/public/assets/libs/font-awesome/less/variables.less');
  53. $iconName = is_file($iconPath) && stripos(file_get_contents($iconPath), '@fa-var-' . $table . ':') ? $table : 'fa fa-circle-o';
  54. //控制器默认以表名进行处理,以下划线进行分隔,如果需要自定义则需要传入controller,格式为目录层级
  55. $controllerArr = !$controller ? explode('_', strtolower($table)) : explode('/', strtolower($controller));
  56. $controllerUrl = implode('/', $controllerArr);
  57. $controllerName = ucfirst(array_pop($controllerArr));
  58. $controllerDir = implode(DS, $controllerArr);
  59. $controllerFile = ($controllerDir ? $controllerDir . DS : '') . $controllerName . '.php';
  60. //非覆盖模式时如果存在控制器文件则报错
  61. if (is_file($controllerFile) && !$force)
  62. {
  63. throw new Exception('controller already exists!\nIf you need to rebuild again, use the parameter --force=true ');
  64. }
  65. //模型默认以表名进行处理,以下划线进行分隔,如果需要自定义则需要传入model,不支持目录层级
  66. if (!$model)
  67. {
  68. $modelarr = explode('_', strtolower($table));
  69. foreach ($modelarr as $k => &$v)
  70. $v = ucfirst($v);
  71. unset($v);
  72. $modelName = implode('', $modelarr);
  73. }
  74. else
  75. {
  76. $modelName = ucfirst($model);
  77. }
  78. $modelFile = ($local ? $adminPath : APP_PATH . 'common' . DS) . 'model' . DS . $modelName . '.php';
  79. //非覆盖模式时如果存在模型文件则报错
  80. if (is_file($modelFile) && !$force)
  81. {
  82. throw new Exception('model already exists!\nIf you need to rebuild again, use the parameter --force=true ');
  83. }
  84. require $adminPath . 'common.php';
  85. //从数据库中获取表字段信息
  86. $columnList = Db::query("SELECT * FROM `information_schema`.`columns` WHERE TABLE_SCHEMA = ? AND table_name = ? ORDER BY ORDINAL_POSITION", [$dbname, $tableName]);
  87. $fields = [];
  88. foreach ($columnList as $k => $v)
  89. {
  90. $fields[] = $v['COLUMN_NAME'];
  91. }
  92. $addList = [];
  93. $editList = [];
  94. $javascriptList = [];
  95. $langList = [];
  96. $field = 'id';
  97. $order = 'id';
  98. $priDefined = FALSE;
  99. $prikey = '';
  100. foreach ($columnList as $k => $v)
  101. {
  102. if ($v['COLUMN_KEY'] == 'PRI')
  103. {
  104. $prikey = $v['COLUMN_NAME'];
  105. break;
  106. }
  107. }
  108. if (!$prikey)
  109. {
  110. throw new Exception('Primary key not found!');
  111. }
  112. $order = $prikey;
  113. try
  114. {
  115. Form::setEscapeHtml(false);
  116. //循环所有字段,开始构造视图的HTML和JS信息
  117. foreach ($columnList as $k => $v)
  118. {
  119. $field = $v['COLUMN_NAME'];
  120. $itemArr = [];
  121. // 这里构建Enum和Set类型的列表数据
  122. if (in_array($v['DATA_TYPE'], ['enum', 'set']))
  123. {
  124. $itemArr = substr($v['COLUMN_TYPE'], strlen($v['DATA_TYPE']) + 1, -1);
  125. $itemArr = explode(',', str_replace("'", '', $itemArr));
  126. }
  127. // 语言列表
  128. if ($v['COLUMN_COMMENT'] != '')
  129. {
  130. $langList[] = $this->getLangItem($field, $v['COLUMN_COMMENT']);
  131. }
  132. //createtime和updatetime是保留字段不能修改和添加
  133. if ($v['COLUMN_KEY'] != 'PRI' && !in_array($field, ['createtime', 'updatetime']))
  134. {
  135. $inputType = $this->getFieldType($v);
  136. // 如果是number类型时增加一个步长
  137. $step = $inputType == 'number' && $v['NUMERIC_SCALE'] > 0 ? "0." . str_repeat(0, $v['NUMERIC_SCALE'] - 1) . "1" : 0;
  138. $attrArr = ['id' => "c-{$field}"];
  139. $cssClassArr = ['form-control'];
  140. $fieldName = "row[{$field}]";
  141. $defaultValue = $v['COLUMN_DEFAULT'];
  142. $editValue = "{\$row.{$field}}";
  143. // 如果默认值为空,则是一个必选项
  144. if ($v['COLUMN_DEFAULT'] == '')
  145. {
  146. $attrArr['required'] = '';
  147. }
  148. if ($field == 'status' && in_array($inputType, ['text', 'number']))
  149. {
  150. //如果状态类型不是enum或set
  151. $itemArr = !$itemArr ? ['normal', 'hidden'] : $itemArr;
  152. $inputType = 'radio';
  153. }
  154. if ($inputType == 'select')
  155. {
  156. $cssClassArr[] = 'selectpicker';
  157. $attrArr['class'] = implode(' ', $cssClassArr);
  158. if ($v['DATA_TYPE'] == 'set')
  159. {
  160. $attrArr['multiple'] = '';
  161. $fieldName .= "[]";
  162. }
  163. $attrStr = $this->getArrayString($attrArr);
  164. $itemArr = $this->getLangArray($itemArr, FALSE);
  165. $itemString = $this->getArrayString($itemArr);
  166. $formAddElement = "{:build_select('{$fieldName}', [{$itemString}], '{$defaultValue}', [{$attrStr}])}";
  167. $formEditElement = "{:build_select('{$fieldName}', [{$itemString}], \$row.{$field}, [{$attrStr}])}";
  168. }
  169. else if ($inputType == 'datetime')
  170. {
  171. $cssClassArr[] = 'datetimepicker';
  172. $attrArr['class'] = implode(' ', $cssClassArr);
  173. $format = "YYYY-MM-DD HH:mm:ss";
  174. $phpFormat = "Y-m-d H:i:s";
  175. $fieldFunc = '';
  176. switch ($v['DATA_TYPE'])
  177. {
  178. case 'year';
  179. $format = "YYYY";
  180. $phpFormat = 'Y';
  181. break;
  182. case 'date';
  183. $format = "YYYY-MM-DD";
  184. $phpFormat = 'Y-m-d';
  185. break;
  186. case 'time';
  187. $format = "HH:mm:ss";
  188. $phpFormat = 'H:i:s';
  189. break;
  190. case 'timestamp';
  191. $fieldFunc = 'datetime';
  192. case 'datetime';
  193. $format = "YYYY-MM-DD HH:mm:ss";
  194. $phpFormat = 'Y-m-d H:i:s';
  195. break;
  196. default:
  197. $fieldFunc = 'datetime';
  198. break;
  199. }
  200. $defaultDateTime = "{:date('{$phpFormat}')}";
  201. $attrArr['data-date-format'] = $format;
  202. $attrArr['data-use-current'] = "true";
  203. $fieldFunc = $fieldFunc ? "|{$fieldFunc}" : "";
  204. $formAddElement = Form::text($fieldName, $defaultDateTime, $attrArr);
  205. $formEditElement = Form::text($fieldName, "{\$row.{$field}{$fieldFunc}}", $attrArr);
  206. }
  207. else if ($inputType == 'checkbox')
  208. {
  209. $fieldName .= "[]";
  210. $itemArr = $this->getLangArray($itemArr, FALSE);
  211. $itemString = $this->getArrayString($itemArr);
  212. $formAddElement = "{:build_checkboxs('{$fieldName}', [{$itemString}], '{$defaultValue}')}";
  213. $formEditElement = "{:build_checkboxs('{$fieldName}', [{$itemString}], \$row.{$field})}";
  214. }
  215. else if ($inputType == 'radio')
  216. {
  217. $itemArr = $this->getLangArray($itemArr, FALSE);
  218. $itemString = $this->getArrayString($itemArr);
  219. $defaultValue = $defaultValue ? $defaultValue : key($itemArr);
  220. $formAddElement = "{:build_radios('{$fieldName}', [{$itemString}], '{$defaultValue}')}";
  221. $formEditElement = "{:build_radios('{$fieldName}', [{$itemString}], \$row.{$field})}";
  222. }
  223. else if ($inputType == 'textarea' || ($inputType == 'text' && $v['CHARACTER_MAXIMUM_LENGTH'] >= 255))
  224. {
  225. $cssClassArr[] = substr($field, -7) == 'content' ? 'summernote' : '';
  226. $attrArr['class'] = implode(' ', $cssClassArr);
  227. $attrArr['rows'] = 5;
  228. $formAddElement = Form::textarea($fieldName, $defaultValue, $attrArr);
  229. $formEditElement = Form::textarea($fieldName, $editValue, $attrArr);
  230. }
  231. else if ($field == 'category_id' || $field == 'category_ids')
  232. {
  233. $type = $table;
  234. if ($field == 'category_ids')
  235. {
  236. $attrArr['multiple'] = '';
  237. }
  238. $attrStr = $this->getArrayString($attrArr);
  239. $formAddElement = "{:build_category_select('{$fieldName}', '{$type}', '{$defaultValue}', [{$attrStr}])}";
  240. $formEditElement = "{:build_category_select('{$fieldName}', '{$type}', \$row.{$field}, [{$attrStr}])}";
  241. }
  242. else
  243. {
  244. //CSS类名
  245. $cssClassArr[] = substr($field, -3) == '_id' ? 'typeahead' : '';
  246. $cssClassArr[] = substr($field, -4) == '_ids' ? 'tagsinput' : '';
  247. $cssClassArr = array_filter($cssClassArr);
  248. //因为有自动完成可输入其它内容
  249. $step = array_intersect($cssClassArr, ['typeahead', 'tagsinput']) ? 0 : $step;
  250. $attrArr['class'] = implode(' ', $cssClassArr);
  251. $isUpload = in_array(substr($field, -4), ['file']) || in_array(substr($field, -5), ['files', 'image']) || in_array(substr($field, -6), ['images', 'avatar']) || in_array(substr($field, -7), ['avatars']) ? TRUE : FALSE;
  252. //如果是步长则加上步长
  253. if ($step)
  254. {
  255. $attrArr['step'] = $step;
  256. }
  257. //如果是图片加上个size
  258. if ($isUpload)
  259. {
  260. $attrArr['size'] = 50;
  261. }
  262. $formAddElement = Form::input($inputType, $fieldName, $defaultValue, $attrArr);
  263. $formEditElement = Form::input($inputType, $fieldName, $editValue, $attrArr);
  264. //如果是图片或文件
  265. if ($isUpload)
  266. {
  267. $formAddElement = $this->getImageUpload($field, $formAddElement);
  268. $formEditElement = $this->getImageUpload($field, $formEditElement);
  269. }
  270. }
  271. //构造添加和编辑HTML信息
  272. $addList[] = $this->getFormGroup($field, $formAddElement);
  273. $editList[] = $this->getFormGroup($field, $formEditElement);
  274. }
  275. //过滤text类型字段
  276. if ($v['DATA_TYPE'] != 'text')
  277. {
  278. //主键
  279. if ($v['COLUMN_KEY'] == 'PRI' && !$priDefined)
  280. {
  281. $priDefined = TRUE;
  282. $javascriptList[] = "{field: 'state', checkbox: true}";
  283. }
  284. //构造JS列信息
  285. $javascriptList[] = $this->getJsColumn($field);
  286. //排序方式,如果有weigh则按weigh,否则按主键排序
  287. $order = $field == 'weigh' ? 'weigh' : $order;
  288. }
  289. }
  290. //JS最后一列加上操作列
  291. $javascriptList[] = str_repeat(" ", 24) . "{field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: Table.api.formatter.operate}";
  292. $addList = implode("\n", array_filter($addList));
  293. $editList = implode("\n", array_filter($editList));
  294. $javascriptList = implode(",\n", array_filter($javascriptList));
  295. $langList = implode(",\n", array_filter($langList));
  296. //表注释
  297. $tableComment = $tableInfo['Comment'];
  298. $tableComment = mb_substr($tableComment, -1) == '表' ? mb_substr($tableComment, 0, -1) . '管理' : $tableComment;
  299. //最终将生成的文件路径
  300. $controllerFile = $adminPath . 'controller' . DS . $controllerFile;
  301. $javascriptFile = ROOT_PATH . 'public' . DS . 'assets' . DS . 'js' . DS . 'backend' . DS . $controllerUrl . '.js';
  302. $addFile = $adminPath . 'view' . DS . $controllerUrl . DS . 'add.html';
  303. $editFile = $adminPath . 'view' . DS . $controllerUrl . DS . 'edit.html';
  304. $indexFile = $adminPath . 'view' . DS . $controllerUrl . DS . 'index.html';
  305. $langFile = $adminPath . 'lang' . DS . Lang::detect() . DS . $controllerUrl . '.php';
  306. $appNamespace = Config::get('app_namespace');
  307. $moduleName = 'admin';
  308. $controllerNamespace = "{$appNamespace}\\{$moduleName}\\controller" . ($controllerDir ? "\\" : "") . str_replace('/', "\\", $controllerDir);
  309. $modelNamespace = "{$appNamespace}\\" . ($local ? $moduleName : "common") . "\\model";
  310. $data = [
  311. 'controllerNamespace' => $controllerNamespace,
  312. 'modelNamespace' => $modelNamespace,
  313. 'controllerUrl' => $controllerUrl,
  314. 'controllerDir' => $controllerDir,
  315. 'controllerName' => $controllerName,
  316. 'modelName' => $modelName,
  317. 'tableComment' => $tableComment,
  318. 'iconName' => $iconName,
  319. 'pk' => $prikey,
  320. 'order' => $order,
  321. 'table' => $table,
  322. 'tableName' => $tableName,
  323. 'addList' => $addList,
  324. 'editList' => $editList,
  325. 'javascriptList' => $javascriptList,
  326. 'langList' => $langList,
  327. 'modelAutoWriteTimestamp' => in_array('createtime', $fields) || in_array('updatetime', $fields) ? "'int'" : 'false',
  328. 'createTime' => in_array('createtime', $fields) ? "'createtime'" : 'false',
  329. 'updateTime' => in_array('updatetime', $fields) ? "'updatetime'" : 'false',
  330. ];
  331. // 生成控制器文件
  332. $result = $this->writeToFile('controller', $data, $controllerFile);
  333. // 生成模型文件
  334. $result = $this->writeToFile('model', $data, $modelFile);
  335. // 生成视图文件
  336. $result = $this->writeToFile('add', $data, $addFile);
  337. $result = $this->writeToFile('edit', $data, $editFile);
  338. $result = $this->writeToFile('index', $data, $indexFile);
  339. // 生成JS文件
  340. $result = $this->writeToFile('javascript', $data, $javascriptFile);
  341. // 生成语言文件
  342. if ($langList)
  343. {
  344. $result = $this->writeToFile('lang', $data, $langFile);
  345. }
  346. }
  347. catch (\think\exception\ErrorException $e)
  348. {
  349. print_r($e);
  350. }
  351. $output->writeln("<info>Build Successed</info>");
  352. }
  353. /**
  354. * 写入到文件
  355. * @param string $name
  356. * @param array $data
  357. * @param string $pathname
  358. * @return mixed
  359. */
  360. protected function writeToFile($name, $data, $pathname)
  361. {
  362. $search = $replace = [];
  363. foreach ($data as $k => $v)
  364. {
  365. $search[] = "{%{$k}%}";
  366. $replace[] = $v;
  367. }
  368. $stub = file_get_contents($this->getStub($name));
  369. $content = str_replace($search, $replace, $stub);
  370. if (!is_dir(dirname($pathname)))
  371. {
  372. mkdir(strtolower(dirname($pathname)), 0755, true);
  373. }
  374. return file_put_contents($pathname, $content);
  375. }
  376. /**
  377. * 获取基础模板
  378. * @param string $name
  379. * @return string
  380. */
  381. protected function getStub($name)
  382. {
  383. return __DIR__ . DS . 'Crud' . DS . 'stubs' . DS . $name . '.stub';
  384. }
  385. protected function getLangItem($field, $content)
  386. {
  387. if (!Lang::has($field))
  388. {
  389. return <<<EOD
  390. '{$field}' => '{$content}'
  391. EOD;
  392. }
  393. else
  394. {
  395. return '';
  396. }
  397. }
  398. /**
  399. * 读取数据和语言数组列表
  400. * @param array $arr
  401. * @return array
  402. */
  403. protected function getLangArray($arr, $withTpl = TRUE)
  404. {
  405. $langArr = [];
  406. foreach ($arr as $k => $v)
  407. {
  408. $langArr[(is_numeric($k) ? $v : $k)] = is_numeric($k) ? ($withTpl ? "{:" : "") . "__('" . ucfirst($v) . "')" . ($withTpl ? "}" : "") : $v;
  409. }
  410. return $langArr;
  411. }
  412. /**
  413. * 将数据转换成带字符串
  414. * @param array $arr
  415. * @return string
  416. */
  417. protected function getArrayString($arr)
  418. {
  419. $stringArr = [];
  420. foreach ($arr as $k => $v)
  421. {
  422. $is_var = in_array(substr($v, 0, 1), ['$', '_']);
  423. if (!$is_var)
  424. {
  425. $v = str_replace("'", "\'", $v);
  426. $k = str_replace("'", "\'", $k);
  427. }
  428. $stringArr[] = "'" . (is_numeric($k) ? $v : $k) . "' => " . (is_numeric($k) ? "__('" . ucfirst($k) . "')" : $is_var ? $v : "'{$v}'");
  429. }
  430. return implode(",", $stringArr);
  431. }
  432. protected function getFieldType(& $v)
  433. {
  434. $inputType = 'text';
  435. switch ($v['DATA_TYPE'])
  436. {
  437. case 'bigint':
  438. case 'int':
  439. case 'mediumint':
  440. case 'smallint':
  441. case 'tinyint':
  442. $inputType = 'number';
  443. break;
  444. case 'enum':
  445. case 'set':
  446. $inputType = 'select';
  447. break;
  448. case 'decimal':
  449. case 'double':
  450. case 'float':
  451. $inputType = 'number';
  452. break;
  453. case 'longtext':
  454. case 'text':
  455. case 'mediumtext':
  456. case 'smalltext':
  457. case 'tinytext':
  458. $inputType = 'textarea';
  459. break;
  460. case 'year';
  461. case 'date';
  462. case 'time';
  463. case 'datetime';
  464. case 'timestamp';
  465. $inputType = 'datetime';
  466. break;
  467. default:
  468. break;
  469. }
  470. $fieldsName = $v['COLUMN_NAME'];
  471. // 如果后缀以time结尾说明也是个时间字段
  472. if (substr($fieldsName, -4) == 'time')
  473. {
  474. $inputType = 'datetime';
  475. }
  476. // 如果后缀以data结尾且类型为enum,说明是个单选框
  477. if (substr($fieldsName, -4) == 'data' && $v['DATA_TYPE'] == 'enum')
  478. {
  479. $inputType = "radio";
  480. }
  481. // 如果后缀以data结尾且类型为set,说明是个复选框
  482. if (substr($fieldsName, -4) == 'data' && $v['DATA_TYPE'] == 'set')
  483. {
  484. $inputType = "checkbox";
  485. }
  486. return $inputType;
  487. }
  488. /**
  489. * 获取表单分组数据
  490. * @param string $field
  491. * @param string $content
  492. * @return string
  493. */
  494. protected function getFormGroup($field, $content)
  495. {
  496. $langField = ucfirst($field);
  497. return<<<EOD
  498. <div class="form-group">
  499. <label for="c-{$field}" class="control-label col-xs-12 col-sm-2">{:__('{$langField}')}:</label>
  500. <div class="col-xs-12 col-sm-8">
  501. {$content}
  502. </div>
  503. </div>
  504. EOD;
  505. }
  506. /**
  507. * 获取图片模板数据
  508. * @param string $field
  509. * @param string $content
  510. * @return array
  511. */
  512. protected function getImageUpload($field, $content)
  513. {
  514. $filter = substr($field, -4) == 'avatar' || substr($field, -5) == 'image' || substr($field, -6) == 'images' ? ' data-mimetype="image/*"' : "";
  515. $multiple = substr($field, -1) == 's' ? ' data-multiple="true"' : ' data-multiple="false"';
  516. $preview = $filter ? ' data-preview-id="p-' . $field . '"' : '';
  517. $previewcontainer = $preview ? '<ul class="row list-inline plupload-preview" id="p-' . $field . '"></ul>' : '';
  518. return <<<EOD
  519. <div class="form-inline">
  520. {$content}
  521. <span><button type="button" id="plupload-{$field}" class="btn btn-danger plupload" data-input-id="c-{$field}"{$filter}{$multiple}{$preview}><i class="fa fa-upload"></i> {:__('Upload')}</button></span>
  522. <span><button type="button" id="fachoose-{$field}" class="btn btn-primary fachoose" data-input-id="c-{$field}"{$filter}{$multiple}><i class="fa fa-list"></i> {:__('Choose')}</button></span>
  523. {$previewcontainer}
  524. </div>
  525. EOD;
  526. }
  527. /**
  528. * 获取JS列数据
  529. * @param string $field
  530. * @return string
  531. */
  532. protected function getJsColumn($field)
  533. {
  534. $lang = ucfirst($field);
  535. $html = str_repeat(" ", 24) . "{field: '{$field}', title: __('{$lang}')";
  536. $formatter = '';
  537. if ($field == 'status')
  538. $formatter = 'status';
  539. else if ($field == 'icon')
  540. $formatter = 'icon';
  541. else if ($field == 'flag')
  542. $formatter = 'flag';
  543. else if (substr($field, -4) == 'time')
  544. $formatter = 'datetime';
  545. else if (substr($field, -3) == 'url')
  546. $formatter = 'url';
  547. else if (substr($field, -5) == 'image')
  548. $formatter = 'image';
  549. if ($formatter)
  550. $html .= ", formatter: Table.api.formatter." . $formatter . "}";
  551. else
  552. $html .= "}";
  553. return $html;
  554. }
  555. }