diff --git a/include/class.organization.php b/include/class.organization.php index 587d0d5a7654231c4f72fc322a9769be615f74cb..32e2c1ec9dd2eaf05d04ea23fd53fc2cf34d88c1 100644 --- a/include/class.organization.php +++ b/include/class.organization.php @@ -106,6 +106,8 @@ class Organization extends OrganizationModel { function addDynamicData($data) { $entry = $this->addForm(OrganizationForm::objects()->one(), 1, $data); + // FIXME: For some reason, the second save here is required or the + // custom data is not properly saved $entry->save(); return $entry; diff --git a/include/class.user.php b/include/class.user.php index 886c18db9759700a816045236fc67d44366cfb2c..db6e7936d3a4c6c32ee9151febdb99834e80686b 100644 --- a/include/class.user.php +++ b/include/class.user.php @@ -254,12 +254,12 @@ class User extends UserModel { return $this->created; } - function addForm($form, $sort=1) { - $form = $form->instanciate(); - $form->set('sort', $sort); - $form->set('object_type', 'U'); - $form->set('object_id', $this->getId()); - $form->save(); + function addForm($form, $sort=1, $data=null) { + $entry = $form->instanciate($sort, $data); + $entry->set('object_type', 'U'); + $entry->set('object_id', $this->getId()); + $entry->save(); + return $entry; } function to_json() { @@ -292,14 +292,11 @@ class User extends UserModel { } function addDynamicData($data) { - $uf = UserForm::getNewInstance(); - $uf->setClientId($this->id); - foreach ($uf->getFields() as $f) - if (isset($data[$f->get('name')])) - $uf->setAnswer($f->get('name'), $data[$f->get('name')]); - $uf->save(); - - return $uf; + $entry = $this->addForm(UserForm::objects()->one(), 1, $data); + // FIXME: For some reason, the second save here is required or the + // custom data is not properly saved + $entry->save(); + return $entry; } function getDynamicData($create=true) {