Skip to content
Snippets Groups Projects
Commit 290b3c02 authored by Peter Rotich's avatar Peter Rotich
Browse files

Add forms getter

Add update routine
Add updated date getter
parent 5d54e8c3
No related branches found
No related tags found
No related merge requests found
...@@ -70,7 +70,7 @@ class DynamicForm extends VerySimpleModel { ...@@ -70,7 +70,7 @@ class DynamicForm extends VerySimpleModel {
function getField($name) { function getField($name) {
foreach ($this->getDynamicFields() as $f) foreach ($this->getDynamicFields() as $f)
if (!strcasecmp($f->get('name'), $name)) if (!strcasecmp($f->get('name'), $name))
return $f; return $f->getImpl();
} }
function hasField($name) { function hasField($name) {
......
...@@ -67,6 +67,7 @@ class UserModel extends VerySimpleModel { ...@@ -67,6 +67,7 @@ class UserModel extends VerySimpleModel {
class User extends UserModel { class User extends UserModel {
var $_entries; var $_entries;
var $_forms;
function __construct($ht) { function __construct($ht) {
parent::__construct($ht); parent::__construct($ht);
...@@ -119,11 +120,16 @@ class User extends UserModel { ...@@ -119,11 +120,16 @@ class User extends UserModel {
return new PersonsName($this->name); return new PersonsName($this->name);
} }
function getUpdateDate() {
return $this->updated;
}
function to_json() { function to_json() {
$info = array( $info = array(
'id' => $this->getId(), 'id' => $this->getId(),
'name' => (string) $this->getName()); 'name' => (string) $this->getName(),
'email' => (string) $this->getEmail());
return JsonDataEncoder::encode($info); return JsonDataEncoder::encode($info);
} }
...@@ -154,6 +160,67 @@ class User extends UserModel { ...@@ -154,6 +160,67 @@ class User extends UserModel {
return $this->_entries; return $this->_entries;
} }
function getForms($populate=true) {
if (!isset($this->_forms)) {
$this->_forms = array();
foreach ($this->getDynamicData() as $cd) {
$cd->addMissingFields();
if($populate
&& ($form = $cd->getForm())
&& $form->get('type') == 'U' ) {
foreach ($cd->getFields() as $f) {
if ($f->get('name') == 'name')
$f->value = $this->getFullName();
elseif ($f->get('name') == 'email')
$f->value = $this->getEmail();
}
}
$this->_forms[] = $cd->getForm();
}
}
return $this->_forms;
}
function updateInfo($vars, &$errors) {
$valid = true;
$forms = $this->getForms(false);
foreach ($forms as $cd) {
if (!$cd->isValid())
$valid = false;
elseif (($f=$cd->getField('email'))
&& $cd->get('type') == 'U'
&& ($u=User::lookup(array('emails__address'=>$f->getClean())))
&& $u->id != $this->getId()) {
$valid = false;
$f->addError('Email is assigned to another user');
}
}
if (!$valid)
return false;
foreach ($this->getDynamicData() as $cd) {
if (($f=$cd->getForm()) && $f->get('type') == 'U') {
if (($name = $f->getField('name'))) {
$this->name = $name->getClean();
$this->save();
}
if (($email = $f->getField('email'))) {
$this->default_email->address = $email->getClean();
$this->default_email->save();
}
}
$cd->save();
}
return true;
}
function save($refetch=false) { function save($refetch=false) {
// Drop commas and reorganize the name without them // Drop commas and reorganize the name without them
$parts = array_map('trim', explode(',', $this->name)); $parts = array_map('trim', explode(',', $this->name));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment