sqlite = $helper->getDB(); if(!$this->sqlite) return; $table = self::cleanTableName($table); $this->table = $table; // load info about the schema itself if($ts) { $sql = "SELECT * FROM schemas WHERE tbl = ? AND ts <= ? ORDER BY ts DESC LIMIT 1"; $opt = array($table, $ts); } else { $sql = "SELECT * FROM schemas WHERE tbl = ? ORDER BY ts DESC LIMIT 1"; $opt = array($table); } $res = $this->sqlite->query($sql, $opt); if($this->sqlite->res2count($res)) { $result = $this->sqlite->res2arr($res); $this->id = $result['id']; $this->chksum = $result['chksum']; } $this->sqlite->res_close($res); if(!$this->id) return; // load existing columns $sql = "SELECT SC.*, T.* FROM schema_cols SC, types T WHERE SC.schema_id = ? AND SC.type_id = T.id ORDER BY SC.sort"; $res = $this->sqlite->query($sql, $opt); $rows = $this->sqlite->res2arr($res); $this->sqlite->res_close($res); foreach($rows as $row) { $class = 'plugin\\struct\\type\\' . $row['class']; $config = json_decode($row['config'], true); $this->columns[$row['col']] = new $class($config, $row['label'], $row['ismulti']); if($row['sort'] > $this->maxsort) $this->maxsort = $row['sort']; } } /** * Cleans any unwanted stuff from table names * * @param string $table * @return string */ static public function cleanTableName($table) { $table = preg_replace('/[^a-z0-9_]+/', '', $table); $table = preg_replace('/^[0-9_]+/', '', $table); $table = trim($table); return $table; } /** * Returns a table to edit the schema * * @todo should this include the form? * * @return string */ public function adminEditor() { $html = ''; $html .= ''; $html .= '
Sort | Label | Multi-Input? | Configuration | Type |
---|