/** * Generate html grid string * * @return string with html form */ public function render() { $sort = 0; $query = $this->request->getQuery(); if (isset($query['sort']) && isset($this->columns[$query['sort']])) { $sort = $query['sort']; } return $this->formatter->render($this->columns, $this->getRecords(), $this->dataManager->getTotalCount(), $this->limit, $this->page, $sort); }
/** * Submit form. Check http confirm and validate fields * * @param Request $request * @throws \Exception */ public function submit(Request $request) { $this->isConfirmed = false; if ($this->formTags['method'] == 'post' && $request->getType() == 'POST') { $this->isConfirmed = true; } $query = $request->getQuery(); if (count($this->fields) > 0 && $this->formTags['method'] == 'get' && isset($query[$this->fields[0]->getName()])) { $this->isConfirmed = true; } if (!$this->isConfirmed) { return; } if ($this->formTags['method'] == 'post') { $storage = $request->getData(); } else { $storage = $request->getQuery(); } //set field data $result = []; foreach ($this->fields as $field) { if (isset($storage[$field->getName()])) { $field->setData($storage[$field->getName()]); } else { if ($field instanceof FileField) { try { $field->setData($request->getFile($field->getName())); } catch (FileNotUploadedException $e) { $field->setData(''); } } else { if (preg_match('/^(.*?)(\\[.*\\])$/', $field->getName(), $result) && isset($storage[$result[1]])) { //array if (!preg_match_all("/\\[(.*?)\\]/", $result[2], $resultDeep)) { throw new \Exception('Invalid field name.'); //FIXME dedicate exception } $value = $storage[$result[1]]; foreach ($resultDeep[1] as $deep) { if (!isset($value[$deep])) { $value = null; break; } $value = $value[$deep]; } if ($result[2] == '') { //FIXME autoincrement field } else { $field->setData($value); } } else { //for checkbox or disabled field $field->setData(null); } } } } //validate if ($request->isFullUploadedData()) { foreach ($this->fields as $field) { if ($field->getValidator()) { if ($error = $field->getValidator()->validate($field->getData())) { $field->setError($error); } } } } else { foreach ($this->fields as $field) { $field->setError('Request data is too large.'); } } }