CommunityID/modules/users/controllers/PersonalinfoController.php

73 lines
2.0 KiB
PHP
Raw Normal View History

2019-07-17 20:08:50 +00:00
<?php
/*
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
* @license http://creativecommons.org/licenses/BSD/ BSD License
* @author Keyboard Monkey Ltd
* @since CommunityID 0.9
* @package CommunityID
* @packager Keyboard Monkeys
*/
2019-07-17 20:16:19 +00:00
class Users_PersonalinfoController extends CommunityID_Controller_Action
2019-07-17 20:08:50 +00:00
{
public function indexAction()
{
$this->_helper->actionStack('index', 'login', 'users');
}
public function showAction()
{
2019-07-17 20:16:19 +00:00
$fields = new Model_Fields();
2019-07-17 20:08:50 +00:00
$this->view->fields = $fields->getValues($this->user);
}
public function editAction()
{
$appSession = Zend_Registry::get('appSession');
if (isset($appSession->personalInfoForm)) {
$this->view->fields = $appSession->personalInfoForm->getElements();
unset($appSession->personalInfoForm);
} else {
2019-07-17 20:16:19 +00:00
$personalInfoForm = new Users_Form_PersonalInfo(null, $this->user);
2019-07-17 20:08:50 +00:00
$this->view->fields = $personalInfoForm->getElements();
}
}
public function saveAction()
{
2019-07-17 20:16:19 +00:00
$form = new Users_Form_PersonalInfo(null, $this->user);
2019-07-17 20:08:50 +00:00
$formData = $this->_request->getPost();
$form->populate($formData);
if (!$form->isValid($formData)) {
$appSession = Zend_Registry::get('appSession');
$appSession->personalInfoForm = $form;
$this->_forward('edit');
return;
}
2019-07-17 20:16:19 +00:00
$fieldsValues = new Model_FieldsValues();
2019-07-17 20:08:50 +00:00
$fieldsValues->deleteForUser($this->user);
foreach ($form->getValues() as $fieldName => $fieldValue) {
if (!$fieldValue) {
continue;
}
$fieldsValue = $fieldsValues->createRow();
$fieldsValue->user_id = $this->user->id;
list(, $fieldId) = explode('_', $fieldName);
$fieldsValue->field_id = $fieldId;
$fieldsValue->value = $fieldValue;
$fieldsValue->save();
}
$this->_forward('show');
}
}