public function getPostedData($objectName) { $obj = parent::getPostedData($objectName); $posted = Request::postArray(); if (isset($posted['blocks'])) { if (strlen($posted['blocks'])) { $posted['blocks'] = serialize(json_decode($posted['blocks'], true)); } else { $posted['blocks'] = serialize(array()); } } else { $posted['blocks'] = serialize(array()); } try { $obj->set('blocks', $posted['blocks']); } catch (Exception $e) { $errors['blocks'] = $this->_lang->INVALID_VALUE; Response::jsonError($this->_lang->FILL_FORM, $errors); } return $obj; }
/** * Get posted data and put it into Db_Object * (in case of failure, JSON error message is sent) * * @param string $objectName * @return Db_Object */ public function getPostedData($objectName) { $id = Request::post('id', 'integer', 0); if ($id) { try { $obj = new Db_Object($objectName, $id); } catch (Exception $e) { Response::jsonError($this->_lang->CANT_EXEC); } } else { try { $obj = new Db_Object($objectName); } catch (Exception $e) { Response::jsonError($this->_lang->CANT_EXEC . '<br>' . $e->getMessage()); } } $acl = $obj->getAcl(); if ($acl && !$acl->canEdit($obj)) { Response::jsonError($this->_lang->CANT_MODIFY); } $posted = Request::postArray(); $fields = $obj->getFields(); $errors = array(); $objectConfig = $obj->getConfig(); $systemFields = $objectConfig->getSystemFieldsConfig(); foreach ($fields as $name) { if ($objectConfig->isRequired($name) && !isset($systemFields[$name]) && (!isset($posted[$name]) || !strlen($posted[$name]))) { $errors[$name] = $this->_lang->CANT_BE_EMPTY; continue; } if ($objectConfig->isBoolean($name) && !isset($posted[$name])) { $posted[$name] = false; } if ($objectConfig->isNull($name) && $objectConfig->isDateField($name) && isset($posted[$name]) && empty($posted[$name])) { $posted[$name] = null; } if (!array_key_exists($name, $posted)) { continue; } if (!$id && (is_string($posted[$name]) && !strlen((string) $posted[$name]) || is_array($posted[$name]) && empty($posted[$name])) && $objectConfig->hasDefault($name)) { continue; } try { $obj->set($name, $posted[$name]); } catch (Exception $e) { $errors[$name] = $this->_lang->INVALID_VALUE; } } if (!empty($errors)) { Response::jsonError($this->_lang->FILL_FORM, $errors); } $errors = $obj->validateUniqueValues(); if (!empty($errors)) { Response::jsonError($this->_lang->FILL_FORM, $errors); } if ($id) { $obj->setId($id); } return $obj; }
public function testPostArray() { Request::updatePost('key', 'val'); $this->assertEquals(Request::postArray(), array('key' => 'val')); }
/** * Save server config */ public function serversSaveAction() { $this->_checkCanEdit(); $serverId = Request::post('id', 'pagecode', ''); if (!strlen($serverId)) { Response::jsonError($this->_lang->WRONG_REQUEST); } $data = Request::postArray(); unset($data['id']); if (!empty($data)) { foreach ($data as $k => &$v) { $v = Filter::filterValue('string', $v); } } $list = $this->_serversConfig->get('list'); $list[$serverId] = $data; $this->_serversConfig->set('list', $list); if (!$this->_serversConfig->save()) { Response::jsonError($this->_lang->CANT_WRITE_FS); } else { Response::jsonSuccess(); } }