* @license PHP License * @package WB * @subpackage content */ /** * Load classes */ WBClass::load('WBContent'); /** * Content component: User_Profile * * Allow user to edit her own data like forename, surname, password, e-mail-address * * @version 1.0.0 * @package WB * @subpackage content */ class WBContent_User_Profile extends WBContent { /** * my parameter list * @var array */ protected $config = array( 'action' => 'display' ); /** * buffered user data, cause this is going to change * @var array */ private $userData = array(); /** * run * * run component * * @return array parameter list */ public function run() { // user required if (!$this->user->isAuthenticated()) { $this->loadTemplates('anon'); $this->config['action'] = 'display'; return $this->config; } $action = strtolower($this->config['action']); $this->userData = $this->user->getData(); switch ($action) { case 'edit': $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 (isset($values['email'])) { unset($values['email']); } $this->userData = array_merge($this->userData, $values); $this->tmpl->addGlobalVars($this->userData); $this->user->set($values); 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; } }