/** * Show the form. * * @param DBEntity $obj the enity to edit. * */ public function showForm($obj) { $form = new BootstrapForm($obj); $ret = $form->open(); $columns = $obj->getColumns(); foreach ($columns as $k => $col) { $read_only = $col->isSequence() || $col->isAutomatic(); $label = $this->getLabel($k, $col); $ret .= $form->new_group($k); $ret .= $form->label($label); $placeholder = null; if ($read_only) { if ($col->isSequence() && !$obj->_isPersistent) { $placeholder = "The ID will be set by the database."; } $ret .= $form->input_disabled($k, $placeholder); } else { if ($col->getType() == DBColumn::VARCHAR) { // A simple input $ret .= $form->input_text($k); } else { if ($col->getType() == DBColumn::INTEGER || $col->getType() == DBColumn::NUMERIC) { // A simple input $ret .= $form->input_number($k); } } } $data = []; $data["property"] = $k; $data["colname"] = $col->getName(); $data["desc"] = $col->getDescription(); $data["label"] = $this->getLabel($k, $col); $data["type"] = $col->getTypeAsString(); $ret .= "<hr>\n"; } $ret .= $form->hidden("_entity", get_class($obj)); $buttons = ['submit' => $obj->_isPersistent ? "Update" : "Insert"]; if ($obj->_isPersistent) { $buttons['delete'] = "Delete"; } $ret .= $form->submit_buttons($buttons); $ret .= $form->close(); echo $ret; }
/** * This function is defined to retrieve * entities having an unique (technical) identifier * name "id". * * @param DBEntity $obj a entity (used for the correct format). * */ function getById($obj, $id) { $keys = $obj->getPrimaryColumns(); $where = array(); foreach ($keys as $key => $col) { $where[$key] = $id; } $unique = $this->selectUnique($obj, $where); return $unique; }