* @package WB * @subpackage user */ /** * Load classes */ WBClass::load('WBContent' , 'WBContent_User' ); /** * Content component: User_Profile * * Allow user to edit her own data like forename, surname, password, e-mail-address * * @version 1.2.0 * @package WB * @subpackage user */ class WBContent_User_Profile extends WBContent_User { /** * my parameter list * @var array */ protected $config = array( 'action' => 'display' ); /** * buffered user data, cause this is going to change * @var array */ private $userData = array(); /** * relation table * @var WBDatasource_RelationTable */ private $relTable; /** * run * * run component * * @return array parameter list */ public function run() { $this->addPageURLs(); // user required if (!$this->user->isAuthenticated()) { $this->loadTemplates('anon'); $this->config['action'] = 'display'; return $this->config; } $action = strtolower($this->config['action']); $this->user->reload(); $this->userData = $this->user->getData(); switch ($action) { case 'edit': if ($this->initRelationTable()) { $this->relTable->inject($this->userData); } $this->processForm('edit', $this->userData); break; default: $this->loadTemplates('display'); break; } return $this->config; } /** * receive output * * fetch output of this content component * * @return string */ public function getString() { if ($this->user->isAuthenticated()) { $this->tmpl->addGlobalVars($this->userData); } return $this->tmpl->getParsedTemplate('snippet'); } /** * save user profile * * @param patForms $form * @param array $values * @return bool always true */ public function onEditValid($form, $values) { if (isset($values['password'])) { unset($values['password']); } if ($this->initRelationTable()) { $this->relTable->extract($values); } $this->userData = array_merge($this->userData, $values); $this->tmpl->addGlobalVars($this->userData); $this->user->set($values); if ($this->initRelationTable()) { $this->relTable->delete($this->user->getId()); $this->relTable->add($this->user->getId()); } return true; } /** * Start relation table * * If relations are configured, start relation table object */ protected function initRelationTable() { if ($this->relTable) { return true; } if (false === $this->relTable) { return false; } // load relation config /** @var WBConfig */ $config = WBClass::create('WBConfig'); $config->load($this->getFormConfigDir(). '/edit'); $conf = $config->get('relation', array()); if (empty($conf)) { $this->relTable = false; return false; } $this->relTable = WBClass::create('WBDatasource_RelationTable'); $this->relTable->setConfig('user', $conf); return true; } /** * location of form config * * Return sub directory where form element definitions are located * * @return string folder */ protected function getFormConfigDir() { return 'user/profile'; } /** * Add form rules to just created form * * @param patForms $form object * @param string name of the xml- and template-filename * @param array $elements list of elements current form * @return bool true on success */ protected function insertFormRules(&$form, $name, $elements) { return true; } }