public function as_input() { if ($this->type == self::PRIMARY_KEY) { return $this->as_pk(); } $html = file_get_contents(realpath(dirname(__FILE__)) . "/html/table.html"); $selc = file_get_contents(realpath(dirname(__FILE__)) . "/html/selectable.html"); $selc = str_replace('{{MORE}}', 'required', $selc); $cont = ""; $model = Kernel::instance($this->refer); $models = $model->filter(); if (isset($models[0])) { $show = new Show($models[0]); $head = $show->as_headrow(false, false, '#'); foreach ($models as $model) { $inps = ""; $pk = $model->get_pk(); $reflex = new ReflectionClass($model->get_called_class()); $properts = $reflex->getProperties(); $val = $this->val(); if ($val == $pk->get()) { $sel = str_replace('required', 'required checked ', $selc); } else { $sel = $selc; } foreach ($properts as $propert) { $name = $propert->getName(); $value = $model->{"get" . ucfirst($name)}(); if ($value instanceof Input && !$value instanceof Constrain || $value instanceof Constrain && $value->getType() != Constrain::PRIMARY_KEY) { $inps .= $value->as_list(); } } $cont .= str_replace(array('{{NAME}}', '{{VALUE}}', '{{CONTENT}}'), array($this->name(), $pk->get(), $inps), $sel); } $html = str_replace(array('{{HEAD}}', '{{BODY}}'), array($head, $cont), $html); } else { $html = '<<-empty->>'; } return $html; }
public static function as_table(array $models, $edit = null, $delete = null) { $html = file_get_contents(realpath(dirname(__FILE__)) . "/html/table.html"); $show = new Show($models[0]); $head = $show->as_headrow($edit, $delete); $body = ""; foreach ($models as $model) { $show->model = $model; $body .= $show->as_row($edit, $delete); } $html = str_replace(array('{{HEAD}}', '{{BODY}}'), array($head, $body), $html); return $html; }